about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJakub Beránek <berykubik@gmail.com>2025-08-15 16:03:59 +0200
committerGitHub <noreply@github.com>2025-08-15 16:03:59 +0200
commit82c6ad3eda37f36f521cffaa7038633ee1fa5ec9 (patch)
treef08818cf58bee980515ebbd80b9adb251208ed14
parent7c93af02e3b77f1f82a02269183500a4f45b7b7e (diff)
parent56b33cd5fa0eb2814f94f5fc636775ac70d10b0e (diff)
downloadrust-82c6ad3eda37f36f521cffaa7038633ee1fa5ec9.tar.gz
rust-82c6ad3eda37f36f521cffaa7038633ee1fa5ec9.zip
Rollup merge of #145413 - joshtriplett:bootstrap-reduce-deps, r=clubby789
bootstrap: Reduce dependencies

Eliminate the `fd-lock` dependency by using the new native locking in std.

Eliminate the `xattr` dependency by turning off a feature flag in `tar`, since
the tarballs that we extract with bootstrap don't need it.
-rw-r--r--src/bootstrap/Cargo.lock27
-rw-r--r--src/bootstrap/Cargo.toml3
-rw-r--r--src/bootstrap/src/bin/main.rs46
3 files changed, 24 insertions, 52 deletions
diff --git a/src/bootstrap/Cargo.lock b/src/bootstrap/Cargo.lock
index 537f4b6184f..be29e77e572 100644
--- a/src/bootstrap/Cargo.lock
+++ b/src/bootstrap/Cargo.lock
@@ -48,7 +48,6 @@ dependencies = [
  "clap",
  "clap_complete",
  "cmake",
- "fd-lock",
  "home",
  "ignore",
  "insta",
@@ -269,17 +268,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
 
 [[package]]
-name = "fd-lock"
-version = "4.0.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0ce92ff622d6dadf7349484f42c93271a0d49b7cc4d466a936405bacbe10aa78"
-dependencies = [
- "cfg-if",
- "rustix",
- "windows-sys 0.59.0",
-]
-
-[[package]]
 name = "filetime"
 version = "0.2.25"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -759,13 +747,12 @@ dependencies = [
 
 [[package]]
 name = "tar"
-version = "0.4.43"
+version = "0.4.44"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c65998313f8e17d0d553d28f91a0df93e4dbbbf770279c7bc21ca0f09ea1a1f6"
+checksum = "1d863878d212c87a19c1a610eb53bb01fe12951c0501cf5a0d65f724914a667a"
 dependencies = [
  "filetime",
  "libc",
- "xattr",
 ]
 
 [[package]]
@@ -1148,16 +1135,6 @@ dependencies = [
 ]
 
 [[package]]
-name = "xattr"
-version = "1.5.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0d65cbf2f12c15564212d48f4e3dfb87923d25d611f2aed18f4cb23f0413d89e"
-dependencies = [
- "libc",
- "rustix",
-]
-
-[[package]]
 name = "xz2"
 version = "0.1.7"
 source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml
index bdf0b42255e..cd5a60187e5 100644
--- a/src/bootstrap/Cargo.toml
+++ b/src/bootstrap/Cargo.toml
@@ -38,7 +38,6 @@ cmake = "=0.1.54"
 build_helper = { path = "../build_helper" }
 clap = { version = "4.4", default-features = false, features = ["std", "usage", "help", "derive", "error-context"] }
 clap_complete = "4.4"
-fd-lock = "4.0"
 home = "0.5"
 ignore = "0.4"
 libc = "0.2"
@@ -51,7 +50,7 @@ serde = "1.0"
 serde_derive = "1.0"
 serde_json = "1.0"
 sha2 = "0.10"
-tar = "0.4"
+tar = { version = "0.4.44", default-features = false }
 termcolor = "1.4"
 toml = "0.5"
 walkdir = "2.4"
diff --git a/src/bootstrap/src/bin/main.rs b/src/bootstrap/src/bin/main.rs
index 8b2d67266a7..93c7faf4f01 100644
--- a/src/bootstrap/src/bin/main.rs
+++ b/src/bootstrap/src/bin/main.rs
@@ -5,8 +5,8 @@
 //! parent directory, and otherwise documentation can be found throughout the `build`
 //! directory in each respective module.
 
-use std::fs::{self, OpenOptions};
-use std::io::{self, BufRead, BufReader, IsTerminal, Write};
+use std::fs::{self, OpenOptions, TryLockError};
+use std::io::{self, BufRead, BufReader, IsTerminal, Read, Write};
 use std::path::Path;
 use std::str::FromStr;
 use std::time::Instant;
@@ -39,38 +39,34 @@ fn main() {
     let config = Config::parse(flags);
 
     let mut build_lock;
-    let _build_lock_guard;
 
     if !config.bypass_bootstrap_lock {
         // Display PID of process holding the lock
         // PID will be stored in a lock file
         let lock_path = config.out.join("lock");
-        let pid = fs::read_to_string(&lock_path);
-
-        build_lock = fd_lock::RwLock::new(t!(fs::OpenOptions::new()
+        build_lock = t!(fs::OpenOptions::new()
+            .read(true)
             .write(true)
-            .truncate(true)
             .create(true)
-            .open(&lock_path)));
-        _build_lock_guard = match build_lock.try_write() {
-            Ok(mut lock) => {
-                t!(lock.write(process::id().to_string().as_ref()));
-                lock
+            .truncate(false)
+            .open(&lock_path));
+        t!(build_lock.try_lock().or_else(|e| {
+            if let TryLockError::Error(e) = e {
+                return Err(e);
             }
-            err => {
-                drop(err);
-                // #135972: We can reach this point when the lock has been taken,
-                // but the locker has not yet written its PID to the file
-                if let Some(pid) = pid.ok().filter(|pid| !pid.is_empty()) {
-                    println!("WARNING: build directory locked by process {pid}, waiting for lock");
-                } else {
-                    println!("WARNING: build directory locked, waiting for lock");
-                }
-                let mut lock = t!(build_lock.write());
-                t!(lock.write(process::id().to_string().as_ref()));
-                lock
+            let mut pid = String::new();
+            t!(build_lock.read_to_string(&mut pid));
+            // #135972: We can reach this point when the lock has been taken,
+            // but the locker has not yet written its PID to the file
+            if !pid.is_empty() {
+                println!("WARNING: build directory locked by process {pid}, waiting for lock");
+            } else {
+                println!("WARNING: build directory locked, waiting for lock");
             }
-        };
+            build_lock.lock()
+        }));
+        t!(build_lock.set_len(0));
+        t!(build_lock.write_all(process::id().to_string().as_bytes()));
     }
 
     // check_version warnings are not printed during setup, or during CI