Crates.io | goiaba |
lib.rs | goiaba |
version | 0.0.3 |
created_at | 2025-09-20 18:29:17.612259+00 |
updated_at | 2025-09-23 19:37:33.703922+00 |
description | Experimental Go parser and compiler |
homepage | |
repository | https://github.com/raphamorim/goiaba |
max_upload_size | |
id | 1848107 |
size | 429,315 |
Experimental Go parser and compiler.
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("Failed to load WASM module");
let mut store = Store::new(&engine, ());
// Instantiate the module
let instance =
Instance::new(&mut store, &module, &[]).expect("Failed to instantiate module");
// Get the exported function
let add_func = instance
.get_typed_func::<(i32, i32), i32>(&mut store, "add")
.expect("Failed to get 'add' function");
// Call the function
let result = add_func
.call(&mut store, (5, 3))
.expect("Failed to call 'add' function");
// Verify the result
assert_eq!(result, 8);
}
goiaba main.go -o main.wasm
goiaba input.go --output output.wasm --verbose
# Generate a complete web project
goiaba main.go -w ./web-project
# Compile with custom output and web generation
goiaba calculator.go -o calc.wasm -w ./demo --verbose
goiaba main.go
GPL-3.0 - Raphael Amorim