@@ -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" ) ]
@@ -406,9 +406,13 @@ pub struct SpirvBuilder {
406
406
/// The target triple, eg. `spirv-unknown-vulkan1.2`
407
407
#[ cfg_attr(
408
408
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
+ )
410
414
) ]
411
- pub target : Option < String > ,
415
+ pub target : Option < SpirvTargetEnv > ,
412
416
/// Cargo features specification for building the shader crate.
413
417
#[ cfg_attr( feature = "clap" , clap( flatten) ) ]
414
418
#[ serde( flatten) ]
@@ -514,10 +518,10 @@ impl Default for SpirvBuilder {
514
518
}
515
519
516
520
impl 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 {
518
522
Self {
519
523
path_to_crate : Some ( path_to_crate. as_ref ( ) . to_owned ( ) ) ,
520
- target : Some ( target. into ( ) ) ,
524
+ target : target. to_spirv_target_env ( ) . ok ( ) ,
521
525
..SpirvBuilder :: default ( )
522
526
}
523
527
}
@@ -784,11 +788,7 @@ fn join_checking_for_separators(strings: Vec<impl Borrow<str>>, sep: &str) -> St
784
788
785
789
// Returns path to the metadata json.
786
790
fn 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 ) ?;
792
792
let path_to_crate = builder
793
793
. path_to_crate
794
794
. as_ref ( )
0 commit comments