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