@@ -6,7 +6,7 @@ use crate::spirv_source::{
6
6
use crate :: { cache_dir, spirv_source:: SpirvSource , target_spec_dir} ;
7
7
use anyhow:: Context as _;
8
8
use log:: trace;
9
- use spirv_builder:: TARGET_SPECS ;
9
+ use spirv_builder:: { SpirvBuilder , TARGET_SPECS } ;
10
10
use std:: io:: Write as _;
11
11
use std:: path:: { Path , PathBuf } ;
12
12
@@ -77,6 +77,28 @@ pub struct Install {
77
77
pub force_overwrite_lockfiles_v4_to_v3 : bool ,
78
78
}
79
79
80
+ /// Represents a functional backend installation, whether it was cached or just installed.
81
+ #[ derive( Clone , Debug ) ]
82
+ pub struct InstalledBackend {
83
+ /// path to the `rustc_codegen_spirv` dylib
84
+ pub rustc_codegen_spirv_location : PathBuf ,
85
+ /// toolchain channel name
86
+ pub toolchain_channel : String ,
87
+ }
88
+
89
+ impl InstalledBackend {
90
+ /// Configures the supplied [`SpirvBuilder`]. `SpirvBuilder.target` must be set and must not change after calling this function.
91
+ pub fn configure_spirv_builder ( & self , builder : & mut SpirvBuilder ) -> anyhow:: Result < ( ) > {
92
+ builder. rustc_codegen_spirv_location = Some ( self . rustc_codegen_spirv_location . clone ( ) ) ;
93
+ builder. toolchain_overwrite = Some ( self . toolchain_channel . clone ( ) ) ;
94
+ builder. path_to_target_spec = Some ( target_spec_dir ( ) ?. join ( format ! (
95
+ "{}.json" ,
96
+ builder. target. as_ref( ) . context( "expect target to be set" ) ?
97
+ ) ) ) ;
98
+ Ok ( ( ) )
99
+ }
100
+ }
101
+
80
102
impl Default for Install {
81
103
#[ inline]
82
104
fn default ( ) -> Self {
@@ -164,7 +186,7 @@ package = "rustc_codegen_spirv"
164
186
165
187
/// Install the binary pair and return the `(dylib_path, toolchain_channel)`.
166
188
#[ expect( clippy:: too_many_lines, reason = "it's fine" ) ]
167
- pub fn run ( & self ) -> anyhow:: Result < ( PathBuf , String ) > {
189
+ pub fn run ( & self ) -> anyhow:: Result < InstalledBackend > {
168
190
// Ensure the cache dir exists
169
191
let cache_dir = cache_dir ( ) ?;
170
192
log:: info!( "cache directory is '{}'" , cache_dir. display( ) ) ;
@@ -282,6 +304,9 @@ package = "rustc_codegen_spirv"
282
304
. context ( "writing target spec files" ) ?;
283
305
}
284
306
285
- Ok ( ( dest_dylib_path, toolchain_channel) )
307
+ Ok ( InstalledBackend {
308
+ rustc_codegen_spirv_location : dest_dylib_path,
309
+ toolchain_channel,
310
+ } )
286
311
}
287
312
}
0 commit comments