@@ -251,75 +251,27 @@ pub enum ParseSourceVersionError {
251
251
InvalidManifestPath ( Utf8PathBuf ) ,
252
252
}
253
253
254
- /// An error indicating that getting the channel of a Rust toolchain from the package failed.
255
- #[ derive( Debug , thiserror:: Error ) ]
256
- #[ non_exhaustive]
257
- pub enum GetChannelError {
258
- /// Package is located at the root of the file system
259
- /// and cannot have a parent.
260
- #[ error( "package located at root" ) ]
261
- PackageAtRoot ,
262
- /// Build script file is not valid or does not exist.
263
- #[ error( "invalid build script {build_script}: {source}" ) ]
264
- InvalidBuildScript {
265
- /// Source of the error.
266
- source : io:: Error ,
267
- /// Path to the build script file.
268
- build_script : Utf8PathBuf ,
269
- } ,
270
- /// There is no line starting with `channel_start`
271
- /// in the build script file contents.
272
- #[ error( "`{channel_start}` line in {build_script:?} not found" ) ]
273
- ChannelStartNotFound {
274
- /// Start of the channel line.
275
- channel_start : & ' static str ,
276
- /// Path to the build script file.
277
- build_script : Utf8PathBuf ,
278
- } ,
279
- /// Channel line does not contain `channel_end`
280
- /// in the build script file contents.
281
- #[ error( "ending `{channel_end}` of line \" {channel_line}\" in {build_script:?} not found" ) ]
282
- ChannelEndNotFound {
283
- /// End of the channel line.
284
- channel_end : & ' static str ,
285
- /// The line containing the channel information.
286
- channel_line : String ,
287
- /// Path to the build script file.
288
- build_script : Utf8PathBuf ,
289
- } ,
290
- /// The range to slice the channel line is not valid.
291
- #[ error( "cannot slice line \" {channel_line}\" of {build_script:?} by range {range:?}" ) ]
292
- InvalidRange {
293
- /// The invalid range.
294
- range : Range < usize > ,
295
- /// The line containing the channel information.
296
- channel_line : String ,
297
- /// Path to the build script file.
298
- build_script : Utf8PathBuf ,
299
- } ,
300
- }
301
-
302
254
/// Parse the `rust-toolchain.toml` in the working tree of the checked-out version of the `rust-gpu` repo.
303
255
///
304
256
/// # Errors
305
257
///
306
258
/// Returns an error if the package is at the root of the filesystem,
307
259
/// build script does not exist, or there is no definition of `channel` in it.
308
260
#[ inline]
309
- pub fn get_channel_from_rustc_codegen_spirv_build_script (
310
- rustc_codegen_spirv_package : & Package ,
311
- ) -> Result < String , GetChannelError > {
312
- let path = rustc_codegen_spirv_package
261
+ pub fn rust_gpu_toolchain_channel (
262
+ rustc_codegen_spirv : & Package ,
263
+ ) -> Result < String , RustGpuToolchainChannelError > {
264
+ let path = rustc_codegen_spirv
313
265
. manifest_path
314
266
. parent ( )
315
- . ok_or ( GetChannelError :: PackageAtRoot ) ?;
267
+ . ok_or ( RustGpuToolchainChannelError :: PackageAtRoot ) ?;
316
268
let build_script = path. join ( "build.rs" ) ;
317
269
318
270
log:: debug!( "Parsing `build.rs` at {build_script:?} for the used toolchain" ) ;
319
271
let contents = match fs:: read_to_string ( & build_script) {
320
272
Ok ( contents) => contents,
321
273
Err ( source) => {
322
- let err = GetChannelError :: InvalidBuildScript {
274
+ let err = RustGpuToolchainChannelError :: InvalidBuildScript {
323
275
source,
324
276
build_script,
325
277
} ;
@@ -332,8 +284,8 @@ pub fn get_channel_from_rustc_codegen_spirv_build_script(
332
284
. lines ( )
333
285
. find ( |line| line. starts_with ( channel_start) )
334
286
else {
335
- let err = GetChannelError :: ChannelStartNotFound {
336
- channel_start,
287
+ let err = RustGpuToolchainChannelError :: ChannelStartNotFound {
288
+ channel_start : channel_start . to_owned ( ) ,
337
289
build_script,
338
290
} ;
339
291
return Err ( err) ;
@@ -346,8 +298,8 @@ pub fn get_channel_from_rustc_codegen_spirv_build_script(
346
298
. find ( channel_end)
347
299
. map ( |end| end + start)
348
300
else {
349
- let err = GetChannelError :: ChannelEndNotFound {
350
- channel_end,
301
+ let err = RustGpuToolchainChannelError :: ChannelEndNotFound {
302
+ channel_end : channel_end . to_owned ( ) ,
351
303
channel_line : channel_line. to_owned ( ) ,
352
304
build_script,
353
305
} ;
@@ -356,7 +308,7 @@ pub fn get_channel_from_rustc_codegen_spirv_build_script(
356
308
357
309
let range = start..end;
358
310
let Some ( channel) = channel_line. get ( range. clone ( ) ) else {
359
- let err = GetChannelError :: InvalidRange {
311
+ let err = RustGpuToolchainChannelError :: InvalidRange {
360
312
range,
361
313
channel_line : channel_line. to_owned ( ) ,
362
314
build_script,
@@ -366,6 +318,54 @@ pub fn get_channel_from_rustc_codegen_spirv_build_script(
366
318
Ok ( channel. to_owned ( ) )
367
319
}
368
320
321
+ /// An error indicating that getting the channel of a Rust toolchain from the package failed.
322
+ #[ derive( Debug , thiserror:: Error ) ]
323
+ #[ non_exhaustive]
324
+ pub enum RustGpuToolchainChannelError {
325
+ /// Package is located at the root of the file system
326
+ /// and cannot have a parent.
327
+ #[ error( "package located at root" ) ]
328
+ PackageAtRoot ,
329
+ /// Build script file is not valid or does not exist.
330
+ #[ error( "invalid build script {build_script}: {source}" ) ]
331
+ InvalidBuildScript {
332
+ /// Source of the error.
333
+ source : io:: Error ,
334
+ /// Path to the build script file.
335
+ build_script : Utf8PathBuf ,
336
+ } ,
337
+ /// There is no line starting with `channel_start`
338
+ /// in the build script file contents.
339
+ #[ error( "`{channel_start}` line in {build_script:?} not found" ) ]
340
+ ChannelStartNotFound {
341
+ /// Start of the channel line.
342
+ channel_start : String ,
343
+ /// Path to the build script file.
344
+ build_script : Utf8PathBuf ,
345
+ } ,
346
+ /// Channel line does not contain `channel_end`
347
+ /// in the build script file contents.
348
+ #[ error( "ending `{channel_end}` of line \" {channel_line}\" in {build_script:?} not found" ) ]
349
+ ChannelEndNotFound {
350
+ /// End of the channel line.
351
+ channel_end : String ,
352
+ /// The line containing the channel information.
353
+ channel_line : String ,
354
+ /// Path to the build script file.
355
+ build_script : Utf8PathBuf ,
356
+ } ,
357
+ /// The range to slice the channel line is not valid.
358
+ #[ error( "cannot slice line \" {channel_line}\" of {build_script:?} by range {range:?}" ) ]
359
+ InvalidRange {
360
+ /// The invalid range.
361
+ range : Range < usize > ,
362
+ /// The line containing the channel information.
363
+ channel_line : String ,
364
+ /// Path to the build script file.
365
+ build_script : Utf8PathBuf ,
366
+ } ,
367
+ }
368
+
369
369
/// Returns a string suitable to use as a directory.
370
370
///
371
371
/// Created from the spirv-builder source dep and the rustc channel.
0 commit comments