Add a shader compilation step to GPUI's build process (#23862)

Mikayla Maki created

This PR prevents situations like
https://github.com/zed-industries/zed/pull/23850, which caused our linux
nightly build to fail to open at all.

This PR also sorts the GPUI build and dev dependencies out from the sea
of platform specific dependencies.

Release Notes:

- N/A

Change summary

Cargo.lock             |  3 ++-
Cargo.toml             |  1 +
crates/gpui/Cargo.toml | 41 ++++++++++++++++++++++++-----------------
crates/gpui/build.rs   | 26 ++++++++++++++++++++++++++
4 files changed, 53 insertions(+), 18 deletions(-)

Detailed changes

Cargo.lock 🔗

@@ -5435,6 +5435,7 @@ dependencies = [
  "lyon",
  "media",
  "metal",
+ "naga",
  "num_cpus",
  "objc",
  "objc2",
@@ -7091,7 +7092,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
 dependencies = [
  "cfg-if",
- "windows-targets 0.48.5",
+ "windows-targets 0.52.6",
 ]
 
 [[package]]

Cargo.toml 🔗

@@ -380,6 +380,7 @@ bitflags = "2.6.0"
 blade-graphics = { git = "https://github.com/kvark/blade", rev = "b16f5c7bd873c7126f48c82c39e7ae64602ae74f" }
 blade-macros = { git = "https://github.com/kvark/blade", rev = "b16f5c7bd873c7126f48c82c39e7ae64602ae74f" }
 blade-util = { git = "https://github.com/kvark/blade", rev = "b16f5c7bd873c7126f48c82c39e7ae64602ae74f" }
+naga = { version = "23.1.0", features = ["wgsl-in"] }
 blake3 = "1.5.3"
 bytes = "1.0"
 cargo_metadata = "0.19"

crates/gpui/Cargo.toml 🔗

@@ -110,23 +110,6 @@ uuid.workspace = true
 waker-fn = "1.2.0"
 lyon = "1.0"
 
-[dev-dependencies]
-backtrace = "0.3"
-collections = { workspace = true, features = ["test-support"] }
-env_logger.workspace = true
-rand.workspace = true
-util = { workspace = true, features = ["test-support"] }
-http_client = { workspace = true, features = ["test-support"] }
-unicode-segmentation.workspace = true
-lyon = { version = "1.0", features = ["extra"] }
-
-[target.'cfg(target_os = "windows")'.build-dependencies]
-embed-resource = "3.0"
-
-[target.'cfg(target_os = "macos")'.build-dependencies]
-bindgen = "0.70.0"
-cbindgen = { version = "0.28.0", default-features = false }
-
 [target.'cfg(target_os = "macos")'.dependencies]
 block = "0.1"
 cocoa.workspace = true
@@ -214,6 +197,30 @@ flume = "0.11"
 rand.workspace = true
 windows.workspace = true
 windows-core = "0.58"
+
+[dev-dependencies]
+backtrace = "0.3"
+collections = { workspace = true, features = ["test-support"] }
+env_logger.workspace = true
+rand.workspace = true
+util = { workspace = true, features = ["test-support"] }
+http_client = { workspace = true, features = ["test-support"] }
+unicode-segmentation.workspace = true
+lyon = { version = "1.0", features = ["extra"] }
+
+[target.'cfg(target_os = "windows")'.build-dependencies]
+embed-resource = "3.0"
+naga.workspace = true
+
+[target.'cfg(target_os = "macos")'.build-dependencies]
+bindgen = "0.70.0"
+cbindgen = { version = "0.28.0", default-features = false }
+naga.workspace = true
+
+[target.'cfg(any(target_os = "linux", target_os = "freebsd"))'.build-dependencies]
+naga.workspace = true
+
+
 [[example]]
 name = "hello_world"
 path = "examples/hello_world.rs"

crates/gpui/build.rs 🔗

@@ -8,6 +8,10 @@ use std::env;
 fn main() {
     let target = env::var("CARGO_CFG_TARGET_OS");
     println!("cargo::rustc-check-cfg=cfg(gles)");
+
+    #[cfg(any(not(target_os = "macos"), feature = "macos-blade"))]
+    check_wgsl_shaders();
+
     match target.as_deref() {
         Ok("macos") => {
             #[cfg(target_os = "macos")]
@@ -27,6 +31,28 @@ fn main() {
     };
 }
 
+#[allow(dead_code)]
+fn check_wgsl_shaders() {
+    use std::path::PathBuf;
+    use std::process;
+    use std::str::FromStr;
+
+    let shader_source_path = "./src/platform/blade/shaders.wgsl";
+    let shader_path = PathBuf::from_str(shader_source_path).unwrap();
+    println!("cargo:rerun-if-changed={}", &shader_path.display());
+
+    let shader_source = std::fs::read_to_string(&shader_path).unwrap();
+
+    match naga::front::wgsl::parse_str(&shader_source) {
+        Ok(_) => {
+            // All clear
+        }
+        Err(e) => {
+            eprintln!("WGSL shader compilation failed:\n{}", e);
+            process::exit(1);
+        }
+    }
+}
 #[cfg(target_os = "macos")]
 mod macos {
     use std::{