Skip to content

Commit 92db0bd

Browse files
npmccallumreitermarkus
authored andcommitted
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 e295d7f commit 92db0bd

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
215215
// don't pass the `-l` flags.
216216
let pass_l_flag = unit.target.is_lib() || !unit.pkg.targets().iter().any(|t| t.is_lib());
217217
let link_type = unit.target.into();
218+
let extra_link_arg = cx.bcx.config.cli_unstable().extra_link_arg;
218219

219220
let dep_info_name = match cx.files().metadata(unit) {
220221
Some(metadata) => format!("{}-{}.d", unit.target.crate_name(), metadata),
@@ -263,6 +264,7 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
263264
&build_scripts,
264265
pass_l_flag,
265266
link_type,
267+
extra_link_arg,
266268
current_id,
267269
)?;
268270
add_plugin_deps(&mut rustc, &script_outputs, &build_scripts, &root_output)?;
@@ -345,6 +347,7 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
345347
build_scripts: &BuildScripts,
346348
pass_l_flag: bool,
347349
link_type: Option<LinkType>,
350+
extra_link_arg: bool,
348351
current_id: PackageId,
349352
) -> CargoResult<()> {
350353
for key in build_scripts.to_link.iter() {
@@ -366,17 +369,15 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
366369
rustc.arg("-l").arg(name);
367370
}
368371
}
369-
370372
if link_type.is_some() {
371-
for arg in output
373+
output
372374
.linker_args
373375
.iter()
374376
.filter(|x| x.0.is_none() || x.0 == link_type)
375-
.map(|x| &x.1)
376-
{
377-
let link_arg = format!("link-arg={}", arg);
378-
rustc.arg("-C").arg(link_arg);
379-
}
377+
.filter(|x| x.0 == Some(LinkType::Cdylib) || extra_link_arg)
378+
.for_each(|x| {
379+
rustc.arg("-C").arg(format!("link-arg={}", x.1));
380+
});
380381
}
381382
}
382383
}

src/cargo/core/features.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ pub struct CliUnstable {
359359
pub terminal_width: Option<Option<usize>>,
360360
pub namespaced_features: bool,
361361
pub weak_dep_features: bool,
362+
pub extra_link_arg: bool,
362363
}
363364

364365
fn deserialize_build_std<'de, D>(deserializer: D) -> Result<Option<Vec<String>>, D::Error>
@@ -466,6 +467,7 @@ impl CliUnstable {
466467
"terminal-width" => self.terminal_width = Some(parse_usize_opt(v)?),
467468
"namespaced-features" => self.namespaced_features = parse_empty(k, v)?,
468469
"weak-dep-features" => self.weak_dep_features = parse_empty(k, v)?,
470+
"extra-link-arg" => self.extra_link_arg = parse_empty(k, v)?,
469471
_ => bail!("unknown `-Z` flag specified: {}", k),
470472
}
471473

0 commit comments

Comments
 (0)