diff --git a/src/cargo/core/compiler/fingerprint/mod.rs b/src/cargo/core/compiler/fingerprint/mod.rs index f13e91b0b1bb..78ac1c3e5b68 100644 --- a/src/cargo/core/compiler/fingerprint/mod.rs +++ b/src/cargo/core/compiler/fingerprint/mod.rs @@ -775,13 +775,26 @@ impl LocalFingerprint { key: K, envs: &BTreeMap>, ) -> LocalFingerprint { - let key = key.as_ref(); + fn get_envs_case_insensitive(key: &str, envs: &BTreeMap>) -> Option { + let upper_case_key: String = key.to_uppercase(); + for (k, v) in envs { + if k.to_uppercase().eq(&upper_case_key) { + return v.to_owned(); + } + } + None + } + + let key: &str = key.as_ref(); let var = key.to_owned(); - let val = envs - .get(key) - .map(|v| v.to_owned()) - .or_else(|| Some(env::var_os(key))) - .and_then(|os_str| os_str?.into_string().ok()); + + let val: Option = if cfg!(windows) { + get_envs_case_insensitive(key, envs) + } else { + envs.get(key).and_then(|v| v.to_owned()) + } + .xor(env::var_os(key)) + .and_then(|os_str| os_str.into_string().ok()); LocalFingerprint::RerunIfEnvChanged { var, val } } diff --git a/tests/testsuite/build_script_env.rs b/tests/testsuite/build_script_env.rs index 639373036241..903156ee863f 100644 --- a/tests/testsuite/build_script_env.rs +++ b/tests/testsuite/build_script_env.rs @@ -20,13 +20,13 @@ fn rerun_if_env_changes_config() { .file( "build.rs", r#" - fn main() { - println!("cargo:rerun-if-env-changed=FOO"); - if let Ok(foo) = std::env::var("FOO") { - assert!(&foo != "bad"); - } - } - "#, +fn main() { + println!("cargo:rerun-if-env-changed=FOO"); + if let Ok(foo) = std::env::var("FOO") { + assert!(&foo != "bad"); + } +} +"#, ) .build(); @@ -48,12 +48,63 @@ fn rerun_if_env_changes_config() { p.cargo("check") .with_status(101) - .with_stderr_data( - "\ + .with_stderr_data(str![[r#" [COMPILING] foo v0.1.0 ([ROOT]/foo) [ERROR] failed to run custom build command for `foo v0.1.0 ([ROOT]/foo)` -...", +... +"#]]) + .run(); +} + +#[cfg(windows)] +#[cargo_test] +fn rerun_if_env_changes_config_in_windows() { + let p = project() + .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) + .file("src/main.rs", "fn main() {}") + .file( + ".cargo/config.toml", + r#" + [env] + Foo = "good" + "#, ) + .file( + "build.rs", + r#" +fn main() { + println!("cargo:rerun-if-env-changed=foo"); + if let Ok(foo) = std::env::var("FOo") { + assert!(&foo != "bad"); + } +} +"#, + ) + .build(); + + p.cargo("check") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.1.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .run(); + + p.change_file( + ".cargo/config.toml", + r#" + [env] + FoO = "bad" + "#, + ); + + p.cargo("check") + .with_status(101) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.1.0 ([ROOT]/foo) +[ERROR] failed to run custom build command for `foo v0.1.0 ([ROOT]/foo)` +... +"#]]) .run(); }