bazelbuild / bazelbuild/bazel

Loaded wasm modules are not shareable between module extension and instantiated repository rules

Open
#26,974 5 comments 0 reactions 0 assignees View on GitHub
help wanted P2 team-ExternalDeps type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the bug:

I have a wasm module that converts toml to json. It's used in [rules_rs](https://github.com/dzbarsky/rules_rs/tree/main) in the hub-and-spokes pattern ("hub" `@cargo` repo provides aliases to targets in "spoke" repos, 1 repo for each crate). The module extension needs to parse the `Cargo.lock` toml file, and each spoke repo needs to parse the `Cargo.toml` in the downloaded crate. Since the download is triggered in the spoke repo via `rctx.download_and_extract`, the parsing must also occur in the spoke repo.

`repository_ctx.load_wasm` is intended to allow loading the module once and executing it repeatedly, but it's not clear how to pass the reference to the loaded module from the module extension to the spoke repos, and It seems wasteful to load the module repeatedly. (Not sure how to get the timing here, but loading this module into `wazero`, a different wasm runtime, takes around 70ms).

This hub-and-spoke model is a common pattern for rulesets that mirror package-manager dependency trees into Bazel (cargo, pnpm/rules_js, pypi/rules_python, etc.)

### Which category does this issue belong to?

_No response_

### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

_No response_

### Which operating system are you running Bazel on?

_No response_

### What is the output of `bazel info release`?

_No response_

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse HEAD` ?

```text

```

### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

_No response_

### Have you found anything relevant by searching the web?

_No response_

### Any other information, logs, or outputs that you want to share?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by tracing repository_ctx.load_wasm across the module-extension and instantiated repository-rule boundaries, then compare it with rctx.download_and_extract in the described hub-and-spoke pattern. Build a minimal reproduction based on rules_rs and verify whether a loaded module reference can be shared; done means establishing supported sharing behavior or documenting the limitation and its cost.

Written by the indexing model from the issue text.

Assessment

Tech stack
wasm
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.