From ce21483b1b29dbe23a3983e01ed1b1a0e64aa509 Mon Sep 17 00:00:00 2001 From: David Herman Date: Fri, 17 May 2024 12:02:04 -0700 Subject: [PATCH] cargo-messages: check normalized crate name in JSON as well as original crate name This is to support a breaking change in upcoming versions of cargo. See: https://github.com/rust-lang/cargo/issues/13867 --- pkgs/cargo-messages/src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkgs/cargo-messages/src/lib.rs b/pkgs/cargo-messages/src/lib.rs index aad2366a..32557751 100644 --- a/pkgs/cargo-messages/src/lib.rs +++ b/pkgs/cargo-messages/src/lib.rs @@ -188,6 +188,13 @@ impl CargoMessages { let mut count: u32 = 0; let mut result: Option = 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)) => { @@ -195,7 +202,7 @@ impl CargoMessages { 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); } }