about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-01-15 14:14:13 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-01-15 14:14:13 +0000
commitabcff71bec1ef1614041e59ea4f947bb0a13267c (patch)
tree5330859817bd2210357b0e14beba5a7b2ced6fb4
parent13197322ec78820cdd3214d8001f81fa4773918b (diff)
downloadrust-abcff71bec1ef1614041e59ea4f947bb0a13267c.tar.gz
rust-abcff71bec1ef1614041e59ea4f947bb0a13267c.zip
Significantly speed up assembling of sysroots
By avoiding some redundant rustc calls and stripping debuginfo for
wrappers. ./y.rs build --sysroot none now runs 44% faster.

Benchmark 1: ./y_before.bin build --sysroot none
  Time (mean ± σ):      2.200 s ±  0.038 s    [User: 2.140 s, System: 0.653 s]
  Range (min … max):    2.171 s …  2.303 s    10 runs

Benchmark 2: ./y_after.bin build --sysroot none
  Time (mean ± σ):      1.528 s ±  0.020 s    [User: 1.388 s, System: 0.490 s]
  Range (min … max):    1.508 s …  1.580 s    10 runs

Summary
  './y_after.bin build --sysroot none' ran
    1.44 ± 0.03 times faster than './y_before.bin build --sysroot none'
-rw-r--r--build_system/bench.rs5
-rw-r--r--build_system/build_sysroot.rs27
-rw-r--r--build_system/rustc_info.rs9
-rw-r--r--build_system/utils.rs19
4 files changed, 25 insertions, 35 deletions
diff --git a/build_system/bench.rs b/build_system/bench.rs
index 1e83f21ba57..01d44dafbdd 100644
--- a/build_system/bench.rs
+++ b/build_system/bench.rs
@@ -4,7 +4,7 @@ use std::path::Path;
 
 use super::path::{Dirs, RelPath};
 use super::prepare::GitRepo;
-use super::rustc_info::{get_file_name, get_wrapper_file_name};
+use super::rustc_info::get_file_name;
 use super::utils::{hyperfine_command, is_ci, spawn_and_wait, CargoProject, Compiler};
 
 pub(crate) static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
@@ -51,7 +51,8 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
         .unwrap();
 
     eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
-    let cargo_clif = RelPath::DIST.to_path(dirs).join(get_wrapper_file_name("cargo-clif", "bin"));
+    let cargo_clif =
+        RelPath::DIST.to_path(dirs).join(get_file_name("cargo_clif", "bin").replace('_', "-"));
     let manifest_path = SIMPLE_RAYTRACER.manifest_path(dirs);
     let target_dir = SIMPLE_RAYTRACER.target_dir(dirs);
 
diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs
index d3bc7ec0128..cbc58365e69 100644
--- a/build_system/build_sysroot.rs
+++ b/build_system/build_sysroot.rs
@@ -3,9 +3,7 @@ use std::path::{Path, PathBuf};
 use std::process::{self, Command};
 
 use super::path::{Dirs, RelPath};
-use super::rustc_info::{
-    get_file_name, get_rustc_version, get_toolchain_name, get_wrapper_file_name,
-};
+use super::rustc_info::{get_cargo_path, get_file_name, get_rustc_version, get_toolchain_name};
 use super::utils::{spawn_and_wait, try_hard_link, CargoProject, Compiler};
 use super::SysrootKind;
 
