Skip to content

Commit

Permalink
Restrict to cdylib the link arg feature
Browse files Browse the repository at this point in the history
  • Loading branch information
lu-zero committed Nov 18, 2018
1 parent d99d7e0 commit 104b861
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 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>(
// If we are a binary and the package also contains a library, then we
// don't pass the `-l` flags.
let pass_l_flag = unit.target.is_lib() || !unit.pkg.targets().iter().any(|t| t.is_lib());
let pass_link_args = unit.target.is_cdylib();
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();
Expand Down Expand Up @@ -257,6 +258,7 @@ fn rustc<'a, 'cfg>(
&build_state,
&build_deps,
pass_l_flag,
pass_link_args,
&current_id,
)?;
add_plugin_deps(&mut rustc, &build_state, &build_deps, &root_output)?;
Expand Down Expand Up @@ -344,6 +346,7 @@ fn rustc<'a, 'cfg>(
build_state: &BuildMap,
build_scripts: &BuildScripts,
pass_l_flag: bool,
pass_link_args: bool,
current_id: &PackageId,
) -> CargoResult<()> {
for key in build_scripts.to_link.iter() {
Expand All @@ -365,9 +368,11 @@ fn rustc<'a, 'cfg>(
rustc.arg("-l").arg(name);
}
}
for arg in output.linker_args.iter() {
let link_arg = format!("link-arg={}", arg);
rustc.arg("-C").arg(link_arg);
if pass_link_args {
for arg in output.linker_args.iter() {
let link_arg = format!("link-arg={}", arg);
rustc.arg("-C").arg(link_arg);
}
}
}
}
Expand Down

0 comments on commit 104b861

Please sign in to comment.