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

"bad magic number" from wasm blob built with Go #81

Closed
maddyblue opened this issue Nov 14, 2019 · 4 comments
Closed

"bad magic number" from wasm blob built with Go #81

maddyblue opened this issue Nov 14, 2019 · 4 comments
Assignees
Labels
🐞 bug Something isn't working

Comments

@maddyblue
Copy link

I have a small go file:

package w

func sum(x, y int) int {
	return x + y
}

I build it to a wasm blob:

GOOS=js GOARCH=wasm go build -o web.wasm w/w.go

But when running wasmer.NewInstance on it, I get:

Failed to instantiate the module:
    compile error: Validation error "Bad magic number"

Does go not build compatible wasm blobs?

@maddyblue maddyblue added the 🐞 bug Something isn't working label Nov 14, 2019
@Hywan
Copy link
Contributor

Hywan commented Nov 15, 2019

wasm2wat tells me the same. The resulting web.wasm file contains this:

!<arch>
__.PKGDEF       0           0     0     644     118       `
go object js wasm go1.12.8 X:framepointer
build id "f4e5LZ0A-5ohVijh4Sns/xwk6yYDmaERJ6X8P8yL1"


$$B
i

@Hywan Hywan self-assigned this Nov 15, 2019
@Hywan
Copy link
Contributor

Hywan commented Nov 18, 2019

I'm not sure Go can generate a WebAssembly module from a library only, it seems to work for a binary only.

I'm closing the issue since it's not related to this project, but feel free to re-open at any moment :-)!

@Hywan Hywan closed this as completed Nov 18, 2019
@waynr
Copy link

waynr commented Nov 20, 2019

For future explorers of the Wasm frontiers, I have gotten past this problem by compiling to wasm with tinygo

@Hywan
Copy link
Contributor

Hywan commented Nov 22, 2019

Yup, tinygo seems a nice solution for this kind of usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants