Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/khal-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ cuda = []
unsafe_remove_boundchecks = []

[dependencies]
glamx = { version = "0.2", default-features = false, features = ["nostd-libm", "bytemuck"] }
glamx = { version = "0.3", default-features = false, features = ["nostd-libm", "bytemuck", "u32", "i32", "f64"] }
rayon = { version = "1", optional = true }
corosensei = { version = "0.3", optional = true }
spirv-std-macros = "0.10.0-alpha.1"
Expand Down
40 changes: 40 additions & 0 deletions crates/khal-std/src/build_script.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//! Build-script helpers for shader crates.
//!
//! Host-only module (gated out of GPU-target builds). Intended to be called
//! from a shader crate's `build.rs` — see [`setup_shader_crate_build`].

/// Standard `build.rs` setup that every shader crate should run.
///
/// Does three things:
///
/// 1. Emits `cargo::metadata=manifest_dir=<path>` so that host crates
/// consuming this shader crate via `KhalBuilder::from_dependency`
/// discover the shader sources both in-workspace and from
/// `crates.io`-fetched copies.
/// 2. Declares the `target_arch_is_gpu` cfg via `cargo::rustc-check-cfg`
/// so `#[cfg(target_arch_is_gpu)]` / `#[cfg(not(target_arch_is_gpu))]`
/// don't trip the `unexpected_cfgs` lint.
/// 3. Sets `target_arch_is_gpu` when compiling for any GPU target
/// (SPIR-V, NVPTX). The host CPU build sees it unset.
///
/// Call from `build.rs`:
///
/// ```no_run
/// khal_std::build_script::setup_shader_crate_build();
/// ```
///
/// The shader crate must list `khal-std` as a `[build-dependencies]` entry
/// (in addition to its regular `[dependencies]` use).
pub fn setup_shader_crate_build() {
let manifest_dir =
std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set by cargo");
println!("cargo::metadata=manifest_dir={manifest_dir}");
println!("cargo:rerun-if-changed=build.rs");

println!("cargo::rustc-check-cfg=cfg(target_arch_is_gpu)");

let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
if matches!(target_arch.as_str(), "spirv" | "nvptx64") {
println!("cargo::rustc-cfg=target_arch_is_gpu");
}
}
6 changes: 6 additions & 0 deletions crates/khal-std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ pub mod num_traits;
/// Synchronization primitives (barriers, atomics).
pub mod sync;

/// Build-script helpers for shader crates. Host-only.
#[cfg(not(any(target_arch = "spirv", target_arch = "nvptx64")))]
pub mod build_script;
#[cfg(not(any(target_arch = "spirv", target_arch = "nvptx64")))]
pub use build_script::*;

/// Re-export of the `glamx` math library.
pub use glamx;

Expand Down
7 changes: 6 additions & 1 deletion crates/khal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ derive = ["khal-derive"]
webgpu = ["khal-derive?/webgpu"]
cpu = ["khal-derive?/cpu"]
cuda = ["dep:cudarc", "khal-derive?/cuda"]
metal = ["dep:metal", "dep:naga", "khal-derive?/webgpu"]
push_constants = []
subgroup_ops = []

Expand All @@ -34,4 +35,8 @@ regex = "1"
bitflags = "2"

# For test_shader_compilation
paste = "1"
paste = "1"

[target.'cfg(target_os = "macos")'.dependencies]
metal = { version = "0.32", optional = true }
naga = { version = "29", optional = true, features = ["spv-in", "msl-out"] }
Loading
Loading