Skip to content

Upgrade Native Wasm Support - #50

Open
zhaohai666 wants to merge 1 commit into
higress-group:mainfrom
zhaohai666:feature/wg-go124-native-wasm
Open

Upgrade Native Wasm Support#50
zhaohai666 wants to merge 1 commit into
higress-group:mainfrom
zhaohai666:feature/wg-go124-native-wasm

Conversation

@zhaohai666

Copy link
Copy Markdown

PR Description: Upgrade Native Wasm Support for Go 1.24
Overview
This PR fully upgrades the wasm-go SDK to natively support Go 1.24+ WASI/Wasm compilation (GOOS=wasip1), eliminating the mandatory dependency on TinyGo. A unified ABI adaptation layer is implemented to achieve dual-toolchain compatibility, supporting both traditional TinyGo compilation and official Go native Wasm compilation. This upgrade significantly improves compilation efficiency, enriches standard library compatibility, and lowers the development threshold for Higress Wasm plugins.
Background
The current wasm-go SDK relies entirely on TinyGo for Wasm building, which suffers from slow compilation speed, incomplete Go standard library support, immature debugging tools, and limited third-party ecosystem compatibility. Starting from Go 1.24, the official toolchain provides stable native WASI Wasm compilation capability, which can effectively resolve the above pain points and bring better development experience and runtime stability.
Core Changes

  1. Unified Wasm ABI Abstraction Layer
  • Defined the standard WasmABI interface in internal/abi/abi.go, covering memory management, foreign function calls, memory read/write, allocation and release capabilities

  • Implemented dual ABI implementations via build tags:

    • tinygo.go: Retain full compatibility with existing TinyGo toolchains
    • go_native.go: Native Wasm adaptation for Go 1.24+, with bump memory allocator and native mutex support
  • Provided compile-time constant judgment to automatically match the corresponding ABI implementation according to the compilation environment

  1. Full ABI Integration & Encapsulation
  • Added pkg/wrapper/abi_integration.go to implement unified callForeignFunction routing, with built-in panic recovery to enhance runtime robustness
  • Refactored core wrappers (plugin_wrapper.go, log_wrapper.go) to replace direct proxywasm calls with unified ABI layer invocation
  • Exposed public memory operation APIs: GetMemoryBuffer, ReadMemory, WriteMemory, AllocMemory, FreeMemory
  • Added complete unit tests to verify memory read/write loops and exception recovery logic
  1. Dual-Toolchain Build Script Optimization
  • Reconstructed Makefile to support one-click switching of dual compilation modes:

    • make build: Traditional TinyGo compilation (backward compatible)
    • make build-native: Go 1.24+ native Wasm compilation
    • make build-all: Build and compare artifacts of both toolchains
    • Supports independent test, lint and cleanup targets for native Wasm scenarios
  1. Compatibility & Performance Verification
  • All core packages (internal/abi, pkg/wrapper, pkg/matcher) pass full unit tests
  • All 5 official example plugins support native Wasm compilation and generate valid WASM binaries
  • Established native Wasm performance baseline: cached compilation speed is greatly optimized, with an average compilation latency of ~430ms
  • Guaranteed full backward compatibility: existing TinyGo plugins work without modification
    Test Result
  • All unit tests passed
  • 7 core SDK packages compile successfully under wasip1 platform
  • 5 demo plugins generate valid Wasm artifacts via Go native toolchain
  • Dual-toolchain switching works normally without compatibility regression
    Advantages & Optimization Outlook
    Current Improvements
  • Faster compilation: Native Go cache mechanism greatly improves iterative development efficiency
  • Complete ecology: Full support of Go standard library and mainstream third-party libraries
  • Better debuggability: Inherits Go’s mature debugging toolchain
    Subsequent Optimization Directions
  • Integrate wasm-opt to further reduce Wasm artifact size
  • Optimize module lazy initialization to reduce package volume
  • Add dual-toolchain automatic verification in CI workflow
    Risk & Mitigation
  • ABI compatibility risk: Strict dual-mode unit testing ensures consistent behavior of TinyGo and native Wasm
  • Toolchain version risk: Lock Go 1.24+ version support and reserve compatibility layers for subsequent iteration
  • Legacy plugin risk: Fully backward compatible, no modification required for existing business plugins
    Related
  • Branch: feature/wg-go124-native-wasm
  • Supports Go 1.24+ native WASI/Wasm compilation
  • Fully backward compatible with existing TinyGo build workflow

@CLAassistant

CLAassistant commented Jul 5, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Signed-off-by: zhaohaihzb <zhaohaihzb@126.com>
@zhaohai666
zhaohai666 force-pushed the feature/wg-go124-native-wasm branch from b539712 to dd4b3e0 Compare July 7, 2026 07:34
@zhaohai666 zhaohai666 closed this Jul 15, 2026
@zhaohai666 zhaohai666 reopened this Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants