about summary refs log tree commit diff
path: root/compiler/rustc_codegen_cranelift/build_system
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2025-01-05 15:44:46 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2025-01-05 15:44:46 +0000
commita94e2d513b8b3113ea53e5abf4403ef4e91914e3 (patch)
tree17bf96e2103b05a754166802f73af0f3c96e1552 /compiler/rustc_codegen_cranelift/build_system
parentdcfa38fe234de9304169afc6638e81d0dd222c06 (diff)
parent918acafef682d0d0ca30b47de4768210417ff362 (diff)
Merge commit '918acafef682d0d0ca30b47de4768210417ff362' into sync_cg_clif-2025-01-05
Diffstat (limited to 'compiler/rustc_codegen_cranelift/build_system')
-rw-r--r--compiler/rustc_codegen_cranelift/build_system/bench.rs47
-rw-r--r--compiler/rustc_codegen_cranelift/build_system/config.rs20
-rw-r--r--compiler/rustc_codegen_cranelift/build_system/main.rs16
-rw-r--r--compiler/rustc_codegen_cranelift/build_system/path.rs16
4 files changed, 29 insertions, 70 deletions
diff --git a/compiler/rustc_codegen_cranelift/build_system/bench.rs b/compiler/rustc_codegen_cranelift/build_system/bench.rs
index 73a0f325fc2..8359b7b5279 100644
--- a/compiler/rustc_codegen_cranelift/build_system/bench.rs
+++ b/compiler/rustc_codegen_cranelift/build_system/bench.rs
@@ -16,11 +16,7 @@ static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
     "<none>",
 );
 
-pub(crate) fn benchmark(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
-    benchmark_simple_raytracer(dirs, bootstrap_host_compiler);
-}
-
-fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
+pub(crate) fn benchmark(dirs: &Dirs, compiler: &Compiler) {
     if std::process::Command::new("hyperfine").output().is_err() {
         eprintln!("Hyperfine not installed");
         eprintln!("Hint: Try `cargo install hyperfine` to install hyperfine");
@@ -39,9 +35,9 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
     };
 
     eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
-    let cargo_clif = dirs
-        .dist_dir
-        .join(get_file_name(&bootstrap_host_compiler.rustc, "cargo_clif", "bin").replace('_', "-"));
+    let cargo_clif = &compiler.cargo;
+    let rustc_clif = &compiler.rustc;
+    let rustflags = &compiler.rustflags.join("\x1f");
     let manifest_path = SIMPLE_RAYTRACER_REPO.source_dir().to_path(dirs).join("Cargo.toml");
     let target_dir = dirs.build_dir.join("simple_raytracer");
 
@@ -56,22 +52,24 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
         target_dir = target_dir.display(),
     );
     let clif_build_cmd = format!(
-        "RUSTC=rustc {cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir} && (rm build/raytracer_cg_clif || true) && ln build/simple_raytracer/debug/main build/raytracer_cg_clif",
+        "RUSTC={rustc_clif} CARGO_ENCODED_RUSTFLAGS=\"{rustflags}\" {cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir} && (rm build/raytracer_cg_clif || true) && ln build/simple_raytracer/debug/main build/raytracer_cg_clif",
         cargo_clif = cargo_clif.display(),
+        rustc_clif = rustc_clif.display(),
         manifest_path = manifest_path.display(),
         target_dir = target_dir.display(),
     );
     let clif_build_opt_cmd = format!(
-        "RUSTC=rustc {cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir} --release && (rm build/raytracer_cg_clif_opt || true) && ln build/simple_raytracer/release/main build/raytracer_cg_clif_opt",
+        "RUSTC={rustc_clif} CARGO_ENCODED_RUSTFLAGS=\"{rustflags}\" {cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir} --release && (rm build/raytracer_cg_clif_opt || true) && ln build/simple_raytracer/release/main build/raytracer_cg_clif_opt",
         cargo_clif = cargo_clif.display(),
+        rustc_clif = rustc_clif.display(),
         manifest_path = manifest_path.display(),
         target_dir = target_dir.display(),
     );
 
