From c2845662e64ee6da39a64812f9c064778fdbab49 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Thu, 18 Apr 2024 20:43:11 +1000 Subject: [PATCH] Bump msrv to 1.63 (#1031) * Update CI to use msrv 1.63 * Bump msrv to 1.63 * Use `Vec::retain_mut` instead of `parallel::retain_unordered_mut` * Rm `parallel::retain_unordered_mut` * Fix typo and run `cargo fmt` * Use `MaybeUninit::{assume_init_ref, write}` Signed-off-by: Jiahao XU --- .github/workflows/main.yml | 6 ++-- Cargo.toml | 2 +- src/lib.rs | 57 ++++++++++++++++++-------------------- src/parallel/job_token.rs | 6 ++-- src/parallel/mod.rs | 17 ------------ 5 files changed, 34 insertions(+), 54 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 974057f0d..7044b230d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -201,13 +201,13 @@ jobs: - uses: actions/checkout@v4 - name: Install Rust run: | - rustup toolchain install 1.53.0 --no-self-update --profile minimal + rustup toolchain install 1.63.0 --no-self-update --profile minimal rustup toolchain install nightly --no-self-update --profile minimal - rustup default 1.53.0 + rustup default 1.63.0 shell: bash - name: Create Cargo.lock with minimal version run: cargo +nightly update -Zminimal-versions - - name: Cache downloaded crates since 1.53 is really slow in fetching + - name: Cache downloaded crates since 1.63 is really slow in fetching uses: Swatinem/rust-cache@v2 - run: cargo check --lib -p cc --locked - run: cargo check --lib -p cc --locked --all-features diff --git a/Cargo.toml b/Cargo.toml index 64d2bf6ef..bcbfffe5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ categories = ["development-tools::build-utils"] # The binary target is only used by tests. exclude = ["/.github", "tests", "src/bin"] edition = "2018" -rust-version = "1.53" +rust-version = "1.63" [dependencies] jobserver = { version = "0.1.20", default-features = false, optional = true } diff --git a/src/lib.rs b/src/lib.rs index 204290cfe..4df12680c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1496,38 +1496,35 @@ impl Build { cell_update(&pendings, |mut pendings| { // Try waiting on them. - parallel::retain_unordered_mut( - &mut pendings, - |(cmd, program, child, _token)| { - match try_wait_on_child( - cmd, - program, - &mut child.0, - &mut stdout, - &mut child.1, - ) { - Ok(Some(())) => { - // Task done, remove the entry - has_made_progress.set(true); - false - } - Ok(None) => true, // Task still not finished, keep the entry - Err(err) => { - // Task fail, remove the entry. - // Since we can only return one error, log the error to make - // sure users always see all the compilation failures. - has_made_progress.set(true); - - if self.cargo_output.warnings { - let _ = writeln!(stdout, "cargo:warning={}", err); - } - error = Some(err); - - false + pendings.retain_mut(|(cmd, program, child, _token)| { + match try_wait_on_child( + cmd, + program, + &mut child.0, + &mut stdout, + &mut child.1, + ) { + Ok(Some(())) => { + // Task done, remove the entry + has_made_progress.set(true); + false + } + Ok(None) => true, // Task still not finished, keep the entry + Err(err) => { + // Task fail, remove the entry. + // Since we can only return one error, log the error to make + // sure users always see all the compilation failures. + has_made_progress.set(true); + + if self.cargo_output.warnings { + let _ = writeln!(stdout, "cargo:warning={}", err); } + error = Some(err); + + false } - }, - ); + } + }); pendings_is_empty = pendings.is_empty(); pendings }); diff --git a/src/parallel/job_token.rs b/src/parallel/job_token.rs index 4fec982f8..17b2d47d8 100644 --- a/src/parallel/job_token.rs +++ b/src/parallel/job_token.rs @@ -34,6 +34,7 @@ impl JobTokenServer { /// that has to be static so that it will be shared by all cc /// compilation. fn new() -> &'static Self { + // TODO: Replace with a OnceLock once MSRV is 1.70 static INIT: Once = Once::new(); static mut JOBSERVER: MaybeUninit = MaybeUninit::uninit(); @@ -42,10 +43,9 @@ impl JobTokenServer { let server = inherited_jobserver::JobServer::from_env() .map(Self::Inherited) .unwrap_or_else(|| Self::InProcess(inprocess_jobserver::JobServer::new())); - JOBSERVER = MaybeUninit::new(server); + JOBSERVER.write(server); }); - // TODO: Poor man's assume_init_ref, as that'd require a MSRV of 1.55. - &*JOBSERVER.as_ptr() + JOBSERVER.assume_init_ref() } } } diff --git a/src/parallel/mod.rs b/src/parallel/mod.rs index d69146dc5..019eae102 100644 --- a/src/parallel/mod.rs +++ b/src/parallel/mod.rs @@ -1,20 +1,3 @@ pub(crate) mod async_executor; pub(crate) mod job_token; pub(crate) mod stderr; - -/// Remove all element in `vec` which `f(element)` returns `false`. -/// -/// TODO: Remove this once the MSRV is bumped to v1.61 -pub(crate) fn retain_unordered_mut(vec: &mut Vec, mut f: F) -where - F: FnMut(&mut T) -> bool, -{ - let mut i = 0; - while i < vec.len() { - if f(&mut vec[i]) { - i += 1; - } else { - vec.swap_remove(i); - } - } -}