@@ -5,58 +5,14 @@ use std::path::{Path, PathBuf};
55use anyhow:: Context as _;
66use rustc_codegen_spirv_cache:: {
77 cache:: cache_dir,
8+ install:: InstalledBackend ,
89 metadata:: { query_metadata, MetadataExt as _} ,
910 spirv_source:: { rust_gpu_toolchain_channel, SpirvSource } ,
1011 target_specs:: update_target_specs_files,
12+ toolchain:: ensure_toolchain_installation,
1113} ;
12- use spirv_builder:: SpirvBuilder ;
1314
14- /// Represents a functional backend installation, whether it was cached or just installed.
15- #[ derive( Clone , Debug , Default ) ]
16- #[ non_exhaustive]
17- pub struct InstalledBackend {
18- /// path to the `rustc_codegen_spirv` dylib
19- pub rustc_codegen_spirv_location : PathBuf ,
20- /// toolchain channel name
21- pub toolchain_channel : String ,
22- /// directory with target-specs json files
23- pub target_spec_dir : PathBuf ,
24- }
25-
26- impl InstalledBackend {
27- /// Creates a new `SpirvBuilder` configured to use this installed backend.
28- #[ expect(
29- clippy:: unreachable,
30- reason = "it's unreachable, no need to return a Result"
31- ) ]
32- #[ expect( clippy:: impl_trait_in_params, reason = "forwarding spirv-builder API" ) ]
33- #[ inline]
34- pub fn to_spirv_builder (
35- & self ,
36- path_to_crate : impl AsRef < Path > ,
37- target : impl Into < String > ,
38- ) -> SpirvBuilder {
39- let mut builder = SpirvBuilder :: new ( path_to_crate, target) ;
40- self . configure_spirv_builder ( & mut builder)
41- . unwrap_or_else ( |_| unreachable ! ( "we set target before calling this function" ) ) ;
42- builder
43- }
44-
45- /// Configures the supplied [`SpirvBuilder`]. `SpirvBuilder.target` must be set and must not change after calling this function.
46- ///
47- /// # Errors
48- /// if `SpirvBuilder.target` is not set
49- #[ inline]
50- pub fn configure_spirv_builder ( & self , builder : & mut SpirvBuilder ) -> anyhow:: Result < ( ) > {
51- builder. rustc_codegen_spirv_location = Some ( self . rustc_codegen_spirv_location . clone ( ) ) ;
52- builder. toolchain_overwrite = Some ( self . toolchain_channel . clone ( ) ) ;
53- builder. path_to_target_spec = Some ( self . target_spec_dir . join ( format ! (
54- "{}.json" ,
55- builder. target. as_ref( ) . context( "expect target to be set" ) ?
56- ) ) ) ;
57- Ok ( ( ) )
58- }
59- }
15+ use crate :: user_consent:: ask_for_user_consent;
6016
6117/// Args for an install
6218#[ expect(
@@ -203,7 +159,8 @@ package = "rustc_codegen_spirv"
203159 Ok ( ( ) )
204160 }
205161
206- /// Install the binary pair and return the [`InstalledBackend`], from which you can create [`SpirvBuilder`] instances.
162+ /// Install the binary pair and return the [`InstalledBackend`],
163+ /// from which you can create [`SpirvBuilder`](spirv_builder::SpirvBuilder) instances.
207164 ///
208165 /// # Errors
209166 /// If the installation somehow fails.
@@ -271,9 +228,9 @@ package = "rustc_codegen_spirv"
271228 . context ( "writing target spec files" ) ?;
272229
273230 log:: debug!( "ensure_toolchain_and_components_exist" ) ;
274- crate :: install_toolchain :: ensure_toolchain_and_components_exist (
231+ ensure_toolchain_installation (
275232 & toolchain_channel,
276- self . auto_install_rust_toolchain ,
233+ ask_for_user_consent ( & toolchain_channel , self . auto_install_rust_toolchain ) ,
277234 )
278235 . context ( "ensuring toolchain and components exist" ) ?;
279236
0 commit comments