|
| 1 | +use camino::Utf8PathBuf; |
| 2 | +use derive_builder::Builder; |
| 3 | + |
| 4 | +#[derive(Builder)] |
| 5 | +pub struct Environment { |
| 6 | + host_triple: String, |
| 7 | + python_binary: String, |
| 8 | + /// The rustc checkout, where the compiler source is located. |
| 9 | + checkout_dir: Utf8PathBuf, |
| 10 | + /// The main directory where the build occurs. Stage0 rustc and cargo have to be available in |
| 11 | + /// this directory before `opt-dist` is started. |
| 12 | + build_dir: Utf8PathBuf, |
| 13 | + /// Directory where the optimization artifacts (PGO/BOLT profiles, etc.) |
| 14 | + /// will be stored. |
| 15 | + artifact_dir: Utf8PathBuf, |
| 16 | + /// Path to the host LLVM used to compile LLVM in `src/llvm-project`. |
| 17 | + host_llvm_dir: Utf8PathBuf, |
| 18 | + /// List of test paths that should be skipped when testing the optimized artifacts. |
| 19 | + skipped_tests: Vec<String>, |
| 20 | + /// Directory containing a pre-built rustc-perf checkout. |
| 21 | + #[builder(default)] |
| 22 | + prebuilt_rustc_perf: Option<Utf8PathBuf>, |
| 23 | + use_bolt: bool, |
| 24 | + shared_llvm: bool, |
| 25 | +} |
| 26 | + |
| 27 | +impl Environment { |
| 28 | + pub fn host_triple(&self) -> &str { |
| 29 | + &self.host_triple |
| 30 | + } |
| 31 | + |
| 32 | + pub fn python_binary(&self) -> &str { |
| 33 | + &self.python_binary |
| 34 | + } |
| 35 | + |
| 36 | + pub fn checkout_path(&self) -> Utf8PathBuf { |
| 37 | + self.checkout_dir.clone() |
| 38 | + } |
| 39 | + |
| 40 | + pub fn build_root(&self) -> Utf8PathBuf { |
| 41 | + self.build_dir.clone() |
| 42 | + } |
| 43 | + |
| 44 | + pub fn build_artifacts(&self) -> Utf8PathBuf { |
| 45 | + self.build_root().join("build").join(&self.host_triple) |
| 46 | + } |
| 47 | + |
| 48 | + pub fn artifact_dir(&self) -> Utf8PathBuf { |
| 49 | + self.artifact_dir.clone() |
| 50 | + } |
| 51 | + |
| 52 | + pub fn cargo_stage_0(&self) -> Utf8PathBuf { |
| 53 | + self.build_artifacts() |
| 54 | + .join("stage0") |
| 55 | + .join("bin") |
| 56 | + .join(format!("cargo{}", executable_extension())) |
| 57 | + } |
| 58 | + |
| 59 | + pub fn rustc_stage_0(&self) -> Utf8PathBuf { |
| 60 | + self.build_artifacts() |
| 61 | + .join("stage0") |
| 62 | + .join("bin") |
| 63 | + .join(format!("rustc{}", executable_extension())) |
| 64 | + } |
| 65 | + |
| 66 | + pub fn rustc_stage_2(&self) -> Utf8PathBuf { |
| 67 | + self.build_artifacts() |
| 68 | + .join("stage2") |
| 69 | + .join("bin") |
| 70 | + .join(format!("rustc{}", executable_extension())) |
| 71 | + } |
| 72 | + |
| 73 | + pub fn prebuilt_rustc_perf(&self) -> Option<Utf8PathBuf> { |
| 74 | + self.prebuilt_rustc_perf.clone() |
| 75 | + } |
| 76 | + |
| 77 | + /// Path to the built rustc-perf benchmark suite. |
| 78 | + pub fn rustc_perf_dir(&self) -> Utf8PathBuf { |
| 79 | + self.artifact_dir.join("rustc-perf") |
| 80 | + } |
| 81 | + |
| 82 | + pub fn host_llvm_dir(&self) -> Utf8PathBuf { |
| 83 | + self.host_llvm_dir.clone() |
| 84 | + } |
| 85 | + |
| 86 | + pub fn use_bolt(&self) -> bool { |
| 87 | + self.use_bolt |
| 88 | + } |
| 89 | + |
| 90 | + pub fn supports_shared_llvm(&self) -> bool { |
| 91 | + self.shared_llvm |
| 92 | + } |
| 93 | + |
| 94 | + pub fn skipped_tests(&self) -> &[String] { |
| 95 | + &self.skipped_tests |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +/// What is the extension of binary executables on this platform? |
| 100 | +#[cfg(target_family = "unix")] |
| 101 | +pub fn executable_extension() -> &'static str { |
| 102 | + "" |
| 103 | +} |
| 104 | + |
| 105 | +#[cfg(target_family = "windows")] |
| 106 | +pub fn executable_extension() -> &'static str { |
| 107 | + ".exe" |
| 108 | +} |
0 commit comments