From 69b84a0f0de4f1d824db61f38e40d3edf8ba80a2 Mon Sep 17 00:00:00 2001 From: Schell Carl Scivally Date: Wed, 31 Jan 2024 23:49:01 +0100 Subject: [PATCH 1/2] feat: allow shader crate cargo features to be passed through spirv-builder --- crates/spirv-builder/src/lib.rs | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/crates/spirv-builder/src/lib.rs b/crates/spirv-builder/src/lib.rs index 572d437956..70902347e4 100644 --- a/crates/spirv-builder/src/lib.rs +++ b/crates/spirv-builder/src/lib.rs @@ -282,11 +282,19 @@ pub enum ShaderPanicStrategy { UNSOUND_DO_NOT_USE_UndefinedBehaviorViaUnreachable, } +/// Cargo features specification for building the shader crate. +#[derive(Default)] +struct ShaderCrateFeatures { + default_features: Option, + features: Vec, +} + pub struct SpirvBuilder { path_to_crate: PathBuf, print_metadata: MetadataPrintout, release: bool, target: String, + shader_crate_features: ShaderCrateFeatures, deny_warnings: bool, multimodule: bool, spirv_metadata: SpirvMetadata, @@ -333,6 +341,7 @@ impl SpirvBuilder { skip_block_layout: false, preserve_bindings: false, + shader_crate_features: ShaderCrateFeatures::default(), } } @@ -459,6 +468,20 @@ impl SpirvBuilder { self } + /// Set --default-features for the target shader crate. + #[must_use] + pub fn shader_crate_default_features(mut self, default_features: bool) -> Self { + self.shader_crate_features.default_features = Some(default_features); + self + } + + /// Set --features for the target shader crate. + #[must_use] + pub fn shader_crate_features(mut self, features: impl IntoIterator) -> Self { + self.shader_crate_features.features = features.into_iter().collect(); + self + } + /// Builds the module. If `print_metadata` is [`MetadataPrintout::Full`], you usually don't have to inspect the path /// in the result, as the environment variable for the path to the module will already be set. pub fn build(mut self) -> Result { @@ -755,6 +778,18 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result { .join(format!("{}.json", builder.target)), ); + if let Some(default_features) = builder.shader_crate_features.default_features { + if !default_features { + cargo.arg("--no-default-features"); + } + } + + if !builder.shader_crate_features.features.is_empty() { + cargo + .arg("--features") + .arg(builder.shader_crate_features.features.join(",")); + } + // NOTE(eddyb) see above how this is computed and why it might be missing. if let Some(target_dir) = target_dir { cargo.arg("--target-dir").arg(target_dir); From 0ae6c4bbde8f94e116a72f81ce1e1137a365067d Mon Sep 17 00:00:00 2001 From: Firestar99 <4696087-firestar99@users.noreply.gitlab.com> Date: Fri, 20 Sep 2024 12:58:55 +0200 Subject: [PATCH 2/2] changelog: add shader crate features PR --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c14ff15722..dba2a620c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Signed for loops like `for _ in 0..4i32 {}` no longer compile. We recommend switching to unsigned for loops and casting back to signed integers in the meanwhile. ### Changed 🛠 +- [PR#13](https://github.com/Rust-GPU/rust-gpu/pull/13) allow cargo features to be passed to the shader crate - [PR#12](https://github.com/rust-gpu/rust-gpu/pull/12) updated toolchain to `nightly-2024-04-24` - [PR#9](https://github.com/Rust-GPU/rust-gpu/pull/9) relaxed `glam` version requirements (`>=0.22, <=0.29`) - [PR#1127](https://github.com/EmbarkStudios/rust-gpu/pull/1127) updated `spirv-tools` to `0.10.0`, which follows `vulkan-sdk-1.3.275`