Skip to content

Commit

Permalink
Add -Z extra-link-arg
Browse files Browse the repository at this point in the history
This hides the new rustc-bin-link-arg and rustc-link-arg build script
configuration items behind an unstable flag.
  • Loading branch information
npmccallum committed Jan 24, 2020
1 parent ab0f482 commit ee2870c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -355,6 +357,7 @@ fn rustc<'a, 'cfg>(
build_scripts: &BuildScripts,
pass_l_flag: bool,
link_type: Option<LinkType>,
extra_link_arg: bool,
current_id: PackageId,
) -> CargoResult<()> {
for key in build_scripts.to_link.iter() {
Expand All @@ -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));
});
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
}

Expand Down

0 comments on commit ee2870c

Please sign in to comment.