Skip to content

Commit 104b861

Browse files
committed
Restrict to cdylib the link arg feature
1 parent d99d7e0 commit 104b861

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
@@ -213,6 +213,7 @@ fn rustc<'a, 'cfg>(
213213
// If we are a binary and the package also contains a library, then we
214214
// don't pass the `-l` flags.
215215
let pass_l_flag = unit.target.is_lib() || !unit.pkg.targets().iter().any(|t| t.is_lib());
216+
let pass_link_args = unit.target.is_cdylib();
216217
let do_rename = unit.target.allows_underscores() && !unit.mode.is_any_test();
217218
let real_name = unit.target.name().to_string();
218219
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)?;
@@ -344,6 +346,7 @@ fn rustc<'a, 'cfg>(
344346
build_state: &BuildMap,
345347
build_scripts: &BuildScripts,
346348
pass_l_flag: bool,
349+
pass_link_args: bool,
347350
current_id: &PackageId,
348351
) -> CargoResult<()> {
349352
for key in build_scripts.to_link.iter() {
@@ -365,9 +368,11 @@ fn rustc<'a, 'cfg>(
365368
rustc.arg("-l").arg(name);
366369
}
367370
}
368-
for arg in output.linker_args.iter() {
369-
let link_arg = format!("link-arg={}", arg);
370-
rustc.arg("-C").arg(link_arg);
371+
if pass_link_args {
372+
for arg in output.linker_args.iter() {
373+
let link_arg = format!("link-arg={}", arg);
374+
rustc.arg("-C").arg(link_arg);
375+
}
371376
}
372377
}
373378
}

0 commit comments

Comments
 (0)