Skip to content
Open
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
21 changes: 21 additions & 0 deletions crates/go/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ struct InterfaceData {
need_unsafe: bool,
need_runtime: bool,
need_math: bool,
has_stubs: bool,
}

impl InterfaceData {
Expand All @@ -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 {
Expand All @@ -186,6 +188,7 @@ impl InterfaceData {
need_unsafe: generator.need_unsafe,
need_runtime: generator.need_pinner,
need_math: generator.need_math,
has_stubs: false,
}
}
}
Expand All @@ -198,6 +201,7 @@ impl From<InterfaceGenerator<'_>> for InterfaceData {
need_unsafe: generator.need_unsafe,
need_runtime: generator.need_runtime,
need_math: false,
has_stubs: generator.has_stubs,
}
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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()
});
}
Expand Down Expand Up @@ -2636,6 +2655,7 @@ struct InterfaceGenerator<'a> {
imports: BTreeSet<String>,
need_unsafe: bool,
need_runtime: bool,
has_stubs: bool,
}

impl<'a> InterfaceGenerator<'a> {
Expand All @@ -2654,6 +2674,7 @@ impl<'a> InterfaceGenerator<'a> {
imports: BTreeSet::new(),
need_unsafe: false,
need_runtime: false,
has_stubs: false,
}
}

Expand Down
Loading