Rust-GPU/rust-gpu

`cargo clippy` with spirv target

Opened this issue · 1 comments

Currently, most projects run cargo clippy on the CPU target and hope that it covers most gpu-specific code as well. But that will ignore all #[gpu-only] functions and entry points, not checking them at all. We should investigate a way we can run clippy with spirv targets. This may be better suited for cargo gpu, since cargo gpu clippy would work quite nicely.

It looks like clippy sets RUSTC_WORKSPACE_WRAPPER and invokes cargo check.

CargoCmd could support applying a SpirvBuilder, which would be most of invoke_rustc (omitting the build command, removal of cargo / rustc env vars, and profile, etc).

impl CargoCmd {
    pub fn spirv_builder(&mut self, builder: &SpirvBuilder);
}

cargo gpu check can use this command. cargo gpu [command] [args..] maps to CARGO=cargo-gpu cargo [command] [args..].

This means that cargo gpu clippy turns into CARGO=cargo-gpu cargo clippy, which then invokes clippy on each package (instead of rustc), inserting additional args and env vars from spirv-builder to the command.

It would be nice to support cargo-expand, useful for debugging macros. This could use the same mechanism, but invokes cargo rustc --profile=check -- -Zunpretty=expanded. So this could be a simple as cargo gpu expand -p foo --lib.

And likewise additional cargo utilities could work without explicitly supporting them.