Skip to content

Commit

Permalink
Bump msrv to 1.63 (#1031)
Browse files Browse the repository at this point in the history
* 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 <Jiahao_XU@outlook.com>
  • Loading branch information
NobodyXu committed Apr 18, 2024
1 parent 84d04e8 commit c284566
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 54 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -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 }
Expand Down
57 changes: 27 additions & 30 deletions src/lib.rs
Expand Up @@ -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
});
Expand Down
6 changes: 3 additions & 3 deletions src/parallel/job_token.rs
Expand Up @@ -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<JobTokenServer> = MaybeUninit::uninit();

Expand All @@ -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()
}
}
}
Expand Down
17 changes: 0 additions & 17 deletions 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<T, F>(vec: &mut Vec<T>, 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);
}
}
}

0 comments on commit c284566

Please sign in to comment.