@@ -42,8 +40,9 @@ pub(crate) fn build_sysroot(
     try_hard_link(cg_clif_dylib_src, &cg_clif_dylib_path);
 
     // Build and copy rustc and cargo wrappers
+    let wrapper_base_name = get_file_name("____", "bin");
     for wrapper in ["rustc-clif", "rustdoc-clif", "cargo-clif"] {
-        let wrapper_name = get_wrapper_file_name(wrapper, "bin");
+        let wrapper_name = wrapper_base_name.replace("____", wrapper);
 
         let mut build_cargo_wrapper_cmd = Command::new(&bootstrap_host_compiler.rustc);
         build_cargo_wrapper_cmd
@@ -51,7 +50,7 @@ pub(crate) fn build_sysroot(
             .arg(RelPath::SCRIPTS.to_path(dirs).join(&format!("{wrapper}.rs")))
             .arg("-o")
             .arg(DIST_DIR.to_path(dirs).join(wrapper_name))
-            .arg("-g");
+            .arg("-Cstrip=debuginfo");
         spawn_and_wait(build_cargo_wrapper_cmd);
     }
 
@@ -89,7 +88,23 @@ pub(crate) fn build_sysroot(
         }
     }
 
-    let mut target_compiler = Compiler::clif_with_triple(&dirs, target_triple);
+    let mut target_compiler = {
+        let dirs: &Dirs = &dirs;
+        let rustc_clif =
+            RelPath::DIST.to_path(&dirs).join(wrapper_base_name.replace("____", "rustc-clif"));
+        let rustdoc_clif =
+            RelPath::DIST.to_path(&dirs).join(wrapper_base_name.replace("____", "rustdoc-clif"));
+
+        Compiler {
+            cargo: get_cargo_path(),
+            rustc: rustc_clif.clone(),
+            rustdoc: rustdoc_clif.clone(),
+            rustflags: String::new(),
+            rustdocflags: String::new(),
+            triple: target_triple,
+            runner: vec![],
+        }
+    };
     if !is_native {
         target_compiler.set_cross_linker_and_runner();
     }
diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs
index 8a7e1c472dd..a70453b4422 100644
--- a/build_system/rustc_info.rs
+++ b/build_system/rustc_info.rs
@@ -93,12 +93,3 @@ pub(crate) fn get_file_name(crate_name: &str, crate_type: &str) -> String {
     assert!(file_name.contains(crate_name));
     file_name
 }
-
-/// Similar to `get_file_name`, but converts any dashes (`-`) in the `crate_name` to
-/// underscores (`_`). This is specially made for the rustc and cargo wrappers
-/// which have a dash in the name, and that is not allowed in a crate name.
-pub(crate) fn get_wrapper_file_name(crate_name: &str, crate_type: &str) -> String {
-    let crate_name = crate_name.replace('-', "_");
-    let wrapper_name = get_file_name(&crate_name, crate_type);
-    wrapper_name.replace('_', "-")
-}
diff --git a/build_system/utils.rs b/build_system/utils.rs
index 07ea482fbbe..21bfb1b1f00 100644
--- a/build_system/utils.rs
+++ b/build_system/utils.rs
@@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
 use std::process::{self, Command, Stdio};
 
 use super::path::{Dirs, RelPath};
-use super::rustc_info::{get_cargo_path, get_rustc_path, get_rustdoc_path, get_wrapper_file_name};
+use super::rustc_info::{get_cargo_path, get_rustc_path, get_rustdoc_path};
 
 #[derive(Clone, Debug)]
 pub(crate) struct Compiler {
@@ -31,23 +31,6 @@ impl Compiler {
         }
     }
 
-    pub(crate) fn clif_with_triple(dirs: &Dirs, triple: String) -> Compiler {
-        let rustc_clif =
-            RelPath::DIST.to_path(&dirs).join(get_wrapper_file_name("rustc-clif", "bin"));
-        let rustdoc_clif =
-            RelPath::DIST.to_path(&dirs).join(get_wrapper_file_name("rustdoc-clif", "bin"));
-
-        Compiler {
-            cargo: get_cargo_path(),
-            rustc: rustc_clif.clone(),
-            rustdoc: rustdoc_clif.clone(),
-            rustflags: String::new(),
-            rustdocflags: String::new(),
-            triple,
-            runner: vec![],
-        }
-    }
-
     pub(crate) fn set_cross_linker_and_runner(&mut self) {
         match self.triple.as_str() {
             "aarch64-unknown-linux-gnu" => {