@@ -251,75 +251,27 @@ pub enum ParseSourceVersionError {
251251 InvalidManifestPath ( Utf8PathBuf ) ,
252252}
253253
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-
302254/// Parse the `rust-toolchain.toml` in the working tree of the checked-out version of the `rust-gpu` repo.
303255///
304256/// # Errors
305257///
306258/// Returns an error if the package is at the root of the filesystem,
307259/// build script does not exist, or there is no definition of `channel` in it.
308260#[ 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
313265 . manifest_path
314266 . parent ( )
315- . ok_or ( GetChannelError :: PackageAtRoot ) ?;
267+ . ok_or ( RustGpuToolchainChannelError :: PackageAtRoot ) ?;
316268 let build_script = path. join ( "build.rs" ) ;
317269
318270 log:: debug!( "Parsing `build.rs` at {build_script:?} for the used toolchain" ) ;
319271 let contents = match fs:: read_to_string ( & build_script) {
320272 Ok ( contents) => contents,
321273 Err ( source) => {
322- let err = GetChannelError :: InvalidBuildScript {
274+ let err = RustGpuToolchainChannelError :: InvalidBuildScript {
323275 source,
324276 build_script,
325277 } ;
@@ -332,8 +284,8 @@ pub fn get_channel_from_rustc_codegen_spirv_build_script(
332284 . lines ( )
333285 . find ( |line| line. starts_with ( channel_start) )
334286 else {
335- let err = GetChannelError :: ChannelStartNotFound {
336- channel_start,
287+ let err = RustGpuToolchainChannelError :: ChannelStartNotFound {
288+ channel_start : channel_start . to_owned ( ) ,
337289 build_script,
338290 } ;
339291 return Err ( err) ;
@@ -346,8 +298,8 @@ pub fn get_channel_from_rustc_codegen_spirv_build_script(
346298 . find ( channel_end)
347299 . map ( |end| end + start)
348300 else {
349- let err = GetChannelError :: ChannelEndNotFound {
350- channel_end,
301+ let err = RustGpuToolchainChannelError :: ChannelEndNotFound {
302+ channel_end : channel_end . to_owned ( ) ,
351303 channel_line : channel_line. to_owned ( ) ,
352304 build_script,
353305 } ;
@@ -356,7 +308,7 @@ pub fn get_channel_from_rustc_codegen_spirv_build_script(
356308
357309 let range = start..end;
358310 let Some ( channel) = channel_line. get ( range. clone ( ) ) else {
359- let err = GetChannelError :: InvalidRange {
311+ let err = RustGpuToolchainChannelError :: InvalidRange {
360312 range,
361313 channel_line : channel_line. to_owned ( ) ,
362314 build_script,
@@ -366,6 +318,54 @@ pub fn get_channel_from_rustc_codegen_spirv_build_script(
366318 Ok ( channel. to_owned ( ) )
367319}
368320
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+
369369/// Returns a string suitable to use as a directory.
370370///
371371/// Created from the spirv-builder source dep and the rustc channel.
0 commit comments