Skip to content

Commit 3497701

Browse files
authored
Always resolve package_id from metadata when finding bootloader and partition table (#632)
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 41eb732 commit 3497701

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
### Fixed
1414
- Fixed help text for size parameter of read-flash subcommand
15+
- [cargo-espflash]: Always resolve package_id from metadata when finding bootloader and partition table (#632)
1516

1617
### Changed
1718

cargo-espflash/src/main.rs

Lines changed: 20 additions & 4 deletions
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::{
@@ -349,6 +349,12 @@ fn build(
349349
.or_else(|| cargo_config.target())
350350
.ok_or_else(|| NoTargetError::new(Some(chip)))?;
351351

352+
let mut metadata_cmd = MetadataCommand::new();
353+
if let Some(features) = &build_options.features {
354+
metadata_cmd.features(cargo_metadata::CargoOpt::SomeFeatures(features.clone()));
355+
}
356+
let metadata = metadata_cmd.exec().into_diagnostic()?;
357+
352358
if !chip.into_target().supports_build_target(target) {
353359
return Err(UnsupportedTargetError::new(target, chip).into());
354360
}
@@ -440,9 +446,19 @@ fn build(
440446

441447
for message in messages {
442448
match message.into_diagnostic()? {
443-
Message::BuildScriptExecuted(script)
444-
if script.package_id.repr.starts_with("esp-idf-sys") =>
445-
{
449+
Message::BuildScriptExecuted(script) => {
450+
// We can't use the `Index` implementation on `Metadata` because `-Zbuild-std`
451+
// pulls in dependencies not listed in the metadata which then causes the `Index`
452+
// implementation to panic.
453+
let Some(package) = metadata.packages.iter().find(|p| p.id == script.package_id)
454+
else {
455+
continue;
456+
};
457+
458+
if package.name != "esp-idf-sys" {
459+
continue;
460+
}
461+
446462
// If the `esp-idf-sys` package is being used, attempt to use the bootloader and
447463
// partition table compiled by `embuild` instead.
448464
let build_path = PathBuf::from(script.out_dir).join("build");

0 commit comments

Comments
 (0)