-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from ritesh089/feature/isolatedwit
feat(isolatedwit): Moving the adder wit to a separate package.
- Loading branch information
Showing
14 changed files
with
115 additions
and
91 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -5,15 +5,9 @@ The WIT package for the calculator consists of a world for each mathematical ope | |
add an `op` enum that delineates each operator. The following example interface only | ||
has an `add` operation: | ||
|
||
```wit | ||
package docs:calculator@0.1.0; | ||
```wit adder | ||
package docs:adder@0.1.0; | ||
interface calculate { | ||
enum op { | ||
add, | ||
} | ||
eval-expression: func(op: op, x: u32, y: u32) -> u32; | ||
} | ||
interface add { | ||
add: func(a: u32, b: u32) -> u32; | ||
|
@@ -22,13 +16,30 @@ interface add { | |
world adder { | ||
export add; | ||
} | ||
``` | ||
|
||
|
||
```wit calculator | ||
package docs:[email protected]; | ||
interface calculate { | ||
enum op { | ||
add, | ||
} | ||
eval-expression: func(op: op, x: u32, y: u32) -> u32; | ||
} | ||
world calculator { | ||
export calculate; | ||
import add; | ||
import docs:adder/add; | ||
} | ||
world app { | ||
import calculate; | ||
} | ||
``` | ||
|
||
|
||
To expand the exercise to add more components, add another operator world, expand the enum, and modify the `command` component to call it. | ||
|
||
## Building and running the example | ||
|
@@ -39,13 +50,14 @@ To compose a calculator component with an add operator, run the following: | |
(cd calculator && cargo component build --release) | ||
(cd adder && cargo component build --release) | ||
(cd command && cargo component build --release) | ||
cd .. | ||
wasm-tools compose calculator/target/wasm32-wasi/release/calculator.wasm -d adder/target/wasm32-wasi/release/adder.wasm -o composed.wasm | ||
wasm-tools compose command/target/wasm32-wasi/release/command.wasm -d composed.wasm -o command.wasm | ||
wasm-tools compose command/target/wasm32-wasi/release/command.wasm -d composed.wasm -o final.wasm | ||
``` | ||
|
||
Now, run the component with wasmtime: | ||
|
||
```sh | ||
wasmtime run command.wasm 1 2 add | ||
wasmtime run final.wasm 1 2 add | ||
1 + 2 = 3 | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ pub mod exports { | |
#[allow(dead_code)] | ||
pub mod docs { | ||
#[allow(dead_code)] | ||
pub mod calculator { | ||
pub mod adder { | ||
#[allow(dead_code, clippy::all)] | ||
pub mod add { | ||
#[used] | ||
|
@@ -27,17 +27,17 @@ pub mod exports { | |
} | ||
#[doc(hidden)] | ||
|
||
macro_rules! __export_docs_calculator_add_0_1_0_cabi{ | ||
macro_rules! __export_docs_adder_add_0_1_0_cabi{ | ||
($ty:ident with_types_in $($path_to_types:tt)*) => (const _: () = { | ||
|
||
#[export_name = "docs:calculator/[email protected]#add"] | ||
#[export_name = "docs:adder/[email protected]#add"] | ||
unsafe extern "C" fn export_add(arg0: i32,arg1: i32,) -> i32 { | ||
$($path_to_types)*::_export_add_cabi::<$ty>(arg0, arg1) | ||
} | ||
};); | ||
} | ||
#[doc(hidden)] | ||
pub(crate) use __export_docs_calculator_add_0_1_0_cabi; | ||
pub(crate) use __export_docs_adder_add_0_1_0_cabi; | ||
} | ||
} | ||
} | ||
|
@@ -142,7 +142,7 @@ mod _rt { | |
macro_rules! __export_adder_impl { | ||
($ty:ident) => (self::export!($ty with_types_in self);); | ||
($ty:ident with_types_in $($path_to_types_root:tt)*) => ( | ||
$($path_to_types_root)*::exports::docs::calculator::add::__export_docs_calculator_add_0_1_0_cabi!($ty with_types_in $($path_to_types_root)*::exports::docs::calculator::add); | ||
$($path_to_types_root)*::exports::docs::adder::add::__export_docs_adder_add_0_1_0_cabi!($ty with_types_in $($path_to_types_root)*::exports::docs::adder::add); | ||
) | ||
} | ||
#[doc(inline)] | ||
|
@@ -151,12 +151,12 @@ pub(crate) use __export_adder_impl as export; | |
#[cfg(target_arch = "wasm32")] | ||
#[link_section = "component-type:wit-bindgen:0.24.0:adder:encoded world"] | ||
#[doc(hidden)] | ||
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 213] = *b"\ | ||
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07Z\x01A\x02\x01A\x02\x01\ | ||
B\x02\x01@\x02\x01ay\x01by\0y\x04\0\x03add\x01\0\x04\x01\x19docs:calculator/add@\ | ||
0.1.0\x05\0\x04\x01\x1bdocs:calculator/[email protected]\x04\0\x0b\x0b\x01\0\x05adder\x03\ | ||
\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070.202.0\x10wit-\ | ||
bindgen-rust\x060.24.0"; | ||
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 203] = *b"\ | ||
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07P\x01A\x02\x01A\x02\x01\ | ||
B\x02\x01@\x02\x01ay\x01by\0y\x04\0\x03add\x01\0\x04\x01\x14docs:adder/add@0.1.0\ | ||
\x05\0\x04\x01\x16docs:adder/[email protected]\x04\0\x0b\x0b\x01\0\x05adder\x03\0\0\0G\ | ||
\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070.202.0\x10wit-bindgen\ | ||
-rust\x060.24.0"; | ||
|
||
#[inline(never)] | ||
#[doc(hidden)] | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
#[allow(dead_code)] | ||
pub mod docs { | ||
#[allow(dead_code)] | ||
pub mod calculator { | ||
pub mod adder { | ||
#[allow(dead_code, clippy::all)] | ||
pub mod add { | ||
#[used] | ||
|
@@ -16,7 +16,7 @@ pub mod docs { | |
pub fn add(a: u32, b: u32) -> u32 { | ||
unsafe { | ||
#[cfg(target_arch = "wasm32")] | ||
#[link(wasm_import_module = "docs:calculator/[email protected]")] | ||
#[link(wasm_import_module = "docs:adder/[email protected]")] | ||
extern "C" { | ||
#[link_name = "add"] | ||
fn wit_import(_: i32, _: i32) -> i32; | ||
|
@@ -216,14 +216,14 @@ pub(crate) use __export_calculator_impl as export; | |
#[cfg(target_arch = "wasm32")] | ||
#[link_section = "component-type:wit-bindgen:0.24.0:calculator:encoded world"] | ||
#[doc(hidden)] | ||
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 313] = *b"\ | ||
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xb8\x01\x01A\x02\x01\ | ||
A\x04\x01B\x02\x01@\x02\x01ay\x01by\0y\x04\0\x03add\x01\0\x03\x01\x19docs:calcul\ | ||
ator/[email protected]\x05\0\x01B\x04\x01m\x01\x03add\x04\0\x02op\x03\0\0\x01@\x03\x02op\ | ||
\x01\x01xy\x01yy\0y\x04\0\x0feval-expression\x01\x02\x04\x01\x1fdocs:calculator/\ | ||
calculate@0.1.0\x05\x01\x04\x01\x20docs:calculator/[email protected]\x04\0\x0b\x10\ | ||
\x01\0\x0acalculator\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-comp\ | ||
onent\x070.202.0\x10wit-bindgen-rust\x060.24.0"; | ||
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 308] = *b"\ | ||
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xb3\x01\x01A\x02\x01\ | ||
A\x04\x01B\x02\x01@\x02\x01ay\x01by\0y\x04\0\x03add\x01\0\x03\x01\x14docs:adder/\ | ||
[email protected]\x05\0\x01B\x04\x01m\x01\x03add\x04\0\x02op\x03\0\0\x01@\x03\x02op\x01\x01\ | ||
xy\x01yy\0y\x04\0\x0feval-expression\x01\x02\x04\x01\x1fdocs:calculator/calculat\ | ||
e@0.1.0\x05\x01\x04\x01\x20docs:calculator/[email protected]\x04\0\x0b\x10\x01\0\x0a\ | ||
calculator\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070\ | ||
.202.0\x10wit-bindgen-rust\x060.24.0"; | ||
|
||
#[inline(never)] | ||
#[doc(hidden)] | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package docs:adder@0.1.0; | ||
|
||
interface add { | ||
add: func(a: u32, b: u32) -> u32; | ||
} | ||
|
||
world adder { | ||
export add; | ||
} |
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
Oops, something went wrong.