Stream: git-wasmtime

Topic: wasmtime / Issue #2247 unknown import: `go::debug` has no...


view this post on Zulip Wasmtime GitHub notifications bot (Sep 30 2020 at 17:55):

nu8 opened Issue #2247:

If I have a Go file like this:

package main
import "fmt"

func main() {
   fmt.Println("May")
}

I can compile like this:

$env:GOARCH = 'wasm'
$env:GOOS = 'js'
go build -o main.wasm a.go

but then I get this error:

PS C:\Users\spenny\Desktop> .\wasmtime.exe .\main.wasm
Error: failed to run main module .\main.wasm

Caused by:
0: failed to instantiate ".\\main.wasm"
1: unknown import: go::debug has not been defined


view this post on Zulip Wasmtime GitHub notifications bot (Sep 30 2020 at 17:55):

nu8 labeled Issue #2247:

If I have a Go file like this:

package main
import "fmt"

func main() {
   fmt.Println("May")
}

I can compile like this:

$env:GOARCH = 'wasm'
$env:GOOS = 'js'
go build -o main.wasm a.go

but then I get this error:

PS C:\Users\spenny\Desktop> .\wasmtime.exe .\main.wasm
Error: failed to run main module .\main.wasm

Caused by:
0: failed to instantiate ".\\main.wasm"
1: unknown import: go::debug has not been defined


view this post on Zulip Wasmtime GitHub notifications bot (Sep 30 2020 at 17:56):

nu8 edited Issue #2247:

If I have a Go file like this:

package main
import "fmt"

func main() {
   fmt.Println("May")
}

I can compile like this:

$env:GOARCH = 'wasm'
$env:GOOS = 'js'
go build -o main.wasm a.go

but then I get this error:

PS C:\Users\spenny\Desktop> .\wasmtime.exe .\main.wasm
Error: failed to run main module .\main.wasm

Caused by:
0: failed to instantiate ".\\main.wasm"
1: unknown import: go::debug has not been defined


view this post on Zulip Wasmtime GitHub notifications bot (Sep 30 2020 at 18:35):

bjorn3 commented on Issue #2247:

Go needs a support file that is written in javascript. This includes the go::debug function. https://github.com/golang/go/blob/master/misc/wasm/wasm_exec.js

view this post on Zulip Wasmtime GitHub notifications bot (Oct 01 2020 at 22:51):

alexcrichton commented on Issue #2247:

Thanks for the report! As @bjorn3 mentioned, though, the wasmtime CLI only predefines the WASI imports, not imports for other runtimes (like Go's). You can provide other wasm modules to load as well, but I don't think there's a wasm version of Go's runtime available right now. I'm not sure if Go supports "standalone" wasm without JS, but that will need to be your compile target right now to natively run in Wasmtime with no extra arguments added.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 01 2020 at 22:51):

alexcrichton closed Issue #2247:

If I have a Go file like this:

package main
import "fmt"

func main() {
   fmt.Println("May")
}

I can compile like this:

$env:GOARCH = 'wasm'
$env:GOOS = 'js'
go build -o main.wasm a.go

but then I get this error:

PS C:\Users\spenny\Desktop> .\wasmtime.exe .\main.wasm
Error: failed to run main module .\main.wasm

Caused by:
0: failed to instantiate ".\\main.wasm"
1: unknown import: go::debug has not been defined


view this post on Zulip Wasmtime GitHub notifications bot (Oct 01 2020 at 22:59):

nu8 commented on Issue #2247:

@alexcrichton so whats the "right" way to do this? I prefer Go, but Im not strictly tied to it.

Does some language, like maybe Rust or something, have a way to do the following? Write a Rust program (perhaps some restriction on what parts of Rust can be used), compile to WASM, then feed the WASM blob to some Runtime? Ideally I dont want to have to deal with any JavaScript, and any step in the process.

If all that is not possible cool, but online some people have been present WASM like I am describing, and I am just curious if thats actually possible with any of the major languages.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 01 2020 at 23:00):

nu8 edited a comment on Issue #2247:

@alexcrichton so whats the "right" way to do this? I prefer Go, but Im not strictly tied to it.

Does some language, like maybe Rust or something, have a way to do the following? Write a Rust program (perhaps some restriction on what parts of Rust can be used), compile to WASM, then feed the WASM blob to some Runtime? Ideally I dont want to have to deal with any JavaScript, and any step in the process.

If all that is not possible cool, but online some people have been presenting WASM like I am describing, and I am just curious if thats actually possible with any of the major languages.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 01 2020 at 23:01):

nu8 edited a comment on Issue #2247:

@alexcrichton so whats the "right" way to do this? I prefer Go, but Im not strictly tied to it.

Does some language, like maybe Rust or something, have a way to do the following? Write a Rust program (perhaps some restriction on what parts of Rust can be used), compile to WASM, then feed the WASM blob to some Runtime? Ideally I dont want to have to deal with any JavaScript, at any step in the process.

If all that is not possible cool, but online some people have been presenting WASM like I am describing, and I am just curious if thats actually possible with any of the major languages.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 01 2020 at 23:04):

alexcrichton commented on Issue #2247:

The right thing to do here depends on what your goal is with Wasmtime. Do you only want to run the CLI? Or are you thinking of using an embedding? Where are you planning on running wasm?

In Rust/C/C++ there's a "wasm32-wasi" target which you compile for which uses WASI that Wasmtime supports.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 01 2020 at 23:10):

nu8 commented on Issue #2247:

Personally I would probably just compile some simple command line programs.
Ideally stuff that would access the filesystem or perhaps download a JSON file,
but I dont know what all WASM even allows.

Of course this is all possible now with many programming languages, but the lure
of WASM is similar to a Java JAR (as I understand it) or .NET Core, in that
anyone with those environments, regardless of OS, can just get your blob (WASM
in this case) and run it on their system.

This would perhaps all people to just distribute a WASM file, instead of stuff
like this:

https://github.com/sharkdp/fd/releases/tag/v8.1.1

where you have to distribute an executable for all the platforms you support. If
I am totally wrong about some or all of this, let me know.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 01 2020 at 23:13):

nu8 edited a comment on Issue #2247:

Personally I would probably just compile some simple command line programs.
Ideally stuff that would access the filesystem or perhaps download a JSON file,
but I dont know what all WASM even allows.

Of course this is all possible now with many programming languages, but the lure
of WASM is similar to a Java JAR (as I understand it) or .NET Core, in that
anyone with those environments, regardless of OS, can just get your blob (WASM
in this case) and run it on their system.

This would perhaps allow people to just distribute a WASM file, instead of stuff
like this:

https://github.com/sharkdp/fd/releases/tag/v8.1.1

where you have to distribute an executable for all the platforms you support. If
I am totally wrong about some or all of this, let me know.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 02 2020 at 14:26):

alexcrichton commented on Issue #2247:

Ok it sounds like for your use case simply compiling a Go program and running it in Wasmtime won't work. It is theoretically possible if you link wasmtime to a runtime which mimics Go's JS runtime, however.


Last updated: Dec 23 2024 at 13:07 UTC