Skip to content

Commit ee2870c

Browse files
committed
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.
1 parent ab0f482 commit ee2870c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/cargo/core/compiler/mod.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ fn rustc<'a, 'cfg>(
213213
let do_rename = unit.target.allows_underscores() && !unit.mode.is_any_test();
214214
let real_name = unit.target.name().to_string();
215215
let crate_name = unit.target.crate_name();
216+
let extra_link_arg = cx.bcx.config.cli_unstable().extra_link_arg;
216217

217218
// Rely on `target_filenames` iterator as source of truth rather than rederiving filestem.
218219
let rustc_dep_info_loc = if do_rename && cx.files().metadata(unit).is_none() {
@@ -261,6 +262,7 @@ fn rustc<'a, 'cfg>(
261262
&build_scripts,
262263
pass_l_flag,
263264
link_type,
265+
extra_link_arg,
264266
current_id,
265267
)?;
266268
add_plugin_deps(&mut rustc, &script_outputs, &build_scripts, &root_output)?;
@@ -355,6 +357,7 @@ fn rustc<'a, 'cfg>(
355357
build_scripts: &BuildScripts,
356358
pass_l_flag: bool,
357359
link_type: Option<LinkType>,
360+
extra_link_arg: bool,
358361
current_id: PackageId,
359362
) -> CargoResult<()> {
360363
for key in build_scripts.to_link.iter() {
@@ -376,17 +379,15 @@ fn rustc<'a, 'cfg>(
376379
rustc.arg("-l").arg(name);
377380
}
378381
}
379-
380382
if link_type.is_some() {
381-
for arg in output
383+
output
382384
.linker_args
383385
.iter()
384386
.filter(|x| x.0.is_none() || x.0 == link_type)
385-
.map(|x| &x.1)
386-
{
387-
let link_arg = format!("link-arg={}", arg);
388-
rustc.arg("-C").arg(link_arg);
389-
}
387+
.filter(|x| x.0 == Some(LinkType::Cdylib) || extra_link_arg)
388+
.for_each(|x| {
389+
rustc.arg("-C").arg(format!("link-arg={}", x.1));
390+
});
390391
}
391392
}
392393
}

src/cargo/core/features.rs

+2
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ pub struct CliUnstable {
342342
pub doctest_xcompile: bool,
343343
pub panic_abort_tests: bool,
344344
pub jobserver_per_rustc: bool,
345+
pub extra_link_arg: bool,
345346
}
346347

347348
impl CliUnstable {
@@ -411,6 +412,7 @@ impl CliUnstable {
411412
"doctest-xcompile" => self.doctest_xcompile = parse_empty(k, v)?,
412413
"panic-abort-tests" => self.panic_abort_tests = parse_empty(k, v)?,
413414
"jobserver-per-rustc" => self.jobserver_per_rustc = parse_empty(k, v)?,
415+
"extra-link-arg" => self.extra_link_arg = parse_empty(k, v)?,
414416
_ => bail!("unknown `-Z` flag specified: {}", k),
415417
}
416418

0 commit comments

Comments
 (0)