Skip to content

Commit 23bce90

Browse files
authored
gen-guest-c: Move the wasm import declarations into the .c file (#447)
Move the `__wasm_` declaration for imports, with its `__attribute__((import_module("..."), import_name("...")))`, out of the .h file and into the .c file. It's not meant to be called by users of the bindings; only the implementation of the bindings.
1 parent bf54958 commit 23bce90

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

crates/gen-guest-c/src/lib.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -656,13 +656,13 @@ impl InterfaceGenerator<'_> {
656656
fn import(&mut self, func: &Function) {
657657
let sig = self.iface.wasm_signature(AbiVariant::GuestImport, func);
658658

659-
self.src.h_fns("\n");
659+
self.src.c_fns("\n");
660660

661661
// In the private C file, print a function declaration which is the
662662
// actual wasm import that we'll be calling, and this has the raw wasm
663663
// signature.
664664
uwriteln!(
665-
self.src.h_fns,
665+
self.src.c_fns,
666666
"__attribute__((import_module(\"{}\"), import_name(\"{}\")))",
667667
self.name,
668668
func.name
@@ -673,23 +673,23 @@ impl InterfaceGenerator<'_> {
673673
func.name.to_snake_case()
674674
));
675675
match sig.results.len() {
676-
0 => self.src.h_fns("void"),
677-
1 => self.src.h_fns(wasm_type(sig.results[0])),
676+
0 => self.src.c_fns("void"),
677+
1 => self.src.c_fns(wasm_type(sig.results[0])),
678678
_ => unimplemented!("multi-value return not supported"),
679679
}
680-
self.src.h_fns(" ");
681-
self.src.h_fns(&import_name);
682-
self.src.h_fns("(");
680+
self.src.c_fns(" ");
681+
self.src.c_fns(&import_name);
682+
self.src.c_fns("(");
683683
for (i, param) in sig.params.iter().enumerate() {
684684
if i > 0 {
685-
self.src.h_fns(", ");
685+
self.src.c_fns(", ");
686686
}
687-
self.src.h_fns(wasm_type(*param));
687+
self.src.c_fns(wasm_type(*param));
688688
}
689689
if sig.params.len() == 0 {
690-
self.src.h_fns("void");
690+
self.src.c_fns("void");
691691
}
692-
self.src.h_fns(");\n");
692+
self.src.c_fns(");\n");
693693

694694
// Print the public facing signature into the header, and since that's
695695
// what we are defining also print it into the C file.
@@ -731,7 +731,7 @@ impl InterfaceGenerator<'_> {
731731

732732
// Print the actual header for this function into the header file, and
733733
// it's what we'll be calling.
734-
let c_sig = self.print_sig(func);
734+
let h_sig = self.print_sig(func);
735735

736736
// Generate, in the C source file, the raw wasm signature that has the
737737
// canonical ABI.
@@ -745,7 +745,7 @@ impl InterfaceGenerator<'_> {
745745
func.name.to_snake_case()
746746
));
747747

748-
let mut f = FunctionBindgen::new(self, c_sig, &import_name);
748+
let mut f = FunctionBindgen::new(self, h_sig, &import_name);
749749
match sig.results.len() {
750750
0 => f.gen.src.c_adapters("void"),
751751
1 => f.gen.src.c_adapters(wasm_type(sig.results[0])),

0 commit comments

Comments
 (0)