Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile for wasm32-unknown-unknown without wasi #4752

Open
berdav opened this issue Feb 23, 2025 · 1 comment
Open

compile for wasm32-unknown-unknown without wasi #4752

berdav opened this issue Feb 23, 2025 · 1 comment
Labels
question Question about usage of TinyGo wasm WebAssembly

Comments

@berdav
Copy link

berdav commented Feb 23, 2025

Hello, I need to compile for wasm32-unknown-unknown architecture. I'm trying to use wasm target with a WIT file like this:

package tinygo:test;

interface test {
  record log {
    message: string,
  }
}

world tinygo-test {
  export test;
}

And an empty main file

package main

func main() {
}

But it leads to an error referring to wasi preview 1.

$ tinygo build -target=wasm -o tgotest.wasm --wit-packag
e ./world.wit --wit-world tinygo-test main.go
error: failed to encode a component from module

Caused by:
    0: failed to decode world from module
    1: module was not valid
    2: failed to resolve import `wasi_snapshot_preview1::proc_exit`
    3: module requires an import interface named `wasi_snapshot_preview1`
`wasm-tools component new` failed: exit status 1

Currently I workaround this, providing a special json file like this as the target:

{
        "llvm-target":   "wasm32-unknown-unknown",
        "cpu":           "generic",
        "features":      "",
        "build-tags":    [
                "tinygo.wasm",
                "wasm_unknown"
        ],
        "buildmode":     "c-shared",
        "goos":          "linux",
        "goarch":        "arm",
        "linker":        "wasm-ld",
        "libc":          "wasmbuiltins",
        "rtlib":         "none",
        "gc":            "none",
        "scheduler":     "none",
        "default-stack-size": 8192,
        "cflags": [ ],
        "ldflags": [
                "--no-entry"
        ],
        "extra-files": [
                "/tmp/c-glue.c"
        ]
}

But it requires C files to implement functions that are still searched by tinygo (namely: abort, free, and malloc).

How can I avoid the use of this workaround and compile wasm without any reference to wasi (p1 or p2) or javascript requirements?

Thanks.

@deadprogram
Copy link
Member

See https://github.com/wasmvision/wasmcv for example of how to do this.

@deadprogram deadprogram added wasm WebAssembly question Question about usage of TinyGo labels Feb 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question about usage of TinyGo wasm WebAssembly
Projects
None yet
Development

No branches or pull requests

2 participants