Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3bd9821

Browse files
committed
Initial ABI Checker support
1 parent 3c97227 commit 3bd9821

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ perf.data.old
1919
/regex
2020
/simple-raytracer
2121
/portable-simd
22+
/abi-checker

build_system/abi_checker.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
use super::build_sysroot;
2+
use super::utils::spawn_and_wait_with_input;
3+
use build_system::SysrootKind;
4+
use std::env;
5+
use std::path::Path;
6+
use std::process::Command;
7+
8+
pub(crate) fn run(
9+
channel: &str,
10+
sysroot_kind: SysrootKind,
11+
target_dir: &Path,
12+
cg_clif_build_dir: &Path,
13+
host_triple: &str,
14+
target_triple: &str,
15+
) {
16+
assert_eq!(
17+
host_triple, target_triple,
18+
"abi-checker not supported on cross-compilation scenarios"
19+
);
20+
21+
eprintln!("Building sysroot for abi-checker");
22+
build_sysroot::build_sysroot(
23+
channel,
24+
sysroot_kind,
25+
target_dir,
26+
cg_clif_build_dir,
27+
host_triple,
28+
target_triple,
29+
);
30+
31+
eprintln!("Running abi-checker");
32+
let mut abi_checker_path = env::current_dir().unwrap();
33+
abi_checker_path.push("abi-checker");
34+
env::set_current_dir(abi_checker_path.clone()).unwrap();
35+
36+
let build_dir = abi_checker_path.parent().unwrap().join("build");
37+
let cg_clif_dylib_path = build_dir.join(if cfg!(windows) { "bin" } else { "lib" }).join(
38+
env::consts::DLL_PREFIX.to_string() + "rustc_codegen_cranelift" + env::consts::DLL_SUFFIX,
39+
);
40+
println!("cg_clif_dylib_path: {}", cg_clif_dylib_path.display());
41+
42+
let pairs = ["rustc_calls_cgclif", "cgclif_calls_rustc", "cgclif_calls_cc", "cc_calls_cgclif"];
43+
44+
for pair in pairs {
45+
eprintln!("[ABI-CHECKER] Running pair {pair}");
46+
47+
let mut cmd = Command::new("cargo");
48+
cmd.arg("run");
49+
cmd.arg("--target");
50+
cmd.arg(target_triple);
51+
cmd.arg("--");
52+
cmd.arg("--pairs");
53+
cmd.arg(pair);
54+
cmd.arg("--add-rustc-codegen-backend");
55+
cmd.arg(format!("cgclif:{}", cg_clif_dylib_path.display()));
56+
57+
let output = spawn_and_wait_with_input(cmd, "".to_string());
58+
59+
// TODO: The correct thing to do here is to check the exit code, but abi-checker
60+
// currently doesn't return 0 on success, so check for the test fail count.
61+
// See: https://github.com/Gankra/abi-checker/issues/10
62+
let failed = !(output.contains("0 failed") && output.contains("0 completely failed"));
63+
if failed {
64+
panic!("abi-checker for pair {} failed!", pair);
65+
}
66+
}
67+
}

build_system/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::process;
44

55
use self::utils::is_ci;
66

7+
mod abi_checker;
78
mod build_backend;
89
mod build_sysroot;
910
mod config;
@@ -21,6 +22,9 @@ fn usage() {
2122
eprintln!(
2223
" ./y.rs test [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]"
2324
);
25+
eprintln!(
26+
" ./y.rs abi-checker [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]"
27+
);
2428
}
2529

2630
macro_rules! arg_error {
@@ -35,6 +39,7 @@ macro_rules! arg_error {
3539
enum Command {
3640
Build,
3741
Test,
42+
AbiChecker,
3843
}
3944

4045
#[derive(Copy, Clone, Debug)]
@@ -66,6 +71,7 @@ pub fn main() {
6671
}
6772
Some("build") => Command::Build,
6873
Some("test") => Command::Test,
74+
Some("abi-checker") => Command::AbiChecker,
6975
Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag),
7076
Some(command) => arg_error!("Unknown command {}", command),
7177
None => {
@@ -152,5 +158,15 @@ pub fn main() {
152158
&target_triple,
153159
);
154160
}
161+
Command::AbiChecker => {
162+
abi_checker::run(
163+
channel,
164+
sysroot_kind,
165+
&target_dir,
166+
&cg_clif_build_dir,
167+
&host_triple,
168+
&target_triple,
169+
);
170+
}
155171
}
156172
}

build_system/prepare.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ pub(crate) fn prepare() {
1414
eprintln!("[INSTALL] hyperfine");
1515
Command::new("cargo").arg("install").arg("hyperfine").spawn().unwrap().wait().unwrap();
1616

17+
clone_repo_shallow_github(
18+
"abi-checker",
19+
"Gankra",
20+
"abi-checker",
21+
"7c1571da6e43f9a37347623e7d5c7d51be664a7b",
22+
);
23+
1724
clone_repo_shallow_github(
1825
"rand",
1926
"rust-random",

0 commit comments

Comments
 (0)