From dc2c80739bcf7ffc0c17f33bc57c83f39d827b2d Mon Sep 17 00:00:00 2001 From: skylar taylor-barrick Date: Wed, 25 Nov 2026 20:02:16 -0600 Subject: [PATCH] Bake on the CPU under coverage so the Sonar shards stop crashing at exit (#840) Merged under Skylar's explicit override (Nightly 792) after green CI, CodeRabbit on this head with no open threads, and an independent adversarial review with no blockers. --- Cargo.toml | 3 +++ crates/engine/src/bake/mesh_map_command.rs | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index de6fc98d..36d12a70 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -104,6 +104,9 @@ egui-phosphor = { path = "vendor/egui-phosphor" } [workspace.lints.rust] unsafe_code = "forbid" +# cargo-llvm-cov always sets `cfg(coverage)`: a coverage build bakes on the CPU (texturecraft-engine +# picks no GPU tracer there) and the cfg would otherwise trip unexpected_cfgs under -D warnings. +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage)'] } [workspace.lints.clippy] dbg_macro = "warn" diff --git a/crates/engine/src/bake/mesh_map_command.rs b/crates/engine/src/bake/mesh_map_command.rs index 3a32bfa9..f253e1e6 100644 --- a/crates/engine/src/bake/mesh_map_command.rs +++ b/crates/engine/src/bake/mesh_map_command.rs @@ -93,6 +93,14 @@ pub fn set_gpu_raytracing(enabled: bool) { /// The tracer a bake starting now uses: the installed one while GPU raytracing is on, else none (the CPU) fn chosen_tracer(installed: Option<&Arc>, enabled: bool) -> Option> { + // The coverage build bakes on the CPU, the fallback every GPU failure takes anyway. Its tests run on + // a headless runner, and the bake's GPU device is created on a worker thread there: tearing that + // GL context down crashes the test process at exit (a wgpu-hal GLES `BadDisplay` panic, or a + // SIGSEGV in the driver), which took a different test down on every run. The compute shaders are + // never line-covered, so nothing is lost. + if cfg!(coverage) { + return None; + } installed.filter(|_| enabled).cloned() } @@ -917,7 +925,9 @@ mod gpu_raytracing_tests { fn bakes_use_the_installed_gpu_tracer_only_while_gpu_raytracing_is_on() { let installed: Arc = Arc::new(NamedTracer); - assert_eq!(chosen_tracer(Some(&installed), true).map(|tracer| tracer.name()), Some("gpu".to_string())); + // A coverage build keeps every bake on the CPU: its headless runner has no GPU to bake on + let gpu = (!cfg!(coverage)).then(|| "gpu".to_string()); + assert_eq!(chosen_tracer(Some(&installed), true).map(|tracer| tracer.name()), gpu, "on casts the rays on the GPU"); assert!(chosen_tracer(Some(&installed), false).is_none(), "off keeps the rays on the CPU"); assert!(chosen_tracer(None, true).is_none(), "no installed tracer bakes on the CPU"); }