Skip to content
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
4 changes: 0 additions & 4 deletions crates/test-rust-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ test = false
name = "resource_floats"
test = false

[[bin]]
name = "resource_import_and_export"
test = false

[[bin]]
name = "resource_with_lists"
test = false
Expand Down
3 changes: 0 additions & 3 deletions crates/test-rust-wasm/src/bin/resource_import_and_export.rs

This file was deleted.

11 changes: 5 additions & 6 deletions crates/test/src/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn compile(runner: &Runner<'_>, compile: &Compile<'_>, compiler: PathBuf) -> Res
cmd.arg(
compile
.bindings_dir
.join(format!("{}.c", compile.component.kind)),
.join(format!("{}.c", compile.component.bindgen.world)),
)
.arg("-I")
.arg(&compile.bindings_dir)
Expand All @@ -161,11 +161,10 @@ fn compile(runner: &Runner<'_>, compile: &Compile<'_>, compiler: PathBuf) -> Res
let mut cmd = Command::new(compiler);
cmd.arg(&compile.component.path)
.arg(&bindings_object)
.arg(
compile
.bindings_dir
.join(format!("{}_component_type.o", compile.component.kind)),
)
.arg(compile.bindings_dir.join(format!(
"{}_component_type.o",
compile.component.bindgen.world
)))
.arg("-I")
.arg(&compile.bindings_dir)
.arg("-Wall")
Expand Down
7 changes: 4 additions & 3 deletions crates/test/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,10 @@ path = 'lib.rs'
let mut cmd = rustc(&compile.component.path, &output);
cmd.env(
"BINDINGS",
compile
.bindings_dir
.join(format!("{}.rs", compile.component.bindgen.world)),
compile.bindings_dir.join(format!(
"{}.rs",
compile.component.bindgen.world.replace('-', "_")
)),
);
for (name, path) in externs {
let arg = format!("--extern={name}={}", path.display());
Expand Down
17 changes: 17 additions & 0 deletions tests/runtime-new/resource-import-and-export/compose.wac
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package example:composition;

let leaf-thing = new test:leaf-thing { ... };
let leaf-toplevel = new test:leaf-toplevel {
test: leaf-thing.test,
thing: leaf-thing.test.thing,
...
};
let intermediate = new test:intermediate {
test: leaf-thing.test,
toplevel-import: leaf-toplevel.toplevel-export,
thing: leaf-thing.test.thing,
...
};
let runner = new test:runner { test: intermediate.test, ... };

export runner...;
61 changes: 61 additions & 0 deletions tests/runtime-new/resource-import-and-export/intermediate.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//@ args = '--rename test:resource-import-and-export/test=test'

#include <assert.h>
#include "intermediate.h"
#include <stdlib.h>
#include <string.h>

struct exports_test_thing_t {
test_own_thing_t thing;
};

intermediate_own_thing_t
exports_intermediate_toplevel_export(intermediate_own_thing_t a) {
return intermediate_toplevel_import(a);
}

exports_test_own_thing_t
exports_test_constructor_thing(uint32_t v) {
exports_test_thing_t *val =
(exports_test_thing_t *)
malloc(sizeof(exports_test_thing_t));
assert(val != NULL);
val->thing = test_constructor_thing(v + 1);
return exports_test_thing_new(val);
}

uint32_t
exports_test_method_thing_foo(exports_test_borrow_thing_t self) {
test_borrow_thing_t borrow =
test_borrow_thing(self->thing);
return test_method_thing_foo(borrow) + 2;
}

void
exports_test_method_thing_bar(exports_test_borrow_thing_t self, uint32_t v) {
test_borrow_thing_t borrow =
test_borrow_thing(self->thing);
test_method_thing_bar(borrow, v + 3);
}

exports_test_own_thing_t
exports_test_static_thing_baz(exports_test_own_thing_t a, exports_test_own_thing_t b) {
exports_test_thing_t *a_rep =
exports_test_thing_rep(a);
exports_test_thing_t *b_rep =
exports_test_thing_rep(b);

test_own_thing_t tmp =
test_static_thing_baz(a_rep->thing, b_rep->thing);
test_borrow_thing_t tmp_borrow =
test_borrow_thing(tmp);
uint32_t ret = test_method_thing_foo(tmp_borrow) + 4;
test_thing_drop_own(tmp);

return exports_test_constructor_thing(ret);
}

void
exports_test_thing_destructor(exports_test_thing_t *rep) {
free(rep);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Import = ResourceImportAndExportWorld.wit.imports.test.resourceImportAndExport.ITest;
using Host = ResourceImportAndExportWorld.wit.imports.test.resourceImportAndExport.TestInterop;
using Import = IntermediateWorld.wit.imports.test.resourceImportAndExport.ITest;
using Host = IntermediateWorld.wit.imports.test.resourceImportAndExport.TestInterop;

namespace ResourceImportAndExportWorld.wit.exports.test.resourceImportAndExport
namespace IntermediateWorld.wit.exports.test.resourceImportAndExport
{
public class TestImpl : ITest {
public class Thing : ITest.Thing, ITest.IThing {
Expand All @@ -26,10 +26,10 @@ public static ITest.Thing Baz(ITest.Thing a, ITest.Thing b) {
}
}

namespace ResourceImportAndExportWorld {
public class ResourceImportAndExportWorldImpl : IResourceImportAndExportWorld {
namespace IntermediateWorld {
public class IntermediateWorldImpl : IIntermediateWorld {
public static Import.Thing ToplevelExport(Import.Thing things) {
return exports.ResourceImportAndExportWorld.ToplevelImport(things);
return exports.IntermediateWorld.ToplevelImport(things);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use std::cell::RefCell;

wit_bindgen::generate!({
path: "../../tests/runtime/resource_import_and_export",
});
include!(env!("BINDINGS"));

use exports::test::resource_import_and_export::test::{GuestThing, Thing as ExportThing};
use std::cell::RefCell;

pub struct Test {}

Expand Down
34 changes: 34 additions & 0 deletions tests/runtime-new/resource-import-and-export/leaf-thing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
include!(env!("BINDINGS"));

use crate::exports::test::resource_import_and_export::test::{Guest, GuestThing, Thing};
use std::cell::Cell;

struct Component;

export!(Component);

struct MyThing(Cell<u32>);

impl Guest for Component {
type Thing = MyThing;
}

impl GuestThing for MyThing {
fn new(v: u32) -> MyThing {
MyThing(Cell::new(v + 1))
}

fn foo(&self) -> u32 {
self.0.get() + 2
}

fn bar(&self, v: u32) {
self.0.set(v + 3);
}

fn baz(a: Thing, b: Thing) -> Thing {
let a = a.get::<MyThing>();
let b = b.get::<MyThing>();
Thing::new(MyThing::new(a.foo() + b.foo() + 4))
}
}
11 changes: 11 additions & 0 deletions tests/runtime-new/resource-import-and-export/leaf-toplevel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include!(env!("BINDINGS"));

export!(Component);

struct Component;

impl Guest for Component {
fn toplevel_export(a: Thing) -> Thing {
a
}
}
21 changes: 21 additions & 0 deletions tests/runtime-new/resource-import-and-export/runner.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use crate::test::resource_import_and_export::test::Thing;

include!(env!("BINDINGS"));

fn main() {
let thing1 = Thing::new(42);

// 42 + 1 (constructor) + 1 (constructor) + 2 (foo) + 2 (foo)
assert_eq!(thing1.foo(), 48);

// 33 + 3 (bar) + 3 (bar) + 2 (foo) + 2 (foo)
thing1.bar(33);
assert_eq!(thing1.foo(), 43);

let thing2 = Thing::new(81);
let thing3 = Thing::baz(thing1, thing2);
assert_eq!(
thing3.foo(),
33 + 3 + 3 + 81 + 1 + 1 + 2 + 2 + 4 + 1 + 2 + 4 + 1 + 1 + 2 + 2
);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//@ dependencies = ['intermediate', 'leaf-thing', 'leaf-toplevel']
//@ wac = 'compose.wac'

package test:resource-import-and-export;

interface test {
Expand All @@ -11,7 +14,16 @@ interface test {
}
}

world resource-import-and-export {
world leaf-thing {
export test;
}

world leaf-toplevel {
use test.{thing};
export toplevel-export: func(a: thing) -> thing;
}

world intermediate {
import test;
export test;

Expand All @@ -20,3 +32,7 @@ world resource-import-and-export {
import toplevel-import: func(a: thing) -> thing;
export toplevel-export: func(a: thing) -> thing;
}

world runner {
import test;
}
1 change: 0 additions & 1 deletion tests/runtime/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ mod flavorful;
mod options;
mod resource_alias;
mod resource_floats;
mod resource_import_and_export;
mod resource_with_lists;
mod resources;
mod results;
Expand Down
87 changes: 0 additions & 87 deletions tests/runtime/resource_import_and_export.rs

This file was deleted.

Loading