4 releases
| 0.3.5 | Sep 10, 2025 |
|---|---|
| 0.3.4 |
|
| 0.2.1 | Aug 27, 2025 |
| 0.2.0 | Jun 28, 2025 |
#1339 in Web programming
174 downloads per month
43KB
947 lines
Wasm Go
🐹 Go WebAssembly plugin for Wasmrun - compile Go projects to WebAssembly using TinyGo.
Installation
As Wasm Plugin in Wasmrun
wasmrun plugin install wasmgo
wasmrun ./my-go-project
Standalone CLI (Experimental)
cargo install wasmgo --features cli
wasmgo compile ./my-go-project
Requirements
Usage
With Wasmrun
# Run with live reload
wasmrun ./my-go-project --watch
# Compile with optimization
wasmrun compile ./my-go-project --optimization size
Standalone CLI (Only for Testing)
# Check project compatibility
wasmgo check ./my-go-project
# Compile project
wasmgo compile ./my-go-project
# Check dependencies
wasmgo deps --install
Plugin Configuration
Plugin configuration is stored in Cargo.toml under the [package.metadata.wasm-plugin] section:
[package.metadata.wasm-plugin]
name = "go"
extensions = ["go"]
entry_files = ["go.mod", "main.go", "cmd/main.go", "app.go"]
[package.metadata.wasm-plugin.capabilities]
compile_wasm = true
compile_webapp = false
live_reload = true
optimization = true
custom_targets = ["wasm"]
[package.metadata.wasm-plugin.dependencies]
tools = ["tinygo", "go"]
This follows Rust ecosystem conventions for tool-specific metadata.
Project Structure
Supports standard Go project layouts:
my-go-project/
├── go.mod
├── main.go
└── ...
Or with cmd directory:
my-go-project/
├── go.mod
├── cmd/
│ └── main.go
└── ...
Example
mkdir hello-wasm && cd hello-wasm
go mod init hello-wasm
cat > main.go << 'EOF'
package main
import "fmt"
func main() {
fmt.Println("Hello, WebAssembly from Go!")
}
EOF
wasmrun
Development
# Build
just build
# Test with example
just create-example hello
just test-example hello
# Validate configuration
just validate-config
# Install locally
just install
Plugin Architecture
This plugin implements the Wasm plugin interface and reads its configuration from Cargo.toml. The configuration includes:
- Extensions: File extensions the plugin handles
- Entry Files: Priority order for entry point detection
- Capabilities: What features the plugin supports
- Dependencies: Required external tools
License
Dependencies
~0.6–1.4MB
~31K SLoC