@@ -5,7 +5,10 @@ use std::io::Write as _;
5
5
use std:: path:: Path ;
6
6
7
7
use 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} ;
9
12
10
13
/// Metadata for the compile targets supported by `rust-gpu`
11
14
const TARGET_SPECS : & [ ( & str , & str ) ] = & [
@@ -80,20 +83,8 @@ pub struct Install {
80
83
}
81
84
82
85
impl 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
-
95
86
/// 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 < ( ) > {
97
88
{
98
89
let main = "fn main() {}" ;
99
90
let src = checkout. join ( "src" ) ;
@@ -102,7 +93,7 @@ impl Install {
102
93
} ;
103
94
104
95
{
105
- let version_spec = match & spirv_cli . source {
96
+ let version_spec = match & source {
106
97
SpirvSource :: CratesIO ( version) => {
107
98
format ! ( "version = \" {}\" " , version)
108
99
}
@@ -159,15 +150,14 @@ package = "rustc_codegen_spirv"
159
150
format ! ( "could not create cache directory '{}'" , cache_dir. display( ) )
160
151
} ) ?;
161
152
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 ( ) ?;
171
161
172
162
let dylib_filename = format ! (
173
163
"{}rustc_codegen_spirv{}" ,
@@ -186,22 +176,36 @@ package = "rustc_codegen_spirv"
186
176
log:: info!( "...and so we are aborting the install step." ) ;
187
177
} else {
188
178
log:: debug!(
189
- "writing rustc_codegen_spirv_dummy source files into '{}'" ,
179
+ "writing ` rustc_codegen_spirv_dummy` source files into '{}'" ,
190
180
checkout. display( )
191
181
) ;
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" ) ;
193
200
self . write_target_spec_files ( )
194
201
. context ( "writing target spec files" ) ?;
195
202
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, ) ;
200
204
201
205
let mut build_command = std:: process:: Command :: new ( "cargo" ) ;
202
206
build_command
203
207
. current_dir ( & checkout)
204
- . arg ( format ! ( "+{}" , spirv_version . channel ) )
208
+ . arg ( format ! ( "+{}" , toolchain_channel ) )
205
209
. args ( [ "build" , "--release" ] )
206
210
. env_remove ( "RUSTC" ) ;
207
211
@@ -221,7 +225,10 @@ package = "rustc_codegen_spirv"
221
225
} )
222
226
. context ( "running build command" ) ?;
223
227
224
- let dylib_path = release. join ( & dylib_filename) ;
228
+ let dylib_path = checkout
229
+ . join ( "target" )
230
+ . join ( "release" )
231
+ . join ( & dylib_filename) ;
225
232
if dylib_path. is_file ( ) {
226
233
log:: info!( "successfully built {}" , dylib_path. display( ) ) ;
227
234
std:: fs:: rename ( & dylib_path, & dest_dylib_path) . context ( "renaming dylib path" ) ?;
0 commit comments