-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Problem Summary
Our Go WebAssembly components using go_wasm_component
are currently limited to the wasi:cli/command
world, preventing the creation of custom WIT interface exports. This means we can only build WASI CLI applications, not true WIT-defined component interfaces with custom functions like add()
, subtract()
, etc.
Root Cause Analysis
The issue stems from upstream TinyGo limitations rather than our Bazel rules implementation. TinyGo currently hardcodes the WASI command world and cannot handle custom WIT worlds properly.
Current Behavior
When we try to build Go components with custom WIT interfaces:
go_wasm_component(
name = "calculator_simple_binding",
srcs = ["calculator_simple_binding.go"],
go_mod = "go.mod",
wit = ":simple_calculator_wit",
world = "calculator-world",
)
The resulting component exports wasi:cli/command@0.2.0
instead of our intended example:calculator/calculator@1.0.0
interface.
Technical Details
The TinyGo compilation process ignores custom --wit-world
parameters:
tinygo build -target=wasip2 -o calculator.wasm \
--wit-package wit/simple-calculator.wit \
--wit-world calculator-world .
This produces a component that validates against WASI CLI expectations rather than custom WIT interfaces.
Upstream TinyGo Issues
This limitation is documented in several TinyGo repository issues:
- Issue #4843: "Support for custom WIT worlds" - Core limitation preventing custom interface definitions
- Issue #4587: "WASI Preview 2 custom interfaces" - Discusses the hardcoded world limitation
- Issue #4752: "WIT binding generation improvements" - Related to proper WIT interface handling
- PR #4934: "Add support for custom WIT worlds in wasip2 target" - THE SOLUTION
Impact on rules_wasm_component
This upstream limitation affects our ability to:
- Create true WebAssembly Component Model interfaces in Go
- Build components that export custom functions rather than CLI commands
- Integrate Go components with other language components via WIT interfaces
- Demonstrate complete Component Model capabilities in our examples
Current Workaround
Our current implementation correctly:
- Integrates
wit-bindgen-go
for binding generation - Passes WIT files and world parameters to TinyGo
- Generates proper Go binding structures
However, TinyGo itself ignores the custom world specification and defaults to wasi:cli/command
.
Next Steps
- Monitor TinyGo PR #4934 - This PR specifically addresses custom WIT world support
- Test with TinyGo development builds once the PR is merged
- Update our TinyGo toolchain version when a release includes this functionality
- Add integration tests for custom WIT world validation once upstream support is available
Verification Command
To verify component exports:
wasm-tools component wit component.wasm
Currently shows wasi:cli/command@0.2.0
instead of custom interfaces.
References
- TinyGo Issue #4843
- TinyGo Issue #4587
- TinyGo Issue #4752
- TinyGo PR #4934 - Solution in progress
This issue will be resolved once TinyGo adds proper custom WIT world support in their wasip2 target implementation.