fix: show build script didnt rerun when target rustflags changed

This commit is contained in:
heisen-li 2024-03-08 20:33:22 +08:00 committed by Weihang Lo
parent 6b27055c45
commit cdda9008a3
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7
1 changed files with 54 additions and 0 deletions

View File

@ -5527,3 +5527,57 @@ fn test_old_syntax_with_old_msrv() {
p.cargo("build -v").run();
p.cargo("run -v").with_stdout("foo\n").run();
}
#[cargo_test]
fn build_script_rerun_when_target_rustflags_change() {
let target = rustc_host();
let p = project()
.file(
"src/main.rs",
r#"
fn main() {
#[cfg(enable)]
println!("hello");
}
"#,
)
.file(
"build.rs",
r#"
use std::env;
fn main() {
if let Ok(rustflags) = env::var("CARGO_ENCODED_RUSTFLAGS") {
if !rustflags.is_empty() {
println!("cargo::rustc-cfg=enable")
}
}
}
"#,
)
.build();
p.cargo("run --target")
.arg(&target)
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([..])
[FINISHED] [..]
[RUNNING] [..]
",
)
.run();
p.cargo("run --target")
.arg(&target)
.env("RUSTFLAGS", "-C opt-level=3")
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([..])
[FINISHED] [..]
[RUNNING] [..]
",
)
.with_stdout("")
.run();
}