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