mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Auto merge of #13560 - heisen-li:build_flag, r=weihanglo
[fix]:Build script not rerun when target rustflags change ### What does this PR try to resolve? Fixes https://github.com/rust-lang/cargo/issues/13003
This commit is contained in:
commit
bd1cf584af
@ -1526,11 +1526,14 @@ See https://doc.rust-lang.org/cargo/reference/build-scripts.html#rerun-if-change
|
|||||||
.collect::<CargoResult<Vec<_>>>()?
|
.collect::<CargoResult<Vec<_>>>()?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let rustflags = build_runner.bcx.rustflags_args(unit).to_vec();
|
||||||
|
|
||||||
Ok(Fingerprint {
|
Ok(Fingerprint {
|
||||||
local: Mutex::new(local),
|
local: Mutex::new(local),
|
||||||
rustc: util::hash_u64(&build_runner.bcx.rustc().verbose_version),
|
rustc: util::hash_u64(&build_runner.bcx.rustc().verbose_version),
|
||||||
deps,
|
deps,
|
||||||
outputs: if overridden { Vec::new() } else { vec![output] },
|
outputs: if overridden { Vec::new() } else { vec![output] },
|
||||||
|
rustflags,
|
||||||
|
|
||||||
// Most of the other info is blank here as we don't really include it
|
// Most of the other info is blank here as we don't really include it
|
||||||
// in the execution of the build script, but... this may be a latent
|
// in the execution of the build script, but... this may be a latent
|
||||||
|
@ -5537,3 +5537,60 @@ fn test_old_syntax_with_old_msrv() {
|
|||||||
p.cargo("build -v").run();
|
p.cargo("build -v").run();
|
||||||
p.cargo("run -v").with_stdout("foo\n").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(
|
||||||
|
"\
|
||||||
|
hello",
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user