Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 24 additions & 39 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1375,29 +1375,32 @@ impl Build {

cell_update(&pendings, |mut pendings| {
// Try waiting on them.
retain_unordered_mut(&mut pendings, |(cmd, program, child, _token)| {
match try_wait_on_child(cmd, program, &mut child.0, &mut stdout) {
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);
parallel::retain_unordered_mut(
&mut pendings,
|(cmd, program, child, _token)| {
match try_wait_on_child(cmd, program, &mut child.0, &mut stdout) {
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
}
error = Some(err);

false
}
}
});
},
);
pendings_is_empty = pendings.is_empty();
pendings
});
Expand Down Expand Up @@ -4344,21 +4347,3 @@ impl Drop for PrintThread {
self.handle.take().unwrap().join().unwrap();
}
}

/// Remove all element in `vec` which `f(element)` returns `false`.
///
/// TODO: Remove this once the MSRV is bumped to v1.61
#[cfg(feature = "parallel")]
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);
}
}
}
17 changes: 17 additions & 0 deletions src/parallel/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
pub(crate) mod async_executor;
pub(crate) mod job_token;

/// 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);
}
}
}