Skip to content

Commit 4ccd858

Browse files
committed
Always resolve package_id from metadata when finding bootloader and partition table
The package ID format was officially documented as an opaque identifier and the only thing we were allowed to do with them is look them up in the cargo metadata. Rust 1.77 switched the package ID field to use the publicly documented "Package ID Specification" format instead, which means that the old logic no longer works. Signed-off-by: Johannes Löthberg <[email protected]>
1 parent 15991b5 commit 4ccd858

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Fixed
1313
- Fixed help text for size parameter of read-flash subcommand
14+
- Always resolve package_id from metadata when finding bootloader and partition table (#632)
1415

1516
### Changed
1617

cargo-espflash/src/main.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
process::{exit, Command, ExitStatus, Stdio},
55
};
66

7-
use cargo_metadata::Message;
7+
use cargo_metadata::{Message, MetadataCommand};
88
use clap::{Args, CommandFactory, Parser, Subcommand};
99
use espflash::{
1010
cli::{
@@ -375,6 +375,12 @@ fn build(
375375
.or_else(|| cargo_config.target())
376376
.ok_or_else(|| NoTargetError::new(Some(chip)))?;
377377

378+
let mut metadata_cmd = MetadataCommand::new();
379+
if let Some(features) = &build_options.features {
380+
metadata_cmd.features(cargo_metadata::CargoOpt::SomeFeatures(features.clone()));
381+
}
382+
let metadata = metadata_cmd.exec().into_diagnostic()?;
383+
378384
if !chip.into_target().supports_build_target(target) {
379385
return Err(UnsupportedTargetError::new(target, chip).into());
380386
}
@@ -466,9 +472,19 @@ fn build(
466472

467473
for message in messages {
468474
match message.into_diagnostic()? {
469-
Message::BuildScriptExecuted(script)
470-
if script.package_id.repr.starts_with("esp-idf-sys") =>
471-
{
475+
Message::BuildScriptExecuted(script) => {
476+
// We can't use the `Index` implementation on `Metadata` because `-Zbuild-std`
477+
// pulls in dependencies not listed in the metadata which then causes the `Index`
478+
// implementation to panic.
479+
let Some(package) = metadata.packages.iter().find(|p| p.id == script.package_id)
480+
else {
481+
continue;
482+
};
483+
484+
if package.name != "esp-idf-sys" {
485+
continue;
486+
}
487+
472488
// If the `esp-idf-sys` package is being used, attempt to use the bootloader and
473489
// partition table compiled by `embuild` instead.
474490
let build_path = PathBuf::from(script.out_dir).join("build");

0 commit comments

Comments
 (0)