Skip to content

Commit d426f12

Browse files
committed
Restrict to cdylib the link arg feature
1 parent 55205ef commit d426f12

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/cargo/core/compiler/mod.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ fn rustc<'a, 'cfg>(
211211
// If we are a binary and the package also contains a library, then we
212212
// don't pass the `-l` flags.
213213
let pass_l_flag = unit.target.is_lib() || !unit.pkg.targets().iter().any(|t| t.is_lib());
214+
let pass_link_args = unit.target.is_cdylib();
214215
let do_rename = unit.target.allows_underscores() && !unit.mode.is_any_test();
215216
let real_name = unit.target.name().to_string();
216217
let crate_name = unit.target.crate_name();
@@ -257,6 +258,7 @@ fn rustc<'a, 'cfg>(
257258
&build_state,
258259
&build_deps,
259260
pass_l_flag,
261+
pass_link_args,
260262
current_id,
261263
)?;
262264
add_plugin_deps(&mut rustc, &build_state, &build_deps, &root_output)?;
@@ -346,6 +348,7 @@ fn rustc<'a, 'cfg>(
346348
build_state: &BuildMap,
347349
build_scripts: &BuildScripts,
348350
pass_l_flag: bool,
351+
pass_link_args: bool,
349352
current_id: PackageId,
350353
) -> CargoResult<()> {
351354
for key in build_scripts.to_link.iter() {
@@ -367,9 +370,11 @@ fn rustc<'a, 'cfg>(
367370
rustc.arg("-l").arg(name);
368371
}
369372
}
370-
for arg in output.linker_args.iter() {
371-
let link_arg = format!("link-arg={}", arg);
372-
rustc.arg("-C").arg(link_arg);
373+
if pass_link_args {
374+
for arg in output.linker_args.iter() {
375+
let link_arg = format!("link-arg={}", arg);
376+
rustc.arg("-C").arg(link_arg);
377+
}
373378
}
374379
}
375380
}

0 commit comments

Comments
 (0)