]> git.lizzy.rs Git - rust.git/blob - build_system/build_backend.rs
Sync from rust 2ddb65c32253872c0e7a02e43ec520877900370e
[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(channel: &str, host_triple: &str) -> PathBuf {
6     let mut cmd = Command::new("cargo");
7     cmd.arg("build").arg("--target").arg(host_triple).arg("--features").arg("unstable-features");
8
9     match channel {
10         "debug" => {}
11         "release" => {
12             cmd.arg("--release");
13         }
14         _ => unreachable!(),
15     }
16
17     if cfg!(unix) {
18         if cfg!(target_os = "macos") {
19             cmd.env(
20                 "RUSTFLAGS",
21                 "-Csplit-debuginfo=unpacked \
22                 -Clink-arg=-Wl,-rpath,@loader_path/../lib \
23                 -Zosx-rpath-install-name"
24                     .to_string()
25                     + env::var("RUSTFLAGS").as_deref().unwrap_or(""),
26             );
27         } else {
28             cmd.env(
29                 "RUSTFLAGS",
30                 "-Clink-arg=-Wl,-rpath=$ORIGIN/../lib ".to_string()
31                     + env::var("RUSTFLAGS").as_deref().unwrap_or(""),
32             );
33         }
34     }
35
36     eprintln!("[BUILD] rustc_codegen_cranelift");
37     crate::utils::spawn_and_wait(cmd);
38
39     Path::new("target").join(host_triple).join(channel)
40 }