From dd9f8e6d10f3b1b2fdf6a4702f38dc44b9cba2cd Mon Sep 17 00:00:00 2001 From: ruchirguitar Date: Wed, 2 Dec 2026 19:43:47 +0530 Subject: [PATCH 1/4] Web: the site publishes the interface's served fonts under fonts/ui/ The web interface font stack fetches its craft-fonts faces from the `fonts/ui/` URLs in SERVED_FONTS, but only crates/text/build.rs's OUT_DIR held those files: the Trunk hook copied the `fonts//` faces alone. On a built site every served interface face (Noto Sans Arabic, Thai and Georgian, NanumGothic, Noto Sans Devanagari) failed to load, and the interface drew those scripts as missing-glyph boxes. `cargo xtask web-fonts` now also publishes the `startup` and `demand` faces of crates/text/web-fonts.txt under `fonts/ui/`, licence beside each, with the same craft-fonts-build `Embed::serve` that build.rs uses, so the files match the table's URLs and integrity values. Test: publishes_the_interface_faces_at_their_served_urls. Fixes #10567. --- Cargo.lock | 1 + docs/development.md | 5 +++-- xtask/Cargo.toml | 2 ++ xtask/src/main.rs | 5 +++-- xtask/src/web_fonts.rs | 47 +++++++++++++++++++++++++++++++++++++++++- 5 files changed, 55 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d0216e2962..d1f40a61ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10418,6 +10418,7 @@ checksum = "9440ea3e5aeabb0ac63af70daf835274065238cdd0cec83418f417eae38bacee" name = "xtask" version = "0.25.1" dependencies = [ + "craft-fonts-build", "serde_json", ] diff --git a/docs/development.md b/docs/development.md index 77e4b736a5..4de0357860 100644 --- a/docs/development.md +++ b/docs/development.md @@ -178,8 +178,8 @@ CRAFT_FONTS_DIR="$PWD/../craft-fonts" cargo xtask ci # also runs the Japanese- that face lacks and that doesn't fit a Latin row, such as Georgian), then the other scripts' faces, then the installed fonts it finds for other scripts on the desktop. On the web the `startup` and `demand` faces of `crates/text/web-fonts.txt` are served under `fonts/ui/` - instead: the stack fetches the UI language's at once and the others the first time text needs - them. + instead (`cargo xtask web-fonts`, the Trunk hook, publishes them there): the stack fetches the UI + language's at once and the others the first time text needs them. - Document tab titles: desktop builds also embed the Noto Sans Condensed SemiBold row of the checkout's opt-in `fonts/latin-manifest.txt` (`Embed::tab_face` in `crates/text/build.rs`). The interface font stack draws document tab titles in it, scaled to the x-height of the @@ -579,6 +579,7 @@ Scores and hour estimates are unchanged. | Date | Change | Summary | |---|---|---| +| 2026-12-02 | patch | Fonts (#10567): the Trunk hook `cargo xtask web-fonts` also publishes the interface's `startup` and `demand` faces under `fonts/ui/`, where `SERVED_FONTS` points; before, the site lacked them and the web interface drew those scripts as missing-glyph boxes. | | 2026-11-24 | minor | Fonts: the interface font stack is the framework's, set up by `ui_fonts()` and installed by `embed::install` (craft-fonts faces, the web's served faces, embedders); `theme::install_fonts` is gone and `interface-fonts` changes nothing. | | 2026-11-12 | minor | Tests (#6860): compare preset refusal roots after canonicalization and Windows display normalization; canonicalize the script fixture base before constructing `MAIN`. This keeps macOS `/var` → `/private/var` aliases from masking the case-sensitivity checks; no production-code change. | | 2026-11-12 | minor | Compile the clipboard failure helper only for Linux/BSD worker callers and unit tests; keep production macOS free of the unused helper without suppressing workspace dead-code warnings. | diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 7a5c83e8b5..53678d8216 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -10,6 +10,8 @@ workspace = true [dependencies] serde_json = { workspace = true } +# The interface faces the web site serves under fonts/ui/, written as crates/text/build.rs serves them. +craft-fonts-build = { workspace = true } # The files of other crates that this crate compiles, for CI's test selection. [package.metadata.craft] diff --git a/xtask/src/main.rs b/xtask/src/main.rs index ce60771034..783c48fd49 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -71,8 +71,9 @@ commands: and built-in tests its interpreter supports and the String, Number, RegExp and Date built-ins tests, printing the counts; then fetch json2.js into corpus/json2 (sha256 verified) and run it - web-fonts copy the craft-fonts faces in crates/text/web-fonts.txt into the web site (the Trunk - post_build hook; a no-op without CRAFT_FONTS_DIR) + web-fonts copy the craft-fonts faces in crates/text/web-fonts.txt into the web site, the + interface's startup and demand faces also under fonts/ui/ (the Trunk post_build + hook; a no-op without CRAFT_FONTS_DIR) "; fn main() -> ExitCode { diff --git a/xtask/src/web_fonts.rs b/xtask/src/web_fonts.rs index b5f3e42d2e..67d36893b3 100644 --- a/xtask/src/web_fonts.rs +++ b/xtask/src/web_fonts.rs @@ -1,7 +1,9 @@ //! `cargo xtask web-fonts`: the Trunk `post_build` hook (`apps/*-web/Trunk.toml`). Copies the //! craft-fonts faces listed in `crates/text/web-fonts.txt` from `$CRAFT_FONTS_DIR` into the site, //! each at `fonts//` with its licence beside it: the URLs -//! `crates/text/build.rs` puts in `WEB_FONTS` (both use `crates/text/build/web_fonts.rs`). +//! `crates/text/build.rs` puts in `WEB_FONTS` (both use `crates/text/build/web_fonts.rs`). The +//! `startup` and `demand` faces are also published under `fonts/ui/`, where the interface font stack +//! fetches them (`SERVED_FONTS`), with the craft-fonts-build `Embed::serve` that build.rs uses. //! //! A no-op without `CRAFT_FONTS_DIR`. A listed face the checkout lacks (an older craft-fonts) is //! skipped with a warning, as `build.rs` does; a file whose SHA-256 doesn't match the manifest is an @@ -31,9 +33,35 @@ fn run_with(root: &Path, craft_fonts: Option, staging: Option) eprintln!("warning: web build won't fetch {} (not in CRAFT_FONTS_DIR={}; an older craft-fonts?)", skipped.join(", "), dir.display()); } println!("web-fonts: copied {copied} font(s) into {}", staging.join("fonts").display()); + let served = serve(&root.join("crates/text/web-fonts.txt"), &dir, &staging)?; + println!("web-fonts: published {served} interface font(s) into {}", staging.join(SERVED_URL).display()); Ok(()) } +/// Where the site serves the interface font stack's faces: the URL prefix `crates/text/build.rs` +/// gives them in `SERVED_FONTS`. +const SERVED_URL: &str = "fonts/ui/"; + +/// Publish the faces the web interface's font stack fetches (the list's `startup` and `demand` +/// lines) into `site` at their `fonts/ui/…` URLs. `crates/text/build.rs` serves the same faces with +/// the same craft-fonts-build `Embed::serve` into its `OUT_DIR`, for the URLs, sizes and integrity +/// values of `SERVED_FONTS`; this puts the files where those URLs point. Returns how many faces. +fn serve(list_path: &Path, dir: &Path, site: &Path) -> Result { + let list = std::fs::read_to_string(list_path).map_err(|e| format!("{}: {e}", list_path.display()))?; + let faces: Vec<(String, String)> = + list::parse_list(&list)?.into_iter().filter(|e| e.startup || e.demand).map(|e| (e.family.to_owned(), e.style.to_owned())).collect(); + // build.rs's table is the one the app uses; this copy, and Embed's hash cache beside it, go. + let scratch = std::env::temp_dir().join(format!("vectorcraft-web-fonts-{}", std::process::id())); + std::fs::create_dir_all(&scratch).map_err(|e| format!("{}: {e}", scratch.display()))?; + let served = craft_fonts_build::Embed::new() + .dir(dir) + .filter(move |f| faces.iter().any(|(family, style)| f.family == *family && f.style == *style)) + .serve(site.join(SERVED_URL), SERVED_URL) + .write(scratch.join("served.rs")); + let _ = std::fs::remove_dir_all(&scratch); + served.map(|faces| faces.len()).map_err(|e| e.to_string()) +} + /// Copy the faces `list_path` names from the craft-fonts checkout `dir` into `site` (at their /// `fonts/…` URLs). Returns how many were copied and the listed faces the checkout lacks. fn copy(list_path: &Path, dir: &Path, site: &Path) -> Result<(usize, Vec), String> { @@ -120,6 +148,23 @@ mod tests { assert_eq!(skipped, ["Missing Sans Bold"], "a face the checkout lacks is skipped, not an error"); } + /// The interface font stack fetches `startup` and `demand` faces from `fonts/ui/` (build.rs's + /// `SERVED_FONTS`), so the site holds them there, licence beside; `background` faces are only + /// fetched from `fonts//`. + #[test] + fn publishes_the_interface_faces_at_their_served_urls() { + let (list, dir, site, _) = fixture("serve", None); + assert_eq!(serve(&list, &dir, &site).unwrap(), 1); + let at = site.join("fonts/ui/a"); + assert_eq!(std::fs::read(at.join("A-Regular.ttf")).unwrap(), b"font bytes"); + assert_eq!(std::fs::read(at.join("OFL.txt")).unwrap(), b"licence"); + + let (list, dir, site, _) = fixture("serve-background", None); + std::fs::write(&list, "background | A Sans | Regular\n").unwrap(); + assert_eq!(serve(&list, &dir, &site).unwrap(), 0); + assert!(!site.join("fonts/ui/a/A-Regular.ttf").exists(), "a background face is not an interface face"); + } + #[test] fn a_file_that_does_not_match_its_manifest_hash_is_an_error() { let (list, dir, site, _) = fixture("mismatch", Some(&"0".repeat(64))); From fd3e127afcab6de388d85d389ac77586877781e4 Mon Sep 17 00:00:00 2001 From: ruchirguitar Date: Wed, 2 Dec 2026 19:47:53 +0530 Subject: [PATCH 2/4] xtask: web-fonts tests set their font policy and each publish run has its own scratch folder The served-faces test passes CRAFT_FONTS_REQUIRED=0 explicitly, so a job that sets it to 1 does not fail its background-only case, and two runs in one process (parallel tests) no longer share the folder for the table they throw away. --- xtask/src/web_fonts.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/xtask/src/web_fonts.rs b/xtask/src/web_fonts.rs index 67d36893b3..a0b6509b5c 100644 --- a/xtask/src/web_fonts.rs +++ b/xtask/src/web_fonts.rs @@ -33,7 +33,7 @@ fn run_with(root: &Path, craft_fonts: Option, staging: Option) eprintln!("warning: web build won't fetch {} (not in CRAFT_FONTS_DIR={}; an older craft-fonts?)", skipped.join(", "), dir.display()); } println!("web-fonts: copied {copied} font(s) into {}", staging.join("fonts").display()); - let served = serve(&root.join("crates/text/web-fonts.txt"), &dir, &staging)?; + let served = serve(&root.join("crates/text/web-fonts.txt"), &dir, &staging, None)?; println!("web-fonts: published {served} interface font(s) into {}", staging.join(SERVED_URL).display()); Ok(()) } @@ -45,16 +45,23 @@ const SERVED_URL: &str = "fonts/ui/"; /// Publish the faces the web interface's font stack fetches (the list's `startup` and `demand` /// lines) into `site` at their `fonts/ui/…` URLs. `crates/text/build.rs` serves the same faces with /// the same craft-fonts-build `Embed::serve` into its `OUT_DIR`, for the URLs, sizes and integrity -/// values of `SERVED_FONTS`; this puts the files where those URLs point. Returns how many faces. -fn serve(list_path: &Path, dir: &Path, site: &Path) -> Result { +/// values of `SERVED_FONTS`; this puts the files where those URLs point. `required` overrides +/// `CRAFT_FONTS_REQUIRED`, which decides it otherwise, as in build.rs. Returns how many faces. +fn serve(list_path: &Path, dir: &Path, site: &Path, required: Option) -> Result { let list = std::fs::read_to_string(list_path).map_err(|e| format!("{}: {e}", list_path.display()))?; let faces: Vec<(String, String)> = list::parse_list(&list)?.into_iter().filter(|e| e.startup || e.demand).map(|e| (e.family.to_owned(), e.style.to_owned())).collect(); // build.rs's table is the one the app uses; this copy, and Embed's hash cache beside it, go. - let scratch = std::env::temp_dir().join(format!("vectorcraft-web-fonts-{}", std::process::id())); + static RUN: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); + let run = RUN.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + let scratch = std::env::temp_dir().join(format!("vectorcraft-web-fonts-{}-{run}", std::process::id())); std::fs::create_dir_all(&scratch).map_err(|e| format!("{}: {e}", scratch.display()))?; - let served = craft_fonts_build::Embed::new() - .dir(dir) + let embed = craft_fonts_build::Embed::new().dir(dir); + let embed = match required { + Some(required) => embed.required(required), + None => embed, + }; + let served = embed .filter(move |f| faces.iter().any(|(family, style)| f.family == *family && f.style == *style)) .serve(site.join(SERVED_URL), SERVED_URL) .write(scratch.join("served.rs")); @@ -154,14 +161,14 @@ mod tests { #[test] fn publishes_the_interface_faces_at_their_served_urls() { let (list, dir, site, _) = fixture("serve", None); - assert_eq!(serve(&list, &dir, &site).unwrap(), 1); + assert_eq!(serve(&list, &dir, &site, Some(false)).unwrap(), 1); let at = site.join("fonts/ui/a"); assert_eq!(std::fs::read(at.join("A-Regular.ttf")).unwrap(), b"font bytes"); assert_eq!(std::fs::read(at.join("OFL.txt")).unwrap(), b"licence"); let (list, dir, site, _) = fixture("serve-background", None); std::fs::write(&list, "background | A Sans | Regular\n").unwrap(); - assert_eq!(serve(&list, &dir, &site).unwrap(), 0); + assert_eq!(serve(&list, &dir, &site, Some(false)).unwrap(), 0); assert!(!site.join("fonts/ui/a/A-Regular.ttf").exists(), "a background face is not an interface face"); } From a1ef841a719dd2b7717b1e2980e3daf30b14d197 Mon Sep 17 00:00:00 2001 From: ruchirguitar Date: Thu, 3 Dec 2026 00:21:31 +0530 Subject: [PATCH 3/4] xtask: web-fonts creates its own scratch folder and the publish test covers a demand face --- xtask/src/web_fonts.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/xtask/src/web_fonts.rs b/xtask/src/web_fonts.rs index a0b6509b5c..5c2309b982 100644 --- a/xtask/src/web_fonts.rs +++ b/xtask/src/web_fonts.rs @@ -52,10 +52,7 @@ fn serve(list_path: &Path, dir: &Path, site: &Path, required: Option) -> R let faces: Vec<(String, String)> = list::parse_list(&list)?.into_iter().filter(|e| e.startup || e.demand).map(|e| (e.family.to_owned(), e.style.to_owned())).collect(); // build.rs's table is the one the app uses; this copy, and Embed's hash cache beside it, go. - static RUN: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); - let run = RUN.fetch_add(1, std::sync::atomic::Ordering::Relaxed); - let scratch = std::env::temp_dir().join(format!("vectorcraft-web-fonts-{}-{run}", std::process::id())); - std::fs::create_dir_all(&scratch).map_err(|e| format!("{}: {e}", scratch.display()))?; + let scratch = new_scratch_dir()?; let embed = craft_fonts_build::Embed::new().dir(dir); let embed = match required { Some(required) => embed.required(required), @@ -69,6 +66,24 @@ fn serve(list_path: &Path, dir: &Path, site: &Path, required: Option) -> R served.map(|faces| faces.len()).map_err(|e| e.to_string()) } +/// A new, empty folder in the temp directory that this call created, so removing it afterwards +/// removes nothing another process or run made: `create_dir` fails on a folder that already +/// exists, and the next name is tried. +fn new_scratch_dir() -> Result { + static RUN: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); + let mut last = String::new(); + for _ in 0..100 { + let run = RUN.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + let path = std::env::temp_dir().join(format!("vectorcraft-web-fonts-{}-{run}", std::process::id())); + match std::fs::create_dir(&path) { + Ok(()) => return Ok(path), + Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => last = format!("{}: {e}", path.display()), + Err(e) => return Err(format!("{}: {e}", path.display())), + } + } + Err(format!("no free scratch folder in the temp directory ({last})")) +} + /// Copy the faces `list_path` names from the craft-fonts checkout `dir` into `site` (at their /// `fonts/…` URLs). Returns how many were copied and the listed faces the checkout lacks. fn copy(list_path: &Path, dir: &Path, site: &Path) -> Result<(usize, Vec), String> { @@ -166,6 +181,11 @@ mod tests { assert_eq!(std::fs::read(at.join("A-Regular.ttf")).unwrap(), b"font bytes"); assert_eq!(std::fs::read(at.join("OFL.txt")).unwrap(), b"licence"); + let (list, dir, site, _) = fixture("serve-demand", None); + std::fs::write(&list, "demand | A Sans | Regular\n").unwrap(); + assert_eq!(serve(&list, &dir, &site, Some(false)).unwrap(), 1); + assert!(site.join("fonts/ui/a/A-Regular.ttf").exists(), "a face fetched on demand is an interface face"); + let (list, dir, site, _) = fixture("serve-background", None); std::fs::write(&list, "background | A Sans | Regular\n").unwrap(); assert_eq!(serve(&list, &dir, &site, Some(false)).unwrap(), 0); From e2e4b3b917725cded27f9871e15a52d7915182fa Mon Sep 17 00:00:00 2001 From: ruchirguitar Date: Thu, 3 Dec 2026 14:25:33 +0530 Subject: [PATCH 4/4] xtask: web-fonts writes its scratch table in a private tempfile folder --- Cargo.lock | 1 + xtask/Cargo.toml | 3 +++ xtask/src/web_fonts.rs | 25 ++++--------------------- 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d1f40a61ee..383ccf4059 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10420,6 +10420,7 @@ version = "0.25.1" dependencies = [ "craft-fonts-build", "serde_json", + "tempfile", ] [[package]] diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 53678d8216..d72887dfde 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -12,6 +12,9 @@ workspace = true serde_json = { workspace = true } # The interface faces the web site serves under fonts/ui/, written as crates/text/build.rs serves them. craft-fonts-build = { workspace = true } +# The private scratch folder web-fonts writes the served-faces table to. Already in Cargo.lock +# (the apps use it), so this adds no new crate. +tempfile = "3" # The files of other crates that this crate compiles, for CI's test selection. [package.metadata.craft] diff --git a/xtask/src/web_fonts.rs b/xtask/src/web_fonts.rs index 5c2309b982..d30ef58c8e 100644 --- a/xtask/src/web_fonts.rs +++ b/xtask/src/web_fonts.rs @@ -52,7 +52,9 @@ fn serve(list_path: &Path, dir: &Path, site: &Path, required: Option) -> R let faces: Vec<(String, String)> = list::parse_list(&list)?.into_iter().filter(|e| e.startup || e.demand).map(|e| (e.family.to_owned(), e.style.to_owned())).collect(); // build.rs's table is the one the app uses; this copy, and Embed's hash cache beside it, go. - let scratch = new_scratch_dir()?; + // A private folder this call creates (random name, created exclusively, owner-only on Unix) + // and removes when `scratch` drops, so nothing another process made is reused or removed. + let scratch = tempfile::Builder::new().prefix("vectorcraft-web-fonts-").tempdir().map_err(|e| format!("scratch folder: {e}"))?; let embed = craft_fonts_build::Embed::new().dir(dir); let embed = match required { Some(required) => embed.required(required), @@ -61,29 +63,10 @@ fn serve(list_path: &Path, dir: &Path, site: &Path, required: Option) -> R let served = embed .filter(move |f| faces.iter().any(|(family, style)| f.family == *family && f.style == *style)) .serve(site.join(SERVED_URL), SERVED_URL) - .write(scratch.join("served.rs")); - let _ = std::fs::remove_dir_all(&scratch); + .write(scratch.path().join("served.rs")); served.map(|faces| faces.len()).map_err(|e| e.to_string()) } -/// A new, empty folder in the temp directory that this call created, so removing it afterwards -/// removes nothing another process or run made: `create_dir` fails on a folder that already -/// exists, and the next name is tried. -fn new_scratch_dir() -> Result { - static RUN: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); - let mut last = String::new(); - for _ in 0..100 { - let run = RUN.fetch_add(1, std::sync::atomic::Ordering::Relaxed); - let path = std::env::temp_dir().join(format!("vectorcraft-web-fonts-{}-{run}", std::process::id())); - match std::fs::create_dir(&path) { - Ok(()) => return Ok(path), - Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => last = format!("{}: {e}", path.display()), - Err(e) => return Err(format!("{}: {e}", path.display())), - } - } - Err(format!("no free scratch folder in the temp directory ({last})")) -} - /// Copy the faces `list_path` names from the craft-fonts checkout `dir` into `site` (at their /// `fonts/…` URLs). Returns how many were copied and the listed faces the checkout lacks. fn copy(list_path: &Path, dir: &Path, site: &Path) -> Result<(usize, Vec), String> {