@@ -90,7 +90,9 @@ use std::path::{Path, PathBuf};
9090use std:: process:: { Command , Stdio } ;
9191use thiserror:: Error ;
9292
93- pub use rustc_codegen_spirv_target_specs:: { SpirvTargetEnv , SpirvTargetParseError } ;
93+ pub use rustc_codegen_spirv_target_specs:: {
94+ IntoSpirvTarget , SpirvTargetEnv , SpirvTargetParseError ,
95+ } ;
9496pub use rustc_codegen_spirv_types:: * ;
9597
9698#[ cfg( feature = "include-target-specs" ) ]
@@ -99,10 +101,8 @@ pub use rustc_codegen_spirv_target_specs::TARGET_SPEC_DIR_PATH;
99101#[ derive( Debug , Error ) ]
100102#[ non_exhaustive]
101103pub enum SpirvBuilderError {
102- #[ error( "`target` must be set, for example `spirv-unknown-vulkan1.2`" ) ]
104+ #[ error( "`target` must be set or was invalid , for example `spirv-unknown-vulkan1.2`" ) ]
103105 MissingTarget ,
104- #[ error( "Error parsing target: {0}" ) ]
105- SpirvTargetParseError ( #[ from] SpirvTargetParseError ) ,
106106 #[ error( "`path_to_crate` must be set" ) ]
107107 MissingCratePath ,
108108 #[ error( "crate path '{0}' does not exist" ) ]
@@ -380,9 +380,13 @@ pub struct SpirvBuilder {
380380 /// The target triple, eg. `spirv-unknown-vulkan1.2`
381381 #[ cfg_attr(
382382 feature = "clap" ,
383- clap( long, default_value = "spirv-unknown-vulkan1.2" )
383+ clap(
384+ long,
385+ default_value = "spirv-unknown-vulkan1.2" ,
386+ value_parser = SpirvTargetEnv :: parse_triple
387+ )
384388 ) ]
385- pub target : Option < String > ,
389+ pub target : Option < SpirvTargetEnv > ,
386390 /// Cargo features specification for building the shader crate.
387391 #[ cfg_attr( feature = "clap" , clap( flatten) ) ]
388392 #[ serde( flatten) ]
@@ -488,10 +492,10 @@ impl Default for SpirvBuilder {
488492}
489493
490494impl SpirvBuilder {
491- pub fn new ( path_to_crate : impl AsRef < Path > , target : impl Into < String > ) -> Self {
495+ pub fn new ( path_to_crate : impl AsRef < Path > , target : impl IntoSpirvTarget ) -> Self {
492496 Self {
493497 path_to_crate : Some ( path_to_crate. as_ref ( ) . to_owned ( ) ) ,
494- target : Some ( target. into ( ) ) ,
498+ target : target. to_spirv_target_env ( ) . ok ( ) ,
495499 ..SpirvBuilder :: default ( )
496500 }
497501 }
@@ -758,11 +762,7 @@ fn join_checking_for_separators(strings: Vec<impl Borrow<str>>, sep: &str) -> St
758762
759763// Returns path to the metadata json.
760764fn invoke_rustc ( builder : & SpirvBuilder ) -> Result < PathBuf , SpirvBuilderError > {
761- let target = builder
762- . target
763- . as_ref ( )
764- . ok_or ( SpirvBuilderError :: MissingTarget ) ?;
765- let target = SpirvTargetEnv :: parse_triple ( target) ?;
765+ let target = builder. target . ok_or ( SpirvBuilderError :: MissingTarget ) ?;
766766 let path_to_crate = builder
767767 . path_to_crate
768768 . as_ref ( )
0 commit comments