]> git.lizzy.rs Git - rust.git/blob - build_system/abi_checker.rs
Merge pull request #1255 from afonso360/abi-checker
[rust.git] / build_system / abi_checker.rs
1 use super::build_sysroot;
2 use super::config;
3 use super::utils::spawn_and_wait;
4 use build_system::SysrootKind;
5 use std::env;
6 use std::path::Path;
7 use std::process::Command;
8
9 pub(crate) fn run(
10     channel: &str,
11     sysroot_kind: SysrootKind,
12     target_dir: &Path,
13     cg_clif_build_dir: &Path,
14     host_triple: &str,
15     target_triple: &str,
16 ) {
17     if !config::get_bool("testsuite.abi-checker") {
18         eprintln!("[SKIP] abi-checker");
19         return;
20     }
21
22     if host_triple != target_triple {
23         eprintln!("[SKIP] abi-checker (cross-compilation not supported)");
24         return;
25     }
26
27     eprintln!("Building sysroot for abi-checker");
28     build_sysroot::build_sysroot(
29         channel,
30         sysroot_kind,
31         target_dir,
32         cg_clif_build_dir,
33         host_triple,
34         target_triple,
35     );
36
37     eprintln!("Running abi-checker");
38     let mut abi_checker_path = env::current_dir().unwrap();
39     abi_checker_path.push("abi-checker");
40     env::set_current_dir(abi_checker_path.clone()).unwrap();
41
42     let build_dir = abi_checker_path.parent().unwrap().join("build");
43     let cg_clif_dylib_path = build_dir.join(if cfg!(windows) { "bin" } else { "lib" }).join(
44         env::consts::DLL_PREFIX.to_string() + "rustc_codegen_cranelift" + env::consts::DLL_SUFFIX,
45     );
46
47     let pairs = ["rustc_calls_cgclif", "cgclif_calls_rustc", "cgclif_calls_cc", "cc_calls_cgclif"];
48
49     let mut cmd = Command::new("cargo");
50     cmd.arg("run");
51     cmd.arg("--target");
52     cmd.arg(target_triple);
53     cmd.arg("--");
54     cmd.arg("--pairs");
55     cmd.args(pairs);
56     cmd.arg("--add-rustc-codegen-backend");
57     cmd.arg(format!("cgclif:{}", cg_clif_dylib_path.display()));
58
59     spawn_and_wait(cmd);
60 }