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.
This commit is contained in:
bjorn3 2025-02-14 12:24:06 +00:00
parent 09e0696586
commit f1b4a1d0d1
3 changed files with 7 additions and 12 deletions

View file

@ -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.

View file

@ -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)");
}

View file

@ -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,
);
}