Skip to content

cargo-gpu in build scripts breaks clippy and miri #93

@tuguzT

Description

@tuguzT

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:

  1. Using recently added cargo-gpu library 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
  1. Before using cargo-gpu library API, I used to create std::process::Command and call it with locally installed cargo-gpu executable; it was silently failing with the similar error with such stderr dump which I took from target/miri/x86_64-pc-windows-msvc/debug/build/simple_shader_builder_command-c861efd69eece953/stderr file:
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.

  1. 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 --package option.
  • On the other hand, running build scripts successfully could be slightly more convenient.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions