Skip to content

Commit

Permalink
testcase(Problem)
Browse files Browse the repository at this point in the history
  • Loading branch information
heisen-li committed Apr 6, 2024
1 parent 6b27055 commit 5ebe68c
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5527,3 +5527,90 @@ 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",
"#![allow(warnings)]
#![cfg_attr(backtrace, feature(mixed_integer_ops))]
",
)
.file(
"build.rs",
r#"
use std::env;
use std::process::{Command, Stdio};
fn main() {
let rustc = env::var_os("RUSTC").unwrap();
let mut cmd = Command::new(rustc);
cmd.stderr(Stdio::null())
.arg("--crate-type=lib")
.arg("--out-dir")
.arg(env::var_os("OUT_DIR").unwrap())
.arg("build/probe.rs");
cmd.arg("--target").arg(env::var_os("TARGET").unwrap());
if let Ok(rustflags) = env::var("CARGO_ENCODED_RUSTFLAGS") {
if !rustflags.is_empty() {
for arg in rustflags.split('\x1f') {
cmd.arg(arg);
}
}
}
let _ = cmd
.status()
.ok()
.unwrap()
.success()
.then(|| println!("cargo:rustc-cfg=backtrace"));
}
"#,
)
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = [""]
edition = "2021"
[features]
default = ["std"]
std = []
"#,
)
.file("build/probe.rs", "#![feature(mixed_integer_ops)]")
.build();

p.cargo("build --target")
.arg(&target)
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([..])
[FINISHED] [..]
",
)
.run();

p.cargo("build --target")
.arg(&target)
.env("RUSTFLAGS", "-Zallow-features=")
.with_status(101)
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([..])
error[E0725]: the feature `mixed_integer_ops` is not in the list of allowed features
--> src/lib.rs:2:32
|
2 | #![cfg_attr(backtrace, feature(mixed_integer_ops))]
| ^^^^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0725`.
[ERROR] could not compile `foo` (lib) due to 1 previous error
",
)
.run();
}

0 comments on commit 5ebe68c

Please sign in to comment.