bytecodealliance / go-modules

WebAssembly, WASI, and Component Model tools for Go
https://go.bytecodealliance.org
Apache License 2.0
72 stars 12 forks source link

Exported WebAssembly function cabi_realloc #184

Open elewis787 opened 1 month ago

elewis787 commented 1 month ago

Are there details on why the export tags for cabi_realloc were removed in 88cdc52

This still seems relevant when targeting wasip1 and using the wasi adapters ( such as the reactor adapter ) to build a component. I have tested this by adding my own cabi_realloc function and using the export tags, then converting to a wasip2 component using the wasmtime adapters.

GOOS=wasip1 GOARCH=wasm go build -o main.wasm main.go

wasm-tools component embed --world word ./wit/lex.wit main.wasm -o main.embed.wasm
wasm-tools component new -o main.component.wasm --adapt wasi_snapshot_preview1=wasi_snapshot_preview1.reactor.wasm main.embed.wasm

experimenting here https://github.com/elewis787/lex

I believe this relates to the work at https://github.com/tinygo-org/tinygo/pull/4451 and https://github.com/golang/go/issues/65199 but hope for some details.

My goal is to use the wit bindings for exported functions and build a wasip2 reactor component in tinygo or go.

ydnar commented 1 month ago

The affected code is not used in the current TinyGo implementation.

In suppose we could make this work in Go, but not TinyGo.

elewis787 commented 1 month ago

I could see it being helpful for go.

Using go 1.24, I was able to use it and then convert a wasip1 module to a component with the adapters. There are likely edge cases I haven't run into.

Mainly just wanted to see if there was more context that I wasn't thinking of 😄.

Calling out that I did use this in a wasmtime-go host implementation when executing an exported function in a module compiled in both go and tiny-go targeting wasip1.

ydnar commented 3 weeks ago

Have you had any luck just using go:linkname with this package, or reimplementing it in your own package?

elewis787 commented 3 weeks ago

Reimplementing it in my own package worked. I will look into the go:linkname.