]> git.lizzy.rs Git - rust.git/blob - build_system/build_backend.rs
Merge pull request #1180 from bjorn3/rust_build_system
[rust.git] / build_system / build_backend.rs
1 use std::env;
2 use std::process::Command;
3
4 pub(crate) fn build_backend(channel: &str) -> String {
5     let mut cmd = Command::new("cargo");
6     cmd.arg("build");
7
8     match channel {
9         "debug" => {}
10         "release" => {
11             cmd.arg("--release");
12         }
13         _ => unreachable!(),
14     }
15
16     if cfg!(unix) {
17         if cfg!(target_os = "macos") {
18             cmd.env(
19                 "RUSTFLAGS",
20                 "-Csplit-debuginfo=unpacked \
21                 -Clink-arg=-Wl,-rpath,@loader_path/../lib \
22                 -Zosx-rpath-install-name"
23                     .to_string()
24                     + env::var("RUSTFLAGS").as_deref().unwrap_or(""),
25             );
26         } else {
27             cmd.env(
28                 "RUSTFLAGS",
29                 "-Clink-arg=-Wl,-rpath=$ORIGIN/../lib ".to_string()
30                     + env::var("RUSTFLAGS").as_deref().unwrap_or(""),
31             );
32         }
33     }
34
35     eprintln!("[BUILD] rustc_codegen_cranelift");
36     crate::utils::spawn_and_wait(cmd);
37
38     crate::rustc_info::get_file_name("rustc_codegen_cranelift", "dylib")
39 }