forked from bytecodealliance/wit-bindgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: preliminary support for WIT templates
This is a minimum viable implementation of WIT templates per WebAssembly/component-model#172. It supports interfaces with at most one wildcard function, which may be expanded (i.e. monomorphized) with a set of substitutions provided by the application developer when generating guest bindings. Signed-off-by: Joel Dice <[email protected]>
- Loading branch information
1 parent
80d9ffa
commit a02b5a5
Showing
21 changed files
with
360 additions
and
182 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,3 +47,7 @@ test = false | |
[[bin]] | ||
name = "results" | ||
test = false | ||
|
||
[[bin]] | ||
name = "wildcards" | ||
test = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include!("../../../../tests/runtime/wildcards/wasm.rs"); | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use anyhow::Result; | ||
use wasmtime::Store; | ||
|
||
wasmtime::component::bindgen!(in "tests/runtime/wildcards"); | ||
|
||
#[derive(Default)] | ||
struct Host; | ||
|
||
impl imports::Host for Host {} | ||
|
||
struct Match(u32); | ||
|
||
impl imports::WildcardMatch<Host> for Match { | ||
fn call(&self, _host: &mut Host, _name: &str) -> Result<u32> { | ||
Ok(self.0) | ||
} | ||
} | ||
|
||
#[test] | ||
fn run() -> Result<()> { | ||
eprintln!("yossa hello"); | ||
crate::run_test( | ||
"wildcards", | ||
|linker| { | ||
eprintln!("yossa add to linker"); | ||
Wildcards::add_to_linker( | ||
linker, | ||
WildcardMatches { | ||
imports: vec![("a", Match(42)), ("b", Match(43)), ("c", Match(44))], | ||
}, | ||
|x| &mut x.0, | ||
) | ||
}, | ||
|store, component, linker| Wildcards::instantiate(store, component, linker), | ||
run_test, | ||
) | ||
} | ||
|
||
fn run_test(wildcards: Wildcards, store: &mut Store<crate::Wasi<Host>>) -> Result<()> { | ||
for (name, value) in [("x", 42), ("y", 43), ("z", 44)] { | ||
assert_eq!( | ||
value, | ||
wildcards | ||
.exports | ||
.get_wildcard_match(name) | ||
.unwrap() | ||
.call(&mut *store)? | ||
); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[wildcards] | ||
imports = ["a", "b", "c"] | ||
exports = ["x", "y", "z"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
wit_bindgen::generate!({ | ||
world: "world", | ||
path: "../../tests/runtime/wildcards", | ||
substitutions_path: "../../tests/runtime/wildcards/substitutions.toml", | ||
}); | ||
|
||
struct Exports; | ||
|
||
export_wildcards!(Exports); | ||
|
||
impl exports::Exports for Exports { | ||
fn x() -> u32 { | ||
imports::a() | ||
} | ||
fn y() -> u32 { | ||
imports::b() | ||
} | ||
fn z() -> u32 { | ||
imports::c() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
interface foo { | ||
*: func() -> u32 | ||
} | ||
|
||
default world wildcards { | ||
import imports: self.foo | ||
export exports: self.foo | ||
} |