-
Notifications
You must be signed in to change notification settings - Fork 63
feat(isolatedwit): Moving the adder wit to a separate package. #136
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
kate-goldenring
merged 9 commits into
bytecodealliance:main
from
ritesh089:feature/isolatedwit
May 28, 2024
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
95a6fa2
feat(isolatedwit): Moving the adder wit to a separate package
ritesh089 50987c2
Merge branch 'main' into feature/isolatedwit
ritesh089 515661a
Update component-model/src/tutorial.md
ritesh089 d810c35
feat(wit): Moving wit outside the packages
ritesh089 ceda489
Update component-model/src/tutorial.md
ritesh089 a45c4d4
Update component-model/src/tutorial.md
ritesh089 8d173c2
Update component-model/src/tutorial.md
ritesh089 0b75a71
Update component-model/src/tutorial.md
ritesh089 4ebfc44
Update component-model/src/tutorial.md
ritesh089 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:[email protected]; | ||
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for the reordering here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the package name to command to show that these components can be isolated in their own packages. Do you prefer to keep the package "docs:calculator"? @kate-goldenring