-    let bench_compile_markdown = dirs.dist_dir.join("bench_compile.md");
+    let bench_compile_markdown = dirs.build_dir.join("bench_compile.md");
 
     let bench_compile = hyperfine_command(
-        1,
+        0,
         bench_runs,
         Some(&clean_cmd),
         &[
@@ -92,23 +90,14 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
 
     eprintln!("[BENCH RUN] ebobby/simple-raytracer");
 
-    let bench_run_markdown = dirs.dist_dir.join("bench_run.md");
-
-    let raytracer_cg_llvm = Path::new(".").join(get_file_name(
-        &bootstrap_host_compiler.rustc,
-        "raytracer_cg_llvm",
-        "bin",
-    ));
-    let raytracer_cg_clif = Path::new(".").join(get_file_name(
-        &bootstrap_host_compiler.rustc,
-        "raytracer_cg_clif",
-        "bin",
-    ));
-    let raytracer_cg_clif_opt = Path::new(".").join(get_file_name(
-        &bootstrap_host_compiler.rustc,
-        "raytracer_cg_clif_opt",
-        "bin",
-    ));
+    let bench_run_markdown = dirs.build_dir.join("bench_run.md");
+
+    let raytracer_cg_llvm =
+        Path::new(".").join(get_file_name(&compiler.rustc, "raytracer_cg_llvm", "bin"));
+    let raytracer_cg_clif =
+        Path::new(".").join(get_file_name(&compiler.rustc, "raytracer_cg_clif", "bin"));
+    let raytracer_cg_clif_opt =
+        Path::new(".").join(get_file_name(&compiler.rustc, "raytracer_cg_clif_opt", "bin"));
     let mut bench_run = hyperfine_command(
         0,
         bench_runs,
diff --git a/compiler/rustc_codegen_cranelift/build_system/config.rs b/compiler/rustc_codegen_cranelift/build_system/config.rs
index ef540cf1f82..37bc4c5d782 100644
--- a/compiler/rustc_codegen_cranelift/build_system/config.rs
+++ b/compiler/rustc_codegen_cranelift/build_system/config.rs
@@ -33,23 +33,3 @@ pub(crate) fn get_bool(name: &str) -> bool {
         true
     }
 }
-
-pub(crate) fn get_value(name: &str) -> Option<String> {
-    let values = load_config_file()
-        .into_iter()
-        .filter(|(key, _)| key == name)
-        .map(|(_, val)| val)
-        .collect::<Vec<_>>();
-    if values.is_empty() {
-        None
-    } else if values.len() == 1 {
-        if values[0].is_none() {
-            eprintln!("Config `{}` missing value", name);
-            process::exit(1);
-        }
-        values.into_iter().next().unwrap()
-    } else {
-        eprintln!("Config `{}` given multiple values: {:?}", name, values);
-        process::exit(1);
-    }
-}
diff --git a/compiler/rustc_codegen_cranelift/build_system/main.rs b/compiler/rustc_codegen_cranelift/build_system/main.rs
index 99e6146657f..3ff9751a3ef 100644
--- a/compiler/rustc_codegen_cranelift/build_system/main.rs
+++ b/compiler/rustc_codegen_cranelift/build_system/main.rs
@@ -156,10 +156,8 @@ fn main() {
         let cargo = rustc_info::get_cargo_path();
         let rustc = rustc_info::get_rustc_path();
         let rustdoc = rustc_info::get_rustdoc_path();
-        let triple = std::env::var("HOST_TRIPLE")
-            .ok()
-            .or_else(|| config::get_value("host"))
-            .unwrap_or_else(|| rustc_info::get_host_triple(&rustc));
+        let triple =
+            std::env::var("HOST_TRIPLE").unwrap_or_else(|_| rustc_info::get_host_triple(&rustc));
         Compiler {
             cargo,
             rustc,
@@ -170,10 +168,8 @@ fn main() {
             runner: vec![],
         }
     };
-    let target_triple = std::env::var("TARGET_TRIPLE")
-        .ok()
-        .or_else(|| config::get_value("target"))
-        .unwrap_or_else(|| bootstrap_host_compiler.triple.clone());
+    let target_triple =
+        std::env::var("TARGET_TRIPLE").unwrap_or_else(|_| bootstrap_host_compiler.triple.clone());
 
     let dirs = path::Dirs {
         source_dir: current_dir.clone(),
@@ -247,7 +243,7 @@ fn main() {
             );
         }
         Command::Bench => {
-            build_sysroot::build_sysroot(
+            let compiler = build_sysroot::build_sysroot(
                 &dirs,
                 sysroot_kind,
                 &cg_clif_dylib,
@@ -255,7 +251,7 @@ fn main() {
                 rustup_toolchain_name.as_deref(),
                 target_triple,
             );
-            bench::benchmark(&dirs, &bootstrap_host_compiler);
+            bench::benchmark(&dirs, &compiler);
         }
     }
 }
diff --git a/compiler/rustc_codegen_cranelift/build_system/path.rs b/compiler/rustc_codegen_cranelift/build_system/path.rs
index 20a81156b71..d6a6558b2be 100644
--- a/compiler/rustc_codegen_cranelift/build_system/path.rs
+++ b/compiler/rustc_codegen_cranelift/build_system/path.rs
@@ -11,20 +11,11 @@ pub(crate) struct Dirs {
 
 #[doc(hidden)]
 #[derive(Debug, Copy, Clone)]
-pub(crate) enum PathBase {
+enum PathBase {
     Source,
     Build,
 }
 
-impl PathBase {
-    fn to_path(self, dirs: &Dirs) -> PathBuf {
-        match self {
-            PathBase::Source => dirs.source_dir.clone(),
-            PathBase::Build => dirs.build_dir.clone(),
-        }
-    }
-}
-
 #[derive(Debug, Copy, Clone)]
 pub(crate) struct RelPath {
     base: PathBase,
@@ -41,6 +32,9 @@ impl RelPath {
     }
 
     pub(crate) fn to_path(&self, dirs: &Dirs) -> PathBuf {
-        self.base.to_path(dirs).join(self.suffix)
+        match self.base {
+            PathBase::Source => dirs.source_dir.join(self.suffix),
+            PathBase::Build => dirs.build_dir.join(self.suffix),
+        }
     }
 }