From db617afe8b188e3c08a26f40a3662833a38e8c3c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 3 Jul 2025 08:40:04 +0200 Subject: [PATCH] only set host-specific CC; improve and de-duplicate native libs testing logic --- src/tools/miri/.github/workflows/ci.yml | 2 +- .../tests/native-lib/pass/ptr_read_access.rs | 4 --- .../tests/native-lib/pass/ptr_write_access.rs | 3 -- .../tests/native-lib/pass/scalar_arguments.rs | 4 --- src/tools/miri/tests/ui.rs | 30 +++++++++++-------- 5 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/tools/miri/.github/workflows/ci.yml b/src/tools/miri/.github/workflows/ci.yml index ed4bcc0dd3b9..11c0f08debe6 100644 --- a/src/tools/miri/.github/workflows/ci.yml +++ b/src/tools/miri/.github/workflows/ci.yml @@ -74,7 +74,7 @@ jobs: run: | sudo apt install gcc-${{ matrix.gcc_cross }} echo "Setting environment variables:" - echo "CC=${{ matrix.gcc_cross }}-gcc" | tee -a $GITHUB_ENV + echo "CC_${{ matrix.host_target }}=${{ matrix.gcc_cross }}-gcc" | tee -a $GITHUB_ENV TARGET_UPPERCASE=$(echo ${{ matrix.host_target }} | tr '[:lower:]-' '[:upper:]_') echo "CARGO_TARGET_${TARGET_UPPERCASE}_LINKER=${{ matrix.gcc_cross }}-gcc" | tee -a $GITHUB_ENV diff --git a/src/tools/miri/tests/native-lib/pass/ptr_read_access.rs b/src/tools/miri/tests/native-lib/pass/ptr_read_access.rs index 3ccfecc6fb37..4c8521353678 100644 --- a/src/tools/miri/tests/native-lib/pass/ptr_read_access.rs +++ b/src/tools/miri/tests/native-lib/pass/ptr_read_access.rs @@ -1,7 +1,3 @@ -// Only works on Unix targets -//@ignore-target: windows wasm -//@only-on-host - fn main() { test_access_pointer(); test_access_simple(); diff --git a/src/tools/miri/tests/native-lib/pass/ptr_write_access.rs b/src/tools/miri/tests/native-lib/pass/ptr_write_access.rs index bd4e0b23601f..86a9c97f4cec 100644 --- a/src/tools/miri/tests/native-lib/pass/ptr_write_access.rs +++ b/src/tools/miri/tests/native-lib/pass/ptr_write_access.rs @@ -1,6 +1,3 @@ -// Only works on Unix targets -//@ignore-target: windows wasm -//@only-on-host //@compile-flags: -Zmiri-permissive-provenance #![feature(box_as_ptr)] diff --git a/src/tools/miri/tests/native-lib/pass/scalar_arguments.rs b/src/tools/miri/tests/native-lib/pass/scalar_arguments.rs index c896bd8dd345..9e99977a692a 100644 --- a/src/tools/miri/tests/native-lib/pass/scalar_arguments.rs +++ b/src/tools/miri/tests/native-lib/pass/scalar_arguments.rs @@ -1,7 +1,3 @@ -// Only works on Unix targets -//@ignore-target: windows wasm -//@only-on-host - extern "C" { fn add_one_int(x: i32) -> i32; fn add_int16(x: i16) -> i16; diff --git a/src/tools/miri/tests/ui.rs b/src/tools/miri/tests/ui.rs index 46472b51f9cd..5239f8338ee1 100644 --- a/src/tools/miri/tests/ui.rs +++ b/src/tools/miri/tests/ui.rs @@ -29,20 +29,17 @@ fn miri_path() -> PathBuf { PathBuf::from(env::var("MIRI").unwrap_or_else(|_| env!("CARGO_BIN_EXE_miri").into())) } -fn get_host() -> String { - rustc_version::VersionMeta::for_command(std::process::Command::new(miri_path())) - .expect("failed to parse rustc version info") - .host -} - pub fn flagsplit(flags: &str) -> Vec { // This code is taken from `RUSTFLAGS` handling in cargo. flags.split(' ').map(str::trim).filter(|s| !s.is_empty()).map(str::to_string).collect() } // Build the shared object file for testing native function calls. -fn build_native_lib() -> PathBuf { - let cc = env::var("CC").unwrap_or_else(|_| "cc".into()); +fn build_native_lib(target: &str) -> PathBuf { + // Loosely follow the logic of the `cc` crate for finding the compiler. + let cc = env::var(format!("CC_{target}")) + .or_else(|_| env::var("CC")) + .unwrap_or_else(|_| "cc".into()); // Target directory that we can write to. let so_target_dir = Path::new(env!("CARGO_TARGET_TMPDIR")).join("miri-native-lib"); // Create the directory if it does not already exist. @@ -201,7 +198,7 @@ fn run_tests( // If we're testing the native-lib functionality, then build the shared object file for testing // external C function calls and push the relevant compiler flag. if path.starts_with("tests/native-lib/") { - let native_lib = build_native_lib(); + let native_lib = build_native_lib(target); let mut flag = std::ffi::OsString::from("-Zmiri-native-lib="); flag.push(native_lib.into_os_string()); config.program.args.push(flag); @@ -305,14 +302,21 @@ fn ui( .with_context(|| format!("ui tests in {path} for {target} failed")) } -fn get_target() -> String { - env::var("MIRI_TEST_TARGET").ok().unwrap_or_else(get_host) +fn get_host() -> String { + rustc_version::VersionMeta::for_command(std::process::Command::new(miri_path())) + .expect("failed to parse rustc version info") + .host +} + +fn get_target(host: &str) -> String { + env::var("MIRI_TEST_TARGET").ok().unwrap_or_else(|| host.to_owned()) } fn main() -> Result<()> { ui_test::color_eyre::install()?; - let target = get_target(); + let host = get_host(); + let target = get_target(&host); let tmpdir = tempfile::Builder::new().prefix("miri-uitest-").tempdir()?; let mut args = std::env::args_os(); @@ -329,7 +333,7 @@ fn main() -> Result<()> { ui(Mode::Panic, "tests/panic", &target, WithDependencies, tmpdir.path())?; ui(Mode::Fail, "tests/fail", &target, WithoutDependencies, tmpdir.path())?; ui(Mode::Fail, "tests/fail-dep", &target, WithDependencies, tmpdir.path())?; - if cfg!(unix) { + if cfg!(unix) && target == host { ui(Mode::Pass, "tests/native-lib/pass", &target, WithoutDependencies, tmpdir.path())?; ui(Mode::Fail, "tests/native-lib/fail", &target, WithoutDependencies, tmpdir.path())?; }