Skip to content

fix(cargo-gpu-install): harden toolchain channel parsing, add tests - #691

Closed
sorinirimies wants to merge 1 commit into
Rust-GPU:mainfrom
sorinirimies:fix/cargo-gpu-toolchain-channel-parsing
Closed

sorinirimies wants to merge 1 commit into
Rust-GPU:mainfrom
sorinirimies:fix/cargo-gpu-toolchain-channel-parsing

Conversation

@sorinirimies

@sorinirimies sorinirimies commented Nov 7, 2026 •

Copy link
Copy Markdown

Summary

cargo gpu install finds the toolchain by text-matching channel = "..." in the checked-out rustc_codegen_spirv/build.rs; cargo xtask update-toolchain rewrites the same line with a regex. Nothing tested that contract, so drift (e.g. indenting the line, or build.rs and rust-toolchain.toml disagreeing) would only show up when users install.

The format has to stay readable for older rust-gpu checkouts, so this keeps it and only makes it more lenient.

 get_channel_from_rustc_codegen_spirv_build_script(package)
   contents = read(build.rs)
-  find line.strip_prefix(`channel = "`); slice to next `"`
+  parse_toolchain_channel(contents)          // pure, unit-tested
+    find line.trim_start().strip_prefix(`channel = "`)
+    split at closing `"`; error if missing or empty

Evidence

New tests in spirv_source::test:

parse_toolchain_channel_of_real_build_script                  ok  // guards the real file
build_script_channel_matches_rust_toolchain_toml              ok  // guards xtask drift
parse_toolchain_channel_takes_first_match_and_allows_indent   ok  // old impl: Err
parse_toolchain_channel_errors                                ok

cargo test -p cargo-gpu-install --features test spirv_source: 9 passed. Clippy -D warnings clean.

Merge Danger

Door: two-way

Blast Radius: small — every input the old parser accepted yields the same channel, except channel = "", which now errors instead of returning an empty string.

`cargo gpu install` reads the toolchain from `rustc_codegen_spirv/build.rs`
by text-matching `channel = "..."`, the same line `cargo xtask` rewrites
via regex. It had no tests, so format drift would only surface at
install time for users.

- Extract the pure `parse_toolchain_channel`; allow leading whitespace,
  reject an empty channel, clearer errors.
- Test it against the real `build.rs`, and that it agrees with
  `rust-toolchain.toml`.
@Firestar99 Firestar99 closed this Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants