From 6b6a72163ec8475a6f1082a96ce3540fbf8cc383 Mon Sep 17 00:00:00 2001 From: Jynn Nelson Date: Fri, 26 Sep 2025 21:52:24 -0700 Subject: [PATCH 1/2] Pass `--no-deps` to cargo metadata We never use anything other than the workspace members and the `target` field. Don't collect unnecessary info. As a side effect, this causes cargo-binutils to work even with very old versions of Cargo that use `resolver = "1"` by default. --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index fae4719..55eee82 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -281,6 +281,7 @@ To see all the flags the proxied tool accepts run `cargo-{} -- --help`.{}", pub fn run(tool: Tool, matches: ArgMatches) -> Result { let mut metadata_command = MetadataCommand::new(); + metadata_command.no_deps(); if tool.needs_build() { if let Some(features) = matches.get_many::("features") { metadata_command.features(CargoOpt::SomeFeatures( From db5311548b1a1be4321c8360d5aa21274d235e3e Mon Sep 17 00:00:00 2001 From: Jynn Nelson Date: Fri, 26 Sep 2025 22:04:13 -0700 Subject: [PATCH 2/2] Don't run `cargo metadata` for tools that don't need it We need metadata in the following cases: - If we are building a tool from source - If this is cargo-objdump and we are parsing the target in order to forward it to llvm-objdump In all other cases, we don't need metadat and we can simply avoid collecting it. Do so. --- src/lib.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 55eee82..1b72307 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -45,7 +45,7 @@ pub struct Context { impl Context { /* Constructors */ /// Get a context structure from a built artifact. - fn from_artifact(metadata: Metadata, artifact: &Artifact) -> Result { + fn from_artifact(metadata: &Metadata, artifact: &Artifact) -> Result { // Currently there is no clean way to get the target triple from cargo so we can only make // an approximation, we do this by extracting the target triple from the artifacts path. // For more info on the path structure see: https://doc.rust-lang.org/cargo/guide/build-cache.html @@ -54,7 +54,7 @@ impl Context { // See: https://github.com/rust-lang/cargo/issues/5579, https://github.com/rust-lang/cargo/issues/8002 // Should always succeed. - let target_path = artifact.filenames[0].strip_prefix(metadata.target_directory)?; + let target_path = artifact.filenames[0].strip_prefix(&metadata.target_directory)?; let target_name = if let Some(Utf8Component::Normal(path)) = target_path.components().next() { // TODO: How will custom profiles impact this? @@ -279,7 +279,7 @@ To see all the flags the proxied tool accepts run `cargo-{} -- --help`.{}", } } -pub fn run(tool: Tool, matches: ArgMatches) -> Result { +fn get_metadata(tool: &Tool, matches: &ArgMatches) -> Result { let mut metadata_command = MetadataCommand::new(); metadata_command.no_deps(); if tool.needs_build() { @@ -303,6 +303,10 @@ pub fn run(tool: Tool, matches: ArgMatches) -> Result { bail!("Unable to find workspace members"); } + Ok(metadata) +} + +pub fn run(tool: Tool, matches: ArgMatches) -> Result { let mut tool_args = vec![]; if let Some(args) = matches.get_many::("args") { tool_args.extend(args.map(|s| s.as_str())); @@ -311,7 +315,8 @@ pub fn run(tool: Tool, matches: ArgMatches) -> Result { let tool_help = tool_args.first() == Some(&"--help"); let target_artifact = if tool.needs_build() && !tool_help { - cargo_build(&matches, &metadata)? + let metadata = get_metadata(&tool, &matches)?; + cargo_build(&matches, &metadata)?.map(|a| (a, metadata)) } else { None }; @@ -319,11 +324,11 @@ pub fn run(tool: Tool, matches: ArgMatches) -> Result { let mut lltool = Command::new(format!("rust-{}", tool.name())); if tool == Tool::Objdump { - let ctxt = if let Some(artifact) = &target_artifact { + let ctxt = if let Some((artifact, metadata)) = &target_artifact { Context::from_artifact(metadata, artifact)? } else { Context::from_flag( - metadata, + get_metadata(&tool, &matches)?, matches.get_one::("target").map(|s| s.as_str()), )? }; @@ -348,7 +353,7 @@ pub fn run(tool: Tool, matches: ArgMatches) -> Result { if tool.needs_build() { // Artifact - if let Some(artifact) = &target_artifact { + if let Some((artifact, _)) = &target_artifact { let file = match &artifact.executable { // Example and bins have an executable Some(val) => val,