@@ -282,11 +282,19 @@ pub enum ShaderPanicStrategy {
282
282
UNSOUND_DO_NOT_USE_UndefinedBehaviorViaUnreachable ,
283
283
}
284
284
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
+
285
292
pub struct SpirvBuilder {
286
293
path_to_crate : PathBuf ,
287
294
print_metadata : MetadataPrintout ,
288
295
release : bool ,
289
296
target : String ,
297
+ shader_crate_features : ShaderCrateFeatures ,
290
298
deny_warnings : bool ,
291
299
multimodule : bool ,
292
300
spirv_metadata : SpirvMetadata ,
@@ -333,6 +341,7 @@ impl SpirvBuilder {
333
341
skip_block_layout : false ,
334
342
335
343
preserve_bindings : false ,
344
+ shader_crate_features : ShaderCrateFeatures :: default ( ) ,
336
345
}
337
346
}
338
347
@@ -459,6 +468,20 @@ impl SpirvBuilder {
459
468
self
460
469
}
461
470
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
+
462
485
/// Builds the module. If `print_metadata` is [`MetadataPrintout::Full`], you usually don't have to inspect the path
463
486
/// in the result, as the environment variable for the path to the module will already be set.
464
487
pub fn build ( mut self ) -> Result < CompileResult , SpirvBuilderError > {
@@ -755,6 +778,18 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result<PathBuf, SpirvBuilderError> {
755
778
. join ( format ! ( "{}.json" , builder. target) ) ,
756
779
) ;
757
780
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
+
758
793
// NOTE(eddyb) see above how this is computed and why it might be missing.
759
794
if let Some ( target_dir) = target_dir {
760
795
cargo. arg ( "--target-dir" ) . arg ( target_dir) ;
0 commit comments