2020-07-02 09:45:41 +00:00
|
|
|
//! Tests for -Zextra-link-arg.
|
|
|
|
|
|
|
|
use cargo_test_support::{basic_bin_manifest, project};
|
|
|
|
|
|
|
|
#[cargo_test]
|
2020-07-02 10:58:10 +00:00
|
|
|
fn build_script_extra_link_arg_bin() {
|
2020-07-02 09:45:41 +00:00
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
"build.rs",
|
|
|
|
r#"
|
|
|
|
fn main() {
|
2020-07-22 00:02:37 +00:00
|
|
|
println!("cargo:rustc-link-arg-bins=--this-is-a-bogus-flag");
|
2020-07-02 09:45:41 +00:00
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("build -Zextra-link-arg -v")
|
|
|
|
.masquerade_as_nightly_cargo()
|
2020-07-02 11:48:30 +00:00
|
|
|
.without_status()
|
2020-07-02 09:45:41 +00:00
|
|
|
.with_stderr_contains(
|
|
|
|
"[RUNNING] `rustc --crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..]",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2021-05-20 19:41:17 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn build_script_extra_link_arg_bin_single() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
|
|
|
|
name = "foobar"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
|
|
|
[[bin]]
|
|
|
|
name = "bar"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
"build.rs",
|
|
|
|
r#"
|
|
|
|
fn main() {
|
|
|
|
println!("cargo:rustc-link-arg-bins=--bogus-flag-all");
|
|
|
|
println!("cargo:rustc-link-arg-bin=foo=--bogus-flag-foo");
|
|
|
|
println!("cargo:rustc-link-arg-bin=bar=--bogus-flag-bar");
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("build -Zextra-link-arg -v")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.without_status()
|
|
|
|
.with_stderr_contains(
|
|
|
|
"[RUNNING] `rustc --crate-name foo [..]-C link-arg=--bogus-flag-all -C link-arg=--bogus-flag-foo[..]",
|
|
|
|
)
|
|
|
|
.with_stderr_contains(
|
|
|
|
"[RUNNING] `rustc --crate-name bar [..]-C link-arg=--bogus-flag-all -C link-arg=--bogus-flag-bar[..]",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2020-07-02 09:45:41 +00:00
|
|
|
#[cargo_test]
|
2020-07-02 10:58:10 +00:00
|
|
|
fn build_script_extra_link_arg() {
|
2020-07-02 09:45:41 +00:00
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
"build.rs",
|
|
|
|
r#"
|
|
|
|
fn main() {
|
|
|
|
println!("cargo:rustc-link-arg=--this-is-a-bogus-flag");
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("build -Zextra-link-arg -v")
|
|
|
|
.masquerade_as_nightly_cargo()
|
2020-07-02 11:48:30 +00:00
|
|
|
.without_status()
|
2020-07-02 09:45:41 +00:00
|
|
|
.with_stderr_contains(
|
|
|
|
"[RUNNING] `rustc --crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..]",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
2020-07-02 10:58:10 +00:00
|
|
|
fn build_script_extra_link_arg_warn_without_flag() {
|
2020-07-02 09:45:41 +00:00
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
"build.rs",
|
|
|
|
r#"
|
|
|
|
fn main() {
|
|
|
|
println!("cargo:rustc-link-arg=--this-is-a-bogus-flag");
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
2020-07-02 11:21:57 +00:00
|
|
|
p.cargo("build -v")
|
2020-07-02 09:45:41 +00:00
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains("warning: cargo:rustc-link-arg requires -Zextra-link-arg flag")
|
|
|
|
.run();
|
|
|
|
}
|
2021-05-29 23:00:35 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn link_arg_missing_target() {
|
|
|
|
// Errors when a given target doesn't exist.
|
|
|
|
let p = project()
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file(
|
|
|
|
"build.rs",
|
|
|
|
r#"fn main() { println!("cargo:rustc-link-arg-cdylib=--bogus"); }"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr("\
|
|
|
|
[COMPILING] foo [..]
|
|
|
|
error: invalid instruction `cargo:rustc-link-arg-cdylib` from build script of `foo v0.0.1 ([ROOT]/foo)`
|
|
|
|
The package foo v0.0.1 ([ROOT]/foo) does not have a cdylib target.
|
|
|
|
")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.change_file(
|
|
|
|
"build.rs",
|
|
|
|
r#"fn main() { println!("cargo:rustc-link-arg-bins=--bogus"); }"#,
|
|
|
|
);
|
|
|
|
|
|
|
|
p.cargo("check -Zextra-link-arg")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr("\
|
|
|
|
[COMPILING] foo [..]
|
|
|
|
error: invalid instruction `cargo:rustc-link-arg-bins` from build script of `foo v0.0.1 ([ROOT]/foo)`
|
|
|
|
The package foo v0.0.1 ([ROOT]/foo) does not have a bin target.
|
|
|
|
")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.change_file(
|
|
|
|
"build.rs",
|
|
|
|
r#"fn main() { println!("cargo:rustc-link-arg-bin=abc=--bogus"); }"#,
|
|
|
|
);
|
|
|
|
|
|
|
|
p.cargo("check -Zextra-link-arg")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo [..]
|
|
|
|
error: invalid instruction `cargo:rustc-link-arg-bin` from build script of `foo v0.0.1 ([ROOT]/foo)`
|
|
|
|
The package foo v0.0.1 ([ROOT]/foo) does not have a bin target with the name `abc`.
|
2021-05-29 23:12:11 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.change_file(
|
|
|
|
"build.rs",
|
|
|
|
r#"fn main() { println!("cargo:rustc-link-arg-bin=abc"); }"#,
|
|
|
|
);
|
|
|
|
|
|
|
|
p.cargo("check -Zextra-link-arg")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo [..]
|
|
|
|
error: invalid instruction `cargo:rustc-link-arg-bin=abc` from build script of `foo v0.0.1 ([ROOT]/foo)`
|
|
|
|
The instruction should have the form cargo:rustc-link-arg-bin=BIN=ARG
|
2021-05-29 23:00:35 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|