diff --git a/Cargo.toml b/Cargo.toml index 80025aa..7143eb3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,5 @@ [workspace] -members = [ - "crates/minislang", - "crates/slang-hal", - "crates/slang-hal-derive", -] +members = ["crates/minislang", "crates/slang-hal", "crates/slang-hal-derive"] resolver = "2" [workspace.dependencies] @@ -13,9 +9,8 @@ anyhow = "1" async-channel = "2" thiserror = "2" futures = "0.3" - -shader-slang = "0.1" -shader-slang-sys = "0.1" +shader-slang = { git = "https://github.com/Vrixyz/slang-rs.git", branch = "static-build", default-features = false } +shader-slang-sys = { git = "https://github.com/Vrixyz/slang-rs.git", branch = "static-build", default-features = false } # TODO: make the wgpu dependency optional too (all backends should be optional but with # wgpu enabled by default). @@ -24,7 +19,7 @@ encase = "0.12" [workspace.lints] rust.unexpected_cfgs = { level = "warn", check-cfg = [ - 'cfg(feature, values("dim2", "dim3"))' + 'cfg(feature, values("dim2", "dim3"))', ] } [profile.release] @@ -32,4 +27,5 @@ opt-level = 'z' [patch.crates-io] #encase = { path = "../encase" } -#shader-slang = { path = "../slang-rs" } \ No newline at end of file +#shader-slang = { path = "../slang-rs" } +shader-slang = { git = "https://github.com/Vrixyz/slang-rs.git", branch = "static-build" } diff --git a/README.md b/README.md index 7c4e2fa..b944b04 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ In order to compile and run any slang project, be sure to define the `SLANG_DIR` 2. Unzip the downloaded directory, and use its path as value to the `SLANG_DIR` environment variable: `SLANG_DIR=/path/to/slang`. Note that the variable must point to the root of the slang installation (i.e. the directory that contains `bin` and `lib`). We recommend adding that as a system-wide environment variables so that it also becomes available to your IDE. +3. Linking statically requires you to compile with `--no-default features --features slang-static`, and an additional environment variable, check out https://github.com/FloatyMonkey/slang-rs/pull/25 for more info. ### Supported backends diff --git a/crates/minislang/Cargo.toml b/crates/minislang/Cargo.toml index 937c93f..2d9ffbb 100644 --- a/crates/minislang/Cargo.toml +++ b/crates/minislang/Cargo.toml @@ -7,6 +7,11 @@ version = "0.1.0" edition = "2024" license = "MIT OR Apache-2.0" +[features] +default = ["slang-static"] +slang-static = ["shader-slang/static"] +slang-dynamic = ["shader-slang/dynamic"] + [dependencies] shader-slang = { workspace = true } shader-slang-sys = { workspace = true } diff --git a/crates/minislang/src/lib.rs b/crates/minislang/src/lib.rs index aba90b7..014ebd3 100644 --- a/crates/minislang/src/lib.rs +++ b/crates/minislang/src/lib.rs @@ -97,9 +97,7 @@ impl SlangCompiler { let entry_points: Vec<_> = module .entry_points() - .filter(|e| { - entry_point.is_none() || Some(e.function_reflection().name()) == entry_point - }) + .filter(|e| entry_point.is_none() || e.function_reflection().name() == entry_point) .map(|e| e.downcast().clone()) .collect(); let program = session diff --git a/crates/slang-hal/Cargo.toml b/crates/slang-hal/Cargo.toml index 4b5d100..79a3bf5 100644 --- a/crates/slang-hal/Cargo.toml +++ b/crates/slang-hal/Cargo.toml @@ -8,9 +8,12 @@ edition = "2024" license = "MIT OR Apache-2.0" [features] +default = ["slang-dynamic"] derive = ["slang-hal-derive"] cuda = ["cudarc"] -cublas = [ "cudarc?/cublas"] +cublas = ["cudarc?/cublas"] +slang-static = ["minislang/slang-static"] +slang-dynamic = ["minislang/slang-dynamic"] [dependencies] nalgebra = { workspace = true } @@ -25,17 +28,21 @@ futures = { workspace = true } async-trait = "0.1" include_dir = "0.7" -minislang = { version = "0.1", path = "../minislang" } +minislang = { version = "0.1", path = "../minislang", default-features = false } slang-hal-derive = { version = "0.1", path = "../slang-hal-derive", optional = true } dashmap = "5" regex = "1" - # For test_shader_compilation paste = "1" # CUDA runtime -cudarc = { version = "0.16", default-features = false, features = ["std", "driver", "dynamic-loading", "cuda-version-from-build-system"], optional = true } +cudarc = { version = "0.16", default-features = false, features = [ + "std", + "driver", + "dynamic-loading", + "cuda-version-from-build-system", +], optional = true } log = "0.4.27" [dev-dependencies] @@ -44,7 +51,7 @@ futures-test = "0.3" serial_test = "3" approx = "0.5" async-std = { version = "1", features = ["attributes"] } -slang-hal = { path = ".", features = ["derive"] } +slang-hal = { path = ".", features = ["derive"], default-features = false } [build-dependencies] -dircpy = "0.3" \ No newline at end of file +dircpy = "0.3" diff --git a/crates/slang-hal/build.rs b/crates/slang-hal/build.rs index 44325da..4f8ec6b 100644 --- a/crates/slang-hal/build.rs +++ b/crates/slang-hal/build.rs @@ -1,8 +1,11 @@ use std::env; use std::path::Path; -// Automatically copy the dynamic libraries from the slang dir to the target dir. +// When not linking statically: automatically copy the dynamic libraries from the slang dir to the target dir. fn main() { + if cfg!(feature = "slang-static") { + return; + } println!("cargo:rerun-if-env-changed=SLANG_LIB_DIR"); let lib_dir = if let Ok(dir) = env::var("SLANG_LIB_DIR") { diff --git a/crates/slang-hal/src/function.rs b/crates/slang-hal/src/function.rs index a125474..38f6923 100644 --- a/crates/slang-hal/src/function.rs +++ b/crates/slang-hal/src/function.rs @@ -53,7 +53,7 @@ impl GpuFunction { buffers.push(( param_var .name() - // .expect("unnamed parameters not supported yet") + .expect("unnamed parameters not supported yet") .to_string(), binding, ));