Skip to content

[test] sharing types between import and export #1328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions tests/runtime/common-types/compose.wac
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package example:composition;

let leaf = new test:leaf {
...
};
let middle = new test:middle {
to-test: leaf.to-test,
...
};
let runner = new test:runner {
to-test: middle.to-test,
...
};

export runner...;
15 changes: 15 additions & 0 deletions tests/runtime/common-types/leaf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <leaf_cpp.h>

using namespace test::common::test_types;

R1 exports::test::common::to_test::Wrap(F1 flag) {
if (flag == F1::kA) {
return R1{ 1, flag };
} else {
return R1{ 2, flag };
}
}

V1 exports::test::common::to_test::VarF(void) {
return V1(V1::B(42));
}
11 changes: 11 additions & 0 deletions tests/runtime/common-types/middle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <middle_cpp.h>

using namespace test::common::test_types;

R1 exports::test::common::to_test::Wrap(F1 flag) {
return ::test::common::to_test::Wrap(flag);
}

V1 exports::test::common::to_test::VarF(void) {
return ::test::common::to_test::VarF();
}
19 changes: 19 additions & 0 deletions tests/runtime/common-types/middle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
include!(env!("BINDINGS"));

use crate::test::common::to_test::{F1, R1, V1};

use exports::test::common::to_test;

pub struct Test {}

export!(Test);

impl to_test::Guest for Test {
fn wrap(flag: F1) -> R1 {
crate::test::common::to_test::wrap(flag)
}

fn var_f() -> V1 {
crate::test::common::to_test::var_f()
}
}
20 changes: 20 additions & 0 deletions tests/runtime/common-types/runner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <assert.h>
#include <runner_cpp.h>

int main() {
using namespace ::test::common::test_types;

R1 res = test::common::to_test::Wrap(F1::kA);
assert(res.b == F1::kA);
assert(res.a == 1);

R1 res2 = test::common::to_test::Wrap(F1::kB);
assert(res2.b == F1::kB);
assert(res2.a == 2);

V1 res3 = test::common::to_test::VarF();
assert(res3.variants.index() == 1);
assert(std::get<1>(res3.variants).value == 42);

return 0;
}
30 changes: 30 additions & 0 deletions tests/runtime/common-types/test.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//@ dependencies = ['middle', 'leaf']
//@ wac = 'compose.wac'

package test:common;

interface test-types {
flags f1 { a, b }
record r1 { a: u8, b: f1 }
variant v1 { a, b(u8) }
}

interface to-test {
use test-types.{f1, r1, v1};

wrap: func(flag: f1) -> r1;
var-f: func() -> v1;
}

world leaf {
export to-test;
}

world middle {
import to-test;
export to-test;
}

world runner {
import to-test;
}