Skip to content

Commit fbd4f74

Browse files
committed
merge: wit-bindgen 0.50
Merge upstream wit-bindgen 0.50.0 into the vendored bindgen subtree. - Bump wit-bindgen-core 0.49 -> 0.50 (wit-parser stays 0.243); no API churn. Non-carries (not applicable to wRPC, dropped from the merge): - the rebooted Go generator (bytecodealliance/wit-bindgen#1447, a brand-new `crates/go/` of ~4k lines plus Go runtime sources). Upstream removed its original Go backend at 0.41 and rewrote a completely different one here; wRPC's `wit-bindgen-go` is the pre-removal fork and continues independently, so the rebooted `crates/go` is dropped (and added to the merge DROP filter going forward). All subsequent Go-only upstream changes likewise do not apply. - bytecodealliance/wit-bindgen#1442 (custom Rust types for `list`) is implemented in the canonical-ABI `bindgen.rs`; wRPC already supports remapping named `list` type aliases through its per-type `with` remapping (bytecodealliance/wit-bindgen#1173, exercised by the `aliased_lists` test). - bytecodealliance/wit-bindgen#1444 (`build.rs` binding-generation helpers) changes `Opts::build()` to return a concrete generator, which is incompatible with wRPC's CLI dispatching Rust and Go generators polymorphically via `Box<dyn WorldGenerator>`; wRPC's primary path is the `generate!` macro. rust codegen (243) and go codegen (81) tests pass; `cargo clippy --workspace` and `cargo doc --workspace` are clean; wasmtime and all examples build. Assisted-by: claude:claude-opus-4-8 Upstream diff: bytecodealliance/wit-bindgen@v0.49.0...v0.50.0
2 parents 98f940a + 6f8b8e7 commit fbd4f74

3 files changed

Lines changed: 154 additions & 8 deletions

File tree

Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ wasmtime-cli-flags = { version = "45", default-features = false }
179179
wasmtime-wasi = { version = "45", default-features = false }
180180
wasmtime-wasi-http = { version = "45", default-features = false }
181181
wit-bindgen = { version = "0.45", default-features = false }
182-
wit-bindgen-core = { version = "0.49", default-features = false }
182+
wit-bindgen-core = { version = "0.50", default-features = false }
183183
wit-bindgen-wrpc = { version = "0.11", default-features = false, path = "./crates/wit-bindgen" }
184184
wit-bindgen-wrpc-go = { version = "0.13", default-features = false, path = "./crates/wit-bindgen-go" }
185185
wit-bindgen-wrpc-rust = { version = "0.11", default-features = false, path = "./crates/wit-bindgen-rust" }

crates/test/src/go.rs

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
use crate::{Compile, LanguageMethods, Runner, Verify};
2+
use anyhow::{Context as _, Result};
3+
use std::env;
4+
use std::fs;
5+
use std::path::{Path, PathBuf};
6+
use std::process::Command;
7+
8+
pub struct Go;
9+
10+
impl LanguageMethods for Go {
11+
fn display(&self) -> &str {
12+
"go"
13+
}
14+
15+
fn comment_prefix_for_test_config(&self) -> Option<&str> {
16+
Some("//@")
17+
}
18+
19+
fn should_fail_verify(
20+
&self,
21+
name: &str,
22+
config: &crate::config::WitConfig,
23+
_args: &[String],
24+
) -> bool {
25+
// TODO: We _do_ support async, but only with a build of Go that has
26+
// [this
27+
// patch](https://github.com/dicej/go/commit/40fc123d5bce6448fc4e4601fd33bad4250b36a5).
28+
// Once we upstream something equivalent, we can remove the ` || name ==
29+
// "async-trait-function.wit"` here.
30+
config.error_context || name == "async-trait-function.wit"
31+
}
32+
33+
fn default_bindgen_args_for_codegen(&self) -> &[&str] {
34+
&["--generate-stubs"]
35+
}
36+
37+
fn prepare(&self, runner: &mut Runner<'_>) -> Result<()> {
38+
let cwd = env::current_dir()?;
39+
let dir = cwd.join(&runner.opts.artifacts).join("go");
40+
41+
super::write_if_different(&dir.join("test.go"), "package main\n\nfunc main() {}")?;
42+
super::write_if_different(&dir.join("go.mod"), "module test\n\ngo 1.25")?;
43+
44+
println!("Testing if `go build` works...");
45+
runner.run_command(
46+
Command::new("go")
47+
.current_dir(&dir)
48+
.env("GOOS", "wasip1")
49+
.env("GOARCH", "wasm")
50+
.arg("build")
51+
.arg("-buildmode=c-shared")
52+
.arg("-ldflags=-checklinkname=0"),
53+
)
54+
}
55+
56+
fn compile(&self, runner: &Runner<'_>, compile: &Compile<'_>) -> Result<()> {
57+
let output = compile.output.with_extension("core.wasm");
58+
59+
// Tests which involve importing and/or exporting more than one
60+
// interface may require more than one file since we can't define more
61+
// than one package in a single file in Go (AFAICT). Here we search for
62+
// files related to `compile.component.path` based on a made-up naming
63+
// convention. For example, if the filename is `test.go`, then we'll
64+
// also include `${prefix}+test.go` for any value of `${prefix}`.
65+
for path in all_paths(&compile.component.path)? {
66+
let test = fs::read_to_string(&path)
67+
.with_context(|| format!("unable to read `{}`", path.display()))?;
68+
let package_name = package_name(&test);
69+
let package_dir = compile.bindings_dir.join(package_name);
70+
fs::create_dir_all(&package_dir)
71+
.with_context(|| format!("unable to create `{}`", package_dir.display()))?;
72+
let output = &package_dir.join(path.file_name().unwrap());
73+
fs::write(output, test.as_bytes())
74+
.with_context(|| format!("unable to write `{}`", output.display()))?;
75+
}
76+
77+
runner.run_command(
78+
Command::new("go")
79+
.current_dir(&compile.bindings_dir)
80+
.env("GOOS", "wasip1")
81+
.env("GOARCH", "wasm")
82+
.arg("build")
83+
.arg("-o")
84+
.arg(&output)
85+
.arg("-buildmode=c-shared")
86+
.arg("-ldflags=-checklinkname=0"),
87+
)?;
88+
89+
runner.convert_p1_to_component(&output, compile)?;
90+
91+
Ok(())
92+
}
93+
94+
fn verify(&self, runner: &Runner<'_>, verify: &Verify<'_>) -> Result<()> {
95+
runner.run_command(
96+
Command::new("go")
97+
.current_dir(&verify.bindings_dir)
98+
.env("GOOS", "wasip1")
99+
.env("GOARCH", "wasm")
100+
.arg("build")
101+
.arg("-o")
102+
.arg(verify.artifacts_dir.join("tmp.wasm"))
103+
.arg("-buildmode=c-shared")
104+
.arg("-ldflags=-checklinkname=0"),
105+
)
106+
}
107+
}
108+
109+
fn package_name(package: &str) -> &str {
110+
package
111+
.split_once('\n')
112+
.unwrap()
113+
.0
114+
.strip_prefix("package ")
115+
.unwrap()
116+
.trim()
117+
}
118+
119+
fn all_paths(path: &Path) -> Result<Vec<PathBuf>> {
120+
let mut paths = vec![path.into()];
121+
let suffix = ".go";
122+
if let Some(name) = path
123+
.file_name()
124+
.unwrap()
125+
.to_str()
126+
.and_then(|name| name.strip_suffix(suffix))
127+
{
128+
let suffix = &format!("+{name}{suffix}");
129+
let parent = path.parent().unwrap();
130+
for entry in parent
131+
.read_dir()
132+
.with_context(|| format!("unable to read dir `{}`", parent.display()))?
133+
{
134+
let entry = entry?;
135+
if entry
136+
.file_name()
137+
.to_str()
138+
.and_then(|name| name.strip_suffix(suffix))
139+
.is_some()
140+
{
141+
paths.push(entry.path());
142+
}
143+
}
144+
}
145+
Ok(paths)
146+
}

0 commit comments

Comments
 (0)