Skip to content

Go: make bindings testable in native Go #1555

@jamesstocktonj1

Description

@jamesstocktonj1

Description

When attempting to run unit tests I get the following compilation error when wit-bindgen go bindings are imported:

$ go test ./...
# <go-project>/types/wasi_logging_logging
<go-project>/types/wasi_logging_logging/wit_bindings.go:42:6: missing function body
FAIL    <go-project> [build failed]
FAIL

With the bindings file showing the following:

...
//go:wasmimport wasi:logging/logging@0.1.0-draft log
func wasm_import_log(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32)
...

wit-bindgen-go got round this issue by including a blank empty.s assembly file within each of the directories which includes a Go file that uses the //go:wasmimport directive. See here for example.

This tricks the Go compile into thinking there is an assembly implementation of the function which has been declared, and so it no longer complains about the missing function body.

Is this something which we could include in these bindings to get around this build error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    gen-goRelated to the Go code generator

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions