@@ -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" ) ]
@@ -406,9 +406,13 @@ pub struct SpirvBuilder {
406406 /// The target triple, eg. `spirv-unknown-vulkan1.2`
407407 #[ cfg_attr(
408408 feature = "clap" ,
409- clap( long, default_value = "spirv-unknown-vulkan1.2" )
409+ clap(
410+ long,
411+ default_value = "spirv-unknown-vulkan1.2" ,
412+ value_parser = SpirvTargetEnv :: parse_triple
413+ )
410414 ) ]
411- pub target : Option < String > ,
415+ pub target : Option < SpirvTargetEnv > ,
412416 /// Cargo features specification for building the shader crate.
413417 #[ cfg_attr( feature = "clap" , clap( flatten) ) ]
414418 #[ serde( flatten) ]
@@ -514,10 +518,10 @@ impl Default for SpirvBuilder {
514518}
515519
516520impl SpirvBuilder {
517- pub fn new ( path_to_crate : impl AsRef < Path > , target : impl Into < String > ) -> Self {
521+ pub fn new ( path_to_crate : impl AsRef < Path > , target : impl IntoSpirvTarget ) -> Self {
518522 Self {
519523 path_to_crate : Some ( path_to_crate. as_ref ( ) . to_owned ( ) ) ,
520- target : Some ( target. into ( ) ) ,
524+ target : target. to_spirv_target_env ( ) . ok ( ) ,
521525 ..SpirvBuilder :: default ( )
522526 }
523527 }
@@ -784,11 +788,7 @@ fn join_checking_for_separators(strings: Vec<impl Borrow<str>>, sep: &str) -> St
784788
785789// Returns path to the metadata json.
786790fn invoke_rustc ( builder : & SpirvBuilder ) -> Result < PathBuf , SpirvBuilderError > {
787- let target = builder
788- . target
789- . as_ref ( )
790- . ok_or ( SpirvBuilderError :: MissingTarget ) ?;
791- let target = SpirvTargetEnv :: parse_triple ( target) ?;
791+ let target = builder. target . ok_or ( SpirvBuilderError :: MissingTarget ) ?;
792792 let path_to_crate = builder
793793 . path_to_crate
794794 . as_ref ( )
0 commit comments