Goiaba An experimental Go parser and WebAssembly compiler written in Rust. Goiaba translates Go source code into WebAssembly bytecode, enabling Go programs to run in web browsers and other WebAssembly environments. Features Parse Go source code into an Abstract Syntax Tree (AST) Compile Go functions to WebAssembly modules Support for fundamental Go language features (functions, control flow, arithmetic) Export Go functions for use in JavaScript/WebAssembly environments Export Go functions for use in Rust through C ABI Export Go functions for use in Zig through C ABI Command-line interface for compilation Programmatic API for integration into Rust projects Installation As a CLI Tool cargo install goiaba As a Library Add to your Cargo.toml : [ dependencies ] goiaba = " * " Usage Command Line Interface Basic compilation: goiaba main.go -o main.wasm Compile with verbose output: goiaba input.go --output output.wasm --verbose Generate a complete web project with HTML and JavaScript: goiaba main.go -w ./web-project Advanced usage with multiple options: goiaba calculator.go -o calc.wasm -w ./demo --verbose Library Usage Basic Compilation use goiaba :: wasm :: compiler :: compile_str ; fn main ( ) { let go_source = r#" package main //export add func add(x int, y int) int { return x + y } "# ; let wasm_bytes = compile_str ( go_source ) . expect ( "Failed to compile Go to WASM" ) ; // Write to file or use with a WASM runtime std :: fs :: write ( "output.wasm" , wasm_bytes ) . expect ( "Failed to write WASM file" ) ; } Executing Compiled WASM use goiaba :: wasm :: compiler :: compile_str ; use wasmtime :: { Engine , Instance , Module , Store } ; fn main ( ) { let go_source = r#" package main //export add func add(x int, y int) int { return x + y } "# ; let wasm_bytes = compile_str ( go_source ) . expect ( "Failed to compile Go to WASM" ) ; // Create a WASM runtime let engine = Engine :: default ( ) ; let module = Module :: from_binary ( & engine , & wasm_bytes ) . expect ( "Fai...
First seen: 2025-10-09 17:20
Last seen: 2025-10-09 23:21