From ee2870cacc37f7a6e611fe4b5419efc7805171e6 Mon Sep 17 00:00:00 2001 From: Nathaniel McCallum Date: Fri, 24 Jan 2020 17:53:51 -0500 Subject: [PATCH] Add -Z extra-link-arg This hides the new rustc-bin-link-arg and rustc-link-arg build script configuration items behind an unstable flag. --- src/cargo/core/compiler/mod.rs | 15 ++++++++------- src/cargo/core/features.rs | 2 ++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 4854880245e..117abf73bbe 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -213,6 +213,7 @@ fn rustc<'a, 'cfg>( let do_rename = unit.target.allows_underscores() && !unit.mode.is_any_test(); let real_name = unit.target.name().to_string(); let crate_name = unit.target.crate_name(); + let extra_link_arg = cx.bcx.config.cli_unstable().extra_link_arg; // Rely on `target_filenames` iterator as source of truth rather than rederiving filestem. let rustc_dep_info_loc = if do_rename && cx.files().metadata(unit).is_none() { @@ -261,6 +262,7 @@ fn rustc<'a, 'cfg>( &build_scripts, pass_l_flag, link_type, + extra_link_arg, current_id, )?; add_plugin_deps(&mut rustc, &script_outputs, &build_scripts, &root_output)?; @@ -355,6 +357,7 @@ fn rustc<'a, 'cfg>( build_scripts: &BuildScripts, pass_l_flag: bool, link_type: Option, + extra_link_arg: bool, current_id: PackageId, ) -> CargoResult<()> { for key in build_scripts.to_link.iter() { @@ -376,17 +379,15 @@ fn rustc<'a, 'cfg>( rustc.arg("-l").arg(name); } } - if link_type.is_some() { - for arg in output + output .linker_args .iter() .filter(|x| x.0.is_none() || x.0 == link_type) - .map(|x| &x.1) - { - let link_arg = format!("link-arg={}", arg); - rustc.arg("-C").arg(link_arg); - } + .filter(|x| x.0 == Some(LinkType::Cdylib) || extra_link_arg) + .for_each(|x| { + rustc.arg("-C").arg(format!("link-arg={}", x.1)); + }); } } } diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index c2ea6622fa8..d579f51224a 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -342,6 +342,7 @@ pub struct CliUnstable { pub doctest_xcompile: bool, pub panic_abort_tests: bool, pub jobserver_per_rustc: bool, + pub extra_link_arg: bool, } impl CliUnstable { @@ -411,6 +412,7 @@ impl CliUnstable { "doctest-xcompile" => self.doctest_xcompile = parse_empty(k, v)?, "panic-abort-tests" => self.panic_abort_tests = parse_empty(k, v)?, "jobserver-per-rustc" => self.jobserver_per_rustc = parse_empty(k, v)?, + "extra-link-arg" => self.extra_link_arg = parse_empty(k, v)?, _ => bail!("unknown `-Z` flag specified: {}", k), }