From f1b4a1d0d135f4aa8c338b1dc98b8296c972ce69 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 14 Feb 2025 12:24:06 +0000 Subject: [PATCH] Remove the build script for miri Setting the TARGET env var can be replaced with using rustc_session::config::host_tuple at runtime. And the check-cfg can be replaced with using the lints section in Cargo.toml. --- src/tools/miri/Cargo.toml | 4 ++++ src/tools/miri/build.rs | 10 ---------- src/tools/miri/src/machine.rs | 5 +++-- 3 files changed, 7 insertions(+), 12 deletions(-) delete mode 100644 src/tools/miri/build.rs diff --git a/src/tools/miri/Cargo.toml b/src/tools/miri/Cargo.toml index de80722fc3df..728a7552fd8c 100644 --- a/src/tools/miri/Cargo.toml +++ b/src/tools/miri/Cargo.toml @@ -67,6 +67,10 @@ default = ["stack-cache"] stack-cache = [] stack-cache-consistency-check = ["stack-cache"] +[lints.rust.unexpected_cfgs] +level = "warn" +check-cfg = ['cfg(bootstrap)'] + # Be aware that this file is inside a workspace when used via the # submodule in the rustc repo. That means there are many cargo features # we cannot use, such as profiles. diff --git a/src/tools/miri/build.rs b/src/tools/miri/build.rs deleted file mode 100644 index 0918c9b13214..000000000000 --- a/src/tools/miri/build.rs +++ /dev/null @@ -1,10 +0,0 @@ -fn main() { - // Don't rebuild miri when nothing changed. - println!("cargo:rerun-if-changed=build.rs"); - // Re-export the TARGET environment variable so it can be accessed by miri. Needed to know the - // "host" triple inside Miri. - let target = std::env::var("TARGET").unwrap(); - println!("cargo:rustc-env=TARGET={target}"); - // Allow some cfgs. - println!("cargo::rustc-check-cfg=cfg(bootstrap)"); -} diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs index 6bd1076a8a84..4ece8f7895de 100644 --- a/src/tools/miri/src/machine.rs +++ b/src/tools/miri/src/machine.rs @@ -713,12 +713,13 @@ impl<'tcx> MiriMachine<'tcx> { clock: Clock::new(config.isolated_op == IsolatedOp::Allow), #[cfg(unix)] native_lib: config.native_lib.as_ref().map(|lib_file_path| { + let host_triple = rustc_session::config::host_tuple(); let target_triple = tcx.sess.opts.target_triple.tuple(); // Check if host target == the session target. - if env!("TARGET") != target_triple { + if host_triple != target_triple { panic!( "calling external C functions in linked .so file requires host and target to be the same: host={}, target={}", - env!("TARGET"), + host_triple, target_triple, ); }