-
Notifications
You must be signed in to change notification settings - Fork 15
Description
Recently I stumbled upon a minor issue when trying to use cargo-gpu inside of a workspace.
Workspace of my project contains crates with unsafe code which I want to test with Miri to catch soundness issues.
Recently added library API of cargo-gpu works great inside of build scripts, but when I try to call Miri at a workspace root, build scripts which compiles my shader crates fails.
I've created minimal reproducible example of such workspace at https://github.com/tuguzT/cargo-gpu-miri; I am sure that workspace of my project is too complicated to demonstrate such issue.
Here is what actually happens there:
- Using recently added
cargo-gpulibrary API fails with this error:
error: failed to run custom build command for `simple_shader_builder_api v0.0.0 (C:\Users\tuguzT\Projects\cargo-gpu-miri\simple_shader_builder_api)`
Caused by:
process didn't exit successfully: `C:\Users\tuguzT\Projects\cargo-gpu-miri\target\miri\debug\build\simple_shader_builder_api-de35662e45b75b83\build-script-build` (exit code: 1)
--- stderr
error: process didn't exit successfully: `C:\Users\tuguzT\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\bin\cargo-miri.exe C:\Users\tuguzT\.rustup\toolchains\nightly-2024-11-22-x86_64-pc-windows-msvc\bin\rustc.exe -vV` (exit code: 1)
--- stderr
fatal error: `cargo-miri` called without RUSTC set; please only invoke this binary through `cargo miri`
Error: BuildFailed
- Before using
cargo-gpulibrary API, I used to createstd::process::Commandand call it with locally installedcargo-gpuexecutable; it was silently failing with the similar error with such stderr dump which I took fromtarget/miri/x86_64-pc-windows-msvc/debug/build/simple_shader_builder_command-c861efd69eece953/stderrfile:
failed to build shaders:
error: process didn't exit successfully: `C:\Users\tuguzT\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\bin\cargo-miri.exe C:\Users\tuguzT\.rustup\toolchains\nightly-2024-11-22-x86_64-pc-windows-msvc\bin\rustc.exe -vV` (exit code: 1)
--- stderr
fatal error: `cargo-miri` called without RUSTC set; please only invoke this binary through `cargo miri`
[2025-07-03T16:30:24Z ERROR cargo_gpu] build failed
Error: build failed
It failed silently because contents of std::process::Command were not checked inside of build script and because examples and benchmarks which compiled such shaders were not executed, and so absence of shader compiled into SPIR-V were not checked.
- After looking at Miri source code, I found this line which, I think, causes these errors described earlier:
https://github.com/rust-lang/miri/blob/8481c42358eeed1a233b8ead7717683529ffde94/cargo-miri/src/main.rs#L102
And so, the question: how cargo-gpu should behave in such case?
Should it really somehow bypass Miri and compile shaders normally or is this an intended behaviour?
- On the one hand, it's not too hard to manually call Miri only on crates which code should be tested on UB, or to filter packages via
--packageoption. - On the other hand, running build scripts successfully could be slightly more convenient.