Modern Apps git

← Modern-Apps.git

general: compile Vulkan shaders in Gradle instead of build.rs

Commit
acf76c8b0bd05499709426478ee086a2c625e3f2
Author
Vayun Mathur <[email protected]>
When
2026-10-30 15:36 UTC (1 month ago)
Parents
010a62e
Five crates (games/kart, games/voxels, library/avatar, library/map,
library/ml) compiled their GLSL to SPIR-V from a cargo build script.
kart, voxels and avatar wrote the .spv next to the sources, and those
files were committed, so any build on a machine with glslc dirtied the
tree. Worse, kart's committed .spv were the 28-byte placeholder stubs
the build script writes when it cannot find glslc: a build from the
committed files draws nothing. Those three scripts also probed
hardcoded paths under one developer's home directory and silently fell
back to the stubs. map and ml already did it properly (OUT_DIR, fail
if glslc is missing), but it was still five copies of glslc discovery.

Shader compilation now lives in build-logic:

- RustNative.kt: new GlslcCompile task, registered as
  :<module>:compileShaders when rustNativeLib is given `shaders`
  (globs under src/main/rust/shaders) and optional `glslcArgs`. It
  runs the pinned NDK's shader-tools glslc and writes <name>.spv to
  <module>/build/spirv, wiping the dir first so a deleted shader
  cannot leave a stale .spv behind. The cargoBuild tasks take its
  output as an input, so a shader edit reruns both, and a missing
  glslc or a compile error fails the build.
- The crates load the SPIR-V with include_bytes! from
  CARGO_MANIFEST_DIR/../../../build/spirv. Rejected passing the dir
  via an env var: ./check and ./test run one cargo invocation across
  several crates, which a single env var cannot serve, and a fixed
  relative path keeps hand-run cargo working once the task has run.
