@@ -5527,3 +5527,90 @@ fn test_old_syntax_with_old_msrv() {
55275527 p. cargo ( "build -v" ) . run ( ) ;
55285528 p. cargo ( "run -v" ) . with_stdout ( "foo\n " ) . run ( ) ;
55295529}
5530+
5531+ #[ cargo_test]
5532+ fn build_script_rerun_when_target_rustflags_change ( ) {
5533+ let target = rustc_host ( ) ;
5534+ let p = project ( )
5535+ . file (
5536+ "src/lib.rs" ,
5537+ "#![allow(warnings)]
5538+ #![cfg_attr(backtrace, feature(mixed_integer_ops))]
5539+ " ,
5540+ )
5541+ . file (
5542+ "build.rs" ,
5543+ r#"
5544+ use std::env;
5545+ use std::process::{Command, Stdio};
5546+ fn main() {
5547+ let rustc = env::var_os("RUSTC").unwrap();
5548+ let mut cmd = Command::new(rustc);
5549+ cmd.stderr(Stdio::null())
5550+ .arg("--crate-type=lib")
5551+ .arg("--out-dir")
5552+ .arg(env::var_os("OUT_DIR").unwrap())
5553+ .arg("build/probe.rs");
5554+ cmd.arg("--target").arg(env::var_os("TARGET").unwrap());
5555+ if let Ok(rustflags) = env::var("CARGO_ENCODED_RUSTFLAGS") {
5556+ if !rustflags.is_empty() {
5557+ for arg in rustflags.split('\x1f') {
5558+ cmd.arg(arg);
5559+ }
5560+ }
5561+ }
5562+ let _ = cmd
5563+ .status()
5564+ .ok()
5565+ .unwrap()
5566+ .success()
5567+ .then(|| println!("cargo:rustc-cfg=backtrace"));
5568+ }
5569+ "# ,
5570+ )
5571+ . file (
5572+ "Cargo.toml" ,
5573+ r#"
5574+ [package]
5575+ name = "foo"
5576+ version = "0.0.1"
5577+ authors = [""]
5578+ edition = "2021"
5579+
5580+ [features]
5581+ default = ["std"]
5582+ std = []
5583+ "# ,
5584+ )
5585+ . file ( "build/probe.rs" , "#![feature(mixed_integer_ops)]" )
5586+ . build ( ) ;
5587+
5588+ p. cargo ( "build --target" )
5589+ . arg ( & target)
5590+ . with_stderr (
5591+ "\
5592+ [COMPILING] foo v0.0.1 ([..])
5593+ [FINISHED] [..]
5594+ " ,
5595+ )
5596+ . run ( ) ;
5597+
5598+ p. cargo ( "build --target" )
5599+ . arg ( & target)
5600+ . env ( "RUSTFLAGS" , "-Zallow-features=" )
5601+ . with_status ( 101 )
5602+ . with_stderr (
5603+ "\
5604+ [COMPILING] foo v0.0.1 ([..])
5605+ error[E0725]: the feature `mixed_integer_ops` is not in the list of allowed features
5606+ --> src/lib.rs:2:32
5607+ |
5608+ 2 | #![cfg_attr(backtrace, feature(mixed_integer_ops))]
5609+ | ^^^^^^^^^^^^^^^^^
5610+
5611+ For more information about this error, try `rustc --explain E0725`.
5612+ [ERROR] could not compile `foo` (lib) due to 1 previous error
5613+ " ,
5614+ )
5615+ . run ( ) ;
5616+ }
0 commit comments