From 6fd1660650c8bf8d00ccdf53506f3eedf67f40fd Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Fri, 29 Jul 2022 08:39:18 +0100 Subject: [PATCH 01/18] Add Windows build artifacts to .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 5aeaf3a1788..38dd5b26063 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ perf.data.old *.string* /y.bin /y.bin.dSYM +/y.exe +/y.pdb /build /build_sysroot/sysroot_src /build_sysroot/compiler-builtins From 3ce83dc4697ad6698ae45e6cdefa8ae3894c57a3 Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 30 Jul 2022 10:32:54 +0100 Subject: [PATCH 02/18] Move test.sh to y.rs test --- .cirrus.yml | 2 +- .github/workflows/main.yml | 2 +- build_system/build_backend.rs | 5 +- build_system/build_sysroot.rs | 12 +- build_system/mod.rs | 42 ++- build_system/prepare.rs | 3 +- build_system/tests.rs | 504 ++++++++++++++++++++++++++++++++++ build_system/utils.rs | 24 +- config.txt | 33 +++ scripts/tests.sh | 203 -------------- test.sh | 13 - 11 files changed, 605 insertions(+), 238 deletions(-) create mode 100644 build_system/tests.rs delete mode 100755 scripts/tests.sh delete mode 100755 test.sh diff --git a/.cirrus.yml b/.cirrus.yml index 61da6a2491c..732edd66196 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -22,4 +22,4 @@ task: - # Reduce amount of benchmark runs as they are slow - export COMPILE_RUNS=2 - export RUN_RUNS=2 - - ./test.sh + - ./y.rs test diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index aa556a21bf8..a36c570ddc8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -103,7 +103,7 @@ jobs: # Enable extra checks export CG_CLIF_ENABLE_VERIFIER=1 - ./test.sh + ./y.rs test - name: Package prebuilt cg_clif run: tar cvfJ cg_clif.tar.xz build diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index 48faec8bc4b..04f8be6f820 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -1,12 +1,11 @@ use std::env; -use std::path::{Path, PathBuf}; use std::process::Command; pub(crate) fn build_backend( channel: &str, host_triple: &str, use_unstable_features: bool, -) -> PathBuf { +) { let mut cmd = Command::new("cargo"); cmd.arg("build").arg("--target").arg(host_triple); @@ -38,6 +37,4 @@ pub(crate) fn build_backend( eprintln!("[BUILD] rustc_codegen_cranelift"); super::utils::spawn_and_wait(cmd); - - Path::new("target").join(host_triple).join(channel) } diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 16cce83dd9c..dddd5a673c5 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -10,10 +10,12 @@ pub(crate) fn build_sysroot( channel: &str, sysroot_kind: SysrootKind, target_dir: &Path, - cg_clif_build_dir: PathBuf, + cg_clif_build_dir: &Path, host_triple: &str, target_triple: &str, ) { + eprintln!("[BUILD] sysroot {:?}", sysroot_kind); + if target_dir.exists() { fs::remove_dir_all(target_dir).unwrap(); } @@ -35,11 +37,17 @@ pub(crate) fn build_sysroot( // Build and copy rustc and cargo wrappers for wrapper in ["rustc-clif", "cargo-clif"] { + let wrapper_name = if cfg!(windows) { + format!("{wrapper}.exe") + } else { + wrapper.to_string() + }; + let mut build_cargo_wrapper_cmd = Command::new("rustc"); build_cargo_wrapper_cmd .arg(PathBuf::from("scripts").join(format!("{wrapper}.rs"))) .arg("-o") - .arg(target_dir.join(wrapper)) + .arg(target_dir.join(wrapper_name)) .arg("-g"); spawn_and_wait(build_cargo_wrapper_cmd); } diff --git a/build_system/mod.rs b/build_system/mod.rs index b897b7fbacf..d1f8ad3e817 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -1,5 +1,5 @@ use std::env; -use std::path::PathBuf; +use std::path::{PathBuf, Path}; use std::process; mod build_backend; @@ -8,6 +8,7 @@ mod config; mod prepare; mod rustc_info; mod utils; +mod tests; fn usage() { eprintln!("Usage:"); @@ -15,6 +16,9 @@ fn usage() { eprintln!( " ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]" ); + eprintln!( + " ./y.rs test [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]" + ); } macro_rules! arg_error { @@ -25,11 +29,13 @@ macro_rules! arg_error { }}; } +#[derive(PartialEq, Debug)] enum Command { Build, + Test, } -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] pub(crate) enum SysrootKind { None, Clif, @@ -52,6 +58,7 @@ pub fn main() { process::exit(0); } Some("build") => Command::Build, + Some("test") => Command::Test, Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag), Some(command) => arg_error!("Unknown command {}", command), None => { @@ -115,14 +122,27 @@ pub fn main() { process::exit(1); } - let cg_clif_build_dir = + let cg_clif_build_dir = Path::new("target").join(&host_triple).join(&channel); + + if command == Command::Test { + // TODO: Should we also build_backend here? + tests::run_tests( + channel, + sysroot_kind, + &target_dir, + &cg_clif_build_dir, + &host_triple, + &target_triple, + ).expect("Failed to run tests"); + } else { build_backend::build_backend(channel, &host_triple, use_unstable_features); - build_sysroot::build_sysroot( - channel, - sysroot_kind, - &target_dir, - cg_clif_build_dir, - &host_triple, - &target_triple, - ); + build_sysroot::build_sysroot( + channel, + sysroot_kind, + &target_dir, + &cg_clif_build_dir, + &host_triple, + &target_triple, + ); + } } diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 8bb00352d3f..7e0fd182d98 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -50,8 +50,7 @@ pub(crate) fn prepare() { spawn_and_wait(build_cmd); fs::copy( Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin")), - // FIXME use get_file_name here too once testing is migrated to rust - "simple-raytracer/raytracer_cg_llvm", + Path::new("simple-raytracer").join(get_file_name("raytracer_cg_llvm", "bin")), ) .unwrap(); } diff --git a/build_system/tests.rs b/build_system/tests.rs new file mode 100644 index 00000000000..74e4b51095f --- /dev/null +++ b/build_system/tests.rs @@ -0,0 +1,504 @@ +use super::build_sysroot; +use super::config; +use super::utils::{spawn_and_wait, spawn_and_wait_with_input}; +use build_system::SysrootKind; +use std::env; +use std::ffi::OsStr; +use std::fs; +use std::path::{Path, PathBuf}; +use std::process::Command; + +type Result = std::result::Result>; + +struct TestCase { + config: &'static str, + func: &'static dyn Fn(&TestRunner), +} + +impl TestCase { + const fn new(config: &'static str, func: &'static dyn Fn(&TestRunner)) -> Self { + Self { config, func } + } +} + +const NO_SYSROOT_SUITE: &[TestCase] = &[ + TestCase::new("build.mini_core", &|runner| { + runner.run_rustc(["example/mini_core.rs", "--crate-name", "mini_core", "--crate-type", "lib,dylib", "--target", &runner.target_triple]); + }), + + TestCase::new("build.example", &|runner| { + runner.run_rustc(["example/example.rs", "--crate-type", "lib", "--target", &runner.target_triple]); + }), + + TestCase::new("jit.mini_core_hello_world", &|runner| { + let mut jit_cmd = runner.rustc_command(["-Zunstable-options", "-Cllvm-args=mode=jit", "-Cprefer-dynamic", "example/mini_core_hello_world.rs", "--cfg", "jit", "--target", &runner.host_triple]); + jit_cmd.env("CG_CLIF_JIT_ARGS", "abc bcd"); + spawn_and_wait(jit_cmd); + + eprintln!("[JIT-lazy] mini_core_hello_world"); + let mut jit_cmd = runner.rustc_command(["-Zunstable-options", "-Cllvm-args=mode=jit-lazy", "-Cprefer-dynamic", "example/mini_core_hello_world.rs", "--cfg", "jit", "--target", &runner.host_triple]); + jit_cmd.env("CG_CLIF_JIT_ARGS", "abc bcd"); + spawn_and_wait(jit_cmd); + }), + + TestCase::new("aot.mini_core_hello_world", &|runner| { + runner.run_rustc(["example/mini_core_hello_world.rs", "--crate-name", "mini_core_hello_world", "--crate-type", "bin", "-g", "--target", &runner.target_triple]); + runner.run_out_command("mini_core_hello_world", ["abc", "bcd"]); + }), +]; + + +const BASE_SYSROOT_SUITE: &[TestCase] = &[ + TestCase::new("aot.arbitrary_self_types_pointers_and_wrappers", &|runner| { + runner.run_rustc(["example/arbitrary_self_types_pointers_and_wrappers.rs", "--crate-name", "arbitrary_self_types_pointers_and_wrappers", "--crate-type", "bin", "--target", &runner.target_triple]); + runner.run_out_command("arbitrary_self_types_pointers_and_wrappers", []); + }), + + TestCase::new("aot.issue_91827_extern_types", &|runner| { + runner.run_rustc(["example/issue-91827-extern-types.rs", "--crate-name", "issue_91827_extern_types", "--crate-type", "bin", "--target", &runner.target_triple]); + runner.run_out_command("issue_91827_extern_types", []); + }), + + TestCase::new("build.alloc_system", &|runner| { + runner.run_rustc(["example/alloc_system.rs", "--crate-type", "lib", "--target", &runner.target_triple]); + }), + + TestCase::new("aot.alloc_example", &|runner| { + runner.run_rustc(["example/alloc_example.rs", "--crate-type", "bin", "--target", &runner.target_triple]); + runner.run_out_command("alloc_example", []); + }), + + TestCase::new("jit.std_example", &|runner| { + runner.run_rustc(["-Zunstable-options", "-Cllvm-args=mode=jit", "-Cprefer-dynamic", "example/std_example.rs", "--target", &runner.host_triple]); + + eprintln!("[JIT-lazy] std_example"); + runner.run_rustc(["-Zunstable-options", "-Cllvm-args=mode=jit-lazy", "-Cprefer-dynamic", "example/std_example.rs", "--target", &runner.host_triple]); + }), + + TestCase::new("aot.std_example", &|runner| { + runner.run_rustc(["example/std_example.rs", "--crate-type", "bin", "--target", &runner.target_triple]); + runner.run_out_command("std_example", ["arg"]); + }), + + TestCase::new("aot.dst_field_align", &|runner| { + runner.run_rustc(["example/dst-field-align.rs", "--crate-name", "dst_field_align", "--crate-type", "bin", "--target", &runner.target_triple]); + runner.run_out_command("dst_field_align", []); + }), + + TestCase::new("aot.subslice-patterns-const-eval", &|runner| { + runner.run_rustc(["example/subslice-patterns-const-eval.rs", "--crate-type", "bin", "-Cpanic=abort", "--target", &runner.target_triple]); + runner.run_out_command("subslice-patterns-const-eval", []); + }), + + TestCase::new("aot.track-caller-attribute", &|runner| { + runner.run_rustc(["example/track-caller-attribute.rs", "--crate-type", "bin", "-Cpanic=abort", "--target", &runner.target_triple]); + runner.run_out_command("track-caller-attribute", []); + }), + + TestCase::new("aot.float-minmax-pass", &|runner| { + runner.run_rustc(["example/float-minmax-pass.rs", "--crate-type", "bin", "-Cpanic=abort", "--target", &runner.target_triple]); + runner.run_out_command("float-minmax-pass", []); + }), + + TestCase::new("aot.mod_bench", &|runner| { + runner.run_rustc(["example/mod_bench.rs", "--crate-type", "bin", "--target", &runner.target_triple]); + runner.run_out_command("mod_bench", []); + }), +]; + +const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ + TestCase::new("test.rust-random/rand", &|runner| { + runner.in_dir(["rand"], |runner| { + runner.run_cargo(["clean"]); + + if runner.host_triple == runner.target_triple { + eprintln!("[TEST] rust-random/rand"); + runner.run_cargo(["test", "--workspace"]); + } else { + eprintln!("[AOT] rust-random/rand"); + runner.run_cargo(["build", "--workspace", "--target", &runner.target_triple, "--tests"]); + } + }); + }), + + TestCase::new("bench.simple-raytracer", &|runner| { + runner.in_dir(["simple-raytracer"], |runner| { + let run_runs = env::var("RUN_RUNS").unwrap_or("10".to_string()); + + if runner.host_triple == runner.target_triple { + eprintln!("[BENCH COMPILE] ebobby/simple-raytracer"); + let mut bench_compile = Command::new("hyperfine"); + bench_compile.arg("--runs"); + bench_compile.arg(&run_runs); + bench_compile.arg("--warmup"); + bench_compile.arg("1"); + bench_compile.arg("--prepare"); + bench_compile.arg(format!("{:?}", runner.cargo_command(["clean"]))); + + if cfg!(windows) { + bench_compile.arg("cmd /C \"set RUSTFLAGS= && cargo build\""); + } else { + bench_compile.arg("RUSTFLAGS='' cargo build"); + } + + bench_compile.arg(format!("{:?}", runner.cargo_command(["build"]))); + spawn_and_wait(bench_compile); + + + + eprintln!("[BENCH RUN] ebobby/simple-raytracer"); + fs::copy(PathBuf::from("./target/debug/main"), PathBuf::from("raytracer_cg_clif")).unwrap(); + + let mut bench_run = Command::new("hyperfine"); + bench_run.arg("--runs"); + bench_run.arg(&run_runs); + bench_run.arg(PathBuf::from("./raytracer_cg_llvm")); + bench_run.arg(PathBuf::from("./raytracer_cg_clif")); + spawn_and_wait(bench_run); + } else { + runner.run_cargo(["clean"]); + eprintln!("[BENCH COMPILE] ebobby/simple-raytracer (skipped)"); + eprintln!("[COMPILE] ebobby/simple-raytracer"); + runner.run_cargo(["build", "--target", &runner.target_triple]); + eprintln!("[BENCH RUN] ebobby/simple-raytracer (skipped)"); + } + }); + }), + + TestCase::new("test.libcore", &|runner| { + runner.in_dir(["build_sysroot", "sysroot_src", "library", "core", "tests"], |runner| { + runner.run_cargo(["clean"]); + + if runner.host_triple == runner.target_triple { + runner.run_cargo(["test"]); + } else { + eprintln!("Cross-Compiling: Not running tests"); + runner.run_cargo(["build", "--target", &runner.target_triple, "--tests"]); + } + }); + }), + + TestCase::new("test.regex-shootout-regex-dna", &|runner| { + runner.in_dir(["regex"], |runner| { + runner.run_cargo(["clean"]); + + // newer aho_corasick versions throw a deprecation warning + let mut lint_rust_flags = runner.rust_flags.clone(); + lint_rust_flags.push("--cap-lints".to_string()); + lint_rust_flags.push("warn".to_string()); + + let mut build_cmd = runner.cargo_command(["build", "--example", "shootout-regex-dna", "--target", &runner.target_triple]); + build_cmd.env("RUSTFLAGS", lint_rust_flags.join(" ")); + + spawn_and_wait(build_cmd); + + if runner.host_triple == runner.target_triple { + let mut run_cmd = runner.cargo_command(["run", "--example", "shootout-regex-dna", "--target", &runner.target_triple]); + run_cmd.env("RUSTFLAGS", lint_rust_flags.join(" ")); + + + let input = fs::read_to_string(PathBuf::from("examples/regexdna-input.txt")).unwrap(); + let expected_path = PathBuf::from("examples/regexdna-output.txt"); + let expected = fs::read_to_string(&expected_path).unwrap(); + + let output = spawn_and_wait_with_input(run_cmd, input); + // Make sure `[codegen mono items] start` doesn't poison the diff + let output = output.lines() + .filter(|line| !line.contains("codegen mono items")) + .filter(|line| !line.contains("Spawned thread")) + .chain(Some("")) // This just adds the trailing newline + .collect::>() + .join("\r\n"); + + + if output != expected { + let res_path = PathBuf::from("res.txt"); + fs::write(&res_path, &output).unwrap(); + + if cfg!(windows) { + println!("Output files don't match!"); + println!("Expected Output:\n{}", expected); + println!("Actual Output:\n{}", output); + } else { + let mut diff = Command::new("diff"); + diff.arg("-u"); + diff.arg(res_path); + diff.arg(expected_path); + spawn_and_wait(diff); + } + + std::process::exit(1); + } + } + }); + }), + + TestCase::new("test.regex", &|runner| { + runner.in_dir(["regex"], |runner| { + runner.run_cargo(["clean"]); + + if runner.host_triple == runner.target_triple { + runner.run_cargo(["test", "--tests", "--", "--exclude-should-panic", "--test-threads", "1", "-Zunstable-options", "-q"]); + } else { + eprintln!("Cross-Compiling: Not running tests"); + runner.run_cargo(["build", "--tests", "--target", &runner.target_triple]); + } + }); + }), + + TestCase::new("test.portable-simd", &|runner| { + runner.in_dir(["portable-simd"], |runner| { + runner.run_cargo(["clean"]); + runner.run_cargo(["build", "--all-targets", "--target", &runner.target_triple]); + + if runner.host_triple == runner.target_triple { + runner.run_cargo(["test", "-q"]); + } + }); + }), +]; + + + +pub(crate) fn run_tests( + channel: &str, + sysroot_kind: SysrootKind, + target_dir: &Path, + cg_clif_build_dir: &Path, + host_triple: &str, + target_triple: &str, +) -> Result<()> { + let runner = TestRunner::new(host_triple.to_string(), target_triple.to_string()); + + if config::get_bool("testsuite.no_sysroot") { + build_sysroot::build_sysroot( + channel, + SysrootKind::None, + &target_dir, + cg_clif_build_dir, + &host_triple, + &target_triple, + ); + + let _ = remove_out_dir(); + runner.run_testsuite(NO_SYSROOT_SUITE); + } else { + eprintln!("[SKIP] no_sysroot tests"); + } + + let run_base_sysroot = config::get_bool("testsuite.base_sysroot"); + let run_extended_sysroot = config::get_bool("testsuite.extended_sysroot"); + + if run_base_sysroot || run_extended_sysroot { + build_sysroot::build_sysroot( + channel, + sysroot_kind, + &target_dir, + cg_clif_build_dir, + &host_triple, + &target_triple, + ); + } + + if run_base_sysroot { + runner.run_testsuite(BASE_SYSROOT_SUITE); + } else { + eprintln!("[SKIP] base_sysroot tests"); + } + + if run_extended_sysroot { + runner.run_testsuite(EXTENDED_SYSROOT_SUITE); + } else { + eprintln!("[SKIP] extended_sysroot tests"); + } + + Ok(()) +} + + +fn remove_out_dir() -> Result<()> { + let out_dir = Path::new("target").join("out"); + Ok(fs::remove_dir_all(out_dir)?) +} + +struct TestRunner { + root_dir: PathBuf, + out_dir: PathBuf, + jit_supported: bool, + rust_flags: Vec, + run_wrapper: Vec, + host_triple: String, + target_triple: String, +} + +impl TestRunner { + pub fn new(host_triple: String, target_triple: String) -> Self { + let root_dir = env::current_dir().unwrap(); + + let mut out_dir = root_dir.clone(); + out_dir.push("target"); + out_dir.push("out"); + + let is_native = host_triple == target_triple; + let jit_supported = target_triple.contains("x86_64") && is_native; + + let env_rust_flags = env::var("RUSTFLAGS").ok(); + let env_run_wrapper = env::var("RUN_WRAPPER").ok(); + + let mut rust_flags: Vec<&str> = env_rust_flags.iter().map(|s| s.as_str()).collect(); + let mut run_wrapper: Vec<&str> = env_run_wrapper.iter().map(|s| s.as_str()).collect(); + + if !is_native { + match target_triple.as_str() { + "aarch64-unknown-linux-gnu" => { + // We are cross-compiling for aarch64. Use the correct linker and run tests in qemu. + rust_flags.insert(0, "-Clinker=aarch64-linux-gnu-gcc"); + run_wrapper.extend(["qemu-aarch64", "-L", "/usr/aarch64-linux-gnu"]); + }, + "x86_64-pc-windows-gnu" => { + // We are cross-compiling for Windows. Run tests in wine. + run_wrapper.push("wine".into()); + } + _ => { + println!("Unknown non-native platform"); + } + } + } + + // FIXME fix `#[linkage = "extern_weak"]` without this + if host_triple.contains("darwin") { + rust_flags.push("-Clink-arg=-undefined"); + rust_flags.push("-Clink-arg=dynamic_lookup"); + } + + Self { + root_dir, + out_dir, + jit_supported, + rust_flags: rust_flags.iter().map(|s| s.to_string()).collect(), + run_wrapper: run_wrapper.iter().map(|s| s.to_string()).collect(), + host_triple, + target_triple, + } + } + + pub fn run_testsuite(&self, tests: &[TestCase]) { + for &TestCase { config, func } in tests { + let is_jit_test = config.contains("jit"); + let (tag, testname) = config.split_once('.').unwrap(); + let tag = tag.to_uppercase(); + + if !config::get_bool(config) || (is_jit_test && !self.jit_supported) { + eprintln!("[{tag}] {testname} (skipped)"); + continue; + } else { + eprintln!("[{tag}] {testname}"); + } + + func(self); + } + } + + fn in_dir<'a, I, F>(&self, dir: I, callback: F) + where + I: IntoIterator, + F: FnOnce(&TestRunner), + { + let current = env::current_dir().unwrap(); + let mut new = current.clone(); + for d in dir { + new.push(d); + } + + env::set_current_dir(new).unwrap(); + callback(self); + env::set_current_dir(current).unwrap(); + } + + fn rustc_command(&self, args: I) -> Command + where + I: IntoIterator, + S: AsRef, + { + let mut rustc_clif = self.root_dir.clone(); + rustc_clif.push("build"); + rustc_clif.push("rustc-clif"); + if cfg!(windows) { + rustc_clif.set_extension("exe"); + } + + let mut cmd = Command::new(rustc_clif); + cmd.args(self.rust_flags.iter()); + cmd.arg("-L"); + cmd.arg(format!("crate={}", self.out_dir.display())); + cmd.arg("--out-dir"); + cmd.arg(format!("{}", self.out_dir.display())); + cmd.arg("-Cdebuginfo=2"); + cmd.args(args); + cmd.env("RUSTFLAGS", self.rust_flags.join(" ")); + cmd + } + + fn run_rustc(&self, args: I) + where + I: IntoIterator, + S: AsRef, + { + spawn_and_wait(self.rustc_command(args)); + } + + fn run_out_command<'a, I>(&self, name: &str, args: I) + where + I: IntoIterator, + { + let mut full_cmd = vec![]; + + // Prepend the RUN_WRAPPER's + for rw in self.run_wrapper.iter() { + full_cmd.push(rw.to_string()); + } + + full_cmd.push({ + let mut out_path = self.out_dir.clone(); + out_path.push(name); + out_path.to_str().unwrap().to_string() + }); + + for arg in args.into_iter() { + full_cmd.push(arg.to_string()); + } + + let mut cmd_iter = full_cmd.into_iter(); + let first = cmd_iter.next().unwrap(); + + let mut cmd = Command::new(first); + cmd.args(cmd_iter); + + spawn_and_wait(cmd); + } + + fn cargo_command(&self, args: I) -> Command + where + I: IntoIterator, + S: AsRef, + { + let mut cargo_clif = self.root_dir.clone(); + cargo_clif.push("build"); + cargo_clif.push("cargo-clif"); + if cfg!(windows) { + cargo_clif.set_extension("exe"); + } + + let mut cmd = Command::new(cargo_clif); + cmd.args(args); + cmd.env("RUSTFLAGS", self.rust_flags.join(" ")); + cmd + } + + fn run_cargo<'a, I>(&self, args: I) + where + I: IntoIterator, + { + spawn_and_wait(self.cargo_command(args)); + } +} diff --git a/build_system/utils.rs b/build_system/utils.rs index 12b5d70fad8..2d2778d2fc0 100644 --- a/build_system/utils.rs +++ b/build_system/utils.rs @@ -1,6 +1,7 @@ use std::fs; use std::path::Path; -use std::process::{self, Command}; +use std::process::{self, Command, Stdio}; +use std::io::Write; #[track_caller] pub(crate) fn try_hard_link(src: impl AsRef, dst: impl AsRef) { @@ -18,6 +19,27 @@ pub(crate) fn spawn_and_wait(mut cmd: Command) { } } +#[track_caller] +pub(crate) fn spawn_and_wait_with_input(mut cmd: Command, input: String) -> String { + let mut child = cmd + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn() + .expect("Failed to spawn child process"); + + let mut stdin = child.stdin.take().expect("Failed to open stdin"); + std::thread::spawn(move || { + stdin.write_all(input.as_bytes()).expect("Failed to write to stdin"); + }); + + let output = child.wait_with_output().expect("Failed to read stdout"); + if !output.status.success() { + process::exit(1); + } + + String::from_utf8(output.stdout).unwrap() +} + pub(crate) fn copy_dir_recursively(from: &Path, to: &Path) { for entry in fs::read_dir(from).unwrap() { let entry = entry.unwrap(); diff --git a/config.txt b/config.txt index b14db27d620..5e4d230776d 100644 --- a/config.txt +++ b/config.txt @@ -15,3 +15,36 @@ # This option can be changed while the build system is already running for as long as sysroot # building hasn't started yet. #keep_sysroot + + +# Testsuite +# +# Each test suite item has a corresponding key here. The default is to run all tests. +# Comment any of these lines to skip individual tests. + +testsuite.no_sysroot +build.mini_core +build.example +jit.mini_core_hello_world +aot.mini_core_hello_world + +testsuite.base_sysroot +aot.arbitrary_self_types_pointers_and_wrappers +aot.issue_91827_extern_types +build.alloc_system +aot.alloc_example +jit.std_example +aot.std_example +aot.dst_field_align +aot.subslice-patterns-const-eval +aot.track-caller-attribute +aot.float-minmax-pass +aot.mod_bench + +testsuite.extended_sysroot +test.rust-random/rand +bench.simple-raytracer +test.libcore +test.regex-shootout-regex-dna +test.regex +test.portable-simd diff --git a/scripts/tests.sh b/scripts/tests.sh deleted file mode 100755 index 9b5ffa40960..00000000000 --- a/scripts/tests.sh +++ /dev/null @@ -1,203 +0,0 @@ -#!/usr/bin/env bash - -set -e - -export CG_CLIF_DISPLAY_CG_TIME=1 -export CG_CLIF_DISABLE_INCR_CACHE=1 - -export HOST_TRIPLE=$(rustc -vV | grep host | cut -d: -f2 | tr -d " ") -export TARGET_TRIPLE=${TARGET_TRIPLE:-$HOST_TRIPLE} - -export RUN_WRAPPER='' - -case "$TARGET_TRIPLE" in - x86_64*) - export JIT_SUPPORTED=1 - ;; - *) - export JIT_SUPPORTED=0 - ;; -esac - -if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then - export JIT_SUPPORTED=0 - if [[ "$TARGET_TRIPLE" == "aarch64-unknown-linux-gnu" ]]; then - # We are cross-compiling for aarch64. Use the correct linker and run tests in qemu. - export RUSTFLAGS='-Clinker=aarch64-linux-gnu-gcc '$RUSTFLAGS - export RUN_WRAPPER='qemu-aarch64 -L /usr/aarch64-linux-gnu' - elif [[ "$TARGET_TRIPLE" == "x86_64-pc-windows-gnu" ]]; then - # We are cross-compiling for Windows. Run tests in wine. - export RUN_WRAPPER='wine' - else - echo "Unknown non-native platform" - fi -fi - -# FIXME fix `#[linkage = "extern_weak"]` without this -if [[ "$(uname)" == 'Darwin' ]]; then - export RUSTFLAGS="$RUSTFLAGS -Clink-arg=-undefined -Clink-arg=dynamic_lookup" -fi - -MY_RUSTC="$(pwd)/build/rustc-clif $RUSTFLAGS -L crate=target/out --out-dir target/out -Cdebuginfo=2" - -function no_sysroot_tests() { - echo "[BUILD] mini_core" - $MY_RUSTC example/mini_core.rs --crate-name mini_core --crate-type lib,dylib --target "$TARGET_TRIPLE" - - echo "[BUILD] example" - $MY_RUSTC example/example.rs --crate-type lib --target "$TARGET_TRIPLE" - - if [[ "$JIT_SUPPORTED" = "1" ]]; then - echo "[JIT] mini_core_hello_world" - CG_CLIF_JIT_ARGS="abc bcd" $MY_RUSTC -Zunstable-options -Cllvm-args=mode=jit -Cprefer-dynamic example/mini_core_hello_world.rs --cfg jit --target "$HOST_TRIPLE" - - echo "[JIT-lazy] mini_core_hello_world" - CG_CLIF_JIT_ARGS="abc bcd" $MY_RUSTC -Zunstable-options -Cllvm-args=mode=jit-lazy -Cprefer-dynamic example/mini_core_hello_world.rs --cfg jit --target "$HOST_TRIPLE" - else - echo "[JIT] mini_core_hello_world (skipped)" - fi - - echo "[AOT] mini_core_hello_world" - $MY_RUSTC example/mini_core_hello_world.rs --crate-name mini_core_hello_world --crate-type bin -g --target "$TARGET_TRIPLE" - $RUN_WRAPPER ./target/out/mini_core_hello_world abc bcd - # (echo "break set -n main"; echo "run"; sleep 1; echo "si -c 10"; sleep 1; echo "frame variable") | lldb -- ./target/out/mini_core_hello_world abc bcd -} - -function base_sysroot_tests() { - echo "[AOT] arbitrary_self_types_pointers_and_wrappers" - $MY_RUSTC example/arbitrary_self_types_pointers_and_wrappers.rs --crate-name arbitrary_self_types_pointers_and_wrappers --crate-type bin --target "$TARGET_TRIPLE" - $RUN_WRAPPER ./target/out/arbitrary_self_types_pointers_and_wrappers - - echo "[AOT] issue_91827_extern_types" - $MY_RUSTC example/issue-91827-extern-types.rs --crate-name issue_91827_extern_types --crate-type bin --target "$TARGET_TRIPLE" - $RUN_WRAPPER ./target/out/issue_91827_extern_types - - echo "[BUILD] alloc_system" - $MY_RUSTC example/alloc_system.rs --crate-type lib --target "$TARGET_TRIPLE" - - echo "[AOT] alloc_example" - $MY_RUSTC example/alloc_example.rs --crate-type bin --target "$TARGET_TRIPLE" - $RUN_WRAPPER ./target/out/alloc_example - - if [[ "$JIT_SUPPORTED" = "1" ]]; then - echo "[JIT] std_example" - $MY_RUSTC -Zunstable-options -Cllvm-args=mode=jit -Cprefer-dynamic example/std_example.rs --target "$HOST_TRIPLE" - - echo "[JIT-lazy] std_example" - $MY_RUSTC -Zunstable-options -Cllvm-args=mode=jit-lazy -Cprefer-dynamic example/std_example.rs --target "$HOST_TRIPLE" - else - echo "[JIT] std_example (skipped)" - fi - - echo "[AOT] std_example" - $MY_RUSTC example/std_example.rs --crate-type bin --target "$TARGET_TRIPLE" - $RUN_WRAPPER ./target/out/std_example arg - - echo "[AOT] dst_field_align" - $MY_RUSTC example/dst-field-align.rs --crate-name dst_field_align --crate-type bin --target "$TARGET_TRIPLE" - $RUN_WRAPPER ./target/out/dst_field_align - - echo "[AOT] subslice-patterns-const-eval" - $MY_RUSTC example/subslice-patterns-const-eval.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE" - $RUN_WRAPPER ./target/out/subslice-patterns-const-eval - - echo "[AOT] track-caller-attribute" - $MY_RUSTC example/track-caller-attribute.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE" - $RUN_WRAPPER ./target/out/track-caller-attribute - - echo "[AOT] float-minmax-pass" - $MY_RUSTC example/float-minmax-pass.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE" - $RUN_WRAPPER ./target/out/float-minmax-pass - - echo "[AOT] mod_bench" - $MY_RUSTC example/mod_bench.rs --crate-type bin --target "$TARGET_TRIPLE" - $RUN_WRAPPER ./target/out/mod_bench -} - -function extended_sysroot_tests() { - pushd rand - ../build/cargo-clif clean - if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then - echo "[TEST] rust-random/rand" - ../build/cargo-clif test --workspace - else - echo "[AOT] rust-random/rand" - ../build/cargo-clif build --workspace --target $TARGET_TRIPLE --tests - fi - popd - - pushd simple-raytracer - if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then - echo "[BENCH COMPILE] ebobby/simple-raytracer" - hyperfine --runs "${RUN_RUNS:-10}" --warmup 1 --prepare "../build/cargo-clif clean" \ - "RUSTFLAGS='' cargo build" \ - "../build/cargo-clif build" - - echo "[BENCH RUN] ebobby/simple-raytracer" - cp ./target/debug/main ./raytracer_cg_clif - hyperfine --runs "${RUN_RUNS:-10}" ./raytracer_cg_llvm ./raytracer_cg_clif - else - ../build/cargo-clif clean - echo "[BENCH COMPILE] ebobby/simple-raytracer (skipped)" - echo "[COMPILE] ebobby/simple-raytracer" - ../build/cargo-clif build --target $TARGET_TRIPLE - echo "[BENCH RUN] ebobby/simple-raytracer (skipped)" - fi - popd - - pushd build_sysroot/sysroot_src/library/core/tests - echo "[TEST] libcore" - ../../../../../build/cargo-clif clean - if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then - ../../../../../build/cargo-clif test - else - ../../../../../build/cargo-clif build --target $TARGET_TRIPLE --tests - fi - popd - - pushd regex - echo "[TEST] rust-lang/regex example shootout-regex-dna" - ../build/cargo-clif clean - export RUSTFLAGS="$RUSTFLAGS --cap-lints warn" # newer aho_corasick versions throw a deprecation warning - # Make sure `[codegen mono items] start` doesn't poison the diff - ../build/cargo-clif build --example shootout-regex-dna --target $TARGET_TRIPLE - if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then - cat examples/regexdna-input.txt \ - | ../build/cargo-clif run --example shootout-regex-dna --target $TARGET_TRIPLE \ - | grep -v "Spawned thread" > res.txt - diff -u res.txt examples/regexdna-output.txt - fi - - if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then - echo "[TEST] rust-lang/regex tests" - ../build/cargo-clif test --tests -- --exclude-should-panic --test-threads 1 -Zunstable-options -q - else - echo "[AOT] rust-lang/regex tests" - ../build/cargo-clif build --tests --target $TARGET_TRIPLE - fi - popd - - pushd portable-simd - echo "[TEST] rust-lang/portable-simd" - ../build/cargo-clif clean - ../build/cargo-clif build --all-targets --target $TARGET_TRIPLE - if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then - ../build/cargo-clif test -q - fi - popd -} - -case "$1" in - "no_sysroot") - no_sysroot_tests - ;; - "base_sysroot") - base_sysroot_tests - ;; - "extended_sysroot") - extended_sysroot_tests - ;; - *) - echo "unknown test suite" - ;; -esac diff --git a/test.sh b/test.sh deleted file mode 100755 index a10924628bb..00000000000 --- a/test.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -set -e - -./y.rs build --sysroot none "$@" - -rm -r target/out || true - -scripts/tests.sh no_sysroot - -./y.rs build "$@" - -scripts/tests.sh base_sysroot -scripts/tests.sh extended_sysroot From c115933fb7be123b6dacc6e95cb87ae44e6d5296 Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 30 Jul 2022 12:48:46 +0100 Subject: [PATCH 03/18] Run tests on windows CI --- .github/workflows/main.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a36c570ddc8..1a947d3551c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -159,19 +159,21 @@ jobs: ./y.exe prepare - name: Build - #name: Test + run: ./y.exe build + + - name: Test run: | # Enable backtraces for easier debugging - #export RUST_BACKTRACE=1 + export RUST_BACKTRACE=1 # Reduce amount of benchmark runs as they are slow - #export COMPILE_RUNS=2 - #export RUN_RUNS=2 + export COMPILE_RUNS=2 + export RUN_RUNS=2 # Enable extra checks - #export CG_CLIF_ENABLE_VERIFIER=1 + export CG_CLIF_ENABLE_VERIFIER=1 - ./y.exe build + ./y.exe test - name: Package prebuilt cg_clif # don't use compression as xzip isn't supported by tar on windows and bzip2 hangs From d0599350a742dfee6f1ff9e60ac91fc2b673a972 Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 30 Jul 2022 12:50:05 +0100 Subject: [PATCH 04/18] Misc cleanups to the test runner --- build_system/build_backend.rs | 5 ++- build_system/mod.rs | 45 +++++++++++++------------- build_system/tests.rs | 59 ++++++++++++++--------------------- 3 files changed, 50 insertions(+), 59 deletions(-) diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index 04f8be6f820..ddc099b5388 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -1,11 +1,12 @@ use std::env; +use std::path::{Path, PathBuf}; use std::process::Command; pub(crate) fn build_backend( channel: &str, host_triple: &str, use_unstable_features: bool, -) { +) -> PathBuf { let mut cmd = Command::new("cargo"); cmd.arg("build").arg("--target").arg(host_triple); @@ -37,4 +38,6 @@ pub(crate) fn build_backend( eprintln!("[BUILD] rustc_codegen_cranelift"); super::utils::spawn_and_wait(cmd); + + Path::new("target").join(&host_triple).join(&channel) } diff --git a/build_system/mod.rs b/build_system/mod.rs index d1f8ad3e817..af75cef04e0 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -1,5 +1,5 @@ use std::env; -use std::path::{PathBuf, Path}; +use std::path::PathBuf; use std::process; mod build_backend; @@ -122,27 +122,28 @@ pub fn main() { process::exit(1); } - let cg_clif_build_dir = Path::new("target").join(&host_triple).join(&channel); + let cg_clif_build_dir = build_backend::build_backend(channel, &host_triple, use_unstable_features); - if command == Command::Test { - // TODO: Should we also build_backend here? - tests::run_tests( - channel, - sysroot_kind, - &target_dir, - &cg_clif_build_dir, - &host_triple, - &target_triple, - ).expect("Failed to run tests"); - } else { - build_backend::build_backend(channel, &host_triple, use_unstable_features); - build_sysroot::build_sysroot( - channel, - sysroot_kind, - &target_dir, - &cg_clif_build_dir, - &host_triple, - &target_triple, - ); + match command { + Command::Test => { + tests::run_tests( + channel, + sysroot_kind, + &target_dir, + &cg_clif_build_dir, + &host_triple, + &target_triple, + ); + }, + Command::Build => { + build_sysroot::build_sysroot( + channel, + sysroot_kind, + &target_dir, + &cg_clif_build_dir, + &host_triple, + &target_triple, + ); + } } } diff --git a/build_system/tests.rs b/build_system/tests.rs index 74e4b51095f..f2166b20fcb 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -8,8 +8,6 @@ use std::fs; use std::path::{Path, PathBuf}; use std::process::Command; -type Result = std::result::Result>; - struct TestCase { config: &'static str, func: &'static dyn Fn(&TestRunner), @@ -183,18 +181,16 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ runner.run_cargo(["clean"]); // newer aho_corasick versions throw a deprecation warning - let mut lint_rust_flags = runner.rust_flags.clone(); - lint_rust_flags.push("--cap-lints".to_string()); - lint_rust_flags.push("warn".to_string()); + let lint_rust_flags = format!("{} --cap-lints warn", runner.rust_flags); let mut build_cmd = runner.cargo_command(["build", "--example", "shootout-regex-dna", "--target", &runner.target_triple]); - build_cmd.env("RUSTFLAGS", lint_rust_flags.join(" ")); + build_cmd.env("RUSTFLAGS", lint_rust_flags.clone()); spawn_and_wait(build_cmd); if runner.host_triple == runner.target_triple { let mut run_cmd = runner.cargo_command(["run", "--example", "shootout-regex-dna", "--target", &runner.target_triple]); - run_cmd.env("RUSTFLAGS", lint_rust_flags.join(" ")); + run_cmd.env("RUSTFLAGS", lint_rust_flags); let input = fs::read_to_string(PathBuf::from("examples/regexdna-input.txt")).unwrap(); @@ -205,7 +201,6 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ // Make sure `[codegen mono items] start` doesn't poison the diff let output = output.lines() .filter(|line| !line.contains("codegen mono items")) - .filter(|line| !line.contains("Spawned thread")) .chain(Some("")) // This just adds the trailing newline .collect::>() .join("\r\n"); @@ -267,7 +262,7 @@ pub(crate) fn run_tests( cg_clif_build_dir: &Path, host_triple: &str, target_triple: &str, -) -> Result<()> { +) { let runner = TestRunner::new(host_triple.to_string(), target_triple.to_string()); if config::get_bool("testsuite.no_sysroot") { @@ -280,7 +275,7 @@ pub(crate) fn run_tests( &target_triple, ); - let _ = remove_out_dir(); + let _ = fs::remove_dir_all(Path::new("target").join("out")); runner.run_testsuite(NO_SYSROOT_SUITE); } else { eprintln!("[SKIP] no_sysroot tests"); @@ -311,22 +306,16 @@ pub(crate) fn run_tests( } else { eprintln!("[SKIP] extended_sysroot tests"); } - - Ok(()) } -fn remove_out_dir() -> Result<()> { - let out_dir = Path::new("target").join("out"); - Ok(fs::remove_dir_all(out_dir)?) -} struct TestRunner { root_dir: PathBuf, out_dir: PathBuf, jit_supported: bool, - rust_flags: Vec, - run_wrapper: Vec, + rust_flags: String, + run_wrapper: String, host_triple: String, target_triple: String, } @@ -342,22 +331,19 @@ impl TestRunner { let is_native = host_triple == target_triple; let jit_supported = target_triple.contains("x86_64") && is_native; - let env_rust_flags = env::var("RUSTFLAGS").ok(); - let env_run_wrapper = env::var("RUN_WRAPPER").ok(); - - let mut rust_flags: Vec<&str> = env_rust_flags.iter().map(|s| s.as_str()).collect(); - let mut run_wrapper: Vec<&str> = env_run_wrapper.iter().map(|s| s.as_str()).collect(); + let mut rust_flags = env::var("RUSTFLAGS").ok().unwrap_or("".to_string()); + let mut run_wrapper = String::new(); if !is_native { match target_triple.as_str() { "aarch64-unknown-linux-gnu" => { // We are cross-compiling for aarch64. Use the correct linker and run tests in qemu. - rust_flags.insert(0, "-Clinker=aarch64-linux-gnu-gcc"); - run_wrapper.extend(["qemu-aarch64", "-L", "/usr/aarch64-linux-gnu"]); + rust_flags = format!("-Clinker=aarch64-linux-gnu-gcc {}", rust_flags); + run_wrapper = "qemu-aarch64 -L /usr/aarch64-linux-gnu".to_string(); }, "x86_64-pc-windows-gnu" => { // We are cross-compiling for Windows. Run tests in wine. - run_wrapper.push("wine".into()); + run_wrapper = "wine".to_string(); } _ => { println!("Unknown non-native platform"); @@ -367,16 +353,15 @@ impl TestRunner { // FIXME fix `#[linkage = "extern_weak"]` without this if host_triple.contains("darwin") { - rust_flags.push("-Clink-arg=-undefined"); - rust_flags.push("-Clink-arg=dynamic_lookup"); + rust_flags = format!("{} -Clink-arg=-undefined -Clink-arg=dynamic_lookup", rust_flags); } Self { root_dir, out_dir, jit_supported, - rust_flags: rust_flags.iter().map(|s| s.to_string()).collect(), - run_wrapper: run_wrapper.iter().map(|s| s.to_string()).collect(), + rust_flags, + run_wrapper, host_triple, target_triple, } @@ -384,9 +369,9 @@ impl TestRunner { pub fn run_testsuite(&self, tests: &[TestCase]) { for &TestCase { config, func } in tests { - let is_jit_test = config.contains("jit"); let (tag, testname) = config.split_once('.').unwrap(); let tag = tag.to_uppercase(); + let is_jit_test = tag == "JIT"; if !config::get_bool(config) || (is_jit_test && !self.jit_supported) { eprintln!("[{tag}] {testname} (skipped)"); @@ -428,14 +413,16 @@ impl TestRunner { } let mut cmd = Command::new(rustc_clif); - cmd.args(self.rust_flags.iter()); + if !self.rust_flags.is_empty() { + cmd.arg(&self.rust_flags); + } cmd.arg("-L"); cmd.arg(format!("crate={}", self.out_dir.display())); cmd.arg("--out-dir"); cmd.arg(format!("{}", self.out_dir.display())); cmd.arg("-Cdebuginfo=2"); cmd.args(args); - cmd.env("RUSTFLAGS", self.rust_flags.join(" ")); + cmd.env("RUSTFLAGS", &self.rust_flags); cmd } @@ -454,8 +441,8 @@ impl TestRunner { let mut full_cmd = vec![]; // Prepend the RUN_WRAPPER's - for rw in self.run_wrapper.iter() { - full_cmd.push(rw.to_string()); + if !self.run_wrapper.is_empty() { + full_cmd.push(self.run_wrapper.clone()); } full_cmd.push({ @@ -491,7 +478,7 @@ impl TestRunner { let mut cmd = Command::new(cargo_clif); cmd.args(args); - cmd.env("RUSTFLAGS", self.rust_flags.join(" ")); + cmd.env("RUSTFLAGS", &self.rust_flags); cmd } From 437b441ff5e9fd5e9d837db1cb03529344b41db1 Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 30 Jul 2022 13:06:37 +0100 Subject: [PATCH 05/18] Use get_file_name everywhere for better cross compilation support --- build_system/build_sysroot.rs | 11 +++---- build_system/mod.rs | 61 ++++++++++++++++++----------------- build_system/prepare.rs | 6 ++-- build_system/rustc_info.rs | 4 ++- 4 files changed, 42 insertions(+), 40 deletions(-) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index dddd5a673c5..14e82a77f86 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -23,7 +23,7 @@ pub(crate) fn build_sysroot( fs::create_dir_all(target_dir.join("lib")).unwrap(); // Copy the backend - let cg_clif_dylib = get_file_name("rustc_codegen_cranelift", "dylib"); + let cg_clif_dylib = get_file_name("rustc_codegen_cranelift", "dylib", target_triple); let cg_clif_dylib_path = target_dir .join(if cfg!(windows) { // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the @@ -37,11 +37,10 @@ pub(crate) fn build_sysroot( // Build and copy rustc and cargo wrappers for wrapper in ["rustc-clif", "cargo-clif"] { - let wrapper_name = if cfg!(windows) { - format!("{wrapper}.exe") - } else { - wrapper.to_string() - }; + let crate_name = wrapper.replace('-', "_"); + let wrapper_name = get_file_name(&crate_name, "bin", target_triple); + let wrapper_name = wrapper_name.replace('_', "-"); + let mut build_cargo_wrapper_cmd = Command::new("rustc"); build_cargo_wrapper_cmd diff --git a/build_system/mod.rs b/build_system/mod.rs index af75cef04e0..0124d47de75 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -48,13 +48,42 @@ pub fn main() { // The target dir is expected in the default location. Guard against the user changing it. env::set_var("CARGO_TARGET_DIR", "target"); + + let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") { + host_triple + } else if let Some(host_triple) = config::get_value("host") { + host_triple + } else { + rustc_info::get_host_triple() + }; + let target_triple = if let Ok(target_triple) = std::env::var("TARGET_TRIPLE") { + if target_triple != "" { + target_triple + } else { + host_triple.clone() // Empty target triple can happen on GHA + } + } else if let Some(target_triple) = config::get_value("target") { + target_triple + } else { + host_triple.clone() + }; + + if target_triple.ends_with("-msvc") { + eprintln!("The MSVC toolchain is not yet supported by rustc_codegen_cranelift."); + eprintln!("Switch to the MinGW toolchain for Windows support."); + eprintln!("Hint: You can use `rustup set default-host x86_64-pc-windows-gnu` to"); + eprintln!("set the global default target to MinGW"); + // process::exit(1); + } + + let mut args = env::args().skip(1); let command = match args.next().as_deref() { Some("prepare") => { if args.next().is_some() { - arg_error!("./x.rs prepare doesn't expect arguments"); + arg_error!("./y.rs prepare doesn't expect arguments"); } - prepare::prepare(); + prepare::prepare(&target_triple); process::exit(0); } Some("build") => Command::Build, @@ -95,35 +124,7 @@ pub fn main() { } target_dir = std::env::current_dir().unwrap().join(target_dir); - let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") { - host_triple - } else if let Some(host_triple) = config::get_value("host") { - host_triple - } else { - rustc_info::get_host_triple() - }; - let target_triple = if let Ok(target_triple) = std::env::var("TARGET_TRIPLE") { - if target_triple != "" { - target_triple - } else { - host_triple.clone() // Empty target triple can happen on GHA - } - } else if let Some(target_triple) = config::get_value("target") { - target_triple - } else { - host_triple.clone() - }; - - if target_triple.ends_with("-msvc") { - eprintln!("The MSVC toolchain is not yet supported by rustc_codegen_cranelift."); - eprintln!("Switch to the MinGW toolchain for Windows support."); - eprintln!("Hint: You can use `rustup set default-host x86_64-pc-windows-gnu` to"); - eprintln!("set the global default target to MinGW"); - process::exit(1); - } - let cg_clif_build_dir = build_backend::build_backend(channel, &host_triple, use_unstable_features); - match command { Command::Test => { tests::run_tests( diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 7e0fd182d98..4580c4b6549 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -8,7 +8,7 @@ use std::process::Command; use super::rustc_info::{get_file_name, get_rustc_path, get_rustc_version}; use super::utils::{copy_dir_recursively, spawn_and_wait}; -pub(crate) fn prepare() { +pub(crate) fn prepare(target_triple: &str) { prepare_sysroot(); eprintln!("[INSTALL] hyperfine"); @@ -49,8 +49,8 @@ pub(crate) fn prepare() { build_cmd.arg("build").env_remove("CARGO_TARGET_DIR").current_dir("simple-raytracer"); spawn_and_wait(build_cmd); fs::copy( - Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin")), - Path::new("simple-raytracer").join(get_file_name("raytracer_cg_llvm", "bin")), + Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin", target_triple)), + Path::new("simple-raytracer").join(get_file_name("raytracer_cg_llvm", "bin", target_triple)), ) .unwrap(); } diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs index 9206bb02bd3..f9689eb2a8c 100644 --- a/build_system/rustc_info.rs +++ b/build_system/rustc_info.rs @@ -43,7 +43,7 @@ pub(crate) fn get_default_sysroot() -> PathBuf { Path::new(String::from_utf8(default_sysroot).unwrap().trim()).to_owned() } -pub(crate) fn get_file_name(crate_name: &str, crate_type: &str) -> String { +pub(crate) fn get_file_name(crate_name: &str, crate_type: &str, target: &str) -> String { let file_name = Command::new("rustc") .stderr(Stdio::inherit()) .args(&[ @@ -51,6 +51,8 @@ pub(crate) fn get_file_name(crate_name: &str, crate_type: &str) -> String { crate_name, "--crate-type", crate_type, + "--target", + target, "--print", "file-names", "-", From ae4fe1d57dd2a00523705f0425a82a759c9bfa3c Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 30 Jul 2022 14:07:02 +0100 Subject: [PATCH 06/18] Use get_file_name in tests --- build_system/build_sysroot.rs | 7 ++----- build_system/rustc_info.rs | 9 +++++++++ build_system/tests.rs | 11 +++-------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 14e82a77f86..cd3216cd624 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -2,7 +2,7 @@ use std::fs; use std::path::{Path, PathBuf}; use std::process::{self, Command}; -use super::rustc_info::{get_file_name, get_rustc_version}; +use super::rustc_info::{get_file_name, get_wrapper_file_name, get_rustc_version}; use super::utils::{spawn_and_wait, try_hard_link}; use super::SysrootKind; @@ -37,10 +37,7 @@ pub(crate) fn build_sysroot( // Build and copy rustc and cargo wrappers for wrapper in ["rustc-clif", "cargo-clif"] { - let crate_name = wrapper.replace('-', "_"); - let wrapper_name = get_file_name(&crate_name, "bin", target_triple); - let wrapper_name = wrapper_name.replace('_', "-"); - + let wrapper_name = get_wrapper_file_name(wrapper, "bin", target_triple); let mut build_cargo_wrapper_cmd = Command::new("rustc"); build_cargo_wrapper_cmd diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs index f9689eb2a8c..63e1d16ead6 100644 --- a/build_system/rustc_info.rs +++ b/build_system/rustc_info.rs @@ -65,3 +65,12 @@ pub(crate) fn get_file_name(crate_name: &str, crate_type: &str, target: &str) -> assert!(file_name.contains(crate_name)); file_name } + +/// Similar to `get_file_name`, but converts any dashes (`-`) in the `crate_name` to +/// underscores (`_`). This is specially made for the the rustc and cargo wrappers +/// which have a dash in the name, and that is not allowed in a crate name. +pub(crate) fn get_wrapper_file_name(crate_name: &str, crate_type: &str, target: &str) -> String { + let crate_name = crate_name.replace('-', "_"); + let wrapper_name = get_file_name(&crate_name, crate_type, target); + wrapper_name.replace('_', "-") +} diff --git a/build_system/tests.rs b/build_system/tests.rs index f2166b20fcb..20d600effd3 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -1,5 +1,6 @@ use super::build_sysroot; use super::config; +use super::rustc_info::get_wrapper_file_name; use super::utils::{spawn_and_wait, spawn_and_wait_with_input}; use build_system::SysrootKind; use std::env; @@ -407,10 +408,7 @@ impl TestRunner { { let mut rustc_clif = self.root_dir.clone(); rustc_clif.push("build"); - rustc_clif.push("rustc-clif"); - if cfg!(windows) { - rustc_clif.set_extension("exe"); - } + rustc_clif.push(get_wrapper_file_name("rustc-clif", "bin", &self.target_triple)); let mut cmd = Command::new(rustc_clif); if !self.rust_flags.is_empty() { @@ -471,10 +469,7 @@ impl TestRunner { { let mut cargo_clif = self.root_dir.clone(); cargo_clif.push("build"); - cargo_clif.push("cargo-clif"); - if cfg!(windows) { - cargo_clif.set_extension("exe"); - } + cargo_clif.push(get_wrapper_file_name("cargo-clif", "bin", &self.target_triple)); let mut cmd = Command::new(cargo_clif); cmd.args(args); From aa2f4072f60c5c129a5597cc59ad908aa502868e Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 30 Jul 2022 15:40:44 +0100 Subject: [PATCH 07/18] Use Windows Env vars in CI --- .github/workflows/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1a947d3551c..832572bcf35 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -164,14 +164,14 @@ jobs: - name: Test run: | # Enable backtraces for easier debugging - export RUST_BACKTRACE=1 + $Env:RUST_BACKTRACE=1 # Reduce amount of benchmark runs as they are slow - export COMPILE_RUNS=2 - export RUN_RUNS=2 + $Env:COMPILE_RUNS=2 + $Env:RUN_RUNS=2 # Enable extra checks - export CG_CLIF_ENABLE_VERIFIER=1 + $Env:CG_CLIF_ENABLE_VERIFIER=1 ./y.exe test From 8ec3d20882f434b9cdbca5c8ed4f3630883b32aa Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 30 Jul 2022 16:35:35 +0100 Subject: [PATCH 08/18] Fix test.regex test --- build_system/tests.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/build_system/tests.rs b/build_system/tests.rs index 20d600effd3..22c8c8a4605 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -186,7 +186,6 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ let mut build_cmd = runner.cargo_command(["build", "--example", "shootout-regex-dna", "--target", &runner.target_triple]); build_cmd.env("RUSTFLAGS", lint_rust_flags.clone()); - spawn_and_wait(build_cmd); if runner.host_triple == runner.target_triple { @@ -233,11 +232,18 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ runner.in_dir(["regex"], |runner| { runner.run_cargo(["clean"]); + // newer aho_corasick versions throw a deprecation warning + let lint_rust_flags = format!("{} --cap-lints warn", runner.rust_flags); + if runner.host_triple == runner.target_triple { - runner.run_cargo(["test", "--tests", "--", "--exclude-should-panic", "--test-threads", "1", "-Zunstable-options", "-q"]); + let mut run_cmd = runner.cargo_command(["test", "--tests", "--", "--exclude-should-panic", "--test-threads", "1", "-Zunstable-options", "-q"]); + run_cmd.env("RUSTFLAGS", lint_rust_flags); + spawn_and_wait(run_cmd); } else { eprintln!("Cross-Compiling: Not running tests"); - runner.run_cargo(["build", "--tests", "--target", &runner.target_triple]); + let mut build_cmd = runner.cargo_command(["build", "--tests", "--target", &runner.target_triple]); + build_cmd.env("RUSTFLAGS", lint_rust_flags.clone()); + spawn_and_wait(build_cmd); } }); }), From f8747f0a53dc5b1284fab7610df39f4861b311e4 Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 30 Jul 2022 20:24:04 +0100 Subject: [PATCH 09/18] Fix aarch64 cross compilation --- build_system/tests.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/build_system/tests.rs b/build_system/tests.rs index 22c8c8a4605..5c69beeaab5 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -322,7 +322,7 @@ struct TestRunner { out_dir: PathBuf, jit_supported: bool, rust_flags: String, - run_wrapper: String, + run_wrapper: Vec, host_triple: String, target_triple: String, } @@ -339,18 +339,18 @@ impl TestRunner { let jit_supported = target_triple.contains("x86_64") && is_native; let mut rust_flags = env::var("RUSTFLAGS").ok().unwrap_or("".to_string()); - let mut run_wrapper = String::new(); + let mut run_wrapper = Vec::new(); if !is_native { match target_triple.as_str() { "aarch64-unknown-linux-gnu" => { // We are cross-compiling for aarch64. Use the correct linker and run tests in qemu. - rust_flags = format!("-Clinker=aarch64-linux-gnu-gcc {}", rust_flags); - run_wrapper = "qemu-aarch64 -L /usr/aarch64-linux-gnu".to_string(); + rust_flags = format!("-Clinker=aarch64-linux-gnu-gcc{}", rust_flags); + run_wrapper = vec!["qemu-aarch64", "-L", "/usr/aarch64-linux-gnu"]; }, "x86_64-pc-windows-gnu" => { // We are cross-compiling for Windows. Run tests in wine. - run_wrapper = "wine".to_string(); + run_wrapper = vec!["wine"]; } _ => { println!("Unknown non-native platform"); @@ -368,7 +368,7 @@ impl TestRunner { out_dir, jit_supported, rust_flags, - run_wrapper, + run_wrapper: run_wrapper.iter().map(|s| s.to_string()).collect(), host_triple, target_triple, } @@ -446,7 +446,7 @@ impl TestRunner { // Prepend the RUN_WRAPPER's if !self.run_wrapper.is_empty() { - full_cmd.push(self.run_wrapper.clone()); + full_cmd.extend(self.run_wrapper.iter().cloned()); } full_cmd.push({ @@ -459,6 +459,7 @@ impl TestRunner { full_cmd.push(arg.to_string()); } + println!("full_CMD: {:?}", full_cmd); let mut cmd_iter = full_cmd.into_iter(); let first = cmd_iter.next().unwrap(); From 393613439a09c7d2c36832eb532a13f140a46552 Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 30 Jul 2022 17:16:10 +0100 Subject: [PATCH 10/18] Fix some cross compilation scenarios in test runner --- build_system/build_sysroot.rs | 4 ++-- build_system/tests.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index cd3216cd624..ed1c04808c5 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -23,7 +23,7 @@ pub(crate) fn build_sysroot( fs::create_dir_all(target_dir.join("lib")).unwrap(); // Copy the backend - let cg_clif_dylib = get_file_name("rustc_codegen_cranelift", "dylib", target_triple); + let cg_clif_dylib = get_file_name("rustc_codegen_cranelift", "dylib", host_triple); let cg_clif_dylib_path = target_dir .join(if cfg!(windows) { // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the @@ -37,7 +37,7 @@ pub(crate) fn build_sysroot( // Build and copy rustc and cargo wrappers for wrapper in ["rustc-clif", "cargo-clif"] { - let wrapper_name = get_wrapper_file_name(wrapper, "bin", target_triple); + let wrapper_name = get_wrapper_file_name(wrapper, "bin", host_triple); let mut build_cargo_wrapper_cmd = Command::new("rustc"); build_cargo_wrapper_cmd diff --git a/build_system/tests.rs b/build_system/tests.rs index 5c69beeaab5..bc13066b020 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -414,7 +414,7 @@ impl TestRunner { { let mut rustc_clif = self.root_dir.clone(); rustc_clif.push("build"); - rustc_clif.push(get_wrapper_file_name("rustc-clif", "bin", &self.target_triple)); + rustc_clif.push(get_wrapper_file_name("rustc-clif", "bin", &self.host_triple)); let mut cmd = Command::new(rustc_clif); if !self.rust_flags.is_empty() { @@ -476,7 +476,7 @@ impl TestRunner { { let mut cargo_clif = self.root_dir.clone(); cargo_clif.push("build"); - cargo_clif.push(get_wrapper_file_name("cargo-clif", "bin", &self.target_triple)); + cargo_clif.push(get_wrapper_file_name("cargo-clif", "bin", &self.host_triple)); let mut cmd = Command::new(cargo_clif); cmd.args(args); From 6ea108bae3358ffee78fcdfb4b442dd8d81b29b4 Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 30 Jul 2022 21:08:21 +0100 Subject: [PATCH 11/18] Split flags whitespace This is probably the wrong way to do this... --- build_system/tests.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/build_system/tests.rs b/build_system/tests.rs index bc13066b020..e4a776259c0 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -417,9 +417,7 @@ impl TestRunner { rustc_clif.push(get_wrapper_file_name("rustc-clif", "bin", &self.host_triple)); let mut cmd = Command::new(rustc_clif); - if !self.rust_flags.is_empty() { - cmd.arg(&self.rust_flags); - } + cmd.args(self.rust_flags.split_whitespace()); cmd.arg("-L"); cmd.arg(format!("crate={}", self.out_dir.display())); cmd.arg("--out-dir"); From 78372d6b411523bc9d1f081ff3951d39367e8f5f Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 30 Jul 2022 21:08:59 +0100 Subject: [PATCH 12/18] Log cloned regex output --- .github/workflows/main.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 832572bcf35..a75c4f97529 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -79,6 +79,10 @@ jobs: git config --global user.email "user@example.com" git config --global user.name "User" ./y.rs prepare + + + - name: log expected output + run: cat -e regex/examples/regexdna-output.txt - name: Build without unstable features env: From bec651ef47efae5732e7b17c4d49e2718544d4c8 Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 30 Jul 2022 22:05:39 +0100 Subject: [PATCH 13/18] Compare lines iterator instead of full output This avoids differences in line endings. --- .github/workflows/main.yml | 4 ---- build_system/tests.rs | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a75c4f97529..832572bcf35 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -79,10 +79,6 @@ jobs: git config --global user.email "user@example.com" git config --global user.name "User" ./y.rs prepare - - - - name: log expected output - run: cat -e regex/examples/regexdna-output.txt - name: Build without unstable features env: diff --git a/build_system/tests.rs b/build_system/tests.rs index e4a776259c0..2c96c5cc175 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -206,7 +206,8 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ .join("\r\n"); - if output != expected { + let output_matches = expected.lines().eq(output.lines()); + if !output_matches { let res_path = PathBuf::from("res.txt"); fs::write(&res_path, &output).unwrap(); @@ -457,7 +458,6 @@ impl TestRunner { full_cmd.push(arg.to_string()); } - println!("full_CMD: {:?}", full_cmd); let mut cmd_iter = full_cmd.into_iter(); let first = cmd_iter.next().unwrap(); From 2f1380036cff86b97de98434b5e59592624d4d54 Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 30 Jul 2022 22:32:06 +0100 Subject: [PATCH 14/18] Cleanup meaningless changes --- build_system/build_backend.rs | 2 +- build_system/mod.rs | 4 ++-- build_system/prepare.rs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index ddc099b5388..48faec8bc4b 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -39,5 +39,5 @@ pub(crate) fn build_backend( eprintln!("[BUILD] rustc_codegen_cranelift"); super::utils::spawn_and_wait(cmd); - Path::new("target").join(&host_triple).join(&channel) + Path::new("target").join(host_triple).join(channel) } diff --git a/build_system/mod.rs b/build_system/mod.rs index 0124d47de75..3a6d58a2a6d 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -73,7 +73,7 @@ pub fn main() { eprintln!("Switch to the MinGW toolchain for Windows support."); eprintln!("Hint: You can use `rustup set default-host x86_64-pc-windows-gnu` to"); eprintln!("set the global default target to MinGW"); - // process::exit(1); + process::exit(1); } @@ -83,7 +83,7 @@ pub fn main() { if args.next().is_some() { arg_error!("./y.rs prepare doesn't expect arguments"); } - prepare::prepare(&target_triple); + prepare::prepare(&host_triple); process::exit(0); } Some("build") => Command::Build, diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 4580c4b6549..b499aaa703c 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -8,7 +8,7 @@ use std::process::Command; use super::rustc_info::{get_file_name, get_rustc_path, get_rustc_version}; use super::utils::{copy_dir_recursively, spawn_and_wait}; -pub(crate) fn prepare(target_triple: &str) { +pub(crate) fn prepare(host_triple: &str) { prepare_sysroot(); eprintln!("[INSTALL] hyperfine"); @@ -49,8 +49,8 @@ pub(crate) fn prepare(target_triple: &str) { build_cmd.arg("build").env_remove("CARGO_TARGET_DIR").current_dir("simple-raytracer"); spawn_and_wait(build_cmd); fs::copy( - Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin", target_triple)), - Path::new("simple-raytracer").join(get_file_name("raytracer_cg_llvm", "bin", target_triple)), + Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin", host_triple)), + Path::new("simple-raytracer").join(get_file_name("raytracer_cg_llvm", "bin", host_triple)), ) .unwrap(); } From 5d7936650d174515730458b29b83e99153365d89 Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 30 Jul 2022 22:58:34 +0100 Subject: [PATCH 15/18] Don't run tests on Windows CI --- .github/workflows/main.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 832572bcf35..e8897e9ae81 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -159,21 +159,19 @@ jobs: ./y.exe prepare - name: Build - run: ./y.exe build - - - name: Test + #name: Test run: | # Enable backtraces for easier debugging - $Env:RUST_BACKTRACE=1 + #$Env:RUST_BACKTRACE=1 # Reduce amount of benchmark runs as they are slow - $Env:COMPILE_RUNS=2 - $Env:RUN_RUNS=2 + #$Env:COMPILE_RUNS=2 + #$Env:RUN_RUNS=2 # Enable extra checks - $Env:CG_CLIF_ENABLE_VERIFIER=1 + #$Env:CG_CLIF_ENABLE_VERIFIER=1 - ./y.exe test + ./y.exe build - name: Package prebuilt cg_clif # don't use compression as xzip isn't supported by tar on windows and bzip2 hangs From f588bfa0956dbd7880c08a22c612e9831df2e3d8 Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 30 Jul 2022 23:04:59 +0100 Subject: [PATCH 16/18] Assume host target in get_file_name --- build_system/build_sysroot.rs | 4 +-- build_system/mod.rs | 58 +++++++++++++++++------------------ build_system/prepare.rs | 6 ++-- build_system/rustc_info.rs | 8 ++--- build_system/tests.rs | 4 +-- 5 files changed, 38 insertions(+), 42 deletions(-) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index ed1c04808c5..6e4b57cf4d3 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -23,7 +23,7 @@ pub(crate) fn build_sysroot( fs::create_dir_all(target_dir.join("lib")).unwrap(); // Copy the backend - let cg_clif_dylib = get_file_name("rustc_codegen_cranelift", "dylib", host_triple); + let cg_clif_dylib = get_file_name("rustc_codegen_cranelift", "dylib"); let cg_clif_dylib_path = target_dir .join(if cfg!(windows) { // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the @@ -37,7 +37,7 @@ pub(crate) fn build_sysroot( // Build and copy rustc and cargo wrappers for wrapper in ["rustc-clif", "cargo-clif"] { - let wrapper_name = get_wrapper_file_name(wrapper, "bin", host_triple); + let wrapper_name = get_wrapper_file_name(wrapper, "bin"); let mut build_cargo_wrapper_cmd = Command::new("rustc"); build_cargo_wrapper_cmd diff --git a/build_system/mod.rs b/build_system/mod.rs index 3a6d58a2a6d..4772a5a7778 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -48,42 +48,13 @@ pub fn main() { // The target dir is expected in the default location. Guard against the user changing it. env::set_var("CARGO_TARGET_DIR", "target"); - - let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") { - host_triple - } else if let Some(host_triple) = config::get_value("host") { - host_triple - } else { - rustc_info::get_host_triple() - }; - let target_triple = if let Ok(target_triple) = std::env::var("TARGET_TRIPLE") { - if target_triple != "" { - target_triple - } else { - host_triple.clone() // Empty target triple can happen on GHA - } - } else if let Some(target_triple) = config::get_value("target") { - target_triple - } else { - host_triple.clone() - }; - - if target_triple.ends_with("-msvc") { - eprintln!("The MSVC toolchain is not yet supported by rustc_codegen_cranelift."); - eprintln!("Switch to the MinGW toolchain for Windows support."); - eprintln!("Hint: You can use `rustup set default-host x86_64-pc-windows-gnu` to"); - eprintln!("set the global default target to MinGW"); - process::exit(1); - } - - let mut args = env::args().skip(1); let command = match args.next().as_deref() { Some("prepare") => { if args.next().is_some() { arg_error!("./y.rs prepare doesn't expect arguments"); } - prepare::prepare(&host_triple); + prepare::prepare(); process::exit(0); } Some("build") => Command::Build, @@ -124,6 +95,33 @@ pub fn main() { } target_dir = std::env::current_dir().unwrap().join(target_dir); + let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") { + host_triple + } else if let Some(host_triple) = config::get_value("host") { + host_triple + } else { + rustc_info::get_host_triple() + }; + let target_triple = if let Ok(target_triple) = std::env::var("TARGET_TRIPLE") { + if target_triple != "" { + target_triple + } else { + host_triple.clone() // Empty target triple can happen on GHA + } + } else if let Some(target_triple) = config::get_value("target") { + target_triple + } else { + host_triple.clone() + }; + + if target_triple.ends_with("-msvc") { + eprintln!("The MSVC toolchain is not yet supported by rustc_codegen_cranelift."); + eprintln!("Switch to the MinGW toolchain for Windows support."); + eprintln!("Hint: You can use `rustup set default-host x86_64-pc-windows-gnu` to"); + eprintln!("set the global default target to MinGW"); + process::exit(1); + } + let cg_clif_build_dir = build_backend::build_backend(channel, &host_triple, use_unstable_features); match command { Command::Test => { diff --git a/build_system/prepare.rs b/build_system/prepare.rs index b499aaa703c..7e0fd182d98 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -8,7 +8,7 @@ use std::process::Command; use super::rustc_info::{get_file_name, get_rustc_path, get_rustc_version}; use super::utils::{copy_dir_recursively, spawn_and_wait}; -pub(crate) fn prepare(host_triple: &str) { +pub(crate) fn prepare() { prepare_sysroot(); eprintln!("[INSTALL] hyperfine"); @@ -49,8 +49,8 @@ pub(crate) fn prepare(host_triple: &str) { build_cmd.arg("build").env_remove("CARGO_TARGET_DIR").current_dir("simple-raytracer"); spawn_and_wait(build_cmd); fs::copy( - Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin", host_triple)), - Path::new("simple-raytracer").join(get_file_name("raytracer_cg_llvm", "bin", host_triple)), + Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin")), + Path::new("simple-raytracer").join(get_file_name("raytracer_cg_llvm", "bin")), ) .unwrap(); } diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs index 63e1d16ead6..913b589afcc 100644 --- a/build_system/rustc_info.rs +++ b/build_system/rustc_info.rs @@ -43,7 +43,7 @@ pub(crate) fn get_default_sysroot() -> PathBuf { Path::new(String::from_utf8(default_sysroot).unwrap().trim()).to_owned() } -pub(crate) fn get_file_name(crate_name: &str, crate_type: &str, target: &str) -> String { +pub(crate) fn get_file_name(crate_name: &str, crate_type: &str) -> String { let file_name = Command::new("rustc") .stderr(Stdio::inherit()) .args(&[ @@ -51,8 +51,6 @@ pub(crate) fn get_file_name(crate_name: &str, crate_type: &str, target: &str) -> crate_name, "--crate-type", crate_type, - "--target", - target, "--print", "file-names", "-", @@ -69,8 +67,8 @@ pub(crate) fn get_file_name(crate_name: &str, crate_type: &str, target: &str) -> /// Similar to `get_file_name`, but converts any dashes (`-`) in the `crate_name` to /// underscores (`_`). This is specially made for the the rustc and cargo wrappers /// which have a dash in the name, and that is not allowed in a crate name. -pub(crate) fn get_wrapper_file_name(crate_name: &str, crate_type: &str, target: &str) -> String { +pub(crate) fn get_wrapper_file_name(crate_name: &str, crate_type: &str) -> String { let crate_name = crate_name.replace('-', "_"); - let wrapper_name = get_file_name(&crate_name, crate_type, target); + let wrapper_name = get_file_name(&crate_name, crate_type); wrapper_name.replace('_', "-") } diff --git a/build_system/tests.rs b/build_system/tests.rs index 2c96c5cc175..2b4ae39a75e 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -415,7 +415,7 @@ impl TestRunner { { let mut rustc_clif = self.root_dir.clone(); rustc_clif.push("build"); - rustc_clif.push(get_wrapper_file_name("rustc-clif", "bin", &self.host_triple)); + rustc_clif.push(get_wrapper_file_name("rustc-clif", "bin")); let mut cmd = Command::new(rustc_clif); cmd.args(self.rust_flags.split_whitespace()); @@ -474,7 +474,7 @@ impl TestRunner { { let mut cargo_clif = self.root_dir.clone(); cargo_clif.push("build"); - cargo_clif.push(get_wrapper_file_name("cargo-clif", "bin", &self.host_triple)); + cargo_clif.push(get_wrapper_file_name("cargo-clif", "bin")); let mut cmd = Command::new(cargo_clif); cmd.args(args); From d489fb9a59338051e1f488c87d8ee55bd25e0208 Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 30 Jul 2022 23:07:03 +0100 Subject: [PATCH 17/18] Don't pass RUSTFLAGS to rustc in tests --- build_system/tests.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/build_system/tests.rs b/build_system/tests.rs index 2b4ae39a75e..f6f3f4831e1 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -425,7 +425,6 @@ impl TestRunner { cmd.arg(format!("{}", self.out_dir.display())); cmd.arg("-Cdebuginfo=2"); cmd.args(args); - cmd.env("RUSTFLAGS", &self.rust_flags); cmd } From 0db9094231138fb29895fc181d534a2a547d168a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 31 Jul 2022 10:15:56 +0000 Subject: [PATCH 18/18] Rustfmt --- build_system/build_sysroot.rs | 2 +- build_system/mod.rs | 7 +- build_system/tests.rs | 234 ++++++++++++++++++++++++++-------- build_system/utils.rs | 2 +- 4 files changed, 187 insertions(+), 58 deletions(-) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 6e4b57cf4d3..7e205b0fd0b 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -2,7 +2,7 @@ use std::fs; use std::path::{Path, PathBuf}; use std::process::{self, Command}; -use super::rustc_info::{get_file_name, get_wrapper_file_name, get_rustc_version}; +use super::rustc_info::{get_file_name, get_rustc_version, get_wrapper_file_name}; use super::utils::{spawn_and_wait, try_hard_link}; use super::SysrootKind; diff --git a/build_system/mod.rs b/build_system/mod.rs index 4772a5a7778..8c7d05993a5 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -7,8 +7,8 @@ mod build_sysroot; mod config; mod prepare; mod rustc_info; -mod utils; mod tests; +mod utils; fn usage() { eprintln!("Usage:"); @@ -122,7 +122,8 @@ pub fn main() { process::exit(1); } - let cg_clif_build_dir = build_backend::build_backend(channel, &host_triple, use_unstable_features); + let cg_clif_build_dir = + build_backend::build_backend(channel, &host_triple, use_unstable_features); match command { Command::Test => { tests::run_tests( @@ -133,7 +134,7 @@ pub fn main() { &host_triple, &target_triple, ); - }, + } Command::Build => { build_sysroot::build_sysroot( channel, diff --git a/build_system/tests.rs b/build_system/tests.rs index f6f3f4831e1..3f225b4efa2 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -22,85 +22,195 @@ impl TestCase { const NO_SYSROOT_SUITE: &[TestCase] = &[ TestCase::new("build.mini_core", &|runner| { - runner.run_rustc(["example/mini_core.rs", "--crate-name", "mini_core", "--crate-type", "lib,dylib", "--target", &runner.target_triple]); + runner.run_rustc([ + "example/mini_core.rs", + "--crate-name", + "mini_core", + "--crate-type", + "lib,dylib", + "--target", + &runner.target_triple, + ]); }), - TestCase::new("build.example", &|runner| { - runner.run_rustc(["example/example.rs", "--crate-type", "lib", "--target", &runner.target_triple]); + runner.run_rustc([ + "example/example.rs", + "--crate-type", + "lib", + "--target", + &runner.target_triple, + ]); }), - TestCase::new("jit.mini_core_hello_world", &|runner| { - let mut jit_cmd = runner.rustc_command(["-Zunstable-options", "-Cllvm-args=mode=jit", "-Cprefer-dynamic", "example/mini_core_hello_world.rs", "--cfg", "jit", "--target", &runner.host_triple]); + let mut jit_cmd = runner.rustc_command([ + "-Zunstable-options", + "-Cllvm-args=mode=jit", + "-Cprefer-dynamic", + "example/mini_core_hello_world.rs", + "--cfg", + "jit", + "--target", + &runner.host_triple, + ]); jit_cmd.env("CG_CLIF_JIT_ARGS", "abc bcd"); spawn_and_wait(jit_cmd); eprintln!("[JIT-lazy] mini_core_hello_world"); - let mut jit_cmd = runner.rustc_command(["-Zunstable-options", "-Cllvm-args=mode=jit-lazy", "-Cprefer-dynamic", "example/mini_core_hello_world.rs", "--cfg", "jit", "--target", &runner.host_triple]); + let mut jit_cmd = runner.rustc_command([ + "-Zunstable-options", + "-Cllvm-args=mode=jit-lazy", + "-Cprefer-dynamic", + "example/mini_core_hello_world.rs", + "--cfg", + "jit", + "--target", + &runner.host_triple, + ]); jit_cmd.env("CG_CLIF_JIT_ARGS", "abc bcd"); spawn_and_wait(jit_cmd); }), - TestCase::new("aot.mini_core_hello_world", &|runner| { - runner.run_rustc(["example/mini_core_hello_world.rs", "--crate-name", "mini_core_hello_world", "--crate-type", "bin", "-g", "--target", &runner.target_triple]); + runner.run_rustc([ + "example/mini_core_hello_world.rs", + "--crate-name", + "mini_core_hello_world", + "--crate-type", + "bin", + "-g", + "--target", + &runner.target_triple, + ]); runner.run_out_command("mini_core_hello_world", ["abc", "bcd"]); }), ]; - const BASE_SYSROOT_SUITE: &[TestCase] = &[ TestCase::new("aot.arbitrary_self_types_pointers_and_wrappers", &|runner| { - runner.run_rustc(["example/arbitrary_self_types_pointers_and_wrappers.rs", "--crate-name", "arbitrary_self_types_pointers_and_wrappers", "--crate-type", "bin", "--target", &runner.target_triple]); + runner.run_rustc([ + "example/arbitrary_self_types_pointers_and_wrappers.rs", + "--crate-name", + "arbitrary_self_types_pointers_and_wrappers", + "--crate-type", + "bin", + "--target", + &runner.target_triple, + ]); runner.run_out_command("arbitrary_self_types_pointers_and_wrappers", []); }), - TestCase::new("aot.issue_91827_extern_types", &|runner| { - runner.run_rustc(["example/issue-91827-extern-types.rs", "--crate-name", "issue_91827_extern_types", "--crate-type", "bin", "--target", &runner.target_triple]); + runner.run_rustc([ + "example/issue-91827-extern-types.rs", + "--crate-name", + "issue_91827_extern_types", + "--crate-type", + "bin", + "--target", + &runner.target_triple, + ]); runner.run_out_command("issue_91827_extern_types", []); }), - TestCase::new("build.alloc_system", &|runner| { - runner.run_rustc(["example/alloc_system.rs", "--crate-type", "lib", "--target", &runner.target_triple]); + runner.run_rustc([ + "example/alloc_system.rs", + "--crate-type", + "lib", + "--target", + &runner.target_triple, + ]); }), - TestCase::new("aot.alloc_example", &|runner| { - runner.run_rustc(["example/alloc_example.rs", "--crate-type", "bin", "--target", &runner.target_triple]); + runner.run_rustc([ + "example/alloc_example.rs", + "--crate-type", + "bin", + "--target", + &runner.target_triple, + ]); runner.run_out_command("alloc_example", []); }), - TestCase::new("jit.std_example", &|runner| { - runner.run_rustc(["-Zunstable-options", "-Cllvm-args=mode=jit", "-Cprefer-dynamic", "example/std_example.rs", "--target", &runner.host_triple]); + runner.run_rustc([ + "-Zunstable-options", + "-Cllvm-args=mode=jit", + "-Cprefer-dynamic", + "example/std_example.rs", + "--target", + &runner.host_triple, + ]); eprintln!("[JIT-lazy] std_example"); - runner.run_rustc(["-Zunstable-options", "-Cllvm-args=mode=jit-lazy", "-Cprefer-dynamic", "example/std_example.rs", "--target", &runner.host_triple]); + runner.run_rustc([ + "-Zunstable-options", + "-Cllvm-args=mode=jit-lazy", + "-Cprefer-dynamic", + "example/std_example.rs", + "--target", + &runner.host_triple, + ]); }), - TestCase::new("aot.std_example", &|runner| { - runner.run_rustc(["example/std_example.rs", "--crate-type", "bin", "--target", &runner.target_triple]); + runner.run_rustc([ + "example/std_example.rs", + "--crate-type", + "bin", + "--target", + &runner.target_triple, + ]); runner.run_out_command("std_example", ["arg"]); }), - TestCase::new("aot.dst_field_align", &|runner| { - runner.run_rustc(["example/dst-field-align.rs", "--crate-name", "dst_field_align", "--crate-type", "bin", "--target", &runner.target_triple]); + runner.run_rustc([ + "example/dst-field-align.rs", + "--crate-name", + "dst_field_align", + "--crate-type", + "bin", + "--target", + &runner.target_triple, + ]); runner.run_out_command("dst_field_align", []); }), - TestCase::new("aot.subslice-patterns-const-eval", &|runner| { - runner.run_rustc(["example/subslice-patterns-const-eval.rs", "--crate-type", "bin", "-Cpanic=abort", "--target", &runner.target_triple]); + runner.run_rustc([ + "example/subslice-patterns-const-eval.rs", + "--crate-type", + "bin", + "-Cpanic=abort", + "--target", + &runner.target_triple, + ]); runner.run_out_command("subslice-patterns-const-eval", []); }), - TestCase::new("aot.track-caller-attribute", &|runner| { - runner.run_rustc(["example/track-caller-attribute.rs", "--crate-type", "bin", "-Cpanic=abort", "--target", &runner.target_triple]); + runner.run_rustc([ + "example/track-caller-attribute.rs", + "--crate-type", + "bin", + "-Cpanic=abort", + "--target", + &runner.target_triple, + ]); runner.run_out_command("track-caller-attribute", []); }), - TestCase::new("aot.float-minmax-pass", &|runner| { - runner.run_rustc(["example/float-minmax-pass.rs", "--crate-type", "bin", "-Cpanic=abort", "--target", &runner.target_triple]); + runner.run_rustc([ + "example/float-minmax-pass.rs", + "--crate-type", + "bin", + "-Cpanic=abort", + "--target", + &runner.target_triple, + ]); runner.run_out_command("float-minmax-pass", []); }), - TestCase::new("aot.mod_bench", &|runner| { - runner.run_rustc(["example/mod_bench.rs", "--crate-type", "bin", "--target", &runner.target_triple]); + runner.run_rustc([ + "example/mod_bench.rs", + "--crate-type", + "bin", + "--target", + &runner.target_triple, + ]); runner.run_out_command("mod_bench", []); }), ]; @@ -115,11 +225,16 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ runner.run_cargo(["test", "--workspace"]); } else { eprintln!("[AOT] rust-random/rand"); - runner.run_cargo(["build", "--workspace", "--target", &runner.target_triple, "--tests"]); + runner.run_cargo([ + "build", + "--workspace", + "--target", + &runner.target_triple, + "--tests", + ]); } }); }), - TestCase::new("bench.simple-raytracer", &|runner| { runner.in_dir(["simple-raytracer"], |runner| { let run_runs = env::var("RUN_RUNS").unwrap_or("10".to_string()); @@ -143,10 +258,9 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ bench_compile.arg(format!("{:?}", runner.cargo_command(["build"]))); spawn_and_wait(bench_compile); - - eprintln!("[BENCH RUN] ebobby/simple-raytracer"); - fs::copy(PathBuf::from("./target/debug/main"), PathBuf::from("raytracer_cg_clif")).unwrap(); + fs::copy(PathBuf::from("./target/debug/main"), PathBuf::from("raytracer_cg_clif")) + .unwrap(); let mut bench_run = Command::new("hyperfine"); bench_run.arg("--runs"); @@ -163,7 +277,6 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ } }); }), - TestCase::new("test.libcore", &|runner| { runner.in_dir(["build_sysroot", "sysroot_src", "library", "core", "tests"], |runner| { runner.run_cargo(["clean"]); @@ -176,7 +289,6 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ } }); }), - TestCase::new("test.regex-shootout-regex-dna", &|runner| { runner.in_dir(["regex"], |runner| { runner.run_cargo(["clean"]); @@ -184,28 +296,40 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ // newer aho_corasick versions throw a deprecation warning let lint_rust_flags = format!("{} --cap-lints warn", runner.rust_flags); - let mut build_cmd = runner.cargo_command(["build", "--example", "shootout-regex-dna", "--target", &runner.target_triple]); + let mut build_cmd = runner.cargo_command([ + "build", + "--example", + "shootout-regex-dna", + "--target", + &runner.target_triple, + ]); build_cmd.env("RUSTFLAGS", lint_rust_flags.clone()); spawn_and_wait(build_cmd); if runner.host_triple == runner.target_triple { - let mut run_cmd = runner.cargo_command(["run", "--example", "shootout-regex-dna", "--target", &runner.target_triple]); + let mut run_cmd = runner.cargo_command([ + "run", + "--example", + "shootout-regex-dna", + "--target", + &runner.target_triple, + ]); run_cmd.env("RUSTFLAGS", lint_rust_flags); - - let input = fs::read_to_string(PathBuf::from("examples/regexdna-input.txt")).unwrap(); + let input = + fs::read_to_string(PathBuf::from("examples/regexdna-input.txt")).unwrap(); let expected_path = PathBuf::from("examples/regexdna-output.txt"); let expected = fs::read_to_string(&expected_path).unwrap(); let output = spawn_and_wait_with_input(run_cmd, input); // Make sure `[codegen mono items] start` doesn't poison the diff - let output = output.lines() + let output = output + .lines() .filter(|line| !line.contains("codegen mono items")) .chain(Some("")) // This just adds the trailing newline .collect::>() .join("\r\n"); - let output_matches = expected.lines().eq(output.lines()); if !output_matches { let res_path = PathBuf::from("res.txt"); @@ -228,7 +352,6 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ } }); }), - TestCase::new("test.regex", &|runner| { runner.in_dir(["regex"], |runner| { runner.run_cargo(["clean"]); @@ -237,18 +360,27 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ let lint_rust_flags = format!("{} --cap-lints warn", runner.rust_flags); if runner.host_triple == runner.target_triple { - let mut run_cmd = runner.cargo_command(["test", "--tests", "--", "--exclude-should-panic", "--test-threads", "1", "-Zunstable-options", "-q"]); + let mut run_cmd = runner.cargo_command([ + "test", + "--tests", + "--", + "--exclude-should-panic", + "--test-threads", + "1", + "-Zunstable-options", + "-q", + ]); run_cmd.env("RUSTFLAGS", lint_rust_flags); spawn_and_wait(run_cmd); } else { eprintln!("Cross-Compiling: Not running tests"); - let mut build_cmd = runner.cargo_command(["build", "--tests", "--target", &runner.target_triple]); + let mut build_cmd = + runner.cargo_command(["build", "--tests", "--target", &runner.target_triple]); build_cmd.env("RUSTFLAGS", lint_rust_flags.clone()); spawn_and_wait(build_cmd); } }); }), - TestCase::new("test.portable-simd", &|runner| { runner.in_dir(["portable-simd"], |runner| { runner.run_cargo(["clean"]); @@ -261,8 +393,6 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ }), ]; - - pub(crate) fn run_tests( channel: &str, sysroot_kind: SysrootKind, @@ -316,8 +446,6 @@ pub(crate) fn run_tests( } } - - struct TestRunner { root_dir: PathBuf, out_dir: PathBuf, @@ -348,7 +476,7 @@ impl TestRunner { // We are cross-compiling for aarch64. Use the correct linker and run tests in qemu. rust_flags = format!("-Clinker=aarch64-linux-gnu-gcc{}", rust_flags); run_wrapper = vec!["qemu-aarch64", "-L", "/usr/aarch64-linux-gnu"]; - }, + } "x86_64-pc-windows-gnu" => { // We are cross-compiling for Windows. Run tests in wine. run_wrapper = vec!["wine"]; diff --git a/build_system/utils.rs b/build_system/utils.rs index 2d2778d2fc0..3282778e254 100644 --- a/build_system/utils.rs +++ b/build_system/utils.rs @@ -1,7 +1,7 @@ use std::fs; +use std::io::Write; use std::path::Path; use std::process::{self, Command, Stdio}; -use std::io::Write; #[track_caller] pub(crate) fn try_hard_link(src: impl AsRef, dst: impl AsRef) {