about summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
authorThe Miri Conjob Bot <miri@cron.bot>2023-10-17 05:05:07 +0000
committerThe Miri Conjob Bot <miri@cron.bot>2023-10-17 05:05:07 +0000
commit2ca415c1c2fc7991027a1cfa332e305b4f27a0f8 (patch)
treea072b8ca50207f8ed55e085580de73b0e37802f3 /src/bootstrap
parent8fa1b6aad2bd14fa2477daf8eeab69464e8878a5 (diff)
parenteccc9e66287d5fd141e458ae3ab25ac96a567972 (diff)
downloadrust-2ca415c1c2fc7991027a1cfa332e305b4f27a0f8.tar.gz
rust-2ca415c1c2fc7991027a1cfa332e305b4f27a0f8.zip
Merge from rustc
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/Cargo.lock4
-rw-r--r--src/bootstrap/Cargo.toml24
-rw-r--r--src/bootstrap/bin/rustc.rs6
-rw-r--r--src/bootstrap/builder/tests.rs1
-rw-r--r--src/bootstrap/compile.rs5
-rw-r--r--src/bootstrap/config.rs2
-rw-r--r--src/bootstrap/config/tests.rs23
-rw-r--r--src/bootstrap/dist.rs14
-rw-r--r--src/bootstrap/download.rs38
-rw-r--r--src/bootstrap/flags.rs3
-rw-r--r--src/bootstrap/lib.rs17
-rw-r--r--src/bootstrap/run.rs32
-rw-r--r--src/bootstrap/test.rs7
13 files changed, 115 insertions, 61 deletions
diff --git a/src/bootstrap/Cargo.lock b/src/bootstrap/Cargo.lock
index f5220e361b3..96a0eb75582 100644
--- a/src/bootstrap/Cargo.lock
+++ b/src/bootstrap/Cargo.lock
@@ -126,9 +126,9 @@ dependencies = [
 
 [[package]]
 name = "clap_complete"
-version = "4.2.2"
+version = "4.4.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "36774babb166352bb4f7b9cb16f781ffa3439d2a8f12cd31bea85a38c888fea3"
+checksum = "e3ae8ba90b9d8b007efe66e55e48fb936272f5ca00349b5b0e89877520d35ea7"
 dependencies = [
  "clap",
 ]
diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml
index 9bf26948af3..006a992eb3c 100644
--- a/src/bootstrap/Cargo.toml
+++ b/src/bootstrap/Cargo.toml
@@ -5,6 +5,9 @@ edition = "2021"
 build = "build.rs"
 default-run = "bootstrap"
 
+[features]
+build-metrics = ["sysinfo"]
+
 [lib]
 path = "lib.rs"
 doctest = false
@@ -31,12 +34,18 @@ test = false
 
 [dependencies]
 build_helper = { path = "../tools/build_helper" }
+cc = "1.0.69"
+clap = { version = "4.2.4", default-features = false, features = ["std", "usage", "help", "derive", "error-context"] }
+clap_complete = "4.4.3"
 cmake = "0.1.38"
 filetime = "0.2"
-cc = "1.0.69"
-libc = "0.2"
 hex = "0.4"
+ignore = "0.4.10"
+libc = "0.2"
 object = { version = "0.32.0", default-features = false, features = ["archive", "coff", "read_core", "unaligned"] }
+once_cell = "1.7.2"
+opener = "0.5"
+semver = "1.0.17"
 serde = "1.0.137"
 # Directly use serde_derive rather than through the derive feature of serde to allow building both
 # in parallel and to allow serde_json and toml to start building as soon as serde has been built.
@@ -46,17 +55,11 @@ sha2 = "0.10"
 tar = "0.4"
 termcolor = "1.2.0"
 toml = "0.5"
-ignore = "0.4.10"
-opener = "0.5"
-once_cell = "1.7.2"
-xz2 = "0.1"
 walkdir = "2"
+xz2 = "0.1"
 
 # Dependencies needed by the build-metrics feature
 sysinfo = { version = "0.26.0", optional = true }
-clap = { version = "4.2.4", default-features = false, features = ["std", "usage", "help", "derive", "error-context"] }
-clap_complete = "4.2.2"
-semver = "1.0.17"
 
 # Solaris doesn't support flock() and thus fd-lock is not option now
 [target.'cfg(not(target_os = "solaris"))'.dependencies]
@@ -80,9 +83,6 @@ features = [
 [dev-dependencies]
 pretty_assertions = "1.4"
 
-[features]
-build-metrics = ["sysinfo"]
-
 # We care a lot about bootstrap's compile times, so don't include debuginfo for
 # dependencies, only bootstrap itself.
 [profile.dev]
diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs
index b7fd2aa9637..6cc5162120a 100644
--- a/src/bootstrap/bin/rustc.rs
+++ b/src/bootstrap/bin/rustc.rs
@@ -193,6 +193,12 @@ fn main() {
         eprintln!("{prefix} libdir: {libdir:?}");
     }
 
+    if env::var_os("RUSTC_BOLT_LINK_FLAGS").is_some() {
+        if let Some("rustc_driver") = crate_name {
+            cmd.arg("-Clink-args=-Wl,-q");
+        }
+    }
+
     let start = Instant::now();
     let (child, status) = {
         let errmsg = format!("\nFailed to run:\n{cmd:?}\n-------------");
diff --git a/src/bootstrap/builder/tests.rs b/src/bootstrap/builder/tests.rs
index 80e66622e8b..0294102286e 100644
--- a/src/bootstrap/builder/tests.rs
+++ b/src/bootstrap/builder/tests.rs
@@ -22,7 +22,6 @@ fn configure_with_args(cmd: &[String], host: &[&str], target: &[&str]) -> Config
         ..Config::parse(&["check".to_owned()])
     });
     submodule_build.update_submodule(Path::new("src/doc/book"));
-    submodule_build.update_submodule(Path::new("src/tools/rust-analyzer"));
     config.submodules = Some(false);
 
     config.ninja_in_file = false;
diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs
index 6821ded1458..623fa5fa111 100644
--- a/src/bootstrap/compile.rs
+++ b/src/bootstrap/compile.rs
@@ -906,6 +906,11 @@ impl Step for Rustc {
             cargo.arg("-p").arg(krate);
         }
 
+        if builder.build.config.enable_bolt_settings && compiler.stage == 1 {
+            // Relocations are required for BOLT to work.
+            cargo.env("RUSTC_BOLT_LINK_FLAGS", "1");
+        }
+
         let _guard = builder.msg_sysroot_tool(
             Kind::Build,
             compiler.stage,
diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs
index 1755c3166de..759d874a089 100644
--- a/src/bootstrap/config.rs
+++ b/src/bootstrap/config.rs
@@ -234,6 +234,7 @@ pub struct Config {
     pub llvm_profile_use: Option<String>,
     pub llvm_profile_generate: bool,
     pub llvm_libunwind_default: Option<LlvmLibunwind>,
+    pub enable_bolt_settings: bool,
 
     pub reproducible_artifacts: Vec<String>,
 
@@ -1128,6 +1129,7 @@ impl Config {
         config.free_args = std::mem::take(&mut flags.free_args);
         config.llvm_profile_use = flags.llvm_profile_use;
         config.llvm_profile_generate = flags.llvm_profile_generate;
+        config.enable_bolt_settings = flags.enable_bolt_settings;
 
         // Infer the rest of the configuration.
 
diff --git a/src/bootstrap/config/tests.rs b/src/bootstrap/config/tests.rs
index d091f33eee4..ae8363b6de9 100644
--- a/src/bootstrap/config/tests.rs
+++ b/src/bootstrap/config/tests.rs
@@ -3,7 +3,12 @@ use crate::config::TomlConfig;
 use super::{Config, Flags};
 use clap::CommandFactory;
 use serde::Deserialize;
-use std::{env, path::Path};
+use std::{
+    env,
+    fs::{remove_file, File},
+    io::Write,
+    path::Path,
+};
 
 fn parse(config: &str) -> Config {
     Config::parse_inner(&["check".to_owned(), "--config=/does/not/exist".to_owned()], |&_| {
@@ -196,3 +201,19 @@ fn rust_optimize() {
 fn invalid_rust_optimize() {
     parse("rust.optimize = \"a\"");
 }
+
+#[test]
+fn verify_file_integrity() {
+    let config = parse("");
+
+    let tempfile = config.tempdir().join(".tmp-test-file");
+    File::create(&tempfile).unwrap().write_all(b"dummy value").unwrap();
+    assert!(tempfile.exists());
+
+    assert!(
+        config
+            .verify(&tempfile, "7e255dd9542648a8779268a0f268b891a198e9828e860ed23f826440e786eae5")
+    );
+
+    remove_file(tempfile).unwrap();
+}
diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs
index 05556d2f679..7bb59e5a611 100644
--- a/src/bootstrap/dist.rs
+++ b/src/bootstrap/dist.rs
@@ -1002,11 +1002,15 @@ impl Step for PlainSourceTarball {
             channel::write_commit_info_file(&plain_dst_src, info);
         }
 
-        // If we're building from git sources, we need to vendor a complete distribution.
-        if builder.rust_info().is_managed_git_subrepository() {
-            // Ensure we have the submodules checked out.
-            builder.update_submodule(Path::new("src/tools/cargo"));
-            builder.update_submodule(Path::new("src/tools/rust-analyzer"));
+        // If we're building from git or tarball sources, we need to vendor
+        // a complete distribution.
+        if builder.rust_info().is_managed_git_subrepository()
+            || builder.rust_info().is_from_tarball()
+        {
+            if builder.rust_info().is_managed_git_subrepository() {
+                // Ensure we have the submodules checked out.
+                builder.update_submodule(Path::new("src/tools/cargo"));
+            }
 
             // Vendor all Cargo dependencies
             let mut cmd = Command::new(&builder.initial_cargo);
diff --git a/src/bootstrap/download.rs b/src/bootstrap/download.rs
index 8e9614ec89a..2a0dec75599 100644
--- a/src/bootstrap/download.rs
+++ b/src/bootstrap/download.rs
@@ -320,25 +320,43 @@ impl Config {
     }
 
     /// Returns whether the SHA256 checksum of `path` matches `expected`.
-    fn verify(&self, path: &Path, expected: &str) -> bool {
+    pub(crate) fn verify(&self, path: &Path, expected: &str) -> bool {
         use sha2::Digest;
 
         self.verbose(&format!("verifying {}", path.display()));
+
+        if self.dry_run() {
+            return false;
+        }
+
         let mut hasher = sha2::Sha256::new();
-        // FIXME: this is ok for rustfmt (4.1 MB large at time of writing), but it seems memory-intensive for rustc and larger components.
-        // Consider using streaming IO instead?
-        let contents = if self.dry_run() { vec![] } else { t!(fs::read(path)) };
-        hasher.update(&contents);
-        let found = hex::encode(hasher.finalize().as_slice());
-        let verified = found == expected;
-        if !verified && !self.dry_run() {
+
+        let file = t!(File::open(path));
+        let mut reader = BufReader::new(file);
+
+        loop {
+            let buffer = t!(reader.fill_buf());
+            let l = buffer.len();
+            // break if EOF
+            if l == 0 {
+                break;
+            }
+            hasher.update(buffer);
+            reader.consume(l);
+        }
+
+        let checksum = hex::encode(hasher.finalize().as_slice());
+        let verified = checksum == expected;
+
+        if !verified {
             println!(
                 "invalid checksum: \n\
-                found:    {found}\n\
+                found:    {checksum}\n\
                 expected: {expected}",
             );
         }
-        return verified;
+
+        verified
     }
 }
 
diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs
index e0291e407b3..5a6a5f37fc6 100644
--- a/src/bootstrap/flags.rs
+++ b/src/bootstrap/flags.rs
@@ -152,6 +152,9 @@ pub struct Flags {
     /// generate PGO profile with llvm built for rustc
     #[arg(global(true), long)]
     pub llvm_profile_generate: bool,
+    /// Enable BOLT link flags
+    #[arg(global(true), long)]
+    pub enable_bolt_settings: bool,
     /// Additional reproducible artifacts that should be added to the reproducible artifacts archive.
     #[arg(global(true), long)]
     pub reproducible_artifact: Vec<String>,
diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
index 5c78015e560..a9a81cb25f6 100644
--- a/src/bootstrap/lib.rs
+++ b/src/bootstrap/lib.rs
@@ -138,18 +138,9 @@ const EXTRA_CHECK_CFGS: &[(Option<Mode>, &str, Option<&[&'static str]>)] = &[
     (Some(Mode::Std), "freebsd13", None),
     (Some(Mode::Std), "backtrace_in_libstd", None),
     /* Extra values not defined in the built-in targets yet, but used in std */
-    // #[cfg(bootstrap)]
-    (Some(Mode::Std), "target_vendor", Some(&["unikraft"])),
     (Some(Mode::Std), "target_env", Some(&["libnx"])),
-    // #[cfg(bootstrap)] hurd
-    (Some(Mode::Std), "target_os", Some(&["teeos", "hurd"])),
-    (Some(Mode::Rustc), "target_os", Some(&["hurd"])),
-    // #[cfg(bootstrap)] mips32r6, mips64r6
-    (
-        Some(Mode::Std),
-        "target_arch",
-        Some(&["asmjs", "spirv", "nvptx", "xtensa", "mips32r6", "mips64r6", "csky"]),
-    ),
+    // (Some(Mode::Std), "target_os", Some(&[])),
+    (Some(Mode::Std), "target_arch", Some(&["asmjs", "spirv", "nvptx", "xtensa"])),
     /* Extra names used by dependencies */
     // FIXME: Used by serde_json, but we should not be triggering on external dependencies.
     (Some(Mode::Rustc), "no_btreemap_remove_entry", None),
@@ -368,6 +359,10 @@ impl Build {
         // https://github.com/rust-lang/rust/blob/a8a33cf27166d3eabaffc58ed3799e054af3b0c6/src/bootstrap/bootstrap.py#L796-L797
         let is_sudo = match env::var_os("SUDO_USER") {
             Some(_sudo_user) => {
+                // SAFETY: getuid() system call is always successful and no return value is reserved
+                // to indicate an error.
+                //
+                // For more context, see https://man7.org/linux/man-pages/man2/geteuid.2.html
                 let uid = unsafe { libc::getuid() };
                 uid == 0
             }
diff --git a/src/bootstrap/run.rs b/src/bootstrap/run.rs
index 4082f5bb9b1..f253f5225a1 100644
--- a/src/bootstrap/run.rs
+++ b/src/bootstrap/run.rs
@@ -1,8 +1,6 @@
 use std::path::PathBuf;
 use std::process::Command;
 
-use clap_complete::shells;
-
 use crate::builder::{Builder, RunConfig, ShouldRun, Step};
 use crate::config::TargetSelection;
 use crate::dist::distdir;
@@ -268,23 +266,29 @@ impl Step for GenerateWindowsSys {
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
 pub struct GenerateCompletions;
 
+macro_rules! generate_completions {
+    ( $( ( $shell:ident, $filename:expr ) ),* ) => {
+        $(
+            if let Some(comp) = get_completion($shell, &$filename) {
+                std::fs::write(&$filename, comp).expect(&format!("writing {} completion", stringify!($shell)));
+            }
+        )*
+    };
+}
+
 impl Step for GenerateCompletions {
     type Output = ();
 
     /// Uses `clap_complete` to generate shell completions.
     fn run(self, builder: &Builder<'_>) {
-        // FIXME(clubby789): enable zsh when clap#4898 is fixed
-        let [bash, fish, powershell] = ["x.py.sh", "x.py.fish", "x.py.ps1"]
-            .map(|filename| builder.src.join("src/etc/completions").join(filename));
-        if let Some(comp) = get_completion(shells::Bash, &bash) {
-            std::fs::write(&bash, comp).expect("writing bash completion");
-        }
-        if let Some(comp) = get_completion(shells::Fish, &fish) {
-            std::fs::write(&fish, comp).expect("writing fish completion");
-        }
-        if let Some(comp) = get_completion(shells::PowerShell, &powershell) {
-            std::fs::write(&powershell, comp).expect("writing powershell completion");
-        }
+        use clap_complete::shells::{Bash, Fish, PowerShell, Zsh};
+
+        generate_completions!(
+            (Bash, builder.src.join("src/etc/completions/x.py.sh")),
+            (Zsh, builder.src.join("src/etc/completions/x.py.zsh")),
+            (Fish, builder.src.join("src/etc/completions/x.py.fish")),
+            (PowerShell, builder.src.join("src/etc/completions/x.py.ps1"))
+        );
     }
 
     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs
index ba030f0f525..fb8ec0355c2 100644
--- a/src/bootstrap/test.rs
+++ b/src/bootstrap/test.rs
@@ -1135,13 +1135,14 @@ help: to skip test's attempt to check tidiness, pass `--skip src/tools/tidy` to
         builder.ensure(ExpandYamlAnchors);
 
         builder.info("x.py completions check");
-        let [bash, fish, powershell] = ["x.py.sh", "x.py.fish", "x.py.ps1"]
+        let [bash, zsh, fish, powershell] = ["x.py.sh", "x.py.zsh", "x.py.fish", "x.py.ps1"]
             .map(|filename| builder.src.join("src/etc/completions").join(filename));
         if builder.config.cmd.bless() {
             builder.ensure(crate::run::GenerateCompletions);
         } else if crate::flags::get_completion(shells::Bash, &bash).is_some()
             || crate::flags::get_completion(shells::Fish, &fish).is_some()
             || crate::flags::get_completion(shells::PowerShell, &powershell).is_some()
+            || crate::flags::get_completion(shells::Zsh, &zsh).is_some()
         {
             eprintln!(
                 "x.py completions were changed; run `x.py run generate-completions` to update them"
@@ -2940,10 +2941,6 @@ impl Step for TestHelpers {
         let _guard = builder.msg_unstaged(Kind::Build, "test helpers", target);
         t!(fs::create_dir_all(&dst));
         let mut cfg = cc::Build::new();
-        // FIXME: Workaround for https://github.com/emscripten-core/emscripten/issues/9013
-        if target.contains("emscripten") {
-            cfg.pic(false);
-        }
 
         // We may have found various cross-compilers a little differently due to our
         // extra configuration, so inform cc of these compilers. Note, though, that