@@ -6,7 +6,7 @@ use crate::spirv_source::{
66use crate :: { cache_dir, spirv_source:: SpirvSource , target_spec_dir} ;
77use anyhow:: Context as _;
88use log:: trace;
9- use spirv_builder:: TARGET_SPECS ;
9+ use spirv_builder:: { SpirvBuilder , TARGET_SPECS } ;
1010use std:: io:: Write as _;
1111use std:: path:: { Path , PathBuf } ;
1212
@@ -77,6 +77,28 @@ pub struct Install {
7777 pub force_overwrite_lockfiles_v4_to_v3 : bool ,
7878}
7979
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+
80102impl Default for Install {
81103 #[ inline]
82104 fn default ( ) -> Self {
@@ -164,7 +186,7 @@ package = "rustc_codegen_spirv"
164186
165187 /// Install the binary pair and return the `(dylib_path, toolchain_channel)`.
166188 #[ 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 > {
168190 // Ensure the cache dir exists
169191 let cache_dir = cache_dir ( ) ?;
170192 log:: info!( "cache directory is '{}'" , cache_dir. display( ) ) ;
@@ -282,6 +304,9 @@ package = "rustc_codegen_spirv"
282304 . context ( "writing target spec files" ) ?;
283305 }
284306
285- Ok ( ( dest_dylib_path, toolchain_channel) )
307+ Ok ( InstalledBackend {
308+ rustc_codegen_spirv_location : dest_dylib_path,
309+ toolchain_channel,
310+ } )
286311 }
287312}
0 commit comments