Skip to content

Commit 4be7583

Browse files
authored
Merge pull request #4439 from RalfJung/ci
only set host-specific CC; improve native libs testing logic
2 parents 143c05a + db617af commit 4be7583

File tree

5 files changed

+18
-25
lines changed

5 files changed

+18
-25
lines changed

src/tools/miri/.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
run: |
7575
sudo apt install gcc-${{ matrix.gcc_cross }}
7676
echo "Setting environment variables:"
77-
echo "CC=${{ matrix.gcc_cross }}-gcc" | tee -a $GITHUB_ENV
77+
echo "CC_${{ matrix.host_target }}=${{ matrix.gcc_cross }}-gcc" | tee -a $GITHUB_ENV
7878
TARGET_UPPERCASE=$(echo ${{ matrix.host_target }} | tr '[:lower:]-' '[:upper:]_')
7979
echo "CARGO_TARGET_${TARGET_UPPERCASE}_LINKER=${{ matrix.gcc_cross }}-gcc" | tee -a $GITHUB_ENV
8080

src/tools/miri/tests/native-lib/pass/ptr_read_access.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// Only works on Unix targets
2-
//@ignore-target: windows wasm
3-
//@only-on-host
4-
51
fn main() {
62
test_access_pointer();
73
test_access_simple();

src/tools/miri/tests/native-lib/pass/ptr_write_access.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Only works on Unix targets
2-
//@ignore-target: windows wasm
3-
//@only-on-host
41
//@compile-flags: -Zmiri-permissive-provenance
52

63
#![feature(box_as_ptr)]

src/tools/miri/tests/native-lib/pass/scalar_arguments.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// Only works on Unix targets
2-
//@ignore-target: windows wasm
3-
//@only-on-host
4-
51
extern "C" {
62
fn add_one_int(x: i32) -> i32;
73
fn add_int16(x: i16) -> i16;

src/tools/miri/tests/ui.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,17 @@ fn miri_path() -> PathBuf {
2929
PathBuf::from(env::var("MIRI").unwrap_or_else(|_| env!("CARGO_BIN_EXE_miri").into()))
3030
}
3131

32-
fn get_host() -> String {
33-
rustc_version::VersionMeta::for_command(std::process::Command::new(miri_path()))
34-
.expect("failed to parse rustc version info")
35-
.host
36-
}
37-
3832
pub fn flagsplit(flags: &str) -> Vec<String> {
3933
// This code is taken from `RUSTFLAGS` handling in cargo.
4034
flags.split(' ').map(str::trim).filter(|s| !s.is_empty()).map(str::to_string).collect()
4135
}
4236

4337
// Build the shared object file for testing native function calls.
44-
fn build_native_lib() -> PathBuf {
45-
let cc = env::var("CC").unwrap_or_else(|_| "cc".into());
38+
fn build_native_lib(target: &str) -> PathBuf {
39+
// Loosely follow the logic of the `cc` crate for finding the compiler.
40+
let cc = env::var(format!("CC_{target}"))
41+
.or_else(|_| env::var("CC"))
42+
.unwrap_or_else(|_| "cc".into());
4643
// Target directory that we can write to.
4744
let so_target_dir = Path::new(env!("CARGO_TARGET_TMPDIR")).join("miri-native-lib");
4845
// Create the directory if it does not already exist.
@@ -201,7 +198,7 @@ fn run_tests(
201198
// If we're testing the native-lib functionality, then build the shared object file for testing
202199
// external C function calls and push the relevant compiler flag.
203200
if path.starts_with("tests/native-lib/") {
204-
let native_lib = build_native_lib();
201+
let native_lib = build_native_lib(target);
205202
let mut flag = std::ffi::OsString::from("-Zmiri-native-lib=");
206203
flag.push(native_lib.into_os_string());
207204
config.program.args.push(flag);
@@ -305,14 +302,21 @@ fn ui(
305302
.with_context(|| format!("ui tests in {path} for {target} failed"))
306303
}
307304

308-
fn get_target() -> String {
309-
env::var("MIRI_TEST_TARGET").ok().unwrap_or_else(get_host)
305+
fn get_host() -> String {
306+
rustc_version::VersionMeta::for_command(std::process::Command::new(miri_path()))
307+
.expect("failed to parse rustc version info")
308+
.host
309+
}
310+
311+
fn get_target(host: &str) -> String {
312+
env::var("MIRI_TEST_TARGET").ok().unwrap_or_else(|| host.to_owned())
310313
}
311314

312315
fn main() -> Result<()> {
313316
ui_test::color_eyre::install()?;
314317

315-
let target = get_target();
318+
let host = get_host();
319+
let target = get_target(&host);
316320
let tmpdir = tempfile::Builder::new().prefix("miri-uitest-").tempdir()?;
317321

318322
let mut args = std::env::args_os();
@@ -329,7 +333,7 @@ fn main() -> Result<()> {
329333
ui(Mode::Panic, "tests/panic", &target, WithDependencies, tmpdir.path())?;
330334
ui(Mode::Fail, "tests/fail", &target, WithoutDependencies, tmpdir.path())?;
331335
ui(Mode::Fail, "tests/fail-dep", &target, WithDependencies, tmpdir.path())?;
332-
if cfg!(unix) {
336+
if cfg!(unix) && target == host {
333337
ui(Mode::Pass, "tests/native-lib/pass", &target, WithoutDependencies, tmpdir.path())?;
334338
ui(Mode::Fail, "tests/native-lib/fail", &target, WithoutDependencies, tmpdir.path())?;
335339
}

0 commit comments

Comments
 (0)