From 0895cd63b940571d29b868ad10f5d624f2855a2e Mon Sep 17 00:00:00 2001 From: Jeff Davis Date: Wed, 20 Nov 2019 14:09:03 -0800 Subject: [PATCH] Propagate linker args upwards in the dependency graph. Suggestion from @froydnj to enable a build script to pass linker args relevant for dependencies of a crate. The use case is to allow specifying "-Wl,-undefined,dynamic_lookup" on MacOS for dynamic library crates with undefined symbols, such as a symbol defined in the program loading the library. We can consider supporting this case in rustc itself to avoid the need for platform-specific flags in typical cdylib cases. But this seems like an independently-useful mechanism that could enable workaround for other linking problems, as well. Enables workaround for #62874 --- src/cargo/core/compiler/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 99fa9874739..7360b4e8dad 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -350,6 +350,12 @@ fn rustc<'a, 'cfg>( for path in output.library_paths.iter() { rustc.arg("-L").arg(path); } + if pass_cdylib_link_args { + for arg in output.linker_args.iter() { + let link_arg = format!("link-arg={}", arg); + rustc.arg("-C").arg(link_arg); + } + } if key.0 == current_id { for cfg in &output.cfgs { rustc.arg("--cfg").arg(cfg); @@ -359,12 +365,6 @@ fn rustc<'a, 'cfg>( rustc.arg("-l").arg(name); } } - if pass_cdylib_link_args { - for arg in output.linker_args.iter() { - let link_arg = format!("link-arg={}", arg); - rustc.arg("-C").arg(link_arg); - } - } } } Ok(())