Skip to content

Commit 3f91921

Browse files
committed
feat: update message in stubbed go exports
Signed-off-by: Andrew Steurer <94206073+asteurer@users.noreply.github.com>
1 parent 7c48901 commit 3f91921

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

crates/go/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ struct InterfaceData {
157157
need_unsafe: bool,
158158
need_runtime: bool,
159159
need_math: bool,
160+
has_stubs: bool,
160161
}
161162

162163
impl InterfaceData {
@@ -166,6 +167,7 @@ impl InterfaceData {
166167
self.need_unsafe |= data.need_unsafe;
167168
self.need_runtime |= data.need_runtime;
168169
self.need_math |= data.need_math;
170+
self.has_stubs |= data.has_stubs;
169171
}
170172

171173
fn imports(&self) -> String {
@@ -186,6 +188,7 @@ impl InterfaceData {
186188
need_unsafe: generator.need_unsafe,
187189
need_runtime: generator.need_pinner,
188190
need_math: generator.need_math,
191+
has_stubs: false,
189192
}
190193
}
191194
}
@@ -198,6 +201,7 @@ impl From<InterfaceGenerator<'_>> for InterfaceData {
198201
need_unsafe: generator.need_unsafe,
199202
need_runtime: generator.need_runtime,
200203
need_math: false,
204+
has_stubs: generator.has_stubs,
201205
}
202206
}
203207
}
@@ -899,6 +903,18 @@ impl WorldGenerator for Go {
899903
"
900904
);
901905

906+
let stub_header = &format!(
907+
"// The exported functions below are stubs which should be
908+
// replaced with your own implementation.
909+
//
910+
// WARNING: Regenerating the bindings with `--generate-stubs` will
911+
// regenerate this file and discard any edits.
912+
//
913+
// Generated by `wit-bindgen` {version} from the following packages:
914+
{packages}
915+
"
916+
);
917+
902918
let src = mem::take(&mut self.src);
903919
let align = self.return_area_align.format(POINTER_SIZE_EXPRESSION);
904920
let size = self.return_area_size.format(POINTER_SIZE_EXPRESSION);
@@ -974,6 +990,7 @@ var {SYNC_EXPORT_PINNER} = runtime.Pinner{{}}
974990
for (name, data) in interfaces {
975991
let imports = data.imports();
976992
let code = &data.code;
993+
let header = if data.has_stubs { stub_header } else { header };
977994

978995
files.push(
979996
&format!("{prefix}{name}/wit_bindings.go"),
@@ -1384,12 +1401,14 @@ func wasm_export_post_return_{name}(result {results}) {{
13841401
.extend(InterfaceData {
13851402
code: format!(
13861403
r#"
1404+
// TODO: Implement
13871405
func {camel}({params}) {results} {{
13881406
panic("not implemented")
13891407
}}
13901408
"#
13911409
),
13921410
imports,
1411+
has_stubs: true,
13931412
..InterfaceData::default()
13941413
});
13951414
}
@@ -2636,6 +2655,7 @@ struct InterfaceGenerator<'a> {
26362655
imports: BTreeSet<String>,
26372656
need_unsafe: bool,
26382657
need_runtime: bool,
2658+
has_stubs: bool,
26392659
}
26402660

26412661
impl<'a> InterfaceGenerator<'a> {
@@ -2654,6 +2674,7 @@ impl<'a> InterfaceGenerator<'a> {
26542674
imports: BTreeSet::new(),
26552675
need_unsafe: false,
26562676
need_runtime: false,
2677+
has_stubs: false,
26572678
}
26582679
}
26592680

0 commit comments

Comments
 (0)