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 {
28542854 }
28552855
28562856 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+ }
28572871 let mut cache = self . env_cache . lock ( ) . unwrap ( ) ;
28582872 if let Some ( val) = cache. get ( v) {
28592873 return val. clone ( ) ;
28602874 }
2861- if self . emit_rerun_if_env_changed {
2875+ if self . emit_rerun_if_env_changed && ! provided_by_cargo ( v ) {
28622876 self . print ( & format ! ( "cargo:rerun-if-env-changed={}" , v) ) ;
28632877 }
28642878 let r = env:: var ( v) . ok ( ) ;
You can’t perform that action at this time.
0 commit comments