@@ -15,20 +15,6 @@ fn main() {
15
15
let target = & * env:: var ( "TARGET" ) . expect ( "TARGET not set" ) ;
16
16
let target_arch = & * env:: var ( "CARGO_CFG_TARGET_ARCH" ) . expect ( "CARGO_CFG_TARGET_ARCH not set" ) ;
17
17
let target_os = & * env:: var ( "CARGO_CFG_TARGET_OS" ) . expect ( "CARGO_CFG_TARGET_OS not set" ) ;
18
- // HACK: If --target is specified, rustflags is not applied to the build
19
- // script itself, so the build script will not be rerun when these are changed.
20
- // TODO: once https://github.com/rust-lang/cargo/issues/13003 is fixed,
21
- // remove this hack in the version that contains the fix.
22
- //
23
- // Ideally, the build script should be rebuilt when CARGO_ENCODED_RUSTFLAGS
24
- // is changed, but since it is an environment variable set by cargo,
25
- // as of 1.62.0-nightly, specifying it as rerun-if-env-changed does not work.
26
- println ! ( "cargo:rerun-if-env-changed=CARGO_ENCODED_RUSTFLAGS" ) ;
27
- println ! ( "cargo:rerun-if-env-changed=RUSTFLAGS" ) ;
28
- println ! ( "cargo:rerun-if-env-changed=CARGO_BUILD_RUSTFLAGS" ) ;
29
- let mut target_upper = target. replace ( [ '-' , '.' ] , "_" ) ;
30
- target_upper. make_ascii_uppercase ( ) ;
31
- println ! ( "cargo:rerun-if-env-changed=CARGO_TARGET_{target_upper}_RUSTFLAGS" ) ;
32
18
33
19
let version = match rustc_version ( ) {
34
20
Some ( version) => version,
@@ -42,6 +28,22 @@ fn main() {
42
28
}
43
29
} ;
44
30
31
+ // https://github.com/rust-lang/rust/pull/123745 (includes https://github.com/rust-lang/cargo/pull/13560) merged in Rust 1.79 (nightly-2024-04-11).
32
+ if !version. probe ( 79 , 2024 , 4 , 10 ) {
33
+ // HACK: If --target is specified, rustflags is not applied to the build
34
+ // script itself, so the build script will not be recompiled when rustflags
35
+ // is changed. That in itself is not a problem, but the old Cargo does
36
+ // not rerun the build script as well, which can be problematic.
37
+ // https://github.com/rust-lang/cargo/issues/13003
38
+ // This problem has been fixed in 1.79 so only older versions need a workaround.
39
+ println ! ( "cargo:rerun-if-env-changed=CARGO_ENCODED_RUSTFLAGS" ) ;
40
+ println ! ( "cargo:rerun-if-env-changed=RUSTFLAGS" ) ;
41
+ println ! ( "cargo:rerun-if-env-changed=CARGO_BUILD_RUSTFLAGS" ) ;
42
+ let mut target_upper = target. replace ( [ '-' , '.' ] , "_" ) ;
43
+ target_upper. make_ascii_uppercase ( ) ;
44
+ println ! ( "cargo:rerun-if-env-changed=CARGO_TARGET_{target_upper}_RUSTFLAGS" ) ;
45
+ }
46
+
45
47
// Note that this is `no_`*, not `has_*`. This allows treating as the latest
46
48
// stable rustc is used when the build script doesn't run. This is useful
47
49
// for non-cargo build systems that don't run the build script.
0 commit comments