From c2230ee61e57ff1e3a158ad7382227863a56b455 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 29 Nov 2026 09:25:58 -0800 Subject: [PATCH] CI: app manifests and doc tests no longer warn - apps/vectorcraft-web: egui_extras moves to the wasm32 dependencies. Its only use is src/web.rs, which builds only for wasm32, so cargo reported it unused on native builds. - apps/vectorcraft: drop the socket2 dev-dependency. Its loopback tests left control_server in #8800 and nothing uses it now. - xtask: the doc-test steps (`cargo xtask ci shard` and the workspace doctests) leave out packages whose only library target is a cdylib, dylib or staticlib. Cargo printed "doc tests are not supported for crate type(s) `cdylib`" for vectorcraft-thumbnail-handler. Packages without a library stay selected, so the shard keeps its features. Warnings on the build host, before and after (cache warm shard `cargo test -p vectorcraft-mcp -p vectorcraft -p vectorcraft-cli -p vectorcraft-web -p xtask --lib --bins --no-run` on a fresh build, and `cargo test -p vectorcraft-thumbnail-handler --doc`): 4 before, 1 after. The one left is `vectorcraft-testkit` in apps/vectorcraft-cli: only the integration tests use it, and the warm step builds only library and binary tests. --- Cargo.lock | 1 - apps/vectorcraft-web/Cargo.toml | 3 +- apps/vectorcraft/Cargo.toml | 2 -- xtask/src/main.rs | 17 +++++++---- xtask/src/shards.rs | 52 +++++++++++++++++++++++++++++++-- 5 files changed, 63 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 520647b95d..4df5d36e3c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8538,7 +8538,6 @@ dependencies = [ "raw-window-handle", "rustix 1.1.6", "serde_json", - "socket2", "tempfile", "vectorcraft-engine", "vectorcraft-render", diff --git a/apps/vectorcraft-web/Cargo.toml b/apps/vectorcraft-web/Cargo.toml index e8b56c29a9..c2b40c7158 100644 --- a/apps/vectorcraft-web/Cargo.toml +++ b/apps/vectorcraft-web/Cargo.toml @@ -20,10 +20,11 @@ vectorcraft-format = { workspace = true } vectorcraft-text = { workspace = true } craft = { workspace = true, features = ["ui", "keymap", "automation", "platform"] } egui = { workspace = true } -egui_extras = { workspace = true } log = { workspace = true } [target.'cfg(target_arch = "wasm32")'.dependencies] +# Image loaders for `src/web.rs`, which builds only for wasm32. +egui_extras = { workspace = true } # `wgpu` pulls egui-wgpu's defaults: WebGPU plus the WebGL2 fallback. eframe = { workspace = true, features = ["default_fonts", "wgpu", "accesskit"] } # The page command API (storytold/craft-libs#413): the request plumbing behind window.vectorcraft. diff --git a/apps/vectorcraft/Cargo.toml b/apps/vectorcraft/Cargo.toml index 1c3e7f39e7..d17c96eaf7 100644 --- a/apps/vectorcraft/Cargo.toml +++ b/apps/vectorcraft/Cargo.toml @@ -129,5 +129,3 @@ winresource = "0.1" [dev-dependencies] tempfile = "3" -# Bound socket buffers in real loopback transport deadline regressions. -socket2 = { workspace = true } diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 7c2e587a7d..08a55df09a 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -316,13 +316,18 @@ fn test_packages(select: &[String], shown: &str, part: Option) -> /// The doctests, which nextest doesn't run. fn cmd_doctests() -> Result<(), String> { - doctest_packages(&["--workspace".to_owned()], "--workspace") + doctest_packages(&shards::members(&metadata()?)?) } -/// [`cmd_doctests`] for the packages `select` picks, shown as `shown`. -fn doctest_packages(select: &[String], shown: &str) -> Result<(), String> { +/// [`cmd_doctests`] for the crates of `crates` that have doc tests. +fn doctest_packages(crates: &[shards::Member]) -> Result<(), String> { + let crates = shards::with_doctests(crates); + if crates.is_empty() { + return Ok(()); + } + let shown = crates.iter().map(|m| format!("-p {}", m.name)).collect::>().join(" "); let mut c = cargo(); - c.arg("test").args(select).arg("--doc"); + c.arg("test").args(shards::select(&crates)).arg("--doc"); run(c, &format!("cargo test {shown} --doc")) } @@ -372,9 +377,9 @@ fn cmd_ci_shard() -> Result<(), String> { steps.push(("test", Box::new(move || test_packages(&s, &w, part)))); // The doctests and the i18n report run once, on a split's first part. let first = part.is_none_or(|p| p.is_first()); - let (s, w) = (select.clone(), shown.clone()); if first { - steps.push(("doctests", Box::new(move || doctest_packages(&s, &w)))); + let c = crates.clone(); + steps.push(("doctests", Box::new(move || doctest_packages(&c)))); } if first && crates.iter().any(|m| m.name == "vectorcraft-ui-egui") { steps.push(("i18n-report", Box::new(move || i18n_report_packages(&select, &shown)))); diff --git a/xtask/src/shards.rs b/xtask/src/shards.rs index 29f5281a84..2a4ae4d927 100644 --- a/xtask/src/shards.rs +++ b/xtask/src/shards.rs @@ -88,6 +88,10 @@ pub struct Member { /// against this repo's geom and pathops by git, so the graph holds a second copy of each. pub id: String, pub version: String, + /// Whether `cargo test --doc` can select this package without a warning: it has no library + /// target, or one of `lib`, `rlib` or `proc-macro` kind. Cargo warns for a selected package + /// whose library is only a `cdylib`, `dylib` or `staticlib`. + pub doctests: bool, } /// What one shard runs, with its crates resolved; a shard of a [`Split`] carries its part. @@ -159,7 +163,7 @@ pub fn members(meta: &Value) -> Result, String> { .filter(|p| p["id"].as_str().is_some_and(|id| ids.contains(id))) .map(|p| { let field = |key: &str| p[key].as_str().map(str::to_owned).ok_or_else(|| format!("cargo metadata: a workspace package has no `{key}`")); - Ok(Member { name: field("name")?, id: field("id")?, version: field("version")? }) + Ok(Member { name: field("name")?, id: field("id")?, version: field("version")?, doctests: has_doctests(p) }) }) .collect::>()?; if members.is_empty() { @@ -168,6 +172,24 @@ pub fn members(meta: &Value) -> Result, String> { Ok(members) } +/// [`Member::doctests`] for the `cargo metadata` package `p`. +fn has_doctests(p: &Value) -> bool { + let kinds = |t: &Value| t["kind"].as_array().into_iter().flatten().filter_map(Value::as_str).map(str::to_owned).collect::>(); + let libraries: Vec> = p["targets"] + .as_array() + .into_iter() + .flatten() + .map(kinds) + .filter(|k| k.iter().any(|k| matches!(k.as_str(), "lib" | "rlib" | "dylib" | "cdylib" | "staticlib" | "proc-macro"))) + .collect(); + libraries.is_empty() || libraries.iter().flatten().any(|k| matches!(k.as_str(), "lib" | "rlib" | "proc-macro")) +} + +/// The crates of `crates` that `cargo test --doc` can select (see [`Member::doctests`]). +pub fn with_doctests(crates: &[Member]) -> Vec { + crates.iter().filter(|m| m.doctests).cloned().collect() +} + /// Each group of `groups` with its crates: a named crate must be a workspace member and named /// once, there must be exactly one [`Group::Rest`], and no test shard may be empty. A split's /// parts 1 to n must be consecutive shards, with at least two parts, and no test pinned twice. @@ -347,7 +369,24 @@ mod tests { use super::*; fn m(name: &str) -> Member { - Member { name: name.into(), id: format!("path+file:///w/{name}#0.1.0"), version: "0.1.0".into() } + Member { name: name.into(), id: format!("path+file:///w/{name}#0.1.0"), version: "0.1.0".into(), doctests: true } + } + + #[test] + fn the_doc_tests_leave_out_only_packages_whose_library_cargo_cannot_doc_test() { + let package = |kinds: &[&str]| serde_json::json!({ "targets": [{ "kind": kinds }, { "kind": ["bin"] }] }); + assert!(has_doctests(&package(&["lib"]))); + assert!(has_doctests(&package(&["rlib"]))); + assert!(has_doctests(&package(&["proc-macro"]))); + assert!(has_doctests(&package(&["cdylib", "rlib"]))); + assert!(has_doctests(&package(&["bin"]))); + assert!(has_doctests(&serde_json::json!({ "targets": [] }))); + assert!(!has_doctests(&package(&["cdylib"]))); + assert!(!has_doctests(&package(&["dylib"]))); + assert!(!has_doctests(&package(&["staticlib"]))); + let mut cdylib = m("cdylib"); + cdylib.doctests = false; + assert_eq!(with_doctests(&[m("a"), cdylib, m("b")]).iter().map(|m| m.name.as_str()).collect::>(), ["a", "b"]); } fn crates(shard: &Shard) -> Vec<&str> { @@ -514,6 +553,15 @@ mod tests { assert_eq!(shards.iter().filter(|s| **s == Shard::Checks).count(), 1); } + #[test] + fn the_workspace_doc_tests_skip_the_cdylib_thumbnail_handler() { + let ws = members(&crate::metadata().unwrap()).unwrap(); + let doctests = |name: &str| ws.iter().find(|m| m.name == name).map(|m| m.doctests); + assert_eq!(doctests("vectorcraft-thumbnail-handler"), Some(false)); + assert_eq!(doctests("vectorcraft-geom"), Some(true)); + assert_eq!(doctests("vectorcraft-cli"), Some(true)); + } + #[test] fn a_feature_only_another_shard_turns_on_is_a_difference() { let ws = [m("lib"), m("geom")];