diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 2a4b6b41fb..4f25f21bc8 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -588,6 +588,17 @@ fn nextest_list(o: &CiOptions, args: &[&str], record: bool) -> Result Vec { + let mut args: Vec = ["nextest", "archive", "--profile", "ci", "--zstd-level", "1"].into_iter().map(Into::into).collect(); + args.extend(test_build_args(&o.exclude, o.corpus).into_iter().map(Into::into)); + args.push("-E".into()); + args.push(shard.archive_filter().into()); + args.push("--archive-file".into()); + args.push(file.as_os_str().to_owned()); + args +} + /// The gate's build job with per-shard archives: builds the tests, lists them, plans which binaries /// (and which parts of the split ones) each shard runs, writes the plan into the target directory /// (every archive carries it, .config/nextest.toml) and writes each shard's archive. @@ -616,17 +627,27 @@ fn build_shard_archives(o: &CiOptions, dir: &Path, name: &str, shards: usize, gp let plan_path = target.join(shards::PLAN_FILE); let json = serde_json::to_string_pretty(&plan).map_err(|e| format!("shard plan: {e}"))?; std::fs::write(&plan_path, json).map_err(|e| format!("{}: {e}", plan_path.display()))?; - for (k, shard) in plan.shards.iter().enumerate() { - let file = dir.join((k + 1).to_string()).join(name); + for k in 0..plan.shards.len() { std::fs::create_dir_all(dir.join((k + 1).to_string())).map_err(|e| format!("{}: {e}", dir.display()))?; - let mut c = cargo(); - c.args(["nextest", "archive", "--profile", "ci"]) - .args(test_build_args(&o.exclude, o.corpus)) - .arg("-E") - .arg(shard.archive_filter()) - .arg("--archive-file") - .arg(&file); - run(c, &format!("cargo nextest archive (shard {}: {} binaries) --archive-file {}", k + 1, shard.binaries.len(), file.display()))?; + } + let results: Vec> = std::thread::scope(|s| { + let handles: Vec<_> = plan + .shards + .iter() + .enumerate() + .map(|(k, shard)| { + let file = dir.join((k + 1).to_string()).join(name); + s.spawn(move || { + let mut c = cargo(); + c.args(shard_archive_args(o, shard, &file)); + run(c, &format!("cargo nextest archive (shard {}: {} binaries) --archive-file {}", k + 1, shard.binaries.len(), file.display())) + }) + }) + .collect(); + handles.into_iter().map(|h| h.join().unwrap_or_else(|_| Err("cargo nextest archive worker thread panicked".into()))).collect() + }); + for result in results { + result?; } Ok(()) } @@ -920,4 +941,14 @@ mod ci_tests { // The workspace's own group exists and parses. assert!(read_gpu_filter().unwrap().contains("package(photocraft-gpu)")); } + + #[test] + fn shard_archive_args_use_fast_zstd_and_shard_filter() { + let o = ci_from_args(&[], vec!["photocraft-web".into()]).unwrap().1; + let shard = shards::Shard { binaries: ["photocraft-geom".into()].into_iter().collect(), parts: Default::default(), seconds: 0.1 }; + let args: Vec = shard_archive_args(&o, &shard, Path::new("/tmp/1/a.tar.zst")).into_iter().map(|a| a.to_string_lossy().into_owned()).collect(); + assert!(args.windows(2).any(|w| w == ["--zstd-level", "1"])); + assert!(args.windows(2).any(|w| w == ["--archive-file", "/tmp/1/a.tar.zst"])); + assert!(args.windows(2).any(|w| w == ["-E", "binary_id(=photocraft-geom)"])); + } }