@@ -81,79 +81,42 @@ use serde::Deserialize;
8181use std:: borrow:: Borrow ;
8282use std:: collections:: HashMap ;
8383use std:: env;
84- use std:: error:: Error ;
85- use std:: fmt;
8684use std:: fs:: File ;
8785use std:: io:: BufReader ;
8886use std:: path:: { Path , PathBuf } ;
8987use std:: process:: { Command , Stdio } ;
88+ use thiserror:: Error ;
9089
9190pub use rustc_codegen_spirv_types:: Capability ;
9291pub use rustc_codegen_spirv_types:: { CompileResult , ModuleResult } ;
9392
94- #[ derive( Debug ) ]
93+ #[ derive( Debug , Error ) ]
9594#[ non_exhaustive]
9695pub enum SpirvBuilderError {
96+ #[ error( "`target` must be set, for example `spirv-unknown-vulkan1.2`" ) ]
97+ NoTargetSet ,
98+ #[ error( "expected `{SPIRV_TARGET_PREFIX}...` target, found `{target}`" ) ]
9799 NonSpirvTarget { target : String } ,
100+ #[ error( "SPIR-V target `{SPIRV_TARGET_PREFIX}-{target_env}` is not supported" ) ]
98101 UnsupportedSpirvTargetEnv { target_env : String } ,
102+ #[ error( "`path_to_crate` must be set" ) ]
103+ NoCratePathSet ,
104+ #[ error( "crate path {0} does not exist" ) ]
99105 CratePathDoesntExist ( PathBuf ) ,
106+ #[ error( "build failed" ) ]
100107 BuildFailed ,
108+ #[ error( "multi-module build cannot be used with print_metadata = MetadataPrintout::Full" ) ]
101109 MultiModuleWithPrintMetadata ,
110+ #[ error( "watching within build scripts will prevent build completion" ) ]
102111 WatchWithPrintMetadata ,
103- MetadataFileMissing ( std:: io:: Error ) ,
104- MetadataFileMalformed ( serde_json:: Error ) ,
112+ #[ error( "multi-module metadata file missing" ) ]
113+ MetadataFileMissing ( #[ from] std:: io:: Error ) ,
114+ #[ error( "unable to parse multi-module metadata file" ) ]
115+ MetadataFileMalformed ( #[ from] serde_json:: Error ) ,
105116}
106117
107118const SPIRV_TARGET_PREFIX : & str = "spirv-unknown-" ;
108119
109- impl fmt:: Display for SpirvBuilderError {
110- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
111- match self {
112- Self :: NonSpirvTarget { target } => {
113- write ! (
114- f,
115- "expected `{SPIRV_TARGET_PREFIX}...` target, found `{target}`"
116- )
117- }
118- Self :: UnsupportedSpirvTargetEnv { target_env } if target_env. starts_with ( "opencl" ) => {
119- write ! (
120- f,
121- "OpenCL targets like `{SPIRV_TARGET_PREFIX}-{target_env}` are not supported"
122- )
123- }
124- Self :: UnsupportedSpirvTargetEnv { target_env } if target_env. starts_with ( "webgpu" ) => {
125- write ! (
126- f,
127- "WebGPU targets like `{SPIRV_TARGET_PREFIX}-{target_env}` are not supported, \
128- consider using `{SPIRV_TARGET_PREFIX}-vulkan1.0` instead"
129- )
130- }
131- Self :: UnsupportedSpirvTargetEnv { target_env } => {
132- write ! (
133- f,
134- "SPIR-V target `{SPIRV_TARGET_PREFIX}-{target_env}` is not supported"
135- )
136- }
137- Self :: CratePathDoesntExist ( path) => {
138- write ! ( f, "crate path {} does not exist" , path. display( ) )
139- }
140- Self :: BuildFailed => f. write_str ( "build failed" ) ,
141- Self :: MultiModuleWithPrintMetadata => f. write_str (
142- "multi-module build cannot be used with print_metadata = MetadataPrintout::Full" ,
143- ) ,
144- Self :: WatchWithPrintMetadata => {
145- f. write_str ( "watching within build scripts will prevent build completion" )
146- }
147- Self :: MetadataFileMissing ( _) => f. write_str ( "multi-module metadata file missing" ) ,
148- Self :: MetadataFileMalformed ( _) => {
149- f. write_str ( "unable to parse multi-module metadata file" )
150- }
151- }
152- }
153- }
154-
155- impl Error for SpirvBuilderError { }
156-
157120#[ derive( Debug , PartialEq , Eq , Clone , Copy ) ]
158121pub enum MetadataPrintout {
159122 /// Print no cargo metadata.
0 commit comments