GraphiteEditor / GraphiteEditor/Graphite

`cargo run` fails on WebAssembly target due to `CARGO_BUILD_TARGET` leaking into `rustc_codegen_spirv` build

未关闭 适合新手
#3,939 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Rust
星标
27.2k
派生
1.3k
平均合并
20 小时 5 分钟
30 天内合并 PR
57

描述

### Summary
When running the standard `cargo run` development workflow, the build fails while compiling the web frontend (`wasm-pack build ./wrapper --dev --target=web`).

The failure occurs in the `raster-nodes-shaders` crate's `build.rs` script. The build script attempts to compile the `rustc_codegen_spirv` compiler backend, but the parent `CARGO_BUILD_TARGET=wasm32-unknown-unknown` environment variable is inherited by the inner `cargo` build. Because WebAssembly does not support dynamic libraries (`dylib`), the inner build fails.

### Error Output
```text
[INFO]: 🎯 Checking for the Wasm target...
[INFO]: 🌀 Compiling to Wasm...
Compiling raster-nodes-shaders v0.1.0 (../Graphite/node-graph/nodes/raster/shaders)
error: failed to run custom build command for `raster-nodes-shaders v0.1.0 (../Graphite/node-graph/nodes/raster/shaders)`

Caused by:
...
error: cannot produce dylib for `rustc_codegen_spirv v0.9.0 (https://github.com/Firestar99/rust-gpu-new?rev=c12f2161...#c12f2161)` as the target `wasm32-unknown-unknown` does not support these crate types
```

### Steps to Reproduce
1. Clone the repository.
2. Ensure Node.js and Rust prerequisites are installed.
3. Run `cargo run`.
4. Observe the build crash when `wasm-pack` reaches `raster-nodes-shaders`.

### Proposed Solution
The inner build initiated by `cargo_gpu::Install` inside `node-graph/nodes/raster/shaders/build.rs` needs to compile for the host OS, not the WebAssembly target.

Clearing the `CARGO_BUILD_TARGET` environment variable inside `build.rs` before it kicks off the `cargo_gpu` build resolves the issue and allows the compilation to succeed:

```rust
// node-graph/nodes/raster/shaders/build.rs

// Inside main():
unsafe { std::env::remove_var("CARGO_BUILD_TARGET"); }

// ... followed by the existing cargo_gpu::Install::from_shader_crate(...) logic
```

### Environment
* **OS:** macOS 26.3.1 (Build 25D2128)
* **Rust Version:** rustc 1.92.0 (ded5c06cf 2025-12-08)
* **Node.js:** v22.21.1

### 🤖 AI disclosure

I used Gemini to help me understand the error message. This message and the fix are mine.

贡献指南

这个仓库没有索引到贡献指南

调研方向

Start with node-graph/nodes/raster/shaders/build.rs and the cargo_gpu::Install::from_shader_crate(...) call. Reproduce the failure with cargo run, then verify the inner build uses the host target rather than the inherited WebAssembly target. Done means the standard cargo run workflow completes past raster-nodes-shaders without the dylib error.

由索引模型根据 Issue 内容生成。

评估

技术栈
rust, wasm
领域
build-system
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
冷清
描述清晰度
描述清楚
新手友好度
68/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。