]> git.lizzy.rs Git - rust.git/blob - build_system/build_backend.rs
ccc50ee4a59bf57544459befa117c5acf5048121
[rust.git] / 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     if use_unstable_features {
14         cmd.arg("--features").arg("unstable-features");
15     }
16
17     match channel {
18         "debug" => {}
19         "release" => {
20             cmd.arg("--release");
21         }
22         _ => unreachable!(),
23     }
24
25     if cfg!(unix) {
26         if cfg!(target_os = "macos") {
27             cmd.env(
28                 "RUSTFLAGS",
29                 "-Csplit-debuginfo=unpacked \
30                 -Clink-arg=-Wl,-rpath,@loader_path/../lib \
31                 -Zosx-rpath-install-name"
32                     .to_string()
33                     + env::var("RUSTFLAGS").as_deref().unwrap_or(""),
34             );
35         } else {
36             cmd.env(
37                 "RUSTFLAGS",
38                 "-Clink-arg=-Wl,-rpath=$ORIGIN/../lib ".to_string()
39                     + env::var("RUSTFLAGS").as_deref().unwrap_or(""),
40             );
41         }
42     }
43
44     eprintln!("[BUILD] rustc_codegen_cranelift");
45     crate::utils::spawn_and_wait(cmd);
46
47     Path::new("target").join(host_triple).join(channel)
48 }