- Module selections: kart and avatar list only their Vulkan pair (the
  *_gles shaders are GLSL ES compiled at run time); voxels and map
  take *.vert/*.frag; ml takes *.comp (*.glsl are #include-only).
  map and ml keep --target-env=vulkan1.1 -O; the others keep glslc
  defaults, so compiled output is unchanged.
- Deleted all five build.rs and the 18 committed .spv. build/ is
  already gitignored. voxels' atlas.bin fallback went with its
  build.rs; atlas.bin is committed, so it never ran.
- ./check and ./test run :<module>:compileShaders for in-scope
  modules with a shaders dir before cargo. CONTRIBUTING.md documents
  the setup. Stale build.rs references in comments are updated.

Behaviour change: kart, voxels and avatar now fail to build without
glslc instead of shipping stub shaders. glslc ships with the NDK the
build already requires.

Verified: compileShaders for all five modules (2/14/2/27/64 .spv);
assembleRelease for :games:kart, :games:voxels, :library:avatar,
:library:map, :library:ml; libkart_engine.so contains the compiled
SPIR-V byte-for-byte; editing kart.frag reruns compileShaders and
cargoBuild; standalone cargo check of all five crates; ./test
--rust-only kart from an empty build/spirv (29 passed); ./check kart
cargo check/clippy/doc green (its detekt failure is pre-existing
UndocumentedPublicClass in untouched Kotlin). rustfmt status of every
touched .rs is unchanged.

Diff

CONTRIBUTING.md
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex bbae84e4a2..6e74e3c405 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -566,6 +566,14 @@ The workspace denies `unsafe_code`, `unwrap_used`, `panic`, `indexing_slicing` a **Packaging 32-bit is two-sided:** the app opts in with `nativeAbis { armv7 = true }` *and* the Rust module must opt in with `extraAbis`. CI currently installs only the aarch64 Rust target. +**Vulkan shaders** live in `src/main/rust/shaders/` and are compiled by Gradle, not `build.rs`.+Pass `shaders = listOf("*.vert", "*.frag")` (globs under `shaders/`) and optionally+`glslcArgs` to `rustNativeLib`. The `:<module>:compileShaders` task writes `<name>.spv` to+`build/spirv/` with the NDK's glslc, and the crate loads it with+`include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/<name>.spv"))`.+`./check` and `./test` run the task before cargo. If you run cargo by hand, run it first.+Don't commit `.spv` files.+ ---  ## Dependencies
build-logic/src/main/kotlin/RustNative.kt
diff --git a/build-logic/src/main/kotlin/RustNative.kt b/build-logic/src/main/kotlin/RustNative.ktindex 8ddae10b5d..5f02c499b6 100644--- a/build-logic/src/main/kotlin/RustNative.kt+++ b/build-logic/src/main/kotlin/RustNative.kt@@ -1,10 +1,26 @@+import org.gradle.api.DefaultTask+import org.gradle.api.GradleException import org.gradle.api.Project+import org.gradle.api.file.ConfigurableFileCollection+import org.gradle.api.file.DirectoryProperty+import org.gradle.api.provider.ListProperty+import org.gradle.api.provider.Property import org.gradle.api.services.BuildService import org.gradle.api.services.BuildServiceParameters import org.gradle.api.tasks.Exec+import org.gradle.api.tasks.Input+import org.gradle.api.tasks.InputDirectory+import org.gradle.api.tasks.InputFiles+import org.gradle.api.tasks.OutputDirectory+import org.gradle.api.tasks.PathSensitive+import org.gradle.api.tasks.PathSensitivity+import org.gradle.api.tasks.TaskAction import org.gradle.internal.os.OperatingSystem import org.gradle.kotlin.dsl.register+import org.gradle.process.ExecOperations+import java.io.File import java.util.Properties+import javax.inject.Inject  /**  * Shared build service that caps concurrent cargoBuild executions to 1.@@ -50,6 +66,53 @@ private fun isRustLengthExempt(path: String): Boolean =  */ data class RustAbi(val abiDir: String, val triple: String, val clangPrefix: String) +/**+ * Compiles GLSL entry points to `<name>.spv` with the NDK's glslc. Crates load the output with+ * `include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/<name>.spv"))`,+ * so standalone cargo (./check, ./test) needs this task to have run first.+ */+abstract class GlslcCompile @Inject constructor(+    private val execOps: ExecOperations,+) : DefaultTask() {+    /** Whole shader dir, so `#include`d files invalidate the task too. */+    @get:InputDirectory+    @get:PathSensitive(PathSensitivity.RELATIVE)+    abstract val shaderDir: DirectoryProperty++    @get:InputFiles+    @get:PathSensitive(PathSensitivity.RELATIVE)+    abstract val sources: ConfigurableFileCollection++    @get:Input+    abstract val glslc: Property<String>++    @get:Input+    abstract val glslcArgs: ListProperty<String>++    @get:OutputDirectory+    abstract val outputDir: DirectoryProperty++    @TaskAction+    fun compile() {+        val compiler = File(glslc.get())+        if (!compiler.isFile) {+            throw GradleException("glslc not found at $compiler. Install NDK $NDK_VERSION.")+        }+        val shaders = sources.files.sortedBy { it.name }+        if (shaders.isEmpty()) throw GradleException("No shaders matched in ${shaderDir.get()}")+        val out = outputDir.get().asFile+        // Wipe first so a deleted shader can't leave a stale .spv behind for include_bytes!.+        out.deleteRecursively()+        out.mkdirs()+        for (src in shaders) {+            val spv = File(out, "${src.name}.spv")+            execOps.exec {+                commandLine(compiler.path, *glslcArgs.get().toTypedArray(), "-o", spv.path, src.path)+            }+        }+    }+}+ private val KNOWN_RUST_ABIS = listOf(     RustAbi(ABI_ARM64, "aarch64-linux-android", "aarch64-linux-android"),     RustAbi(ABI_ARMV7, "armv7-linux-androideabi", "armv7a-linux-androideabi"),@@ -80,6 +143,11 @@ private val KNOWN_RUST_ABIS = listOf(  *                   String list at configuration time so the build stays  *                   configuration-cache compatible (only the strings cross into  *                   the task action, never the Project).+ * @param shaders    Glob patterns under `$srcDir/shaders` to compile to SPIR-V into+ *                   `build/spirv` ahead of the cargo build (see [GlslcCompile]). Empty+ *                   means the crate has no Vulkan shaders. Only supported with the+ *                   default [srcDir], since crates locate `build/spirv` relative to it.+ * @param glslcArgs  Extra glslc flags, e.g. `--target-env=vulkan1.1`, `-O`.  */ fun Project.rustNativeLib(     crate: String,@@ -87,6 +155,8 @@ fun Project.rustNativeLib(     extraAbis: List<String> = emptyList(),     features: List<String> = emptyList(),     srcDir: String = "src/main/rust",+    shaders: List<String> = emptyList(),+    glslcArgs: List<String> = emptyList(), ) {     // Serialize cargoBuild across all Rust modules to avoid concurrent rustup installs.     val rustLock = gradle.sharedServices.registerIfAbsent(@@ -141,6 +211,19 @@ fun Project.rustNativeLib(     val cargoFeatureArgs: List<String> =         if (features.isNotEmpty()) listOf("--features", features.joinToString(",")) else emptyList() +    val compileShaders = if (shaders.isEmpty()) null else {+        require(srcDir == "src/main/rust") { "rustNativeLib($crate): shaders need the default srcDir" }+        val glslcExe = if (OperatingSystem.current().isWindows) "glslc.exe" else "glslc"+        tasks.register<GlslcCompile>("compileShaders") {+            description = "Compiles $crate's GLSL to SPIR-V."+            shaderDir.set(file("$srcDir/shaders"))+            sources.from(fileTree("$srcDir/shaders") { include(shaders) })+            glslc.set("$ndkRoot/shader-tools/$hostTag/$glslcExe")+            this.glslcArgs.set(glslcArgs)+            outputDir.set(layout.buildDirectory.dir("spirv"))+        }+    }+     val perAbi = rustAbis.map { abi ->         val (abiDir, triple) = abi         tasks.register<Exec>("cargoBuild_${crate}_${abiDir.replace('-', '_')}") {@@ -163,15 +246,10 @@ fun Project.rustNativeLib(              inputs.dir("$srcDir/src")             inputs.file("$srcDir/Cargo.toml")-            // The crate's own build script and whatever it generates from. `:library:ml`'s-            // build.rs compiles `shaders/*.comp` to SPIR-V and `include_bytes!`s the result, so-            // a shader edit changes the .so - but without these two the task stays up to date,-            // cargo is never invoked, and the old SPIR-V ships. That failure is silent and it-            // makes shader A/B measurements read as "no effect".-            //-            // Optional because not every Rust module here has either.             file("$srcDir/build.rs").takeIf { it.isFile }?.let { inputs.file(it) }-            file("$srcDir/shaders").takeIf { it.isDirectory }?.let { inputs.dir(it) }+            // The crate include_bytes!s build/spirv, so a shader edit must re-run cargo;+            // otherwise the task stays up to date and the old SPIR-V silently ships.+            compileShaders?.let { inputs.files(it).withPropertyName("spirv") }             // `:library:ml`'s build.rs also compiles `schema/maml2.fbs` to Rust via             // flatc and `include!`s the result, so a schema edit changes the .so too.             // Same staleness hazard as shaders above: without this the task stays up
check
diff --git a/check b/checkindex ca78a96ac3..dd1e9ddaff 100644--- a/check+++ b/check@@ -90,6 +90,8 @@ TASKS=() for mod in "${MODS[@]}"; do   gmod="$(echo "$mod" | tr '/' ':')"   TASKS+=(":$gmod:detekt" ":$gmod:lint")+  # cargo include_bytes!s the SPIR-V this task writes to build/spirv.+  [[ -d "$ROOT/$mod/src/main/rust/shaders" ]] && TASKS+=(":$gmod:compileShaders") done echo "Modules (${#MODS[@]}): ${MODS[*]}" echo "Gradle tasks: ${TASKS[*]}"
games/kart/build.gradle.kts
diff --git a/games/kart/build.gradle.kts b/games/kart/build.gradle.ktsindex 2df014e4f9..d9df3c4d35 100644--- a/games/kart/build.gradle.kts+++ b/games/kart/build.gradle.kts@@ -38,7 +38,13 @@ androidComponents { // armeabi-v7a as well as arm64: the ONN box runs this app directly on 32-bit // Google TV hardware. Only kart_engine opts in (:library:e2ee-p2p precedent) — // no other native module changes.-rustNativeLib("kart_engine", "kart", extraAbis = listOf(ABI_ARMV7))+rustNativeLib(+    "kart_engine",+    "kart",+    extraAbis = listOf(ABI_ARMV7),+    // kart_gles.* are GLSL ES, compiled at run time by the GLES fallback.+    shaders = listOf("kart.vert", "kart.frag"),+)  dependencies {     implementation(project(":sdk:controller"))
games/kart/src/main/rust/build.rs
diff --git a/games/kart/src/main/rust/build.rs b/games/kart/src/main/rust/build.rsdeleted file mode 100644index b44ca7f074..0000000000--- a/games/kart/src/main/rust/build.rs+++ /dev/null@@ -1,100 +0,0 @@-use std::path::PathBuf;-use std::process::Command;--/// Compile the kart shaders to SPIR-V with glslc when available.-///-/// Same arrangement as games/voxels: `include_bytes!` in vulkan/pipeline.rs-/// requires the `.spv` files to exist even when no glslc is installed, so a-/// minimal valid module is written as a fallback (it draws nothing useful, but-/// the crate still builds and the CPU-side race sim still ticks).-fn main() {-    let shaders_dir = PathBuf::from("shaders");-    let pairs = [("kart.vert", "kart.vert.spv"), ("kart.frag", "kart.frag.spv")];--    if let Some(glslc) = find_glslc() {-        println!("cargo:warning=Found glslc at {}", glslc.display());-        for (src, spv) in &pairs {-            let _ = Command::new(&glslc)-                .arg("-o")-                .arg(shaders_dir.join(spv))-                .arg(shaders_dir.join(src))-                .status();-        }-    }--    for (src, spv) in &pairs {-        let out = shaders_dir.join(spv);-        if !out.exists() {-            let bytes = if src.ends_with(".vert") {-                minimal_vert_spv()-            } else {-                minimal_frag_spv()-            };-            std::fs::write(&out, bytes).ok();-        }-        println!("cargo:rerun-if-changed=shaders/{src}");-    }-    println!("cargo:rerun-if-changed=build.rs");-}--/// glslc ships with the NDK (shader-tools) on every host OS; fall back to-/// PATH. The Windows path is read from the same SDK the Gradle build uses.-fn find_glslc() -> Option<PathBuf> {-    let mut candidates: Vec<PathBuf> = Vec::new();-    let sdk = std::env::var("ANDROID_HOME")-        .or_else(|_| std::env::var("ANDROID_SDK_ROOT"))-        .ok();-    if let Some(sdk) = sdk {-        for tag in ["windows-x86_64", "linux-x86_64", "darwin-x86_64"] {-            candidates.push(-                PathBuf::from(&sdk)-                    .join("ndk")-                    .join("29.0.14206865")-                    .join("shader-tools")-                    .join(tag)-                    .join(if tag.starts_with("windows") {-                        "glslc.exe"-                    } else {-                        "glslc"-                    }),-            );-        }-    }-    for mac_linux in [-        "/Users/vayun/devmate-android-toolchain/android-sdk/ndk/29.0.14206865/shader-tools/darwin-x86_64/glslc",-        "/Users/vayun/devmate-android-toolchain/android-sdk/ndk/29.0.14206865/shader-tools/linux-x86_64/glslc",-    ] {-        candidates.push(PathBuf::from(mac_linux));-    }-    for c in candidates {-        if c.exists() {-            return Some(c);-        }-    }-    let probe = if cfg!(windows) { "where" } else { "which" };-    if Command::new(probe)-        .arg("glslc")-        .output()-        .map(|o| o.status.success())-        .unwrap_or(false)-    {-        return Some(PathBuf::from("glslc"));-    }-    None-}--fn minimal_vert_spv() -> Vec<u8> {-    vec![-        0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x08, 0x00,-        0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00,-        0x01, 0x00, 0x00, 0x00,-    ]-}--fn minimal_frag_spv() -> Vec<u8> {-    vec![-        0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x08, 0x00,-        0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00,-        0x01, 0x00, 0x00, 0x00,-    ]-}
games/kart/src/main/rust/shaders/kart.frag.spv
diff --git a/games/kart/src/main/rust/shaders/kart.frag.spv b/games/kart/src/main/rust/shaders/kart.frag.spvdeleted file mode 100644index d27f8d838e..0000000000Binary files a/games/kart/src/main/rust/shaders/kart.frag.spv and /dev/null differ
games/kart/src/main/rust/shaders/kart.vert.spv
diff --git a/games/kart/src/main/rust/shaders/kart.vert.spv b/games/kart/src/main/rust/shaders/kart.vert.spvdeleted file mode 100644index 9f20d208d4..0000000000Binary files a/games/kart/src/main/rust/shaders/kart.vert.spv and /dev/null differ
games/kart/src/main/rust/src/gles/shaders.rs
diff --git a/games/kart/src/main/rust/src/gles/shaders.rs b/games/kart/src/main/rust/src/gles/shaders.rsindex 66c4f749d0..02fc571bdd 100644--- a/games/kart/src/main/rust/src/gles/shaders.rs+++ b/games/kart/src/main/rust/src/gles/shaders.rs@@ -1,7 +1,7 @@ //! GLSL ES program: compile + link the `kart_gles` shader twins. //! //! The Vulkan SPIR-V pair gains GLSL ES 3.0 sources (built untouched by-//! `build.rs`, which only knows `kart.vert`/`kart.frag`); the UBO becomes+//! `compileShaders`, which only knows `kart.vert`/`kart.frag`); the UBO becomes //! three uniforms (`uViewProj` / `uSunDir` / `uCamPos`). Every failure //! surfaces the driver info log so logcat names the bad line, not just //! "link failed".
games/kart/src/main/rust/src/vulkan/pipeline.rs
diff --git a/games/kart/src/main/rust/src/vulkan/pipeline.rs b/games/kart/src/main/rust/src/vulkan/pipeline.rsindex 980281ce9e..93706a1264 100644--- a/games/kart/src/main/rust/src/vulkan/pipeline.rs+++ b/games/kart/src/main/rust/src/vulkan/pipeline.rs@@ -8,8 +8,8 @@ use ash::vk; use std::ffi::CString; -const KART_VERT_SPV: &[u8] = include_bytes!("../../shaders/kart.vert.spv");-const KART_FRAG_SPV: &[u8] = include_bytes!("../../shaders/kart.frag.spv");+const KART_VERT_SPV: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/kart.vert.spv"));+const KART_FRAG_SPV: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/kart.frag.spv"));  /// Pipeline + layout + the single UBO descriptor set. pub struct Pipelines {
games/voxels/build.gradle.kts
diff --git a/games/voxels/build.gradle.kts b/games/voxels/build.gradle.ktsindex 4b84632328..24b946b6c4 100644--- a/games/voxels/build.gradle.kts+++ b/games/voxels/build.gradle.kts@@ -26,7 +26,7 @@ androidComponents { }  // Full Rust + Vulkan engine (ash) with Matcha texture atlas (16 textures → 64x64)-rustNativeLib("voxels_engine", "voxels")+rustNativeLib("voxels_engine", "voxels", shaders = listOf("*.vert", "*.frag"))  dependencies {     implementation(project(":sdk:games"))
games/voxels/src/main/rust/build.rs
diff --git a/games/voxels/src/main/rust/build.rs b/games/voxels/src/main/rust/build.rsdeleted file mode 100644index f2257ef0a1..0000000000--- a/games/voxels/src/main/rust/build.rs+++ /dev/null@@ -1,109 +0,0 @@-use std::path::PathBuf;-use std::process::Command;--fn main() {-    let shaders_dir = PathBuf::from("shaders");-    let glslc = find_glslc();--    let vert = shaders_dir.join("block.vert");-    let frag = shaders_dir.join("block.frag");-    let vert_spv = shaders_dir.join("block.vert.spv");-    let frag_spv = shaders_dir.join("block.frag.spv");-    let sky_vert = shaders_dir.join("sky.vert");-    let sky_frag = shaders_dir.join("sky.frag");-    let sky_vert_spv = shaders_dir.join("sky.vert.spv");-    let sky_frag_spv = shaders_dir.join("sky.frag.spv");-    let cloud_frag = shaders_dir.join("cloud.frag");-    let cloud_frag_spv = shaders_dir.join("cloud.frag.spv");-    let entity_vert = shaders_dir.join("entity.vert");-    let entity_vert_spv = shaders_dir.join("entity.vert.spv");-    let entity_frag = shaders_dir.join("entity.frag");-    let entity_frag_spv = shaders_dir.join("entity.frag.spv");-    let shadow_vert = shaders_dir.join("shadow.vert");-    let shadow_vert_spv = shaders_dir.join("shadow.vert.spv");-    let water_vert = shaders_dir.join("water.vert");-    let water_frag = shaders_dir.join("water.frag");-    let water_vert_spv = shaders_dir.join("water.vert.spv");-    let water_frag_spv = shaders_dir.join("water.frag.spv");-    let post = [("post.vert","post.vert.spv"), ("bright.frag","bright.frag.spv"), ("blur.frag","blur.frag.spv"), ("composite.frag","composite.frag.spv")];-    let atlas_bin = shaders_dir.join("atlas.bin");--    if !atlas_bin.exists() {-        println!("cargo:warning=atlas.bin missing, creating checker fallback 64x64");-        let mut atlas = vec![0u8; 64*64*4];-        for y in 0..64 { for x in 0..64 {-            let i = (y*64 + x)*4;-            let checker = ((x/8 + y/8) %2)==0;-            if checker { atlas[i]=255; atlas[i+1]=0; atlas[i+2]=255; atlas[i+3]=255; }-            else { atlas[i]=0; atlas[i+1]=0; atlas[i+2]=0; atlas[i+3]=255; }-        }}-        std::fs::write(&atlas_bin, atlas).ok();-    }--    if let Some(glslc_path) = &glslc {-        println!("cargo:warning=Found glslc at {}", glslc_path.display());-        let _ = Command::new(glslc_path).arg("-o").arg(&vert_spv).arg(&vert).status();-        let _ = Command::new(glslc_path).arg("-o").arg(&frag_spv).arg(&frag).status();-        let _ = Command::new(glslc_path).arg("-o").arg(&sky_vert_spv).arg(&sky_vert).status();-        let _ = Command::new(glslc_path).arg("-o").arg(&sky_frag_spv).arg(&sky_frag).status();-        let _ = Command::new(glslc_path).arg("-o").arg(&cloud_frag_spv).arg(&cloud_frag).status();-        let _ = Command::new(glslc_path).arg("-o").arg(&entity_vert_spv).arg(&entity_vert).status();-        let _ = Command::new(glslc_path).arg("-o").arg(&entity_frag_spv).arg(&entity_frag).status();-        let _ = Command::new(glslc_path).arg("-o").arg(&shadow_vert_spv).arg(&shadow_vert).status();-        let _ = Command::new(glslc_path).arg("-o").arg(&water_vert_spv).arg(&water_vert).status();-        let _ = Command::new(glslc_path).arg("-o").arg(&water_frag_spv).arg(&water_frag).status();-        for (src, spv) in &post {-            let _ = Command::new(glslc_path).arg("-o").arg(shaders_dir.join(spv)).arg(shaders_dir.join(src)).status();-        }-    }--    if !vert_spv.exists() { std::fs::write(&vert_spv, minimal_vert_spv()).ok(); }-    if !frag_spv.exists() { std::fs::write(&frag_spv, minimal_frag_spv()).ok(); }-    // include_bytes! requires these to exist even if glslc is unavailable.-    if !sky_vert_spv.exists() { std::fs::write(&sky_vert_spv, minimal_vert_spv()).ok(); }-    if !sky_frag_spv.exists() { std::fs::write(&sky_frag_spv, minimal_frag_spv()).ok(); }-    if !cloud_frag_spv.exists() { std::fs::write(&cloud_frag_spv, minimal_frag_spv()).ok(); }-    if !entity_vert_spv.exists() { std::fs::write(&entity_vert_spv, minimal_vert_spv()).ok(); }-    if !entity_frag_spv.exists() { std::fs::write(&entity_frag_spv, minimal_frag_spv()).ok(); }-    if !shadow_vert_spv.exists() { std::fs::write(&shadow_vert_spv, minimal_vert_spv()).ok(); }-    if !water_vert_spv.exists() { std::fs::write(&water_vert_spv, minimal_vert_spv()).ok(); }-    if !water_frag_spv.exists() { std::fs::write(&water_frag_spv, minimal_frag_spv()).ok(); }-    for (src, spv) in &post {-        let p = shaders_dir.join(spv);-        if !p.exists() { std::fs::write(&p, if src.ends_with(".vert") { minimal_vert_spv() } else { minimal_frag_spv() }).ok(); }-    }--    println!("cargo:rerun-if-changed=shaders/block.vert");-    println!("cargo:rerun-if-changed=shaders/block.frag");-    println!("cargo:rerun-if-changed=shaders/sky.vert");-    println!("cargo:rerun-if-changed=shaders/sky.frag");-    println!("cargo:rerun-if-changed=shaders/cloud.frag");-    println!("cargo:rerun-if-changed=shaders/entity.vert");-    println!("cargo:rerun-if-changed=shaders/entity.frag");-    println!("cargo:rerun-if-changed=shaders/shadow.vert");-    println!("cargo:rerun-if-changed=shaders/water.vert");-    println!("cargo:rerun-if-changed=shaders/water.frag");-    println!("cargo:rerun-if-changed=shaders/post.vert");-    println!("cargo:rerun-if-changed=shaders/bright.frag");-    println!("cargo:rerun-if-changed=shaders/blur.frag");-    println!("cargo:rerun-if-changed=shaders/composite.frag");-    println!("cargo:rerun-if-changed=shaders/atlas.bin");-    println!("cargo:rerun-if-changed=build.rs");-}--fn find_glslc() -> Option<PathBuf> {-    for c in [-        "/Users/vayun/devmate-android-toolchain/android-sdk/ndk/29.0.14206865/shader-tools/darwin-x86_64/glslc",-        "/Users/vayun/devmate-android-toolchain/android-sdk/ndk/29.0.14206865/shader-tools/linux-x86_64/glslc",-    ] {-        let p = PathBuf::from(c);-        if p.exists() { return Some(p); }-    }-    if Command::new("which").arg("glslc").output().map(|o| o.status.success()).unwrap_or(false) {-        return Some(PathBuf::from("glslc"));-    }-    None-}--fn minimal_vert_spv() -> Vec<u8> { vec![0x03,0x02,0x23,0x07, 0x00,0x00,0x01,0x00, 0x0a,0x00,0x08,0x00, 0x28,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x11,0x00,0x02,0x00, 0x01,0x00,0x00,0x00] }-fn minimal_frag_spv() -> Vec<u8> { vec![0x03,0x02,0x23,0x07, 0x00,0x00,0x01,0x00, 0x0a,0x00,0x08,0x00, 0x1c,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x11,0x00,0x02,0x00, 0x01,0x00,0x00,0x00] }
games/voxels/src/main/rust/shaders/block.frag.spv
diff --git a/games/voxels/src/main/rust/shaders/block.frag.spv b/games/voxels/src/main/rust/shaders/block.frag.spvdeleted file mode 100644index 54f3b79ee9..0000000000Binary files a/games/voxels/src/main/rust/shaders/block.frag.spv and /dev/null differ
games/voxels/src/main/rust/shaders/block.vert.spv
diff --git a/games/voxels/src/main/rust/shaders/block.vert.spv b/games/voxels/src/main/rust/shaders/block.vert.spvdeleted file mode 100644index 352135b471..0000000000Binary files a/games/voxels/src/main/rust/shaders/block.vert.spv and /dev/null differ
games/voxels/src/main/rust/shaders/blur.frag.spv
diff --git a/games/voxels/src/main/rust/shaders/blur.frag.spv b/games/voxels/src/main/rust/shaders/blur.frag.spvdeleted file mode 100644index d68cf77a56..0000000000Binary files a/games/voxels/src/main/rust/shaders/blur.frag.spv and /dev/null differ
games/voxels/src/main/rust/shaders/bright.frag.spv
diff --git a/games/voxels/src/main/rust/shaders/bright.frag.spv b/games/voxels/src/main/rust/shaders/bright.frag.spvdeleted file mode 100644index 2a1cb1d892..0000000000Binary files a/games/voxels/src/main/rust/shaders/bright.frag.spv and /dev/null differ
games/voxels/src/main/rust/shaders/cloud.frag.spv
diff --git a/games/voxels/src/main/rust/shaders/cloud.frag.spv b/games/voxels/src/main/rust/shaders/cloud.frag.spvdeleted file mode 100644index 830362d7f2..0000000000Binary files a/games/voxels/src/main/rust/shaders/cloud.frag.spv and /dev/null differ
games/voxels/src/main/rust/shaders/composite.frag.spv
diff --git a/games/voxels/src/main/rust/shaders/composite.frag.spv b/games/voxels/src/main/rust/shaders/composite.frag.spvdeleted file mode 100644index cf1a7c537d..0000000000Binary files a/games/voxels/src/main/rust/shaders/composite.frag.spv and /dev/null differ
games/voxels/src/main/rust/shaders/entity.frag.spv
diff --git a/games/voxels/src/main/rust/shaders/entity.frag.spv b/games/voxels/src/main/rust/shaders/entity.frag.spvdeleted file mode 100644index 51cb701ae1..0000000000Binary files a/games/voxels/src/main/rust/shaders/entity.frag.spv and /dev/null differ
games/voxels/src/main/rust/shaders/entity.vert.spv
diff --git a/games/voxels/src/main/rust/shaders/entity.vert.spv b/games/voxels/src/main/rust/shaders/entity.vert.spvdeleted file mode 100644index c6a4ee79ec..0000000000Binary files a/games/voxels/src/main/rust/shaders/entity.vert.spv and /dev/null differ
games/voxels/src/main/rust/shaders/post.vert.spv
diff --git a/games/voxels/src/main/rust/shaders/post.vert.spv b/games/voxels/src/main/rust/shaders/post.vert.spvdeleted file mode 100644index d9c05ea395..0000000000Binary files a/games/voxels/src/main/rust/shaders/post.vert.spv and /dev/null differ
games/voxels/src/main/rust/shaders/shadow.vert.spv
diff --git a/games/voxels/src/main/rust/shaders/shadow.vert.spv b/games/voxels/src/main/rust/shaders/shadow.vert.spvdeleted file mode 100644index 62c78c21cd..0000000000Binary files a/games/voxels/src/main/rust/shaders/shadow.vert.spv and /dev/null differ
games/voxels/src/main/rust/shaders/sky.frag.spv
diff --git a/games/voxels/src/main/rust/shaders/sky.frag.spv b/games/voxels/src/main/rust/shaders/sky.frag.spvdeleted file mode 100644index ff19e2f1c5..0000000000Binary files a/games/voxels/src/main/rust/shaders/sky.frag.spv and /dev/null differ
games/voxels/src/main/rust/shaders/sky.vert.spv
diff --git a/games/voxels/src/main/rust/shaders/sky.vert.spv b/games/voxels/src/main/rust/shaders/sky.vert.spvdeleted file mode 100644index 36632f61db..0000000000Binary files a/games/voxels/src/main/rust/shaders/sky.vert.spv and /dev/null differ
games/voxels/src/main/rust/shaders/water.frag.spv
diff --git a/games/voxels/src/main/rust/shaders/water.frag.spv b/games/voxels/src/main/rust/shaders/water.frag.spvdeleted file mode 100644index fda45a5fc2..0000000000Binary files a/games/voxels/src/main/rust/shaders/water.frag.spv and /dev/null differ
games/voxels/src/main/rust/shaders/water.vert.spv
diff --git a/games/voxels/src/main/rust/shaders/water.vert.spv b/games/voxels/src/main/rust/shaders/water.vert.spvdeleted file mode 100644index 61ac44276a..0000000000Binary files a/games/voxels/src/main/rust/shaders/water.vert.spv and /dev/null differ
games/voxels/src/main/rust/src/vulkan/pipeline.rs
diff --git a/games/voxels/src/main/rust/src/vulkan/pipeline.rs b/games/voxels/src/main/rust/src/vulkan/pipeline.rsindex 08dc846c7e..9593d23351 100644--- a/games/voxels/src/main/rust/src/vulkan/pipeline.rs+++ b/games/voxels/src/main/rust/src/vulkan/pipeline.rs@@ -1,19 +1,19 @@ use ash::vk; use std::ffi::CString;-const BLOCK_VERT_SPV: &[u8] = include_bytes!("../../shaders/block.vert.spv");-const BLOCK_FRAG_SPV: &[u8] = include_bytes!("../../shaders/block.frag.spv");-const SKY_VERT_SPV: &[u8] = include_bytes!("../../shaders/sky.vert.spv");-const SKY_FRAG_SPV: &[u8] = include_bytes!("../../shaders/sky.frag.spv");-const CLOUD_FRAG_SPV: &[u8] = include_bytes!("../../shaders/cloud.frag.spv");-const ENTITY_VERT_SPV: &[u8] = include_bytes!("../../shaders/entity.vert.spv");-const ENTITY_FRAG_SPV: &[u8] = include_bytes!("../../shaders/entity.frag.spv");-const SHADOW_VERT_SPV: &[u8] = include_bytes!("../../shaders/shadow.vert.spv");-const WATER_VERT_SPV: &[u8] = include_bytes!("../../shaders/water.vert.spv");-const WATER_FRAG_SPV: &[u8] = include_bytes!("../../shaders/water.frag.spv");-const POST_VERT_SPV: &[u8] = include_bytes!("../../shaders/post.vert.spv");-const BRIGHT_FRAG_SPV: &[u8] = include_bytes!("../../shaders/bright.frag.spv");-const BLUR_FRAG_SPV: &[u8] = include_bytes!("../../shaders/blur.frag.spv");-const COMPOSITE_FRAG_SPV: &[u8] = include_bytes!("../../shaders/composite.frag.spv");+const BLOCK_VERT_SPV: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/block.vert.spv"));+const BLOCK_FRAG_SPV: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/block.frag.spv"));+const SKY_VERT_SPV: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/sky.vert.spv"));+const SKY_FRAG_SPV: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/sky.frag.spv"));+const CLOUD_FRAG_SPV: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/cloud.frag.spv"));+const ENTITY_VERT_SPV: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/entity.vert.spv"));+const ENTITY_FRAG_SPV: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/entity.frag.spv"));+const SHADOW_VERT_SPV: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/shadow.vert.spv"));+const WATER_VERT_SPV: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/water.vert.spv"));+const WATER_FRAG_SPV: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/water.frag.spv"));+const POST_VERT_SPV: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/post.vert.spv"));+const BRIGHT_FRAG_SPV: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/bright.frag.spv"));+const BLUR_FRAG_SPV: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/blur.frag.spv"));+const COMPOSITE_FRAG_SPV: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/composite.frag.spv")); pub struct Pipelines {     pub layout: vk::PipelineLayout,     pub pipeline: vk::Pipeline,
library/avatar/build.gradle.kts
diff --git a/library/avatar/build.gradle.kts b/library/avatar/build.gradle.ktsindex c0d9a01458..85ac895ddd 100644--- a/library/avatar/build.gradle.kts+++ b/library/avatar/build.gradle.kts@@ -29,4 +29,9 @@ dependencies { // Same arrangement as :library:map: the crate builds into rustJniLibs and // YuuAvatarNative.isAvailable gates every call, so devices without the .so // keep the 2D YuuFace preview. arm64 only (map precedent).-rustNativeLib("yuu_avatar", "avatar")+rustNativeLib(+    "yuu_avatar",+    "avatar",+    // yuu_avatar_gles.* are GLSL ES, compiled at run time by the GLES path.+    shaders = listOf("yuu_avatar.vert", "yuu_avatar.frag"),+)
library/avatar/src/main/rust/build.rs
diff --git a/library/avatar/src/main/rust/build.rs b/library/avatar/src/main/rust/build.rsdeleted file mode 100644index c71dd43550..0000000000--- a/library/avatar/src/main/rust/build.rs+++ /dev/null@@ -1,143 +0,0 @@-use std::path::PathBuf;-use std::process::Command;--/// Compile the Yuu avatar shaders to SPIR-V with glslc when available.-///-/// Same arrangement as games/voxels and games/kart: `include_bytes!` in-/// vulkan/pipeline.rs requires the `.spv` files to exist even when no glslc is-/// installed, so a minimal valid module is written as a fallback (it draws-/// nothing useful, but the crate still builds).-fn main() {-    let shaders_dir = PathBuf::from("shaders");-    let pairs = [("yuu_avatar.vert", "yuu_avatar.vert.spv"), ("yuu_avatar.frag", "yuu_avatar.frag.spv")];--    if let Some(glslc) = find_glslc() {-        println!("cargo:warning=Found glslc at {}", glslc.display());-        for (src, spv) in &pairs {-            let _ = Command::new(&glslc)-                .arg("-o")-                .arg(shaders_dir.join(spv))-                .arg(shaders_dir.join(src))-                .status();-        }-    }--    for (src, spv) in &pairs {-        let out = shaders_dir.join(spv);-        if !out.exists() {-            let bytes = if src.ends_with(".vert") {-                minimal_vert_spv()-            } else {-                minimal_frag_spv()-            };-            std::fs::write(&out, bytes).ok();-        }-        println!("cargo:rerun-if-changed=shaders/{src}");-    }-    println!("cargo:rerun-if-changed=build.rs");-}--/// glslc ships with the NDK (shader-tools) on every host OS; fall back to-/// PATH. Probes SDK-derived NDK locations and PATH first; a pinned-/// machine-specific path is the last resort so other hosts/CI don't silently-/// fall to the minimal-SPIRV fallback.-fn find_glslc() -> Option<PathBuf> {-    // PATH first: hermetic toolchains (CI) win over host SDK probing.-    let probe = if cfg!(windows) { "where" } else { "which" };-    if Command::new(probe)-        .arg("glslc")-        .output()-        .map(|o| o.status.success())-        .unwrap_or(false)-    {-        return Some(PathBuf::from("glslc"));-    }-    let mut candidates: Vec<PathBuf> = Vec::new();-    let sdk = std::env::var("ANDROID_HOME")-        .or_else(|_| std::env::var("ANDROID_SDK_ROOT"))-        .ok();-    if let Some(sdk) = sdk {-        // Prefer the newest installed NDK over the pinned revision.-        if let Ok(ndk_dir) = std::fs::read_dir(PathBuf::from(&sdk).join("ndk")) {-            let mut versions: Vec<_> = ndk_dir.filter_map(|e| e.ok().map(|e| e.path())).collect();-            versions.sort();-            for ndk in versions.iter().rev() {-                for tag in ["windows-x86_64", "linux-x86_64", "darwin-x86_64"] {-                    candidates.push(-                        ndk.join("shader-tools").join(tag).join(if tag.starts_with("windows") {-                            "glslc.exe"-                        } else {-                            "glslc"-                        }),-                    );-                }-            }-        }-        // Pinned fallback (kept for hosts with only this NDK).-        for tag in ["windows-x86_64", "linux-x86_64", "darwin-x86_64"] {-            candidates.push(-                PathBuf::from(&sdk)-                    .join("ndk")-                    .join("29.0.14206865")-                    .join("shader-tools")-                    .join(tag)-                    .join(if tag.starts_with("windows") {-                        "glslc.exe"-                    } else {-                        "glslc"-                    }),-            );-        }-    }-    for mac_linux in [-        "/Users/vayun/devmate-android-toolchain/android-sdk/ndk/29.0.14206865/shader-tools/darwin-x86_64/glslc",-        "/Users/vayun/devmate-android-toolchain/android-sdk/ndk/29.0.14206865/shader-tools/linux-x86_64/glslc",-    ] {-        candidates.push(PathBuf::from(mac_linux));-    }-    // Common Windows SDK locations (local.properties is Gradle-only; cargo-    // builds outside Gradle need these or they silently fall to the minimal-    // SPV stub — which Mali drivers SIGSEGV parsing).-    for windows_sdk in [-        "C:\\Android\\Sdk",-        "C:\\Users\\Vayun\\AppData\\Local\\Android\\Sdk",-    ] {-        for tag in ["windows-x86_64", "linux-x86_64", "darwin-x86_64"] {-            if let Ok(ndk_dir) = std::fs::read_dir(PathBuf::from(windows_sdk).join("ndk")) {-                let mut versions: Vec<_> = ndk_dir.filter_map(|e| e.ok().map(|e| e.path())).collect();-                versions.sort();-                for ndk in versions.iter().rev() {-                    candidates.push(-                        ndk.join("shader-tools").join(tag).join(if tag.starts_with("windows") {-                            "glslc.exe"-                        } else {-                            "glslc"-                        }),-                    );-                }-            }-        }-    }-    for c in candidates {-        if c.exists() {-            return Some(c);-        }-    }-    None-}--fn minimal_vert_spv() -> Vec<u8> {-    vec![-        0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x08, 0x00,-        0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00,-        0x01, 0x00, 0x00, 0x00,-    ]-}--fn minimal_frag_spv() -> Vec<u8> {-    vec![-        0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x08, 0x00,-        0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00,-        0x01, 0x00, 0x00, 0x00,-    ]-}
library/avatar/src/main/rust/shaders/yuu_avatar.frag.spv
diff --git a/library/avatar/src/main/rust/shaders/yuu_avatar.frag.spv b/library/avatar/src/main/rust/shaders/yuu_avatar.frag.spvdeleted file mode 100644index 0246464f28..0000000000Binary files a/library/avatar/src/main/rust/shaders/yuu_avatar.frag.spv and /dev/null differ
library/avatar/src/main/rust/shaders/yuu_avatar.vert.spv
diff --git a/library/avatar/src/main/rust/shaders/yuu_avatar.vert.spv b/library/avatar/src/main/rust/shaders/yuu_avatar.vert.spvdeleted file mode 100644index 6fea242e2f..0000000000Binary files a/library/avatar/src/main/rust/shaders/yuu_avatar.vert.spv and /dev/null differ
library/avatar/src/main/rust/src/gles/shaders.rs
diff --git a/library/avatar/src/main/rust/src/gles/shaders.rs b/library/avatar/src/main/rust/src/gles/shaders.rsindex 10d6948c04..fbe9284d13 100644--- a/library/avatar/src/main/rust/src/gles/shaders.rs+++ b/library/avatar/src/main/rust/src/gles/shaders.rs@@ -1,7 +1,7 @@ //! GLSL ES program: compile + link the `yuu_avatar_gles` shader twins. //! //! The Vulkan SPIR-V pair gains GLSL ES 3.0 sources (built untouched by-//! `build.rs`, which only knows `yuu_avatar.vert`/`yuu_avatar.frag`); the UBO+//! `compileShaders`, which only knows `yuu_avatar.vert`/`yuu_avatar.frag`); the UBO //! becomes uniforms (`uViewProj` / `uSunDir` / `uCamPos` / `uBones[32]` / //! `uAlbedo`). Every failure surfaces the driver info log so logcat names the //! bad line, not just "link failed".
library/avatar/src/main/rust/src/vulkan/pipeline.rs
diff --git a/library/avatar/src/main/rust/src/vulkan/pipeline.rs b/library/avatar/src/main/rust/src/vulkan/pipeline.rsindex a39be15501..758b69f119 100644--- a/library/avatar/src/main/rust/src/vulkan/pipeline.rs+++ b/library/avatar/src/main/rust/src/vulkan/pipeline.rs@@ -8,8 +8,8 @@ use ash::vk; use std::ffi::CString; -const YUU_VERT_SPV: &[u8] = include_bytes!("../../shaders/yuu_avatar.vert.spv");-const YUU_FRAG_SPV: &[u8] = include_bytes!("../../shaders/yuu_avatar.frag.spv");+const YUU_VERT_SPV: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/yuu_avatar.vert.spv"));+const YUU_FRAG_SPV: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/yuu_avatar.frag.spv"));  /// Pipeline + layout + the UBO/sampler descriptor set. pub struct Pipelines {
library/map/build.gradle.kts
diff --git a/library/map/build.gradle.kts b/library/map/build.gradle.ktsindex c403c1e01c..5c6c3dcb37 100644--- a/library/map/build.gradle.kts+++ b/library/map/build.gradle.kts@@ -67,9 +67,8 @@ dependencies { // system image on such a host means full-system QEMU translation, so this is the only // practical way to exercise the GPU path here. Never on by default. //-// Shaders are GLSL compiled to SPIR-V by the crate's own build.rs, which resolves glslc-// from the NDK and fails the build if it cannot — deliberately unlike-// games/voxels/src/main/rust/build.rs, which writes a 28-byte stub and then draws nothing.+// Shaders are GLSL compiled to SPIR-V by the `compileShaders` task (build-logic+// GlslcCompile), which fails the build if glslc is missing or a shader does not compile. rustNativeLib(     "map_renderer",     "map",@@ -78,4 +77,6 @@ rustNativeLib(     } else {         emptyList()     },+    shaders = listOf("*.vert", "*.frag"),+    glslcArgs = listOf("--target-env=vulkan1.1", "-O"), )
library/map/src/main/rust/build.rs
diff --git a/library/map/src/main/rust/build.rs b/library/map/src/main/rust/build.rsdeleted file mode 100644index 10f78a82f9..0000000000--- a/library/map/src/main/rust/build.rs+++ /dev/null@@ -1,200 +0,0 @@-//! Compiles the GLSL in `shaders/` to SPIR-V with the NDK's `glslc`.-//!-//! # This deliberately does not do what `games/voxels/build.rs` does-//!-//! That build script (`build.rs:94-106`) resolves `glslc` from two hardcoded-//! absolute paths under one developer's home directory, and when it finds neither-//! it calls `minimal_vert_spv()` / `minimal_frag_spv()` — writing a **28-byte stub**-//! consisting of a SPIR-V header and a single `OpCapability`. A build that takes-//! that path succeeds, installs, runs, and draws nothing at all, with no warning-//! anywhere. The failure surfaces as "the screen is black" long after the build.-//!-//! So this script resolves the compiler from the environment for the *host*-//! platform it is running on, and [`panic!`]s if it cannot find it or if a shader-//! fails to compile. A missing shader compiler must stop the build.-//!-//! SPIR-V is `include_bytes!`d rather than shipped as an asset: the shaders are-//! part of the renderer, and an asset can be missing at run time while a linked-//! `&[u8]` cannot.--use std::env;-use std::path::{Path, PathBuf};-use std::process::Command;--fn main() {-    let out_dir = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR"));-    let shader_dir =-        PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR")).join("shaders");--    let glslc = find_glslc();-    println!("cargo:rerun-if-changed=build.rs");-    println!("cargo:rerun-if-changed=shaders");--    let mut compiled = 0;-    let mut entries: Vec<PathBuf> = std::fs::read_dir(&shader_dir)-        .unwrap_or_else(|e| panic!("cannot read {}: {e}", shader_dir.display()))-        .filter_map(|e| e.ok().map(|e| e.path()))-        .filter(|p| {-            matches!(-                p.extension().and_then(|e| e.to_str()),-                Some("vert") | Some("frag") | Some("comp")-            )-        })-        .collect();-    // Sorted so the build is reproducible and a diff of the log is stable.-    entries.sort();--    for shader in &entries {-        let name = shader.file_name().expect("shader file name");-        println!("cargo:rerun-if-changed={}", shader.display());-        let target = out_dir.join(format!("{}.spv", name.to_string_lossy()));--        let output = Command::new(&glslc)-            .arg("--target-env=vulkan1.1")-            .arg("-O")-            .arg("-o")-            .arg(&target)-            .arg(shader)-            .output()-            .unwrap_or_else(|e| panic!("cannot run {}: {e}", glslc.display()));--        if !output.status.success() {-            panic!(-                "glslc failed on {}:\n{}{}",-                shader.display(),-                String::from_utf8_lossy(&output.stdout),-                String::from_utf8_lossy(&output.stderr),-            );-        }-        // A zero-exit that wrote nothing usable is the silent-stub case, caught here-        // rather than at run time on a black screen.-        let written = std::fs::metadata(&target).map(|m| m.len()).unwrap_or(0);-        if written < MIN_SPIRV_BYTES {-            panic!(-                "glslc produced {written} bytes for {}; a real SPIR-V module is at least \-                 {MIN_SPIRV_BYTES} bytes",-                shader.display(),-            );-        }-        compiled += 1;-    }--    if compiled == 0 {-        panic!("no shaders found in {}", shader_dir.display());-    }-}--/// A SPIR-V module is a five-word header plus at least a few instructions.-const MIN_SPIRV_BYTES: u64 = 64;--/// `glslc` for the **host** platform, from the NDK.-///-/// Cargo runs this script on the build machine while cross-compiling for Android,-/// so the host triple is what matters, not the target. Searched in order:-///-/// 1. `GLSLC` — an explicit override, for a CI image that puts it elsewhere.-/// 2. `ANDROID_NDK_HOME` / `ANDROID_NDK_ROOT` — set directly by some CI setups.-/// 3. `ANDROID_HOME` / `ANDROID_SDK_ROOT`, then the highest installed `ndk/*`.-/// 4. `sdk.dir` from the repo's `local.properties`, which is what a dev box has.-/// 5. `glslc` on `PATH`.-fn find_glslc() -> PathBuf {-    if let Some(explicit) = env::var_os("GLSLC").map(PathBuf::from) {-        if explicit.is_file() {-            return explicit;-        }-        panic!("GLSLC is set to {explicit:?} but that is not a file");-    }--    let host = host_dir();-    let executable = if cfg!(windows) { "glslc.exe" } else { "glslc" };--    let mut ndks: Vec<PathBuf> = Vec::new();-    for key in ["ANDROID_NDK_HOME", "ANDROID_NDK_ROOT"] {-        if let Some(dir) = env::var_os(key) {-            ndks.push(PathBuf::from(dir));-        }-    }-    let mut sdks: Vec<PathBuf> = Vec::new();-    for key in ["ANDROID_HOME", "ANDROID_SDK_ROOT"] {-        if let Some(dir) = env::var_os(key) {-            sdks.push(PathBuf::from(dir));-        }-    }-    if let Some(dir) = sdk_dir_from_local_properties() {-        sdks.push(dir);-    }-    for sdk in &sdks {-        // Highest version first, so a box with several NDKs uses the newest.-        let mut installed: Vec<PathBuf> = std::fs::read_dir(sdk.join("ndk"))-            .into_iter()-            .flatten()-            .filter_map(|e| e.ok().map(|e| e.path()))-            .filter(|p| p.is_dir())-            .collect();-        installed.sort();-        installed.reverse();-        ndks.extend(installed);-    }--    for ndk in &ndks {-        let candidate = ndk.join("shader-tools").join(&host).join(executable);-        if candidate.is_file() {-            return candidate;-        }-    }--    if Command::new(executable)-        .arg("--version")-        .output()-        .map(|o| o.status.success())-        .unwrap_or(false)-    {-        return PathBuf::from(executable);-    }--    panic!(-        "glslc not found. Looked for ndk/*/shader-tools/{host}/{executable} under \-         {sdks:?} and {ndks:?}, then on PATH. Install the NDK, or set GLSLC. The map \-         renderer cannot draw without shaders, so this build stops here rather than \-         producing an app with an empty map.",-    );-}--/// The NDK's prebuilt-tool directory name for the host we are running on.-fn host_dir() -> String {-    let os = if cfg!(target_os = "windows") {-        "windows"-    } else if cfg!(target_os = "macos") {-        "darwin"-    } else {-        "linux"-    };-    // The NDK ships x86_64 host tools even on arm64 macOS, where they run under-    // Rosetta, so the host CPU is deliberately not consulted.-    format!("{os}-x86_64")-}--/// `sdk.dir` out of the repo root's `local.properties`.-///-/// Walks up from the crate rather than assuming a depth, so moving the crate does-/// not silently break shader compilation.-fn sdk_dir_from_local_properties() -> Option<PathBuf> {-    let mut dir: &Path = &PathBuf::from(env::var("CARGO_MANIFEST_DIR").ok()?);-    loop {-        let candidate = dir.join("local.properties");-        if candidate.is_file() {-            let text = std::fs::read_to_string(&candidate).ok()?;-            for line in text.lines() {-                let line = line.trim();-                if let Some(value) = line.strip_prefix("sdk.dir=") {-                    // Gradle properties escape the Windows separator.-                    return Some(PathBuf::from(-                        value.replace("\\\\", "\\").replace("\\:", ":"),-                    ));-                }-            }-            return None;-        }-        dir = dir.parent()?;-    }-}
library/map/src/main/rust/src/vulkan/pick/pipeline.rs
diff --git a/library/map/src/main/rust/src/vulkan/pick/pipeline.rs b/library/map/src/main/rust/src/vulkan/pick/pipeline.rsindex 97e847b741..15a74d82eb 100644--- a/library/map/src/main/rust/src/vulkan/pick/pipeline.rs+++ b/library/map/src/main/rust/src/vulkan/pick/pipeline.rs@@ -1,7 +1,7 @@ use ash::vk; -const PICK_VERT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/pick.vert.spv"));-const PICK_FRAG: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/pick.frag.spv"));+const PICK_VERT: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/pick.vert.spv"));+const PICK_FRAG: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/pick.frag.spv"));  /// Build the pick pipeline: position-only unit quad, no blend (an integer attachment cannot /// blend), no depth or stencil, writing the slot id.
library/map/src/main/rust/src/vulkan/pipeline/mod.rs
diff --git a/library/map/src/main/rust/src/vulkan/pipeline/mod.rs b/library/map/src/main/rust/src/vulkan/pipeline/mod.rsindex e6dc3302c6..c4f4b907cf 100644--- a/library/map/src/main/rust/src/vulkan/pipeline/mod.rs+++ b/library/map/src/main/rust/src/vulkan/pipeline/mod.rs@@ -1,4 +1,4 @@-//! The fill and line pipelines, built from the SPIR-V `build.rs` compiled.+//! The fill and line pipelines, built from the SPIR-V the Gradle `compileShaders` task compiled. //! //! # Push constants, and no descriptor sets at all //!
library/map/src/main/rust/src/vulkan/pipeline/shaders.rs
diff --git a/library/map/src/main/rust/src/vulkan/pipeline/shaders.rs b/library/map/src/main/rust/src/vulkan/pipeline/shaders.rsindex 143deb300d..9e5bada30f 100644--- a/library/map/src/main/rust/src/vulkan/pipeline/shaders.rs+++ b/library/map/src/main/rust/src/vulkan/pipeline/shaders.rs@@ -1,55 +1,55 @@ use ash::vk; use std::ffi::CStr; -pub(super) const FILL_VERT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/fill.vert.spv"));-pub(super) const FILL_FRAG: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/fill.frag.spv"));+pub(super) const FILL_VERT: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/fill.vert.spv"));+pub(super) const FILL_FRAG: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/fill.frag.spv")); /// Orthographic-sphere globe variants: bend tile-local geometry onto the ball /// (see the `*_globe.vert` headers). Only built into globe pipelines; the flat /// pipelines above never reference them, so flat output is unchanged. pub(super) const FILL_GLOBE_VERT: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/fill_globe.vert.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/fill_globe.vert.spv")); pub(super) const FILL_GLOBE_FRAG: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/fill_globe.frag.spv"));-pub(super) const LINE_VERT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/line.vert.spv"));-pub(super) const LINE_FRAG: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/line.frag.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/fill_globe.frag.spv"));+pub(super) const LINE_VERT: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/line.vert.spv"));+pub(super) const LINE_FRAG: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/line.frag.spv")); pub(super) const LINE_GLOBE_VERT: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/line_globe.vert.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/line_globe.vert.spv")); pub(super) const LINE_GLOBE_FRAG: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/line_globe.frag.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/line_globe.frag.spv")); pub(super) const RIBBON_VERT: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/road_surface.vert.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/road_surface.vert.spv")); pub(super) const RIBBON_FRAG: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/road_surface.frag.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/road_surface.frag.spv")); pub(super) const RIBBON_GLOBE_VERT: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/road_surface_globe.vert.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/road_surface_globe.vert.spv")); pub(super) const RIBBON_GLOBE_FRAG: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/road_surface_globe.frag.spv"));-pub(super) const SYMBOL_VERT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/symbol.vert.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/road_surface_globe.frag.spv"));+pub(super) const SYMBOL_VERT: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/symbol.vert.spv")); pub(super) const SYMBOL_BILLBOARD_VERT: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/symbol_billboard.vert.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/symbol_billboard.vert.spv")); /// Globe label bending (see `symbol_globe.vert`): the globe symbol/icon path. pub(super) const SYMBOL_GLOBE_VERT: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/symbol_globe.vert.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/symbol_globe.vert.spv")); /// Moon raster pair (see `moon.vert`/`moon.frag`): the maps-only lunar globe.-pub(super) const MOON_VERT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/moon.vert.spv"));-pub(super) const MOON_FRAG: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/moon.frag.spv"));-pub(super) const SYMBOL_FRAG: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/symbol.frag.spv"));-pub(super) const SPRITE_FRAG: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/sprite.frag.spv"));-pub(super) const PUCK_VERT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/puck.vert.spv"));-pub(super) const PUCK_FRAG: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/puck.frag.spv"));+pub(super) const MOON_VERT: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/moon.vert.spv"));+pub(super) const MOON_FRAG: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/moon.frag.spv"));+pub(super) const SYMBOL_FRAG: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/symbol.frag.spv"));+pub(super) const SPRITE_FRAG: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/sprite.frag.spv"));+pub(super) const PUCK_VERT: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/puck.vert.spv"));+pub(super) const PUCK_FRAG: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/puck.frag.spv")); pub(super) const BUILDING_VERT: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/building.vert.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/building.vert.spv")); pub(super) const BUILDING_FRAG: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/building.frag.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/building.frag.spv")); pub(super) const TERRAIN_VERT: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/terrain.vert.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/terrain.vert.spv")); pub(super) const TERRAIN_FRAG: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/terrain.frag.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/terrain.frag.spv")); pub(super) unsafe fn shader_module(     device: &ash::Device,     spirv: &[u8], ) -> Result<vk::ShaderModule, String> {-    // SPIR-V is a stream of 32-bit words. `build.rs` guarantees a real module, so a+    // SPIR-V is a stream of 32-bit words. `compileShaders` guarantees a real module, so a     // misaligned length here would be a build-system bug rather than bad input.     if spirv.len() % 4 != 0 || spirv.len() < 20 {         return Err(format!("{} bytes is not a SPIR-V module", spirv.len()));
library/ml/build.gradle.kts
diff --git a/library/ml/build.gradle.kts b/library/ml/build.gradle.ktsindex 88311e6b04..5b0ce81a94 100644--- a/library/ml/build.gradle.kts+++ b/library/ml/build.gradle.kts@@ -16,8 +16,8 @@ androidComponents { // (CMake was deliberately removed — see maps/build.gradle.kts:29-31), so cargo does the // cross-compile and the NDK is only reached for its clang wrappers and glslc. //-// Shaders are GLSL compute compiled to SPIR-V by the crate's own build.rs, which resolves-// glslc from the NDK and fails the build if it cannot.+// Shaders are GLSL compute compiled to SPIR-V by the `compileShaders` task (build-logic+// GlslcCompile); `*.glsl` are #include-only and not compiled on their own. // `-PemulatorAbi=x86_64` additionally cross-compiles for the emulator's ABI so the gate can be // exercised on an x86_64 host. Off unless asked for, so no default or release build is affected. rustNativeLib(@@ -28,4 +28,6 @@ rustNativeLib(     } else {         emptyList()     },+    shaders = listOf("*.comp"),+    glslcArgs = listOf("--target-env=vulkan1.1", "-O"), )
library/ml/src/main/rust/build.rs
diff --git a/library/ml/src/main/rust/build.rs b/library/ml/src/main/rust/build.rsdeleted file mode 100644index 9c5e9b4458..0000000000--- a/library/ml/src/main/rust/build.rs+++ /dev/null@@ -1,197 +0,0 @@-//! Compiles the GLSL in `shaders/` to SPIR-V with the NDK's `glslc`.-//!-//! Copied from `library/map/src/main/rust/build.rs`, which already globbed `.comp`-//! alongside `.vert`/`.frag` and already targeted `vulkan1.1`. Only the doc comments-//! and the final panic message differ.-//!-//! # This deliberately does not do what `games/voxels/build.rs` does-//!-//! That build script (`build.rs:94-106`) resolves `glslc` from two hardcoded-//! absolute paths under one developer's home directory, and when it finds neither-//! it calls `minimal_vert_spv()` / `minimal_frag_spv()` — writing a **28-byte stub**-//! consisting of a SPIR-V header and a single `OpCapability`. A build that takes-//! that path succeeds, installs, runs, and draws nothing at all, with no warning-//! anywhere. The failure surfaces as "the screen is black" long after the build.-//!-//! So this script resolves the compiler from the environment for the *host*-//! platform it is running on, and [`panic!`]s if it cannot find it or if a shader-//! fails to compile. A missing shader compiler must stop the build.-//!-//! SPIR-V is `include_bytes!`d rather than shipped as an asset: the shaders are-//! part of the runtime, and an asset can be missing at run time while a linked-//! `&[u8]` cannot.--use std::env;-use std::path::{Path, PathBuf};-use std::process::Command;--fn main() {-    let out_dir = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR"));-    let shader_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"))-        .join("shaders");--    let glslc = find_glslc();-    println!("cargo:rerun-if-changed=build.rs");-    println!("cargo:rerun-if-changed=shaders");--    let mut compiled = 0;-    let mut entries: Vec<PathBuf> = std::fs::read_dir(&shader_dir)-        .unwrap_or_else(|e| panic!("cannot read {}: {e}", shader_dir.display()))-        .filter_map(|e| e.ok().map(|e| e.path()))-        .filter(|p| {-            matches!(-                p.extension().and_then(|e| e.to_str()),-                Some("vert") | Some("frag") | Some("comp")-            )-        })-        .collect();-    // Sorted so the build is reproducible and a diff of the log is stable.-    entries.sort();--    for shader in &entries {-        let name = shader.file_name().expect("shader file name");-        println!("cargo:rerun-if-changed={}", shader.display());-        let target = out_dir.join(format!("{}.spv", name.to_string_lossy()));--        let output = Command::new(&glslc)-            .arg("--target-env=vulkan1.1")-            .arg("-O")-            .arg("-o")-            .arg(&target)-            .arg(shader)-            .output()-            .unwrap_or_else(|e| panic!("cannot run {}: {e}", glslc.display()));--        if !output.status.success() {-            panic!(-                "glslc failed on {}:\n{}{}",-                shader.display(),-                String::from_utf8_lossy(&output.stdout),-                String::from_utf8_lossy(&output.stderr),-            );-        }-        // A zero-exit that wrote nothing usable is the silent-stub case, caught here-        // rather than at run time on a black screen.-        let written = std::fs::metadata(&target).map(|m| m.len()).unwrap_or(0);-        if written < MIN_SPIRV_BYTES {-            panic!(-                "glslc produced {written} bytes for {}; a real SPIR-V module is at least \-                 {MIN_SPIRV_BYTES} bytes",-                shader.display(),-            );-        }-        compiled += 1;-    }--    if compiled == 0 {-        panic!("no shaders found in {}", shader_dir.display());-    }-}--/// A SPIR-V module is a five-word header plus at least a few instructions.-const MIN_SPIRV_BYTES: u64 = 64;--/// `glslc` for the **host** platform, from the NDK.-///-/// Cargo runs this script on the build machine while cross-compiling for Android,-/// so the host triple is what matters, not the target. Searched in order:-///-/// 1. `GLSLC` — an explicit override, for a CI image that puts it elsewhere.-/// 2. `ANDROID_NDK_HOME` / `ANDROID_NDK_ROOT` — set directly by some CI setups.-/// 3. `ANDROID_HOME` / `ANDROID_SDK_ROOT`, then the highest installed `ndk/*`.-/// 4. `sdk.dir` from the repo's `local.properties`, which is what a dev box has.-/// 5. `glslc` on `PATH`.-fn find_glslc() -> PathBuf {-    if let Some(explicit) = env::var_os("GLSLC").map(PathBuf::from) {-        if explicit.is_file() {-            return explicit;-        }-        panic!("GLSLC is set to {explicit:?} but that is not a file");-    }--    let host = host_dir();-    let executable = if cfg!(windows) { "glslc.exe" } else { "glslc" };--    let mut ndks: Vec<PathBuf> = Vec::new();-    for key in ["ANDROID_NDK_HOME", "ANDROID_NDK_ROOT"] {-        if let Some(dir) = env::var_os(key) {-            ndks.push(PathBuf::from(dir));-        }-    }-    let mut sdks: Vec<PathBuf> = Vec::new();-    for key in ["ANDROID_HOME", "ANDROID_SDK_ROOT"] {-        if let Some(dir) = env::var_os(key) {-            sdks.push(PathBuf::from(dir));-        }-    }-    if let Some(dir) = sdk_dir_from_local_properties() {-        sdks.push(dir);-    }-    for sdk in &sdks {-        // Highest version first, so a box with several NDKs uses the newest.-        let mut installed: Vec<PathBuf> = std::fs::read_dir(sdk.join("ndk"))-            .into_iter()-            .flatten()-            .filter_map(|e| e.ok().map(|e| e.path()))-            .filter(|p| p.is_dir())-            .collect();-        installed.sort();-        installed.reverse();-        ndks.extend(installed);-    }--    for ndk in &ndks {-        let candidate = ndk.join("shader-tools").join(&host).join(executable);-        if candidate.is_file() {-            return candidate;-        }-    }--    if Command::new(executable).arg("--version").output().map(|o| o.status.success()).unwrap_or(false) {-        return PathBuf::from(executable);-    }--    panic!(-        "glslc not found. Looked for ndk/*/shader-tools/{host}/{executable} under \-         {sdks:?} and {ndks:?}, then on PATH. Install the NDK, or set GLSLC. Every \-         layer of both networks is a compute shader, so this build stops here rather \-         than producing a runtime that reports itself unavailable on every device.",-    );-}--/// The NDK's prebuilt-tool directory name for the host we are running on.-fn host_dir() -> String {-    let os = if cfg!(target_os = "windows") {-        "windows"-    } else if cfg!(target_os = "macos") {-        "darwin"-    } else {-        "linux"-    };-    // The NDK ships x86_64 host tools even on arm64 macOS, where they run under-    // Rosetta, so the host CPU is deliberately not consulted.-    format!("{os}-x86_64")-}--/// `sdk.dir` out of the repo root's `local.properties`.-///-/// Walks up from the crate rather than assuming a depth, so moving the crate does-/// not silently break shader compilation.-fn sdk_dir_from_local_properties() -> Option<PathBuf> {-    let mut dir: &Path = &PathBuf::from(env::var("CARGO_MANIFEST_DIR").ok()?);-    loop {-        let candidate = dir.join("local.properties");-        if candidate.is_file() {-            let text = std::fs::read_to_string(&candidate).ok()?;-            for line in text.lines() {-                let line = line.trim();-                if let Some(value) = line.strip_prefix("sdk.dir=") {-                    // Gradle properties escape the Windows separator.-                    return Some(PathBuf::from(value.replace("\\\\", "\\").replace("\\:", ":")));-                }-            }-            return None;-        }-        dir = dir.parent()?;-    }-}
library/ml/src/main/rust/shaders/common.glsl
diff --git a/library/ml/src/main/rust/shaders/common.glsl b/library/ml/src/main/rust/shaders/common.glslindex 2901859c58..9824ba64e4 100644--- a/library/ml/src/main/rust/shaders/common.glsl+++ b/library/ml/src/main/rust/shaders/common.glsl@@ -1,6 +1,6 @@ // Shared declarations for every compute shader in this runtime. //-// Not a shader itself: `build.rs` compiles only `.vert`/`.frag`/`.comp`, so this is+// Not a shader itself: `compileShaders` compiles only `*.comp` here, so this is // pulled in by `#include` and never compiled alone. glslc resolves the path relative // to the including file. //
library/ml/src/main/rust/shaders/gemv_a_control.comp
diff --git a/library/ml/src/main/rust/shaders/gemv_a_control.comp b/library/ml/src/main/rust/shaders/gemv_a_control.compindex 544abab34b..f0c9ba8659 100644--- a/library/ml/src/main/rust/shaders/gemv_a_control.comp+++ b/library/ml/src/main/rust/shaders/gemv_a_control.comp@@ -2,7 +2,7 @@ //! VARIANT A — CONTROL. Byte-for-byte the body of `shaders/probe_ssbo.comp`. //! //! TEMPORARY probe shader for task 9. Source of truth is-//! `analysis/gemv_probe/gemv_a_control.comp`; this copy exists only because `build.rs`+//! `analysis/gemv_probe/gemv_a_control.comp`; this copy exists only because `compileShaders` //! compiles `shaders/*.comp` and direct `glslc` invocation is unavailable in this //! environment. Not referenced by `pipeline.rs::SPIRV`, so it is compiled but not shipped. //! Delete both this and the other four `gemv_*.comp` when the experiment is done.
library/ml/src/main/rust/src/vulkan/imageprobe.rs
diff --git a/library/ml/src/main/rust/src/vulkan/imageprobe.rs b/library/ml/src/main/rust/src/vulkan/imageprobe.rsindex f74630a622..ddc3e82244 100644--- a/library/ml/src/main/rust/src/vulkan/imageprobe.rs+++ b/library/ml/src/main/rust/src/vulkan/imageprobe.rs@@ -31,8 +31,8 @@ use ash::vk; use crate::vulkan::buffers::Buffer; use crate::vulkan::context::Context; -const SSBO: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/probe_ssbo.comp.spv"));-const TEXEL: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/probe_texel.comp.spv"));+const SSBO: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/probe_ssbo.comp.spv"));+const TEXEL: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/probe_texel.comp.spv"));  /// Bytes to sweep. Comfortably past any cache, and the order of a large weight tensor. const BYTES: u64 = 256 * 1024 * 1024;
library/ml/src/main/rust/src/vulkan/pipeline.rs
diff --git a/library/ml/src/main/rust/src/vulkan/pipeline.rs b/library/ml/src/main/rust/src/vulkan/pipeline.rsindex 79be9f2b17..794dba5192 100644--- a/library/ml/src/main/rust/src/vulkan/pipeline.rs+++ b/library/ml/src/main/rust/src/vulkan/pipeline.rs@@ -14,9 +14,9 @@ //! //! # SPIR-V is linked in, not shipped //!-//! `build.rs` compiles `shaders/*.comp` into `$OUT_DIR` and panics if `glslc` is missing-//! or a shader fails, so these `include_bytes!` cannot silently become stubs the way-//! `games/voxels` does. An asset can be absent at run time; a `&'static [u8]` cannot.+//! The Gradle `compileShaders` task compiles `shaders/*.comp` into `build/spirv` and fails if+//! `glslc` is missing or a shader fails, so these `include_bytes!` cannot silently become stubs.+//! An asset can be absent at run time; a `&'static [u8]` cannot.  use std::sync::Arc; @@ -28,67 +28,67 @@ use super::context::Context; use super::pipeline_extra::{CONV_POINT_Q2K, CONV_Q2K, QUANTIZE, QUANTIZE_BLOCKS}; use super::segment::Segment; -const CONV: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/conv.comp.spv"));+const CONV: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/conv.comp.spv")); const CONV_TRANSPOSE: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/conv_transpose.comp.spv"));-const MAXPOOL: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/maxpool.comp.spv"));-const AVGPOOL: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/avgpool.comp.spv"));-const RESIZE: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/resize.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/conv_transpose.comp.spv"));+const MAXPOOL: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/maxpool.comp.spv"));+const AVGPOOL: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/avgpool.comp.spv"));+const RESIZE: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/resize.comp.spv")); const RESIZE_NEAREST: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/resize_nearest.comp.spv"));-const GAP: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/gap.comp.spv"));-const ADD: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/add.comp.spv"));-const MUL_BCAST: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/mul_bcast.comp.spv"));-const AFFINE: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/affine.comp.spv"));-const LAYERNORM: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/layernorm.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/resize_nearest.comp.spv"));+const GAP: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/gap.comp.spv"));+const ADD: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/add.comp.spv"));+const MUL_BCAST: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/mul_bcast.comp.spv"));+const AFFINE: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/affine.comp.spv"));+const LAYERNORM: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/layernorm.comp.spv")); const INSTANCENORM: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/instancenorm.comp.spv"));-const RMSNORM: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/rmsnorm.comp.spv"));-const ATTN_SCORES: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/attn_scores.comp.spv"));-const SOFTMAX: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/softmax.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/instancenorm.comp.spv"));+const RMSNORM: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/rmsnorm.comp.spv"));+const ATTN_SCORES: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/attn_scores.comp.spv"));+const SOFTMAX: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/softmax.comp.spv")); const SOFTMAX_CAUSAL: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/softmax_causal.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/softmax_causal.comp.spv")); const SOFTMAX_PREFIX: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/softmax_prefix.comp.spv"));-const CACHE_WRITE: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/cache_write.comp.spv"));-const SOFTCAP: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/softcap.comp.spv"));-const ACTIVATE: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/activate.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/softmax_prefix.comp.spv"));+const CACHE_WRITE: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/cache_write.comp.spv"));+const SOFTCAP: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/softcap.comp.spv"));+const ACTIVATE: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/activate.comp.spv")); const GATED_ACTIVATE: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/gated_activate.comp.spv"));-const MUL_SCALAR: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/mul_scalar.comp.spv"));-const CLAMP: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/clamp.comp.spv"));-const ATTN_APPLY: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/attn_apply.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/gated_activate.comp.spv"));+const MUL_SCALAR: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/mul_scalar.comp.spv"));+const CLAMP: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/clamp.comp.spv"));+const ATTN_APPLY: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/attn_apply.comp.spv")); const ATTN_SCORES_RELATIVE: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/attn_scores_relative.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/attn_scores_relative.comp.spv")); const ATTN_APPLY_RELATIVE: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/attn_apply_relative.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/attn_apply_relative.comp.spv")); const ATTN_SCORES_BANDED: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/attn_scores_banded.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/attn_scores_banded.comp.spv")); const ATTN_APPLY_BANDED: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/attn_apply_banded.comp.spv"));-const EMBED: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/embed.comp.spv"));-const MUL: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/mul.comp.spv"));-const CONV_POINT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/conv_point.comp.spv"));-const CONV_INT8: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/conv_int8.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/attn_apply_banded.comp.spv"));+const EMBED: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/embed.comp.spv"));+const MUL: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/mul.comp.spv"));+const CONV_POINT: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/conv_point.comp.spv"));+const CONV_INT8: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/conv_int8.comp.spv")); const CONV_POINT_INT8: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/conv_point_int8.comp.spv"));-const CONSTANT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/constant.comp.spv"));-const ADD_BCAST: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/add_bcast.comp.spv"));-const ROTARY: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/rotary.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/conv_point_int8.comp.spv"));+const CONSTANT: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/constant.comp.spv"));+const ADD_BCAST: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/add_bcast.comp.spv"));+const ROTARY: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/rotary.comp.spv")); const ATTN_SCORES_CACHED: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/attn_scores_cached.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/attn_scores_cached.comp.spv")); const ATTN_APPLY_CACHED: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/attn_apply_cached.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/attn_apply_cached.comp.spv")); const CONV_VEC_INT8: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/conv_vec_int8.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/conv_vec_int8.comp.spv")); const CONV_VEC_INT4: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/conv_vec_int4.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/conv_vec_int4.comp.spv")); const CONV_POINT_INT4: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/conv_point_int4.comp.spv"));-const CONV_VEC_Q2K: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/conv_vec_q2k.comp.spv"));-const ARGMAX: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/argmax.comp.spv"));-const ARGMAX_FOLD: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/argmax_fold.comp.spv"));-const TOPK: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/topk.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/conv_point_int4.comp.spv"));+const CONV_VEC_Q2K: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/conv_vec_q2k.comp.spv"));+const ARGMAX: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/argmax.comp.spv"));+const ARGMAX_FOLD: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/argmax_fold.comp.spv"));+const TOPK: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/topk.comp.spv")); /// Every shader, in the order `Shaders::create` destructures them (the Q2_K pair, /// `QUANTIZE`, and the `compute_pipeline` / `shader_module` helpers live in /// `pipeline_extra.rs` for length).
library/ml/src/main/rust/src/vulkan/pipeline_extra.rs
diff --git a/library/ml/src/main/rust/src/vulkan/pipeline_extra.rs b/library/ml/src/main/rust/src/vulkan/pipeline_extra.rsindex 41b7154c1f..6f3875713d 100644--- a/library/ml/src/main/rust/src/vulkan/pipeline_extra.rs+++ b/library/ml/src/main/rust/src/vulkan/pipeline_extra.rs@@ -9,19 +9,19 @@ use super::pipeline::{Cleanup, Shaders, SPIRV}; // Lives here rather than in `pipeline.rs` so that file stays under the // 500-line Rust limit. pub(crate) const QUANTIZE: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/quantize.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/quantize.comp.spv"));  // The Q2_K pair, beside the table they join (see `SPIRV`). Same reason as // `QUANTIZE` above: `pipeline.rs` must stay under the 500-line Rust limit. pub(crate) const CONV_POINT_Q2K: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/conv_point_q2k.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/conv_point_q2k.comp.spv")); pub(crate) const CONV_Q2K: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/conv_q2k.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/conv_q2k.comp.spv")); pub(crate) const QUANTIZE_BLOCKS: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/quantize_blocks.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/quantize_blocks.comp.spv")); /// Declares `DotProductKHR`, so it is built only on a device that enabled the extension. const CONV_POINT_INT4_DOT: &[u8] =-    include_bytes!(concat!(env!("OUT_DIR"), "/conv_point_int4_dot.comp.spv"));+    include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../build/spirv/conv_point_int4_dot.comp.spv"));  impl Shaders {     /// Compile every shader and build the two layouts. Called once per device.
test
diff --git a/test b/testindex 41af1b61dd..d5c5bab9d4 100644--- a/test+++ b/test@@ -583,6 +583,15 @@ if [[ $RUN_RUST -eq 1 ]]; then   if [[ ! -x "$CARGO_BIN" ]] && ! command -v "$CARGO_BIN" >/dev/null 2>&1; then     echo "Error: cargo not found ($CARGO_BIN)." >&2; exit 1   fi+  # cargo include_bytes!s the SPIR-V that :mod:compileShaders writes to build/spirv.+  SHADER_TASKS=()+  for mod in "${MODS[@]}"; do+    [[ -d "$ROOT/$mod/src/main/rust/shaders" ]] && SHADER_TASKS+=(":$(echo "$mod" | tr '/' ':'):compileShaders")+  done+  if [[ ${#SHADER_TASKS[@]} -gt 0 ]]; then+    echo "Running: $SCRIPT_DIR/gradlew ${SHADER_TASKS[*]}"+    "$SCRIPT_DIR/gradlew" "${SHADER_TASKS[@]}" --console=plain || RUST_RC=$?+  fi   if [[ ${#ROOT_CRATES[@]} -eq 0 && ${#STANDALONE_DIRS[@]} -eq 0 ]]; then     echo "No Rust crates in scope; cargo steps skipped."   elif [[ $NO_COV -eq 1 ]]; then