bazelbuild / bazelbuild/rules_rust

wgpu fails to build in wasm build - incorrect features?

Open
#1,820 0 comments 1 reaction 0 assignees View on GitHub
bug external-crates needs-triage
Dominant language
Starlark
Stars
843
Forks
651
Avg merge
2d 18h
Merged PRs (30d)
15

Description

I'm trying to generate a wasm binary that uses wgpu. However, it fails to build under bazel while I'm able to build it using cargo.

```
ERROR: /home/doug/.cache/bazel/_bazel_doug/b0db08dbefda9318e6dcb1f83205b236/external/crate_index_cargo_workspace__ash-0.37.2-1.3.238/BUILD.bazel:22:13: Compiling Rust rlib ash v0.37.2+1.3.238 (95 files) failed: (Exit 1): process_wrapper failed: error executing command (from target @crate_index_cargo_workspace__ash-0.37.2-1.3.238//:ash) bazel-out/k8-opt-exec-2B5CBBC6-ST-e846b08c7501/bin/external/rules_rust/util/process_wrapper/process_wrapper --env-file ... (remaining 38 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
error[E0432]: unresolved import `libloading::Library`
--> external/crate_index_cargo_workspace__ash-0.37.2-1.3.238/src/entry.rs:16:5
|
16 | use libloading::Library;
| ^^^^^^^^^^^^^^^^^^^ no `Library` in the root

error[E0425]: cannot find value `LIB_PATH` in this scope
--> external/crate_index_cargo_workspace__ash-0.37.2-1.3.238/src/entry.rs:76:25
|
76 | Self::load_from(LIB_PATH)
| ^^^^^^^^ not found in this scope

error[E0282]: type annotations needed
--> external/crate_index_cargo_workspace__ash-0.37.2-1.3.238/src/entry.rs:164:25
|
164 | _lib_guard: None,
| ^^^^ cannot infer type of the type parameter `T` declared on the enum `Option`
|
help: consider specifying the generic argument
|
164 | _lib_guard: None::,
| +++++

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0282, E0425, E0432.
For more information about an error, try `rustc --explain E0282`.
Target //cargo_workspace/rng:rng_bindgen failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 180.079s, Critical Path: 32.13s
INFO: 489 processes: 223 internal, 266 linux-sandbox.
FAILED: Build did NOT complete successfully
```

I believe this error is caused by features being incorrectly enabled/disabled in the build. However, I'm not sure what's going wrong.

The library `ash` that is trying to use `libloading` is referenced by `wgpu-hal`:

```
bazel cquery --platforms=@rules_rust//rust/platform:wasm 'somepath(//cargo_workspace/rng:rng_bindgen, @crate_index_cargo_workspace__ash-0.37.2-1.3.238//:all)' 1 ↵
INFO: Build option --platforms has changed, discarding analysis cache.
INFO: Analyzed 5 targets (322 packages loaded, 13371 targets configured).
INFO: Found 5 targets...
//cargo_workspace/rng:rng_bindgen (07cfa71)
//cargo_workspace/rng:rng_shared (07cfa71)
@crate_index_cargo_workspace__wgpu-0.15.0//:wgpu (07cfa71)
@crate_index_cargo_workspace__wgpu-core-0.15.0//:wgpu_core (07cfa71)
@crate_index_cargo_workspace__wgpu-hal-0.15.1//:wgpu_hal (07cfa71)
@crate_index_cargo_workspace__ash-0.37.2-1.3.238//:ash (07cfa71)
INFO: Elapsed time: 1.040s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 0 total actions
```

However, if you look at the `wgpu-hal` [Cargo.toml](https://github.com/gfx-rs/wgpu/blob/41de797c745d317e93b9cf50e7446faff7f65954/wgpu-hal/Cargo.toml#L32), it's listed as an optional dependency that's only enabled for the `vulkan` feature.

## Steps to reproduce

I've made a small reproduction of the problem using one of the rules_rust examples. The main changes I made are:

- Add a wasm build in the [BUILD](https://github.com/Dig-Doug/rules_rust/blob/wgpu-test/examples/crate_universe/cargo_workspace/rng/BUILD.bazel)
- Add `wgpu` as a dependency in the [Cargo.toml](https://github.com/Dig-Doug/rules_rust/blob/wgpu-test/examples/crate_universe/cargo_workspace/rng/Cargo.toml)

```
cd /tmp
git clone https://github.com/Dig-Doug/rules_rust.git
cd rules_rust
git checkout wgpu-test
cd examples/crate_universe/
bazel build //cargo_workspace/rng:rng_bindgen
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.