From 3f9192109b8a7fbbb8cad0726f82d80d9772a9f2 Mon Sep 17 00:00:00 2001 From: Andrew Steurer <94206073+asteurer@users.noreply.github.com> Date: Mon, 27 Jul 2026 01:29:05 -0500 Subject: [PATCH] feat: update message in stubbed go exports Signed-off-by: Andrew Steurer <94206073+asteurer@users.noreply.github.com> --- crates/go/src/lib.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/go/src/lib.rs b/crates/go/src/lib.rs index faa5e5b8d..de49ffe9f 100644 --- a/crates/go/src/lib.rs +++ b/crates/go/src/lib.rs @@ -157,6 +157,7 @@ struct InterfaceData { need_unsafe: bool, need_runtime: bool, need_math: bool, + has_stubs: bool, } impl InterfaceData { @@ -166,6 +167,7 @@ impl InterfaceData { self.need_unsafe |= data.need_unsafe; self.need_runtime |= data.need_runtime; self.need_math |= data.need_math; + self.has_stubs |= data.has_stubs; } fn imports(&self) -> String { @@ -186,6 +188,7 @@ impl InterfaceData { need_unsafe: generator.need_unsafe, need_runtime: generator.need_pinner, need_math: generator.need_math, + has_stubs: false, } } } @@ -198,6 +201,7 @@ impl From> for InterfaceData { need_unsafe: generator.need_unsafe, need_runtime: generator.need_runtime, need_math: false, + has_stubs: generator.has_stubs, } } } @@ -899,6 +903,18 @@ impl WorldGenerator for Go { " ); + let stub_header = &format!( + "// The exported functions below are stubs which should be +// replaced with your own implementation. +// +// WARNING: Regenerating the bindings with `--generate-stubs` will +// regenerate this file and discard any edits. +// +// Generated by `wit-bindgen` {version} from the following packages: +{packages} +" + ); + let src = mem::take(&mut self.src); let align = self.return_area_align.format(POINTER_SIZE_EXPRESSION); let size = self.return_area_size.format(POINTER_SIZE_EXPRESSION); @@ -974,6 +990,7 @@ var {SYNC_EXPORT_PINNER} = runtime.Pinner{{}} for (name, data) in interfaces { let imports = data.imports(); let code = &data.code; + let header = if data.has_stubs { stub_header } else { header }; files.push( &format!("{prefix}{name}/wit_bindings.go"), @@ -1384,12 +1401,14 @@ func wasm_export_post_return_{name}(result {results}) {{ .extend(InterfaceData { code: format!( r#" +// TODO: Implement func {camel}({params}) {results} {{ panic("not implemented") }} "# ), imports, + has_stubs: true, ..InterfaceData::default() }); } @@ -2636,6 +2655,7 @@ struct InterfaceGenerator<'a> { imports: BTreeSet, need_unsafe: bool, need_runtime: bool, + has_stubs: bool, } impl<'a> InterfaceGenerator<'a> { @@ -2654,6 +2674,7 @@ impl<'a> InterfaceGenerator<'a> { imports: BTreeSet::new(), need_unsafe: false, need_runtime: false, + has_stubs: false, } }