Skip to content

Commit ad98571

Browse files
committed
feat: migrate to vanity imports
Signed-off-by: Andrew Steurer <[email protected]>
1 parent 85d10eb commit ad98571

File tree

34 files changed

+179
-1124
lines changed

34 files changed

+179
-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: 22 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 `wit-bindgen-go`, 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,20 @@ 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
32+
- `go.bytecodealliance.org/pkg/wit/runtime`: defines low-level functions for supporting the component model ABI
2333
- `<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
2434
- 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
2535
- `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
2636
- The exported resource type definitions must be provided by the application developer
2737
- 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
38+
- (if needed) `go.bytecodealliance.org/pkg/wit/types`:
39+
- defines `Tuple<N>` types as required by the WIT world
40+
- defines an `Option` type as required by the WIT world
41+
- defines a `Result` type as required by the WIT world
42+
- defines a `Unit` type as required by the WIT world
43+
- defines a `StreamReader` and `StreamWriter` types as required by the WIT world
44+
- defines a `FutureReader` and `FutureWriter` types as required by the WIT world
45+
- (if needed) `go.bytecodealliance.org/pkg/wit/async`: defines low-level functions for integrating the Go scheduler with the component model async ABI
3546

3647
Note that async support currently requires [a patched version of
3748
Go](https://github.com/dicej/go/releases/tag/go1.25.5-wasi-on-idle). Code
@@ -60,7 +71,7 @@ interface foo {
6071
a: s32,
6172
b: string,
6273
}
63-
74+
6475
echo: func(x: thing) -> tuple<s32, string>;
6576
}
6677
@@ -89,6 +100,7 @@ func Echo(x Thing) (int32, string) {
89100
return x.A, x.B
90101
}
91102
EOF
103+
go mod tidy
92104
GOARCH="wasm" GOOS="wasip1" go build -o core.wasm -buildmode=c-shared -ldflags=-checklinkname=0
93105
wasm-tools component embed -w test ../world.wit core.wasm -o core-with-wit.wasm
94106
wasm-tools component new --adapt ../wasi_snapshot_preview1.reactor.wasm core-with-wit.wasm -o component.wasm
@@ -106,6 +118,7 @@ func Run() (int32, string) {
106118
return Echo(Thing{42, "hello, world!"})
107119
}
108120
EOF
121+
go mod tidy
109122
GOARCH="wasm" GOOS="wasip1" go build -o core.wasm -buildmode=c-shared -ldflags=-checklinkname=0
110123
wasm-tools component embed -w runner ../world.wit core.wasm -o core-with-wit.wasm
111124
wasm-tools component new --adapt ../wasi_snapshot_preview1.reactor.wasm core-with-wit.wasm -o component.wasm

0 commit comments

Comments
 (0)