Skip to content

Commit

Permalink
cargo-messages: check normalized crate name in JSON as well as origin…
Browse files Browse the repository at this point in the history
…al crate name

This is to support a breaking change in upcoming versions of cargo. See:

    rust-lang/cargo#13867
  • Loading branch information
dherman committed May 17, 2024
1 parent 33c70e4 commit ce21483
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkgs/cargo-messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,21 @@ impl CargoMessages {
let mut count: u32 = 0;
let mut result: Option<Artifact> = None;

// Starting around Rust 1.78 or 1.79, cargo will begin normalizing
// crate names in the JSON output, so to support both old and new
// versions of cargo, we need to compare against both variants.
//
// See: https://github.com/rust-lang/cargo/issues/13867
let normalized_crate_name = crate_name.replace('-', '_');

while let Some(msg) = self.next() {
match msg {
Ok(Message::CompilerArtifact(artifact)) => {
count += 1;
if self.verbose() {
eprintln!("[cargo-messages] found artifact for {}", artifact.target.name);
}
if result.is_none() && &artifact.target.name == crate_name {
if result.is_none() && &artifact.target.name == crate_name || &artifact.target.name == normalized_crate_name {
result = Some(artifact);
}
}
Expand Down

0 comments on commit ce21483

Please sign in to comment.