Skip to content

Go Component WIT World Limitations - TinyGo Hardcoded to wasi:cli/command #80

@avrabe

Description

@avrabe

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:

  1. Create true WebAssembly Component Model interfaces in Go
  2. Build components that export custom functions rather than CLI commands
  3. Integrate Go components with other language components via WIT interfaces
  4. 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

  1. Monitor TinyGo PR #4934 - This PR specifically addresses custom WIT world support
  2. Test with TinyGo development builds once the PR is merged
  3. Update our TinyGo toolchain version when a release includes this functionality
  4. 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

This issue will be resolved once TinyGo adds proper custom WIT world support in their wasip2 target implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions