@@ -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,40 @@ 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
+ /// Creates a new `SpirvBuilder` configured to use this installed backend.
91
+ pub fn to_spirv_builder (
92
+ & self ,
93
+ path_to_crate : impl AsRef < Path > ,
94
+ target : impl Into < String > ,
95
+ ) -> SpirvBuilder {
96
+ let mut builder = SpirvBuilder :: new ( path_to_crate, target) ;
97
+ self . configure_spirv_builder ( & mut builder)
98
+ . expect ( "unreachable" ) ;
99
+ builder
100
+ }
101
+
102
+ /// Configures the supplied [`SpirvBuilder`]. `SpirvBuilder.target` must be set and must not change after calling this function.
103
+ pub fn configure_spirv_builder ( & self , builder : & mut SpirvBuilder ) -> anyhow:: Result < ( ) > {
104
+ builder. rustc_codegen_spirv_location = Some ( self . rustc_codegen_spirv_location . clone ( ) ) ;
105
+ builder. toolchain_overwrite = Some ( self . toolchain_channel . clone ( ) ) ;
106
+ builder. path_to_target_spec = Some ( target_spec_dir ( ) ?. join ( format ! (
107
+ "{}.json" ,
108
+ builder. target. as_ref( ) . context( "expect target to be set" ) ?
109
+ ) ) ) ;
110
+ Ok ( ( ) )
111
+ }
112
+ }
113
+
80
114
impl Default for Install {
81
115
#[ inline]
82
116
fn default ( ) -> Self {
@@ -164,7 +198,7 @@ package = "rustc_codegen_spirv"
164
198
165
199
/// Install the binary pair and return the `(dylib_path, toolchain_channel)`.
166
200
#[ expect( clippy:: too_many_lines, reason = "it's fine" ) ]
167
- pub fn run ( & mut self ) -> anyhow:: Result < ( PathBuf , String ) > {
201
+ pub fn run ( & mut self ) -> anyhow:: Result < InstalledBackend > {
168
202
// Ensure the cache dir exists
169
203
let cache_dir = cache_dir ( ) ?;
170
204
log:: info!( "cache directory is '{}'" , cache_dir. display( ) ) ;
@@ -282,6 +316,9 @@ package = "rustc_codegen_spirv"
282
316
. context ( "writing target spec files" ) ?;
283
317
}
284
318
285
- Ok ( ( dest_dylib_path, toolchain_channel) )
319
+ Ok ( InstalledBackend {
320
+ rustc_codegen_spirv_location : dest_dylib_path,
321
+ toolchain_channel,
322
+ } )
286
323
}
287
324
}
0 commit comments