]> git.lizzy.rs Git - rust.git/blob - build_system/build_backend.rs
Sync from rust 00fcc82df204ab81cd887da7d04c023a201afd5b
[rust.git] / build_system / build_backend.rs
1 use std::env;
2 use std::path::PathBuf;
3
4 use super::rustc_info::get_file_name;
5 use super::utils::{cargo_command, is_ci};
6
7 pub(crate) fn build_backend(
8     channel: &str,
9     host_triple: &str,
10     use_unstable_features: bool,
11 ) -> PathBuf {
12     let source_dir = std::env::current_dir().unwrap();
13     let mut cmd = cargo_command("cargo", "build", Some(host_triple), &source_dir);
14
15     cmd.env("CARGO_BUILD_INCREMENTAL", "true"); // Force incr comp even in release mode
16
17     let mut rustflags = env::var("RUSTFLAGS").unwrap_or_default();
18
19     if is_ci() {
20         // Deny warnings on CI
21         rustflags += " -Dwarnings";
22
23         // Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway
24         cmd.env("CARGO_BUILD_INCREMENTAL", "false");
25     }
26
27     if use_unstable_features {
28         cmd.arg("--features").arg("unstable-features");
29     }
30
31     match channel {
32         "debug" => {}
33         "release" => {
34             cmd.arg("--release");
35         }
36         _ => unreachable!(),
37     }
38
39     cmd.env("RUSTFLAGS", rustflags);
40
41     eprintln!("[BUILD] rustc_codegen_cranelift");
42     super::utils::spawn_and_wait(cmd);
43
44     source_dir
45         .join("target")
46         .join(host_triple)
47         .join(channel)
48         .join(get_file_name("rustc_codegen_cranelift", "dylib"))
49 }