@@ -92,6 +92,7 @@ use thiserror::Error;
92
92
pub use rustc_codegen_spirv_target_specs:: {
93
93
IntoSpirvTarget , SpirvTargetEnv , SpirvTargetParseError ,
94
94
} ;
95
+ pub use rustc_codegen_spirv_target_specs:: { deserialize_target, serialize_target} ;
95
96
pub use rustc_codegen_spirv_types:: * ;
96
97
97
98
#[ cfg( feature = "include-target-specs" ) ]
@@ -100,8 +101,10 @@ pub use rustc_codegen_spirv_target_specs::TARGET_SPEC_DIR_PATH;
100
101
#[ derive( Debug , Error ) ]
101
102
#[ non_exhaustive]
102
103
pub enum SpirvBuilderError {
103
- #[ error( "`target` must be set or was invalid , for example `spirv-unknown-vulkan1.2`" ) ]
104
+ #[ error( "`target` must be set, for example `spirv-unknown-vulkan1.2`" ) ]
104
105
MissingTarget ,
106
+ #[ error( "Error parsing target: {0}" ) ]
107
+ SpirvTargetParseError ( #[ from] SpirvTargetParseError ) ,
105
108
#[ error( "`path_to_crate` must be set" ) ]
106
109
MissingCratePath ,
107
110
#[ error( "crate path '{0}' does not exist" ) ]
@@ -382,10 +385,14 @@ pub struct SpirvBuilder {
382
385
clap(
383
386
long,
384
387
default_value = "spirv-unknown-vulkan1.2" ,
385
- value_parser = SpirvTargetEnv :: parse_triple
388
+ value_parser = Self :: parse_target
386
389
)
387
390
) ]
388
- pub target : Option < SpirvTargetEnv > ,
391
+ #[ serde(
392
+ serialize_with = "serialize_target" ,
393
+ deserialize_with = "deserialize_target"
394
+ ) ]
395
+ pub target : Option < Result < SpirvTargetEnv , SpirvTargetParseError > > ,
389
396
/// Cargo features specification for building the shader crate.
390
397
#[ cfg_attr( feature = "clap" , clap( flatten) ) ]
391
398
#[ serde( flatten) ]
@@ -454,6 +461,12 @@ pub struct SpirvBuilder {
454
461
455
462
#[ cfg( feature = "clap" ) ]
456
463
impl SpirvBuilder {
464
+ fn parse_target (
465
+ target : & str ,
466
+ ) -> Result < Result < SpirvTargetEnv , SpirvTargetParseError > , clap:: Error > {
467
+ Ok ( SpirvTargetEnv :: parse_triple ( target) )
468
+ }
469
+
457
470
/// Clap value parser for `Capability`.
458
471
fn parse_spirv_capability ( capability : & str ) -> Result < Capability , clap:: Error > {
459
472
use core:: str:: FromStr ;
@@ -494,7 +507,7 @@ impl SpirvBuilder {
494
507
pub fn new ( path_to_crate : impl AsRef < Path > , target : impl IntoSpirvTarget ) -> Self {
495
508
Self {
496
509
path_to_crate : Some ( path_to_crate. as_ref ( ) . to_owned ( ) ) ,
497
- target : target. to_spirv_target_env ( ) . ok ( ) ,
510
+ target : Some ( target. to_spirv_target_env ( ) ) ,
498
511
..SpirvBuilder :: default ( )
499
512
}
500
513
}
@@ -761,7 +774,10 @@ fn join_checking_for_separators(strings: Vec<impl Borrow<str>>, sep: &str) -> St
761
774
762
775
// Returns path to the metadata json.
763
776
fn invoke_rustc ( builder : & SpirvBuilder ) -> Result < PathBuf , SpirvBuilderError > {
764
- let target = builder. target . ok_or ( SpirvBuilderError :: MissingTarget ) ?;
777
+ let target = builder
778
+ . target
779
+ . clone ( )
780
+ . ok_or ( SpirvBuilderError :: MissingTarget ) ??;
765
781
let path_to_crate = builder
766
782
. path_to_crate
767
783
. as_ref ( )
0 commit comments