Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 27 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ allow_attributes_without_reason = 'warn'
anyhow = { workspace = true}
clap = { version = "4.5.53", features = ["derive"] }
regex = "1.12.2"
wat = { version = "1.243.0"}
# TODO: Update once v0.52.0 releases
wit-bindgen-go = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "822fdb1ae6279933be9f0a6b18901adf9997398d" }
wit-component = "0.244.0"
wit-parser = "0.244.0"
wat = { version = "1.245.1"}
wit-bindgen-go = { git = "https://github.com/asteurer/wit-bindgen", rev = "ad98571fdd93de6057c4572e16ba5c6f5ac17ae7" }
wit-component = "0.245.1"
wit-parser = "0.245.1"
2 changes: 1 addition & 1 deletion examples/wasip2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
### Prerequisites
- [**componentize-go**](https://github.com/bytecodealliance/componentize-go) - Latest version
- [**go**](https://go.dev/dl/) - v1.25+
- [**wasmtime**](https://github.com/bytecodealliance/wasmtime) - Latest version
- [**wasmtime**](https://github.com/bytecodealliance/wasmtime) - v40.0.2

### Run
```sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package export_wasi_http_incoming_handler
import (
. "wit_component/wasi_http_types"

. "github.com/bytecodealliance/wit-bindgen/wit_types"
. "go.bytecodealliance.org/pkg/wit/types"
)

// Handle the specified `Request`, returning a `Response`
Expand Down
2 changes: 1 addition & 1 deletion examples/wasip3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ everything is merged, we'll be able to switch to the upstream releases.
### Prerequisites
- [**componentize-go**](https://github.com/bytecodealliance/componentize-go) - Latest version
- [**go**](https://github.com/dicej/go/releases/tag/go1.25.5-wasi-on-idle) - The [Makefile](./Makefile) installs the patched version of Go.
- [**wasmtime**](https://github.com/bytecodealliance/wasmtime) - Latest version
- [**wasmtime**](https://github.com/bytecodealliance/wasmtime) - v40.0.2

This will build the dependencies, generate Go bindings from the
`wasi:http@0.3.0-rc-2025-09-16` WIT files, build the component, and run it using
Expand Down
6 changes: 3 additions & 3 deletions examples/wasip3/export_wasi_http_handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"wit_component/wasi_http_handler"
. "wit_component/wasi_http_types"

. "github.com/bytecodealliance/wit-bindgen/wit_types"
. "go.bytecodealliance.org/pkg/wit/types"
)

// Handle the specified `Request`, returning a `Response`
Expand Down Expand Up @@ -58,7 +58,7 @@ func Handle(request *Request) Result[*Response, ErrorCode] {
channel := make(chan Tuple2[string, string])
for _, url := range urls {
go func() {
channel <- Tuple2[string, string]{url, getSha256(url)}
channel <- Tuple2[string, string]{F0: url, F1: getSha256(url)}
}()
}

Expand All @@ -70,7 +70,7 @@ func Handle(request *Request) Result[*Response, ErrorCode] {

response, send := ResponseNew(
FieldsFromList([]Tuple2[string, []uint8]{
Tuple2[string, []uint8]{"content-type", []uint8("text/plain")},
{F0: "content-type", F1: []uint8("text/plain")},
}).Ok(),
Some(rx),
trailersFuture(),
Expand Down
18 changes: 16 additions & 2 deletions src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn generate_bindings(
output: Option<&Path>,
pkg_name: Option<String>,
) -> Result<()> {
let (resolve, world) = parse_wit(wit_path, world, features, all_features)?;
let (mut resolve, world) = parse_wit(wit_path, world, features, all_features)?;
let mut files = Default::default();

let format = if should_format {
Expand All @@ -22,14 +22,24 @@ pub fn generate_bindings(
wit_bindgen_go::Format::False
};

// If the user wants to create a package rather than a standalone binary, provide them with the
// go.bytecodealliance.org/pkg version that needs to be placed in their go.mod file
let mut message: Option<String> = None;
if pkg_name.is_some() {
message = Some(format!(
"Success! Please add the following line to your 'go.mod' file:\n\nrequire {}",
wit_bindgen_go::remote_pkg_version()
));
}

wit_bindgen_go::Opts {
generate_stubs,
format,
pkg_name,
..Default::default()
}
.build()
.generate(&resolve, world, &mut files)?;
.generate(&mut resolve, world, &mut files)?;

let output_path = match output {
Some(p) => make_path_absolute(&p.to_path_buf())?,
Expand All @@ -45,5 +55,9 @@ pub fn generate_bindings(
std::fs::write(&file_path, contents)?;
}

if let Some(msg) = message {
println!("{msg}");
}

Ok(())
}
Loading