@@ -282,11 +282,19 @@ pub enum ShaderPanicStrategy {
282282 UNSOUND_DO_NOT_USE_UndefinedBehaviorViaUnreachable ,
283283}
284284
285+ /// Cargo features specification for building the shader crate.
286+ #[ derive( Default ) ]
287+ struct ShaderCrateFeatures {
288+ default_features : Option < bool > ,
289+ features : Vec < String > ,
290+ }
291+
285292pub struct SpirvBuilder {
286293 path_to_crate : PathBuf ,
287294 print_metadata : MetadataPrintout ,
288295 release : bool ,
289296 target : String ,
297+ shader_crate_features : ShaderCrateFeatures ,
290298 deny_warnings : bool ,
291299 multimodule : bool ,
292300 spirv_metadata : SpirvMetadata ,
@@ -333,6 +341,7 @@ impl SpirvBuilder {
333341 skip_block_layout : false ,
334342
335343 preserve_bindings : false ,
344+ shader_crate_features : ShaderCrateFeatures :: default ( ) ,
336345 }
337346 }
338347
@@ -459,6 +468,20 @@ impl SpirvBuilder {
459468 self
460469 }
461470
471+ /// Set --default-features for the target shader crate.
472+ #[ must_use]
473+ pub fn shader_crate_default_features ( mut self , default_features : bool ) -> Self {
474+ self . shader_crate_features . default_features = Some ( default_features) ;
475+ self
476+ }
477+
478+ /// Set --features for the target shader crate.
479+ #[ must_use]
480+ pub fn shader_crate_features ( mut self , features : impl IntoIterator < Item = String > ) -> Self {
481+ self . shader_crate_features . features = features. into_iter ( ) . collect ( ) ;
482+ self
483+ }
484+
462485 /// Builds the module. If `print_metadata` is [`MetadataPrintout::Full`], you usually don't have to inspect the path
463486 /// in the result, as the environment variable for the path to the module will already be set.
464487 pub fn build ( mut self ) -> Result < CompileResult , SpirvBuilderError > {
@@ -755,6 +778,18 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result<PathBuf, SpirvBuilderError> {
755778 . join ( format ! ( "{}.json" , builder. target) ) ,
756779 ) ;
757780
781+ if let Some ( default_features) = builder. shader_crate_features . default_features {
782+ if !default_features {
783+ cargo. arg ( "--no-default-features" ) ;
784+ }
785+ }
786+
787+ if !builder. shader_crate_features . features . is_empty ( ) {
788+ cargo
789+ . arg ( "--features" )
790+ . arg ( builder. shader_crate_features . features . join ( "," ) ) ;
791+ }
792+
758793 // NOTE(eddyb) see above how this is computed and why it might be missing.
759794 if let Some ( target_dir) = target_dir {
760795 cargo. arg ( "--target-dir" ) . arg ( target_dir) ;
0 commit comments