Skip to content

Commit 395bca1

Browse files
authored
Merge pull request #710 from FractalFir/abi-cafe
Added support for testing the backend with abi-cafe
2 parents fda0bb9 + ed441b6 commit 395bca1

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

build_system/src/abi_test.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
use std::ffi::OsStr;
2+
use std::path::Path;
3+
4+
use crate::utils::run_command_with_output;
5+
6+
fn show_usage() {
7+
println!(
8+
r#"
9+
`abi-test` command help:
10+
--help : Show this help"#
11+
);
12+
}
13+
14+
pub fn run() -> Result<(), String> {
15+
let mut args = std::env::args().skip(2);
16+
while let Some(arg) = args.next() {
17+
match arg.as_str() {
18+
"--help" => {
19+
show_usage();
20+
return Ok(());
21+
}
22+
_ => return Err(format!("Unknown option {}", arg)),
23+
}
24+
}
25+
// Ensure that we have a cloned version of abi-cafe on hand.
26+
crate::utils::git_clone(
27+
"https://github.com/Gankra/abi-cafe.git",
28+
Some("clones/abi-cafe".as_ref()),
29+
true,
30+
)
31+
.map_err(|err| (format!("Git clone failed with message: {err:?}!")))?;
32+
// Configure abi-cafe to use the exact same rustc version we use - this is crucial.
33+
// Otherwise, the concept of ABI compatibility becomes meanignless.
34+
std::fs::copy("rust-toolchain", "clones/abi-cafe/rust-toolchain")
35+
.expect("Could not copy toolchain configs!");
36+
// Get the backend path.
37+
// We will use the *debug* build of the backend - it has more checks enabled.
38+
let backend_path = std::path::absolute("target/debug/librustc_codegen_gcc.so").unwrap();
39+
let backend_arg = format!("--add-rustc-codegen-backend=cg_gcc:{}", backend_path.display());
40+
// Run ABI cafe using cargo.
41+
let cmd: &[&dyn AsRef<OsStr>] = &[
42+
&"cargo",
43+
&"run",
44+
&"--release",
45+
&"--",
46+
&backend_arg,
47+
// Test rust-LLVM to Rust-GCC calls
48+
&"--pairs",
49+
&"rustc_calls_cg_gcc",
50+
&"--pairs",
51+
&"cg_gcc_calls_rustc",
52+
// Test Rust-GCC to C calls
53+
&"--pairs",
54+
&"cg_gcc_calls_c",
55+
&"--pairs",
56+
&"c_calls_cg_gcc",
57+
];
58+
// Run ABI cafe.
59+
run_command_with_output(cmd, Some(&Path::new("clones/abi-cafe")))?;
60+
61+
Ok(())
62+
}

build_system/src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{env, process};
22

3+
mod abi_test;
34
mod build;
45
mod clean;
56
mod clone_gcc;
@@ -12,7 +13,6 @@ mod rust_tools;
1213
mod rustc_info;
1314
mod test;
1415
mod utils;
15-
1616
const BUILD_DIR: &str = "build";
1717

1818
macro_rules! arg_error {
@@ -44,7 +44,8 @@ Commands:
4444
info : Displays information about the build environment and project configuration.
4545
clone-gcc : Clones the GCC compiler from a specified source.
4646
fmt : Runs rustfmt
47-
fuzz : Fuzzes `cg_gcc` using rustlantis"
47+
fuzz : Fuzzes `cg_gcc` using rustlantis
48+
abi-test : Runs the abi-cafe test suite on the codegen, checking for ABI compatibility with LLVM"
4849
);
4950
}
5051

@@ -59,6 +60,7 @@ pub enum Command {
5960
Info,
6061
Fmt,
6162
Fuzz,
63+
AbiTest,
6264
}
6365

6466
fn main() {
@@ -77,6 +79,7 @@ fn main() {
7779
Some("test") => Command::Test,
7880
Some("info") => Command::Info,
7981
Some("clone-gcc") => Command::CloneGcc,
82+
Some("abi-test") => Command::AbiTest,
8083
Some("fmt") => Command::Fmt,
8184
Some("fuzz") => Command::Fuzz,
8285
Some("--help") => {
@@ -102,6 +105,7 @@ fn main() {
102105
Command::CloneGcc => clone_gcc::run(),
103106
Command::Fmt => fmt::run(),
104107
Command::Fuzz => fuzz::run(),
108+
Command::AbiTest => abi_test::run(),
105109
} {
106110
eprintln!("Command failed to run: {e}");
107111
process::exit(1);

0 commit comments

Comments
 (0)