]> git.lizzy.rs Git - rust.git/blob - build_system/abi_checker.rs
Initial ABI Checker support
[rust.git] / build_system / abi_checker.rs
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 }