]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_cranelift/build_system/build_backend.rs
Merge commit '7d53619064ab7045c383644cb445052d2a3d46db' into sync_cg_clif-2023-02-09
[rust.git] / compiler / rustc_codegen_cranelift / build_system / build_backend.rs
1 use std::env;
2 use std::path::PathBuf;
3
4 use super::path::{Dirs, RelPath};
5 use super::rustc_info::get_file_name;
6 use super::utils::{is_ci, is_ci_opt, CargoProject, Compiler};
7
8 pub(crate) static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "cg_clif");
9
10 pub(crate) fn build_backend(
11     dirs: &Dirs,
12     channel: &str,
13     bootstrap_host_compiler: &Compiler,
14     use_unstable_features: bool,
15 ) -> PathBuf {
16     let mut cmd = CG_CLIF.build(&bootstrap_host_compiler, dirs);
17
18     cmd.env("CARGO_BUILD_INCREMENTAL", "true"); // Force incr comp even in release mode
19
20     let mut rustflags = env::var("RUSTFLAGS").unwrap_or_default();
21
22     if is_ci() {
23         // Deny warnings on CI
24         rustflags += " -Dwarnings";
25
26         // Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway
27         cmd.env("CARGO_BUILD_INCREMENTAL", "false");
28
29         if !is_ci_opt() {
30             cmd.env("CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS", "true");
31         }
32     }
33
34     if use_unstable_features {
35         cmd.arg("--features").arg("unstable-features");
36     }
37
38     match channel {
39         "debug" => {}
40         "release" => {
41             cmd.arg("--release");
42         }
43         _ => unreachable!(),
44     }
45
46     cmd.env("RUSTFLAGS", rustflags);
47
48     eprintln!("[BUILD] rustc_codegen_cranelift");
49     super::utils::spawn_and_wait(cmd);
50
51     CG_CLIF
52         .target_dir(dirs)
53         .join(&bootstrap_host_compiler.triple)
54         .join(channel)
55         .join(get_file_name("rustc_codegen_cranelift", "dylib"))
56 }