Skip to content

Commit ff9543d

Browse files
authored
feat: migrate to vanity imports (#1548)
* feat: migrate to vanity imports Signed-off-by: Andrew Steurer <[email protected]> * fix(go): improving documentation Signed-off-by: Andrew Steurer <[email protected]> --------- Signed-off-by: Andrew Steurer <[email protected]>
1 parent e182ef5 commit ff9543d

File tree

34 files changed

+182
-1124
lines changed

34 files changed

+182
-1124
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
[submodule "tests/codegen/wasi-clocks"]
1414
path = tests/codegen/wasi-clocks
1515
url = https://github.com/WebAssembly/wasi-clocks
16+
[submodule "crates/go/src/pkg"]
17+
path = crates/go/src/pkg
18+
url = https://github.com/bytecodealliance/go-pkg

crates/go/README.md

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@
22

33
This tool generates Go bindings for a chosen WIT world.
44

5+
## Contributing
6+
7+
If changes need to be made to the `go.bytecodealliance.org/pkg` files referenced by the generated bindings, here are the steps that need to be taken:
8+
- Make the required changes to the [bytecodealliance/go-pkg](https://github.com/bytecodealliance/go-pkg) Go files and tag a release.
9+
- Update the `crates/go/src/pkg` git submodule to reflect the most-recent release of `go-pkg`.
10+
- Update the `REMOTE_PKG_VERSION` constant in [lib.rs](./src/lib.rs) to reflect the most-recent release of `go-pkg`.
11+
- Make the required changes to `wit-bindgen-go`.
12+
513
## Usage
614

15+
The easiest way to use `wit-bindgen-go` is through the [componentize-go](https://github.com/bytecodealliance/componentize-go) tool. See below for using `wit-bindgen-go` directly.
16+
717
To generate bindings with this crate, issue the `go` subcommand to `wit-bindgen`:
818

919
```bash
@@ -19,19 +29,24 @@ world provided:
1929
- You can replace this with your own version (e.g. referencing third party dependencies) if desired
2030
- `wit_bindings.go`: defines the `main` package for the module, including low-level, `//go:export`-annotated entrypoint functions corresponding to exported functions
2131
- These entrypoint functions in turn call high-level functions which must be provided by the application developer
22-
- `wit_runtime/wit_runtime.go`: defines low-level functions for supporting the component model ABI
2332
- `<name>/wit_bindings.go`: defines any types generated for the interface named `<name>` (or `wit_world` for WIT types defined at the world level), plus any imported functions
2433
- Note that the types placed in these files include all types for both imported and exported interfaces, except for exported resource types and any types which depend on exported resource types
2534
- `export_<name>/wit_bindings.go`: defines intrinsics for use with any exported resource types generated for the interface named `<name>` (or `wit_world` for WIT types defined at the world level), plus any types which depend on those exported resource types, plus any exported functions
2635
- The exported resource type definitions must be provided by the application developer
2736
- The `export_<name>` package is also the place to define any exported functions
28-
- (if needed) `wit_types/wit_tuples.go`: defines `Tuple<N>` types as required by the WIT world
29-
- (if needed) `wit_types/wit_async.go`: defines low-level functions for integrating the Go scheduler with the component model async ABI
30-
- (if needed) `wit_types/wit_option.go`: defines an `Option` type if required by the WIT world
31-
- (if needed) `wit_types/wit_result.go`: defines an `Result` type if required by the WIT world
32-
- (if needed) `wit_types/wit_unit.go`: defines an `Unit` type if required by the WIT world
33-
- (if needed) `wit_types/wit_stream.go`: defines a `StreamReader` and `StreamWriter` types if required by the WIT world
34-
- (if needed) `wit_types/wit_future.go`: defines a `FutureReader` and `FutureWriter` types if required by the WIT world
37+
38+
The generated files will reference the following files in the [bytecodealliance/go-pkg](https://github.com/bytecodealliance/go-pkg) repository:
39+
40+
- `go.bytecodealliance.org/pkg/wit/runtime`: defines low-level functions for supporting the component model ABI
41+
- `go.bytecodealliance.org/pkg/wit/types` (if needed):
42+
- defines `Tuple<N>` types as required by the WIT world
43+
- defines an `Option` type as required by the WIT world
44+
- defines a `Result` type as required by the WIT world
45+
- defines a `Unit` type as required by the WIT world
46+
- defines a `StreamReader` and `StreamWriter` types as required by the WIT world
47+
- defines a `FutureReader` and `FutureWriter` types as required by the WIT world
48+
- `go.bytecodealliance.org/pkg/wit/async` (if needed): defines low-level functions for integrating the Go scheduler with the component model async ABI
49+
3550

3651
Note that async support currently requires [a patched version of
3752
Go](https://github.com/dicej/go/releases/tag/go1.25.5-wasi-on-idle). Code
@@ -60,7 +75,7 @@ interface foo {
6075
a: s32,
6176
b: string,
6277
}
63-
78+
6479
echo: func(x: thing) -> tuple<s32, string>;
6580
}
6681
@@ -89,6 +104,7 @@ func Echo(x Thing) (int32, string) {
89104
return x.A, x.B
90105
}
91106
EOF
107+
go mod tidy
92108
GOARCH="wasm" GOOS="wasip1" go build -o core.wasm -buildmode=c-shared -ldflags=-checklinkname=0
93109
wasm-tools component embed -w test ../world.wit core.wasm -o core-with-wit.wasm
94110
wasm-tools component new --adapt ../wasi_snapshot_preview1.reactor.wasm core-with-wit.wasm -o component.wasm
@@ -106,6 +122,7 @@ func Run() (int32, string) {
106122
return Echo(Thing{42, "hello, world!"})
107123
}
108124
EOF
125+
go mod tidy
109126
GOARCH="wasm" GOOS="wasip1" go build -o core.wasm -buildmode=c-shared -ldflags=-checklinkname=0
110127
wasm-tools component embed -w runner ../world.wit core.wasm -o core-with-wit.wasm
111128
wasm-tools component new --adapt ../wasi_snapshot_preview1.reactor.wasm core-with-wit.wasm -o component.wasm

0 commit comments

Comments
 (0)