@@ -5,7 +5,10 @@ use std::io::Write as _;
55use std:: path:: Path ;
66
77use crate :: args:: InstallArgs ;
8- use crate :: { cache_dir, spirv_cli:: SpirvCli , spirv_source:: SpirvSource , target_spec_dir} ;
8+ use crate :: spirv_source:: {
9+ get_channel_from_rustc_codegen_spirv_build_script, get_package_from_crate,
10+ } ;
11+ use crate :: { cache_dir, spirv_source:: SpirvSource , target_spec_dir} ;
912
1013/// Metadata for the compile targets supported by `rust-gpu`
1114const TARGET_SPECS : & [ ( & str , & str ) ] = & [
@@ -80,20 +83,8 @@ pub struct Install {
8083}
8184
8285impl Install {
83- /// Returns a [`SpirvCLI`] instance, responsible for ensuring the right version of the `rustc_codegen_spirv` crate.
84- fn spirv_cli ( & self ) -> anyhow:: Result < SpirvCli > {
85- SpirvCli :: new (
86- & self . spirv_install . shader_crate ,
87- self . spirv_install . spirv_builder_source . clone ( ) ,
88- self . spirv_install . spirv_builder_version . clone ( ) ,
89- self . spirv_install . rust_toolchain . clone ( ) ,
90- self . spirv_install . auto_install_rust_toolchain ,
91- self . spirv_install . force_overwrite_lockfiles_v4_to_v3 ,
92- )
93- }
94-
9586 /// Create the `rustc_codegen_spirv_dummy` crate that depends on `rustc_codegen_spirv`
96- fn write_source_files ( spirv_cli : & SpirvCli , checkout : & Path ) -> anyhow:: Result < ( ) > {
87+ fn write_source_files ( source : & SpirvSource , checkout : & Path ) -> anyhow:: Result < ( ) > {
9788 {
9889 let main = "fn main() {}" ;
9990 let src = checkout. join ( "src" ) ;
@@ -102,7 +93,7 @@ impl Install {
10293 } ;
10394
10495 {
105- let version_spec = match & spirv_cli . source {
96+ let version_spec = match & source {
10697 SpirvSource :: CratesIO ( version) => {
10798 format ! ( "version = \" {}\" " , version)
10899 }
@@ -159,15 +150,14 @@ package = "rustc_codegen_spirv"
159150 format ! ( "could not create cache directory '{}'" , cache_dir. display( ) )
160151 } ) ?;
161152
162- let spirv_version = self . spirv_cli ( ) . context ( "running spirv cli" ) ?;
163- spirv_version
164- . ensure_toolchain_and_components_exist ( )
165- . context ( "ensuring toolchain and components exist" ) ?;
166-
167- let checkout = spirv_version
168- . cached_checkout_path ( )
169- . context ( "getting cached checkout path" ) ?;
170- let release = checkout. join ( "target" ) . join ( "release" ) ;
153+ // TODO what about lockfiles?
154+ // let spirv_version = self.spirv_cli().context("running spirv cli")?;
155+ let source = SpirvSource :: new (
156+ & self . spirv_install . shader_crate ,
157+ self . spirv_install . spirv_builder_source . as_deref ( ) ,
158+ self . spirv_install . spirv_builder_version . as_deref ( ) ,
159+ ) ?;
160+ let checkout = source. install_dir ( ) ?;
171161
172162 let dylib_filename = format ! (
173163 "{}rustc_codegen_spirv{}" ,
@@ -186,22 +176,36 @@ package = "rustc_codegen_spirv"
186176 log:: info!( "...and so we are aborting the install step." ) ;
187177 } else {
188178 log:: debug!(
189- "writing rustc_codegen_spirv_dummy source files into '{}'" ,
179+ "writing ` rustc_codegen_spirv_dummy` source files into '{}'" ,
190180 checkout. display( )
191181 ) ;
192- Self :: write_source_files ( & spirv_version, & checkout) . context ( "writing source files" ) ?;
182+ Self :: write_source_files ( & source, & checkout) . context ( "writing source files" ) ?;
183+
184+ log:: debug!( "resolving toolchain version to use" ) ;
185+ let rustc_codegen_spirv = get_package_from_crate ( & checkout, "rustc_codegen_spirv" )
186+ . context ( "get `rustc_codegen_spirv` metadata" ) ?;
187+ let toolchain_channel =
188+ get_channel_from_rustc_codegen_spirv_build_script ( & rustc_codegen_spirv)
189+ . context ( "read toolchain from `rustc_codegen_spirv`'s build.rs" ) ?;
190+ log:: info!( "selected toolchain channel `{toolchain_channel:?}`" ) ;
191+
192+ log:: debug!( "ensure_toolchain_and_components_exist" ) ;
193+ crate :: install_toolchain:: ensure_toolchain_and_components_exist (
194+ & toolchain_channel,
195+ self . spirv_install . auto_install_rust_toolchain ,
196+ )
197+ . context ( "ensuring toolchain and components exist" ) ?;
198+
199+ log:: debug!( "write_target_spec_files" ) ;
193200 self . write_target_spec_files ( )
194201 . context ( "writing target spec files" ) ?;
195202
196- crate :: user_output!(
197- "Compiling shader-specific `rustc_codegen_spirv` for {}\n " ,
198- self . spirv_install. shader_crate. display( )
199- ) ;
203+ crate :: user_output!( "Compiling `rustc_codegen_spirv` from source {}\n " , source, ) ;
200204
201205 let mut build_command = std:: process:: Command :: new ( "cargo" ) ;
202206 build_command
203207 . current_dir ( & checkout)
204- . arg ( format ! ( "+{}" , spirv_version . channel ) )
208+ . arg ( format ! ( "+{}" , toolchain_channel ) )
205209 . args ( [ "build" , "--release" ] )
206210 . env_remove ( "RUSTC" ) ;
207211
@@ -221,7 +225,10 @@ package = "rustc_codegen_spirv"
221225 } )
222226 . context ( "running build command" ) ?;
223227
224- let dylib_path = release. join ( & dylib_filename) ;
228+ let dylib_path = checkout
229+ . join ( "target" )
230+ . join ( "release" )
231+ . join ( & dylib_filename) ;
225232 if dylib_path. is_file ( ) {
226233 log:: info!( "successfully built {}" , dylib_path. display( ) ) ;
227234 std:: fs:: rename ( & dylib_path, & dest_dylib_path) . context ( "renaming dylib path" ) ?;
0 commit comments