]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_cranelift/build_system/build_backend.rs
Rollup merge of #93469 - compiler-errors:issue-93450, r=estebank
[rust.git] / compiler / rustc_codegen_cranelift / build_system / build_backend.rs
1 use std::env;
2 use std::path::{Path, PathBuf};
3 use std::process::Command;
4
5 pub(crate) fn build_backend(
6     channel: &str,
7     host_triple: &str,
8     use_unstable_features: bool,
9 ) -> PathBuf {
10     let mut cmd = Command::new("cargo");
11     cmd.arg("build").arg("--target").arg(host_triple);
12
13     cmd.env("CARGO_BUILD_INCREMENTAL", "true"); // Force incr comp even in release mode
14
15     let mut rustflags = env::var("RUSTFLAGS").unwrap_or_default();
16
17     if env::var("CI").as_ref().map(|val| &**val) == Ok("true") {
18         // Deny warnings on CI
19         rustflags += " -Dwarnings";
20
21         // Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway
22         cmd.env("CARGO_BUILD_INCREMENTAL", "false");
23     }
24
25     if use_unstable_features {
26         cmd.arg("--features").arg("unstable-features");
27     }
28
29     match channel {
30         "debug" => {}
31         "release" => {
32             cmd.arg("--release");
33         }
34         _ => unreachable!(),
35     }
36
37     // Set the rpath to make the cg_clif executable find librustc_codegen_cranelift without changing
38     // LD_LIBRARY_PATH
39     if cfg!(unix) {
40         if cfg!(target_os = "macos") {
41             rustflags += " -Csplit-debuginfo=unpacked \
42                 -Clink-arg=-Wl,-rpath,@loader_path/../lib \
43                 -Zosx-rpath-install-name";
44         } else {
45             rustflags += " -Clink-arg=-Wl,-rpath=$ORIGIN/../lib ";
46         }
47     }
48
49     cmd.env("RUSTFLAGS", rustflags);
50
51     eprintln!("[BUILD] rustc_codegen_cranelift");
52     super::utils::spawn_and_wait(cmd);
53
54     Path::new("target").join(host_triple).join(channel)
55 }