]> git.lizzy.rs Git - rust.git/blob - build_system/abi_checker.rs
Pass all pairs to abi-checker
[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
41     let pairs = ["rustc_calls_cgclif", "cgclif_calls_rustc", "cgclif_calls_cc", "cc_calls_cgclif"];
42
43     let mut cmd = Command::new("cargo");
44     cmd.arg("run");
45     cmd.arg("--target");
46     cmd.arg(target_triple);
47     cmd.arg("--");
48     cmd.arg("--pairs");
49     cmd.args(pairs);
50     cmd.arg("--add-rustc-codegen-backend");
51     cmd.arg(format!("cgclif:{}", cg_clif_dylib_path.display()));
52
53     let output = spawn_and_wait_with_input(cmd, "".to_string());
54
55     // TODO: The correct thing to do here is to check the exit code, but abi-checker
56     // currently doesn't return 0 on success, so check for the test fail count.
57     // See: https://github.com/Gankra/abi-checker/issues/10
58     let failed = !(output.contains("0 failed") && output.contains("0 completely failed"));
59     if failed {
60         panic!("abi-checker failed!");
61     }
62 }