@@ -90,7 +90,9 @@ use std::path::{Path, PathBuf};
90
90
use std:: process:: { Command , Stdio } ;
91
91
use thiserror:: Error ;
92
92
93
- pub use rustc_codegen_spirv_target_specs:: { SpirvTargetEnv , SpirvTargetParseError } ;
93
+ pub use rustc_codegen_spirv_target_specs:: {
94
+ IntoSpirvTarget , SpirvTargetEnv , SpirvTargetParseError ,
95
+ } ;
94
96
pub use rustc_codegen_spirv_types:: * ;
95
97
96
98
#[ cfg( feature = "include-target-specs" ) ]
@@ -99,10 +101,8 @@ pub use rustc_codegen_spirv_target_specs::TARGET_SPEC_DIR_PATH;
99
101
#[ derive( Debug , Error ) ]
100
102
#[ non_exhaustive]
101
103
pub 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`" ) ]
103
105
MissingTarget ,
104
- #[ error( "Error parsing target: {0}" ) ]
105
- SpirvTargetParseError ( #[ from] SpirvTargetParseError ) ,
106
106
#[ error( "`path_to_crate` must be set" ) ]
107
107
MissingCratePath ,
108
108
#[ error( "crate path '{0}' does not exist" ) ]
@@ -380,9 +380,13 @@ pub struct SpirvBuilder {
380
380
/// The target triple, eg. `spirv-unknown-vulkan1.2`
381
381
#[ cfg_attr(
382
382
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
+ )
384
388
) ]
385
- pub target : Option < String > ,
389
+ pub target : Option < SpirvTargetEnv > ,
386
390
/// Cargo features specification for building the shader crate.
387
391
#[ cfg_attr( feature = "clap" , clap( flatten) ) ]
388
392
#[ serde( flatten) ]
@@ -488,10 +492,10 @@ impl Default for SpirvBuilder {
488
492
}
489
493
490
494
impl 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 {
492
496
Self {
493
497
path_to_crate : Some ( path_to_crate. as_ref ( ) . to_owned ( ) ) ,
494
- target : Some ( target. into ( ) ) ,
498
+ target : target. to_spirv_target_env ( ) . ok ( ) ,
495
499
..SpirvBuilder :: default ( )
496
500
}
497
501
}
@@ -758,11 +762,7 @@ fn join_checking_for_separators(strings: Vec<impl Borrow<str>>, sep: &str) -> St
758
762
759
763
// Returns path to the metadata json.
760
764
fn 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 ) ?;
766
766
let path_to_crate = builder
767
767
. path_to_crate
768
768
. as_ref ( )
0 commit comments