Skip to content

wit/bindgen: fix wasm-tools WIT generation bugs#287

Merged
ydnar merged 15 commits intomainfrom
ydnar/issue281
Jan 27, 2025
Merged

wit/bindgen: fix wasm-tools WIT generation bugs#287
ydnar merged 15 commits intomainfrom
ydnar/issue281

Conversation

@ydnar
Copy link
Collaborator

@ydnar ydnar commented Jan 20, 2025

Errors from wasm-tools were being silently swallowed, masking a number of related issues:

  1. WIT keywords in qualified interface or package names (like import foo:foo/flags were not being escaped (foo:foo/%flags).
  2. Errors from wasm-tools invocations (in wasm) were being silently ignored. They are now logged and returned. Errors returned from wasm-tools component embed are now fatal.
  3. Testdata tests in package wit/bindgen now supply a logger to Go().

The synthetic world now uses the original WIT package, to allow inline import foo: interface { ... } with inline use statements that refer to other interfaces or worlds in the same package.

Fixes #281.

@ydnar ydnar self-assigned this Jan 21, 2025
@ydnar ydnar marked this pull request as ready for review January 21, 2025 01:51
@ydnar ydnar merged commit 7ef22df into main Jan 27, 2025
15 checks passed
@ydnar ydnar deleted the ydnar/issue281 branch January 27, 2025 18:35
sd2k added a commit to sd2k/tinygo that referenced this pull request Feb 24, 2025
This commit switches from wasm-tools-go to the newer
go.bytecodealliance.org repository.

Right now it's pinned to the latest commit on the `main` branch
because there were some important fixes in
bytecodealliance/go-modules#287, but once
there's been a new release we can switch to a proper version.

The `cm` package moved from a submodule to a separate module, so
the Makefile has been updated to reflect that. The `wasi-syscall`
and `wasi-cm` Make targets needed updating to work with the latest
versions of the tooling.

Unfortunately, building with this version doesn't actually work due
to an import cycle. For example, trying to build the [example] with:

```bash
$ GOTOOLCHAIN=go1.23.6 ../../go/tinygo/build/tinygo build -target=wasip2 -o add.wasm -wit-package wit/add.wit -wit-world adder main.go

package command-line-arguments
        imports runtime
        imports internal/cm
        imports encoding/json
        imports fmt
        imports os
        imports io/fs
        imports time
        imports syscall
        imports internal/cm: import cycle not allowed

package command-line-arguments
        imports runtime
        imports internal/cm
        imports encoding/json
        imports encoding/base64
        imports encoding/binary
        imports slices
        imports iter
        imports runtime: import cycle not allowed
```

I'm pretty sure this was caused by
bytecodealliance/go-modules#279 which added the
`encoding/json` import.

[example]: https://component-model.bytecodealliance.org/language-support/go.html
sd2k added a commit to sd2k/tinygo that referenced this pull request Feb 24, 2025
This commit switches from wasm-tools-go to the newer
go.bytecodealliance.org repository.

Right now it's pinned to the latest commit on the `main` branch
because there were some important fixes in
bytecodealliance/go-modules#287, but once
there's been a new release we can switch to a proper version.

The `cm` package moved from a submodule to a separate module, so
the Makefile has been updated to reflect that. The `wasi-syscall`
and `wasi-cm` Make targets needed updating to work with the latest
versions of the tooling.

Unfortunately, building with this version doesn't actually work due
to an import cycle. For example, trying to build the [example] with:

```bash
$ GOTOOLCHAIN=go1.23.6 ../../go/tinygo/build/tinygo build -target=wasip2 -o add.wasm -wit-package wit/add.wit -wit-world adder main.go

package command-line-arguments
        imports runtime
        imports internal/cm
        imports encoding/json
        imports fmt
        imports os
        imports io/fs
        imports time
        imports syscall
        imports internal/cm: import cycle not allowed

package command-line-arguments
        imports runtime
        imports internal/cm
        imports encoding/json
        imports encoding/base64
        imports encoding/binary
        imports slices
        imports iter
        imports runtime: import cycle not allowed
```

I'm pretty sure this was caused by
bytecodealliance/go-modules#279 which added the
`encoding/json` import.

[example]: https://component-model.bytecodealliance.org/language-support/go.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bindgen 0.5.0 fails to handle (transitive?) versioned imports

1 participant