@@ -89,7 +89,9 @@ use std::path::{Path, PathBuf};
8989use std:: process:: { Command , Stdio } ;
9090use thiserror:: Error ;
9191
92- pub use rustc_codegen_spirv_target_specs:: { SpirvTargetEnv , SpirvTargetParseError } ;
92+ pub use rustc_codegen_spirv_target_specs:: {
93+ IntoSpirvTarget , SpirvTargetEnv , SpirvTargetParseError ,
94+ } ;
9395pub use rustc_codegen_spirv_types:: * ;
9496
9597#[ cfg( feature = "include-target-specs" ) ]
@@ -98,10 +100,8 @@ pub use rustc_codegen_spirv_target_specs::TARGET_SPEC_DIR_PATH;
98100#[ derive( Debug , Error ) ]
99101#[ non_exhaustive]
100102pub enum SpirvBuilderError {
101- #[ error( "`target` must be set, for example `spirv-unknown-vulkan1.2`" ) ]
103+ #[ error( "`target` must be set or was invalid , for example `spirv-unknown-vulkan1.2`" ) ]
102104 MissingTarget ,
103- #[ error( "Error parsing target: {0}" ) ]
104- SpirvTargetParseError ( #[ from] SpirvTargetParseError ) ,
105105 #[ error( "`path_to_crate` must be set" ) ]
106106 MissingCratePath ,
107107 #[ error( "crate path '{0}' does not exist" ) ]
@@ -379,9 +379,13 @@ pub struct SpirvBuilder {
379379 /// The target triple, eg. `spirv-unknown-vulkan1.2`
380380 #[ cfg_attr(
381381 feature = "clap" ,
382- clap( long, default_value = "spirv-unknown-vulkan1.2" )
382+ clap(
383+ long,
384+ default_value = "spirv-unknown-vulkan1.2" ,
385+ value_parser = SpirvTargetEnv :: parse_triple
386+ )
383387 ) ]
384- pub target : Option < String > ,
388+ pub target : Option < SpirvTargetEnv > ,
385389 /// Cargo features specification for building the shader crate.
386390 #[ cfg_attr( feature = "clap" , clap( flatten) ) ]
387391 #[ serde( flatten) ]
@@ -487,10 +491,10 @@ impl Default for SpirvBuilder {
487491}
488492
489493impl SpirvBuilder {
490- pub fn new ( path_to_crate : impl AsRef < Path > , target : impl Into < String > ) -> Self {
494+ pub fn new ( path_to_crate : impl AsRef < Path > , target : impl IntoSpirvTarget ) -> Self {
491495 Self {
492496 path_to_crate : Some ( path_to_crate. as_ref ( ) . to_owned ( ) ) ,
493- target : Some ( target. into ( ) ) ,
497+ target : target. to_spirv_target_env ( ) . ok ( ) ,
494498 ..SpirvBuilder :: default ( )
495499 }
496500 }
@@ -757,11 +761,7 @@ fn join_checking_for_separators(strings: Vec<impl Borrow<str>>, sep: &str) -> St
757761
758762// Returns path to the metadata json.
759763fn invoke_rustc ( builder : & SpirvBuilder ) -> Result < PathBuf , SpirvBuilderError > {
760- let target = builder
761- . target
762- . as_ref ( )
763- . ok_or ( SpirvBuilderError :: MissingTarget ) ?;
764- let target = SpirvTargetEnv :: parse_triple ( target) ?;
764+ let target = builder. target . ok_or ( SpirvBuilderError :: MissingTarget ) ?;
765765 let path_to_crate = builder
766766 . path_to_crate
767767 . as_ref ( )
0 commit comments