File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -2854,11 +2854,25 @@ impl Build {
2854
2854
}
2855
2855
2856
2856
fn getenv ( & self , v : & str ) -> Option < String > {
2857
+ // Returns true for environment variables cargo sets for build scripts:
2858
+ // https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts
2859
+ //
2860
+ // This handles more of the vars than we actually use (it tries to check
2861
+ // complete-ish set), just to avoid needing maintenance if/when new
2862
+ // calls to `getenv`/`getenv_unwrap` are added.
2863
+ fn provided_by_cargo ( envvar : & str ) -> bool {
2864
+ match envvar {
2865
+ v if v. starts_with ( "CARGO" ) || v. starts_with ( "RUSTC" ) => true ,
2866
+ "HOST" | "TARGET" | "RUSTDOC" | "OUT_DIR" | "OPT_LEVEL" | "DEBUG" | "PROFILE"
2867
+ | "NUM_JOBS" | "RUSTFLAGS" => true ,
2868
+ _ => false ,
2869
+ }
2870
+ }
2857
2871
let mut cache = self . env_cache . lock ( ) . unwrap ( ) ;
2858
2872
if let Some ( val) = cache. get ( v) {
2859
2873
return val. clone ( ) ;
2860
2874
}
2861
- if self . emit_rerun_if_env_changed {
2875
+ if self . emit_rerun_if_env_changed && ! provided_by_cargo ( v ) {
2862
2876
self . print ( & format ! ( "cargo:rerun-if-env-changed={}" , v) ) ;
2863
2877
}
2864
2878
let r = env:: var ( v) . ok ( ) ;
You can’t perform that action at this time.
0 commit comments