Skip to content

Commit 5382aa6

Browse files
committed
Add rustc-link-arg-bin key to specify per-bin link args.
1 parent 0895469 commit 5382aa6

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,24 @@ impl BuildOutput {
571571
warnings.push(format!("cargo:{} requires -Zextra-link-arg flag", key));
572572
}
573573
}
574+
"rustc-link-arg-bin" => {
575+
if extra_link_arg {
576+
let parts = value.splitn(2, "=").collect::<Vec<_>>();
577+
if parts.len() == 2 {
578+
linker_args.push((
579+
LinkType::SingleBin(parts[0].to_string()),
580+
parts[1].to_string(),
581+
));
582+
} else {
583+
warnings.push(format!(
584+
"cargo:{} has invalid syntax: expected `cargo:{}=BIN=ARG`",
585+
key, key
586+
));
587+
}
588+
} else {
589+
warnings.push(format!("cargo:{} requires -Zextra-link-arg flag", key));
590+
}
591+
}
574592
"rustc-link-arg" => {
575593
if extra_link_arg {
576594
linker_args.push((LinkType::All, value));

src/cargo/core/compiler/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ use cargo_util::{paths, ProcessBuilder, ProcessError};
6262

6363
const RUSTDOC_CRATE_VERSION_FLAG: &str = "--crate-version";
6464

65-
#[derive(Copy, Clone, Hash, Debug, PartialEq, Eq)]
65+
#[derive(Clone, Hash, Debug, PartialEq, Eq)]
6666
pub enum LinkType {
6767
All,
6868
Cdylib,
6969
Bin,
70+
SingleBin(String),
7071
Test,
7172
Bench,
7273
Example,
@@ -78,6 +79,7 @@ impl LinkType {
7879
LinkType::All => true,
7980
LinkType::Cdylib => target.is_cdylib(),
8081
LinkType::Bin => target.is_bin(),
82+
LinkType::SingleBin(name) => target.is_bin() && target.name() == name,
8183
LinkType::Test => target.is_test(),
8284
LinkType::Bench => target.is_bench(),
8385
LinkType::Example => target.is_exe_example(),

0 commit comments

Comments
 (0)