Skip to content

Commit 118e96f

Browse files
authored
fix(go): fix the build error of generated code for empty resource type (#930)
* add test cases for issue929 Signed-off-by: Jiaxiao Zhou (Mossaka) <[email protected]> * feat(go): generate exported interfaces when exported_resources are not empty this commit changes the `wit_bindgen_go::interface::Finish()` function to generate the interface functions when either export_funcs are not empty or exported_resources are not empty. Signed-off-by: Jiaxiao Zhou (Mossaka) <[email protected]> * test(go): add one more test Signed-off-by: Jiaxiao Zhou (Mossaka) <[email protected]> * skip issue929 tests for rust Signed-off-by: Jiaxiao Zhou (Mossaka) <[email protected]> * skip issue929 tests for teavm-java Signed-off-by: Jiaxiao Zhou (Mossaka) <[email protected]> * skip issue929 tests for csharp Signed-off-by: Jiaxiao Zhou (Mossaka) <[email protected]> --------- Signed-off-by: Jiaxiao Zhou (Mossaka) <[email protected]>
1 parent 913baad commit 118e96f

File tree

9 files changed

+81
-1
lines changed

9 files changed

+81
-1
lines changed

crates/csharp/tests/codegen.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ macro_rules! codegen_test {
6161
"wasi-filesystem",
6262
"wasi-http",
6363
"wasi-io",
64+
"issue929",
65+
"issue929-no-import",
66+
"issue929-no-export",
67+
"issue929-only-methods",
6468
]
6569
.contains(&$name)
6670
{

crates/go/src/interface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ impl InterfaceGenerator<'_> {
937937
}
938938

939939
pub(crate) fn finish(&mut self) {
940-
if !self.export_funcs.is_empty() {
940+
if !self.export_funcs.is_empty() || !self.exported_resources.is_empty() {
941941
let interface_var_name = &self.get_interface_var_name();
942942
let interface_name = &self.namespace();
943943

crates/rust/tests/codegen.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ mod codegen_tests {
55
macro_rules! codegen_test {
66
(wasi_cli $name:tt $test:tt) => {};
77
(wasi_http $name:tt $test:tt) => {};
8+
(issue929 $name:tt $test:tt) => {};
9+
(issue929_no_import $name:tt $test:tt) => {};
10+
(issue929_no_export $name:tt $test:tt) => {};
11+
(issue929_only_methods $name:tt $test:tt) => {};
812
($id:ident $name:tt $test:tt) => {
913
mod $id {
1014
wit_bindgen::generate!({

crates/rust/tests/codegen_no_std.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ mod codegen_tests {
1616
macro_rules! codegen_test {
1717
(wasi_cli $name:tt $test:tt) => {};
1818
(wasi_http $name:tt $test:tt) => {};
19+
(issue929 $name:tt $test:tt) => {};
20+
(issue929_no_import $name:tt $test:tt) => {};
21+
(issue929_no_export $name:tt $test:tt) => {};
22+
(issue929_only_methods $name:tt $test:tt) => {};
1923
($id:ident $name:tt $test:tt) => {
2024
mod $id {
2125
wit_bindgen::generate!({

crates/teavm-java/tests/codegen.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ macro_rules! codegen_test {
2525
(wasi_filesystem $name:tt $test:tt) => {};
2626
(wasi_http $name:tt $test:tt) => {};
2727
(wasi_io $name:tt $test:tt) => {};
28+
(issue929 $name:tt $test:tt) => {};
29+
(issue929_no_import $name:tt $test:tt) => {};
30+
(issue929_no_export $name:tt $test:tt) => {};
31+
(issue929_only_methods $name:tt $test:tt) => {};
2832

2933
($id:ident $name:tt $test:tt) => {
3034
#[test]

tests/codegen/issue929-no-export.wit

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package foo:bar;
2+
3+
interface f {
4+
resource fd;
5+
}
6+
7+
interface utils {
8+
use f.{fd};
9+
my-func: func() -> own<fd>;
10+
}
11+
12+
world test {
13+
export utils;
14+
}

tests/codegen/issue929-no-import.wit

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package foo:bar;
2+
3+
interface f {
4+
resource fd;
5+
}
6+
7+
interface utils {
8+
use f.{fd};
9+
my-func: func() -> own<fd>;
10+
}
11+
12+
world test {
13+
export f;
14+
export utils;
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package foo:bar;
2+
3+
interface f {
4+
resource fd {
5+
get-a: func() -> s32;
6+
set-a: func(a: s32);
7+
}
8+
}
9+
10+
interface utils {
11+
use f.{fd};
12+
my-func: func() -> own<fd>;
13+
}
14+
15+
world test {
16+
import f;
17+
export f;
18+
export utils;
19+
}

tests/codegen/issue929.wit

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package foo:bar;
2+
3+
interface f {
4+
resource fd;
5+
}
6+
7+
interface utils {
8+
use f.{fd};
9+
my-func: func() -> own<fd>;
10+
}
11+
12+
world test {
13+
import f;
14+
export f;
15+
export utils;
16+
}

0 commit comments

Comments
 (0)