Skip to content

Commit

Permalink
fix(go): fix the build error of generated code for empty resource type (
Browse files Browse the repository at this point in the history
#930)

* add test cases for issue929

Signed-off-by: Jiaxiao Zhou (Mossaka) <duibao55328@gmail.com>

* 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) <duibao55328@gmail.com>

* test(go): add one more test

Signed-off-by: Jiaxiao Zhou (Mossaka) <duibao55328@gmail.com>

* skip issue929 tests for rust

Signed-off-by: Jiaxiao Zhou (Mossaka) <duibao55328@gmail.com>

* skip issue929 tests for teavm-java

Signed-off-by: Jiaxiao Zhou (Mossaka) <duibao55328@gmail.com>

* skip issue929 tests for csharp

Signed-off-by: Jiaxiao Zhou (Mossaka) <duibao55328@gmail.com>

---------

Signed-off-by: Jiaxiao Zhou (Mossaka) <duibao55328@gmail.com>
  • Loading branch information
Mossaka authored Apr 25, 2024
1 parent 913baad commit 118e96f
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 1 deletion.
4 changes: 4 additions & 0 deletions crates/csharp/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ macro_rules! codegen_test {
"wasi-filesystem",
"wasi-http",
"wasi-io",
"issue929",
"issue929-no-import",
"issue929-no-export",
"issue929-only-methods",
]
.contains(&$name)
{
Expand Down
2 changes: 1 addition & 1 deletion crates/go/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ impl InterfaceGenerator<'_> {
}

pub(crate) fn finish(&mut self) {
if !self.export_funcs.is_empty() {
if !self.export_funcs.is_empty() || !self.exported_resources.is_empty() {
let interface_var_name = &self.get_interface_var_name();
let interface_name = &self.namespace();

Expand Down
4 changes: 4 additions & 0 deletions crates/rust/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ mod codegen_tests {
macro_rules! codegen_test {
(wasi_cli $name:tt $test:tt) => {};
(wasi_http $name:tt $test:tt) => {};
(issue929 $name:tt $test:tt) => {};
(issue929_no_import $name:tt $test:tt) => {};
(issue929_no_export $name:tt $test:tt) => {};
(issue929_only_methods $name:tt $test:tt) => {};
($id:ident $name:tt $test:tt) => {
mod $id {
wit_bindgen::generate!({
Expand Down
4 changes: 4 additions & 0 deletions crates/rust/tests/codegen_no_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ mod codegen_tests {
macro_rules! codegen_test {
(wasi_cli $name:tt $test:tt) => {};
(wasi_http $name:tt $test:tt) => {};
(issue929 $name:tt $test:tt) => {};
(issue929_no_import $name:tt $test:tt) => {};
(issue929_no_export $name:tt $test:tt) => {};
(issue929_only_methods $name:tt $test:tt) => {};
($id:ident $name:tt $test:tt) => {
mod $id {
wit_bindgen::generate!({
Expand Down
4 changes: 4 additions & 0 deletions crates/teavm-java/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ macro_rules! codegen_test {
(wasi_filesystem $name:tt $test:tt) => {};
(wasi_http $name:tt $test:tt) => {};
(wasi_io $name:tt $test:tt) => {};
(issue929 $name:tt $test:tt) => {};
(issue929_no_import $name:tt $test:tt) => {};
(issue929_no_export $name:tt $test:tt) => {};
(issue929_only_methods $name:tt $test:tt) => {};

($id:ident $name:tt $test:tt) => {
#[test]
Expand Down
14 changes: 14 additions & 0 deletions tests/codegen/issue929-no-export.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package foo:bar;

interface f {
resource fd;
}

interface utils {
use f.{fd};
my-func: func() -> own<fd>;
}

world test {
export utils;
}
15 changes: 15 additions & 0 deletions tests/codegen/issue929-no-import.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package foo:bar;

interface f {
resource fd;
}

interface utils {
use f.{fd};
my-func: func() -> own<fd>;
}

world test {
export f;
export utils;
}
19 changes: 19 additions & 0 deletions tests/codegen/issue929-only-methods.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package foo:bar;

interface f {
resource fd {
get-a: func() -> s32;
set-a: func(a: s32);
}
}

interface utils {
use f.{fd};
my-func: func() -> own<fd>;
}

world test {
import f;
export f;
export utils;
}
16 changes: 16 additions & 0 deletions tests/codegen/issue929.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package foo:bar;

interface f {
resource fd;
}

interface utils {
use f.{fd};
my-func: func() -> own<fd>;
}

world test {
import f;
export f;
export utils;
}

0 comments on commit 118e96f

Please sign in to comment.