Skip to content

Add abi-checker to y.rs and run it on CI #1255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ jobs:

./y.rs test


- name: Run abi-checker
if: matrix.env.TARGET_TRIPLE == ''
run: ./y.rs abi-checker

- name: Package prebuilt cg_clif
run: tar cvfJ cg_clif.tar.xz build

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ perf.data.old
/regex
/simple-raytracer
/portable-simd
/abi-checker
67 changes: 67 additions & 0 deletions build_system/abi_checker.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use super::build_sysroot;
use super::utils::spawn_and_wait_with_input;
use build_system::SysrootKind;
use std::env;
use std::path::Path;
use std::process::Command;

pub(crate) fn run(
channel: &str,
sysroot_kind: SysrootKind,
target_dir: &Path,
cg_clif_build_dir: &Path,
host_triple: &str,
target_triple: &str,
) {
assert_eq!(
host_triple, target_triple,
"abi-checker not supported on cross-compilation scenarios"
);

eprintln!("Building sysroot for abi-checker");
build_sysroot::build_sysroot(
channel,
sysroot_kind,
target_dir,
cg_clif_build_dir,
host_triple,
target_triple,
);

eprintln!("Running abi-checker");
let mut abi_checker_path = env::current_dir().unwrap();
abi_checker_path.push("abi-checker");
env::set_current_dir(abi_checker_path.clone()).unwrap();

let build_dir = abi_checker_path.parent().unwrap().join("build");
let cg_clif_dylib_path = build_dir.join(if cfg!(windows) { "bin" } else { "lib" }).join(
env::consts::DLL_PREFIX.to_string() + "rustc_codegen_cranelift" + env::consts::DLL_SUFFIX,
);
println!("cg_clif_dylib_path: {}", cg_clif_dylib_path.display());

let pairs = ["rustc_calls_cgclif", "cgclif_calls_rustc", "cgclif_calls_cc", "cc_calls_cgclif"];

for pair in pairs {
eprintln!("[ABI-CHECKER] Running pair {pair}");

let mut cmd = Command::new("cargo");
cmd.arg("run");
cmd.arg("--target");
cmd.arg(target_triple);
cmd.arg("--");
cmd.arg("--pairs");
cmd.arg(pair);
cmd.arg("--add-rustc-codegen-backend");
cmd.arg(format!("cgclif:{}", cg_clif_dylib_path.display()));

let output = spawn_and_wait_with_input(cmd, "".to_string());

// TODO: The correct thing to do here is to check the exit code, but abi-checker
// currently doesn't return 0 on success, so check for the test fail count.
// See: https://github.com/Gankra/abi-checker/issues/10
let failed = !(output.contains("0 failed") && output.contains("0 completely failed"));
if failed {
panic!("abi-checker for pair {} failed!", pair);
}
}
}
16 changes: 16 additions & 0 deletions build_system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::process;

use self::utils::is_ci;

mod abi_checker;
mod build_backend;
mod build_sysroot;
mod config;
Expand All @@ -21,6 +22,9 @@ fn usage() {
eprintln!(
" ./y.rs test [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]"
);
eprintln!(
" ./y.rs abi-checker [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]"
);
}

macro_rules! arg_error {
Expand All @@ -35,6 +39,7 @@ macro_rules! arg_error {
enum Command {
Build,
Test,
AbiChecker,
}

#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -66,6 +71,7 @@ pub fn main() {
}
Some("build") => Command::Build,
Some("test") => Command::Test,
Some("abi-checker") => Command::AbiChecker,
Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag),
Some(command) => arg_error!("Unknown command {}", command),
None => {
Expand Down Expand Up @@ -152,5 +158,15 @@ pub fn main() {
&target_triple,
);
}
Command::AbiChecker => {
abi_checker::run(
channel,
sysroot_kind,
&target_dir,
&cg_clif_build_dir,
&host_triple,
&target_triple,
);
}
}
}
7 changes: 7 additions & 0 deletions build_system/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ pub(crate) fn prepare() {
eprintln!("[INSTALL] hyperfine");
Command::new("cargo").arg("install").arg("hyperfine").spawn().unwrap().wait().unwrap();

clone_repo_shallow_github(
"abi-checker",
"Gankra",
"abi-checker",
"7c1571da6e43f9a37347623e7d5c7d51be664a7b",
);

clone_repo_shallow_github(
"rand",
"rust-random",
Expand Down