]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_cranelift/build_system/build_backend.rs
Auto merge of #103431 - Dylan-DPC:rollup-oozfo89, r=Dylan-DPC
[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 use super::utils::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 mut cmd = Command::new("cargo");
13     cmd.arg("build").arg("--target").arg(host_triple);
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     Path::new("target").join(host_triple).join(channel)
45 }