Skip to content

Commit 57faf5b

Browse files
committed
add linking tests
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
1 parent 7681a93 commit 57faf5b

File tree

29 files changed

+794
-7
lines changed

29 files changed

+794
-7
lines changed

crates/wit-component/tests/components.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ use wit_parser::{PackageId, Resolve, UnresolvedPackage};
2525
/// `$name`, can be specified for multiple `$name`s
2626
/// * [optional] `adapt-$name.wit` - required for each `*.wat` adapter to
2727
/// describe imports/exports of the adapter.
28+
/// * [optional] `stub-missing-functions` - if linking libraries and this file
29+
/// exists, `Linker::stub_missing_functions` will be set to `true`. The
30+
/// contents of the file are ignored.
2831
///
2932
/// And the output files are one of the following:
3033
///
@@ -78,13 +81,16 @@ fn component_encoding_via_flags() -> Result<()> {
7881
.map(|path| ("dlopen-lib-", path, true)),
7982
);
8083

81-
let linker = libs.try_fold(
82-
Linker::default().validate(true),
83-
|linker, (prefix, path, dl_openable)| {
84-
let (name, wasm) = read_name_and_module(prefix, &path?, &resolve, pkg)?;
85-
Ok::<_, Error>(linker.library(&name, &wasm, dl_openable)?)
86-
},
87-
)?;
84+
let mut linker = Linker::default().validate(true);
85+
86+
if path.join("stub-missing-functions").is_file() {
87+
linker = linker.stub_missing_functions(true);
88+
}
89+
90+
let linker = libs.try_fold(linker, |linker, (prefix, path, dl_openable)| {
91+
let (name, wasm) = read_name_and_module(prefix, &path?, &resolve, pkg)?;
92+
Ok::<_, Error>(linker.library(&name, &wasm, dl_openable)?)
93+
})?;
8894

8995
adapters
9096
.try_fold(linker, |linker, path| {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
duplicate symbol(s): [
2+
(
3+
"bar",
4+
Export {
5+
name: "foo",
6+
ty: Function(
7+
FunctionType {
8+
parameters: [
9+
I32,
10+
],
11+
results: [
12+
I32,
13+
],
14+
},
15+
),
16+
},
17+
[
18+
"bar",
19+
"foo",
20+
],
21+
),
22+
(
23+
"foo",
24+
Export {
25+
name: "foo",
26+
ty: Function(
27+
FunctionType {
28+
parameters: [
29+
I32,
30+
],
31+
results: [
32+
I32,
33+
],
34+
},
35+
),
36+
},
37+
[
38+
"bar",
39+
"foo",
40+
],
41+
),
42+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(module
2+
(@dylink.0
3+
(mem-info (memory 0 4))
4+
(needed "foo")
5+
)
6+
(type (func (param i32) (result i32)))
7+
(import "env" "foo" (func $import_foo (type 0)))
8+
(func $bar (type 0) (param i32) (result i32)
9+
unreachable
10+
)
11+
(export "bar" (func $bar))
12+
(export "foo" (func $bar))
13+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package test:test
2+
3+
world lib-bar { }
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(module
2+
(@dylink.0
3+
(mem-info (memory 0 4))
4+
(needed "bar")
5+
)
6+
(type (func (param i32) (result i32)))
7+
(import "test:test/test" "foo" (func $import_foo (type 0)))
8+
(import "env" "foo" (func $import_foo2 (type 0)))
9+
(import "env" "bar" (func $import_bar (type 0)))
10+
(func $foo (type 0) (param i32) (result i32)
11+
unreachable
12+
)
13+
(export "test:test/test#foo" (func $foo))
14+
(export "foo" (func $foo))
15+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package test:test
2+
3+
interface test {
4+
foo: func(v: s32) -> s32
5+
}
6+
7+
world lib-foo {
8+
import test
9+
export test
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
missing libraries: [
2+
(
3+
"foo",
4+
[
5+
"bar",
6+
],
7+
),
8+
]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(module
2+
(@dylink.0
3+
(mem-info (memory 0 4))
4+
(needed "bar")
5+
)
6+
(type (func (param i32) (result i32)))
7+
(import "test:test/test" "foo" (func $import_foo (type 0)))
8+
(import "env" "foo" (func $import_foo2 (type 0)))
9+
(import "env" "bar" (func $import_bar (type 0)))
10+
(func $foo (type 0) (param i32) (result i32)
11+
unreachable
12+
)
13+
(export "test:test/test#foo" (func $foo))
14+
(export "foo" (func $foo))
15+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package test:test
2+
3+
interface test {
4+
foo: func(v: s32) -> s32
5+
}
6+
7+
world lib-foo {
8+
import test
9+
export test
10+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
unresolved symbol(s): [
2+
(
3+
"foo",
4+
Export {
5+
name: "bar",
6+
ty: Function(
7+
FunctionType {
8+
parameters: [
9+
I32,
10+
],
11+
results: [
12+
I32,
13+
],
14+
},
15+
),
16+
},
17+
),
18+
(
19+
"foo",
20+
Export {
21+
name: "foo",
22+
ty: Function(
23+
FunctionType {
24+
parameters: [
25+
I32,
26+
],
27+
results: [
28+
I32,
29+
],
30+
},
31+
),
32+
},
33+
),
34+
]

0 commit comments

Comments
 (0)