From ee634fbb40d7522093b3edf52b9f04f959c8c007 Mon Sep 17 00:00:00 2001 From: heisen-li Date: Fri, 8 Mar 2024 20:33:22 +0800 Subject: [PATCH] testcase(Problem) --- tests/testsuite/build_script.rs | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index a60c59b0b25d..c66a8fc33af2 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -5527,3 +5527,50 @@ fn test_old_syntax_with_old_msrv() { p.cargo("build -v").run(); p.cargo("run -v").with_stdout("foo\n").run(); } + +#[cargo_test] +fn build_script_rerun_when_target_rustflags_change() { + let target = rustc_host(); + let p = project() + .file( + "src/lib.rs", + "#![cfg_attr(enable, feature(error_generic_member_access))] + ", + ) + .file( + "build.rs", + r#" + use std::env; + + fn main() { + if let Ok(rustflags) = env::var("CARGO_ENCODED_RUSTFLAGS") { + if !rustflags.is_empty() { + println!("cargo::rustc-cfg=enable") + } + } + } + "#, + ) + .build(); + + p.cargo("build --target") + .arg(&target) + .with_stderr( + "\ +[COMPILING] foo v0.0.1 ([..]) +[FINISHED] [..] +", + ) + .run(); + + p.cargo("build --target") + .arg(&target) + .env("RUSTFLAGS", "-C opt-level=3") + .with_stderr( + "\ +[COMPILING] foo v0.0.1 ([..]) +[FINISHED] [..] +", + ) + .run(); +}