cargo:rerun-if-env-changed
doesn't work with env
configuration #10358
Closed
Description
Problem
When a build.rs
script emits cargo:rerun-if-env-changed
, it is not re-run when the value of the specified variable is changed via the env
configuration.
Steps
build.rs
:
pub fn main() {
println!("cargo:rerun-if-env-changed=FOO");
if let Ok(foo) = std::env::var("FOO") {
assert!(&foo != "bad");
}
}
.cargo/config.toml
:
[env]
FOO = "good"
- Run
cargo build
, it succeeds. - Change
.cargo/config.toml
to this:
[env]
FOO = "bad"
- Run
cargo build
again, and it uses the cached build and succeeds. It should runbuild.rs
again, and it should fail.
Workaround
- Run
FOO=bar cargo build
, ignore the result. - Run
cargo build
again, now it runsbuild.rs
withFOO=bad
from the config and fails as expected.
Possible Solution(s)
No response
Notes
No response
Version
cargo 1.58.0 (7f08ace4f 2021-11-24)
release: 1.58.0
commit-hash: 7f08ace4f1305de7f3b1b0e2f765911957226bd4
commit-date: 2021-11-24
host: x86_64-unknown-linux-gnu
libgit2: 1.3.0 (sys:0.13.23 vendored)
libcurl: 7.80.0-DEV (sys:0.4.51+curl-7.80.0 vendored ssl:OpenSSL/1.1.1l)
os: Debian 11 (bullseye) [64-bit]