diff --git a/src/cargo/core/compiler/fingerprint/mod.rs b/src/cargo/core/compiler/fingerprint/mod.rs index f13e91b0b1bb..94cd2f65624d 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_env_value(key: &str, envs: &BTreeMap>) -> Option { + if cfg!(windows) { + 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(); + } + } + } + env::var_os(key) + } + + 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 = match envs.get(key) { + Some(v) => v.to_owned(), + None => get_env_value(key, envs), + } + .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..e929b87519ab 100644 --- a/tests/testsuite/build_script_env.rs +++ b/tests/testsuite/build_script_env.rs @@ -7,6 +7,26 @@ use cargo_test_support::str; #[cargo_test] fn rerun_if_env_changes_config() { + let build = if cfg!(windows) { + r#" +fn main() { + println!("cargo:rerun-if-env-changed=fOO"); + if let Ok(foo) = std::env::var("Foo") { + assert!(&foo != "bad"); + } +} +"# + } else { + r#" +fn main() { + println!("cargo:rerun-if-env-changed=FOO"); + if let Ok(foo) = std::env::var("FOO") { + assert!(&foo != "bad"); + } +} +"# + }; + let p = project() .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("src/main.rs", "fn main() {}") @@ -17,17 +37,7 @@ fn rerun_if_env_changes_config() { 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"); - } - } - "#, - ) + .file("build.rs", build) .build(); p.cargo("check") @@ -48,12 +58,11 @@ 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(); }