From 95a6fa2b18bee897b55bd13363e0622273b21b0a Mon Sep 17 00:00:00 2001 From: rrai35 Date: Wed, 8 May 2024 23:13:57 -0400 Subject: [PATCH 1/8] feat(isolatedwit): Moving the adder wit to a separate package --- component-model/examples/tutorial/README.md | 35 +- .../examples/tutorial/adder/Cargo.lock | 424 +----------------- .../examples/tutorial/adder/Cargo.toml | 8 +- .../examples/tutorial/adder/src/bindings.rs | 166 +++++++ .../examples/tutorial/adder/src/lib.rs | 8 +- .../examples/tutorial/adder/wit/world.wit | 9 + .../examples/tutorial/calculator/Cargo.lock | 424 +----------------- .../examples/tutorial/calculator/Cargo.toml | 5 +- .../tutorial/calculator/src/bindings.rs | 233 ++++++++++ .../examples/tutorial/calculator/src/lib.rs | 7 +- .../examples/tutorial/command/Cargo.lock | 377 +--------------- .../examples/tutorial/command/Cargo.toml | 5 +- .../examples/tutorial/command/src/bindings.rs | 151 +++++++ .../examples/tutorial/command/src/main.rs | 4 +- .../examples/tutorial/wit/calculator.wit | 18 +- component-model/src/tutorial.md | 52 ++- 16 files changed, 658 insertions(+), 1268 deletions(-) create mode 100644 component-model/examples/tutorial/adder/src/bindings.rs create mode 100644 component-model/examples/tutorial/adder/wit/world.wit create mode 100644 component-model/examples/tutorial/calculator/src/bindings.rs create mode 100644 component-model/examples/tutorial/command/src/bindings.rs diff --git a/component-model/examples/tutorial/README.md b/component-model/examples/tutorial/README.md index 7bb6f7da..63b3acac 100644 --- a/component-model/examples/tutorial/README.md +++ b/component-model/examples/tutorial/README.md @@ -5,30 +5,41 @@ 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 adder +package docs:adder; + + +interface add { + add: func(a: u32, b: u32) -> u32; +} + +world adder { + export add; +} +``` + + ```wit -package docs:calculator@0.1.0 +package docs:calculator; interface calculate { enum op { add, } - eval-expression: func(op: op, x: u32, y: u32) -> u32 -} - -interface add { - add: func(a: u32, b: u32) -> u32 + eval-expression: func(op: op, x: u32, y: u32) -> u32; } -world adder { - export add +world calculator { + export calculate; + import docs:adder/add; } -world calculator { - export calculate - import 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 @@ -46,6 +57,6 @@ wasm-tools compose command/target/wasm32-wasi/release/command.wasm -d composed.w Now, run the component with wasmtime: ```sh -wasmtime run --wasm component-model command.wasm 1 2 add +wasmtime run command.wasm 1 2 add 1 + 2 = 3 ``` diff --git a/component-model/examples/tutorial/adder/Cargo.lock b/component-model/examples/tutorial/adder/Cargo.lock index b903bc6f..90e98753 100644 --- a/component-model/examples/tutorial/adder/Cargo.lock +++ b/component-model/examples/tutorial/adder/Cargo.lock @@ -6,21 +6,9 @@ version = 3 name = "adder" version = "0.1.0" dependencies = [ - "cargo-component-bindings", + "wit-bindgen-rt", ] -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "bitflags" version = "2.4.0" @@ -28,412 +16,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" [[package]] -name = "cargo-component-bindings" -version = "0.1.0" -source = "git+https://github.com/bytecodealliance/cargo-component#86ccf3e9e57885784d5a32dcbb162813d5c820ba" -dependencies = [ - "cargo-component-macro", - "wit-bindgen", -] - -[[package]] -name = "cargo-component-macro" -version = "0.1.0" -source = "git+https://github.com/bytecodealliance/cargo-component#86ccf3e9e57885784d5a32dcbb162813d5c820ba" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-bindgen-rust-lib", - "wit-component", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "hashbrown" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - -[[package]] -name = "idna" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "indexmap" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" -dependencies = [ - "equivalent", - "hashbrown", - "serde", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f478948fd84d9f8e86967bf432640e46adfb5a4bd4f14ef7e864ab38220534ae" - -[[package]] -name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[package]] -name = "proc-macro2" -version = "1.0.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "pulldown-cmark" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a1a2f1f0a7ecff9c31abbe177637be0e97a0aef46cf8738ece09327985d998" -dependencies = [ - "bitflags 1.3.2", - "memchr", - "unicase", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "semver" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" - -[[package]] -name = "serde" -version = "1.0.188" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.188" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.105" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "smallvec" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" - -[[package]] -name = "spdx" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71" -dependencies = [ - "smallvec", -] - -[[package]] -name = "syn" -version = "2.0.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - -[[package]] -name = "unicase" -version = "2.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" -dependencies = [ - "version_check", -] - -[[package]] -name = "unicode-bidi" -version = "0.3.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" - -[[package]] -name = "unicode-ident" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" - -[[package]] -name = "unicode-normalization" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "url" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasm-encoder" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ba64e81215916eaeb48fee292f29401d69235d62d8b8fd92a7b2844ec5ae5f7" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-metadata" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08dc59d1fa569150851542143ca79438ca56845ccb31696c70225c638e063471" -dependencies = [ - "anyhow", - "indexmap", - "serde", - "serde_json", - "spdx", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.112.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e986b010f47fcce49cf8ea5d5f9e5d2737832f12b53ae8ae785bbe895d0877bf" -dependencies = [ - "indexmap", - "semver", -] - -[[package]] -name = "wit-bindgen" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8a3e8e965dc50e6eb4410d9a11720719fadc6a1713803ea5f3be390b81c8279" -dependencies = [ - "bitflags 2.4.0", - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77255512565dfbd0b61de466e854918041d1da53c7bc049d6188c6e02643dc1e" -dependencies = [ - "anyhow", - "wit-component", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "399c60e6ea8598d1380e792f13d557007834f0fb799fea6503408cbc5debb4ae" -dependencies = [ - "anyhow", - "heck", - "wasm-metadata", - "wit-bindgen-core", - "wit-bindgen-rust-lib", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-lib" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd9fb7a43c7dc28b0b727d6ae01bf369981229b7539e768fba2b7a4df13feeeb" -dependencies = [ - "heck", - "wit-bindgen-core", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44cea5ed784da06da0e55836a6c160e7502dbe28771c2368a595e8606243bf22" -dependencies = [ - "anyhow", - "proc-macro2", - "syn", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-bindgen-rust-lib", - "wit-component", -] - -[[package]] -name = "wit-component" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d9f2d16dd55d1a372dcfd4b7a466ea876682a5a3cb97e71ec9eef04affa876" -dependencies = [ - "anyhow", - "bitflags 2.4.0", - "indexmap", - "log", - "serde", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.11.0" +name = "wit-bindgen-rt" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e8b849bea13cc2315426b16efe6eb6813466d78f5fde69b0bb150c9c40e0dc" +checksum = "3b0780cf7046630ed70f689a098cd8d56c5c3b22f2a7379bbdb088879963ff96" dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "pulldown-cmark", - "semver", - "unicode-xid", - "url", + "bitflags", ] diff --git a/component-model/examples/tutorial/adder/Cargo.toml b/component-model/examples/tutorial/adder/Cargo.toml index b19ae721..d4628cb9 100644 --- a/component-model/examples/tutorial/adder/Cargo.toml +++ b/component-model/examples/tutorial/adder/Cargo.toml @@ -6,16 +6,12 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cargo-component-bindings = { git = "https://github.com/bytecodealliance/cargo-component" } +wit-bindgen-rt = { version = "0.24.0", features = ["bitflags"] } [lib] crate-type = ["cdylib"] [package.metadata.component] -package = "docs:calculator" - -[package.metadata.component.target] -path = "../wit/calculator.wit" -world = "adder" +package = "docs:adder" [package.metadata.component.dependencies] diff --git a/component-model/examples/tutorial/adder/src/bindings.rs b/component-model/examples/tutorial/adder/src/bindings.rs new file mode 100644 index 00000000..fb474c09 --- /dev/null +++ b/component-model/examples/tutorial/adder/src/bindings.rs @@ -0,0 +1,166 @@ +// Generated by `wit-bindgen` 0.24.0. DO NOT EDIT! +// Options used: +#[allow(dead_code)] +pub mod exports { + #[allow(dead_code)] + pub mod docs { + #[allow(dead_code)] + pub mod adder { + #[allow(dead_code, clippy::all)] + pub mod add { + #[used] + #[doc(hidden)] + #[cfg(target_arch = "wasm32")] + static __FORCE_SECTION_REF: fn() = + super::super::super::super::__link_custom_section_describing_imports; + use super::super::super::super::_rt; + #[doc(hidden)] + #[allow(non_snake_case)] + pub unsafe fn _export_add_cabi(arg0: i32, arg1: i32) -> i32 { + #[cfg(target_arch = "wasm32")] + _rt::run_ctors_once(); + let result0 = T::add(arg0 as u32, arg1 as u32); + _rt::as_i32(result0) + } + pub trait Guest { + fn add(a: u32, b: u32) -> u32; + } + #[doc(hidden)] + + macro_rules! __export_docs_adder_add_cabi{ + ($ty:ident with_types_in $($path_to_types:tt)*) => (const _: () = { + + #[export_name = "docs:adder/add#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_adder_add_cabi; + } + } + } +} +mod _rt { + + #[cfg(target_arch = "wasm32")] + pub fn run_ctors_once() { + wit_bindgen_rt::run_ctors_once(); + } + + pub fn as_i32(t: T) -> i32 { + t.as_i32() + } + + pub trait AsI32 { + fn as_i32(self) -> i32; + } + + impl<'a, T: Copy + AsI32> AsI32 for &'a T { + fn as_i32(self) -> i32 { + (*self).as_i32() + } + } + + impl AsI32 for i32 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for u32 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for i16 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for u16 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for i8 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for u8 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for char { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for usize { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } +} + +/// Generates `#[no_mangle]` functions to export the specified type as the +/// root implementation of all generated traits. +/// +/// For more information see the documentation of `wit_bindgen::generate!`. +/// +/// ```rust +/// # macro_rules! export{ ($($t:tt)*) => (); } +/// # trait Guest {} +/// struct MyType; +/// +/// impl Guest for MyType { +/// // ... +/// } +/// +/// export!(MyType); +/// ``` +#[allow(unused_macros)] +#[doc(hidden)] + +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::adder::add::__export_docs_adder_add_cabi!($ty with_types_in $($path_to_types_root)*::exports::docs::adder::add); + ) +} +#[doc(inline)] +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; 191] = *b"\ +\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07D\x01A\x02\x01A\x02\x01\ +B\x02\x01@\x02\x01ay\x01by\0y\x04\0\x03add\x01\0\x04\x01\x0edocs:adder/add\x05\0\ +\x04\x01\x10docs:adder/adder\x04\0\x0b\x0b\x01\0\x05adder\x03\0\0\0G\x09producer\ +s\x01\x0cprocessed-by\x02\x0dwit-component\x070.202.0\x10wit-bindgen-rust\x060.2\ +4.0"; + +#[inline(never)] +#[doc(hidden)] +#[cfg(target_arch = "wasm32")] +pub fn __link_custom_section_describing_imports() { + wit_bindgen_rt::maybe_link_cabi_realloc(); +} diff --git a/component-model/examples/tutorial/adder/src/lib.rs b/component-model/examples/tutorial/adder/src/lib.rs index 2460a13f..1e1f91de 100644 --- a/component-model/examples/tutorial/adder/src/lib.rs +++ b/component-model/examples/tutorial/adder/src/lib.rs @@ -1,5 +1,7 @@ -cargo_component_bindings::generate!(); -use bindings::exports::docs::calculator::add::Guest; +#[allow(warnings)] +mod bindings; + +use bindings::exports::docs::adder::add::Guest; struct Component; @@ -8,3 +10,5 @@ impl Guest for Component { a + b } } + +bindings::export!(Component with_types_in bindings); \ No newline at end of file diff --git a/component-model/examples/tutorial/adder/wit/world.wit b/component-model/examples/tutorial/adder/wit/world.wit new file mode 100644 index 00000000..ab60731f --- /dev/null +++ b/component-model/examples/tutorial/adder/wit/world.wit @@ -0,0 +1,9 @@ +package docs:adder; + +interface add { + add: func(a: u32, b: u32) -> u32; +} + +world adder { + export add; +} \ No newline at end of file diff --git a/component-model/examples/tutorial/calculator/Cargo.lock b/component-model/examples/tutorial/calculator/Cargo.lock index 92ae88c2..1501d800 100644 --- a/component-model/examples/tutorial/calculator/Cargo.lock +++ b/component-model/examples/tutorial/calculator/Cargo.lock @@ -2,18 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "bitflags" version = "2.4.0" @@ -24,416 +12,14 @@ checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" name = "calculator" version = "0.1.0" dependencies = [ - "cargo-component-bindings", -] - -[[package]] -name = "cargo-component-bindings" -version = "0.1.0" -source = "git+https://github.com/bytecodealliance/cargo-component#86ccf3e9e57885784d5a32dcbb162813d5c820ba" -dependencies = [ - "cargo-component-macro", - "wit-bindgen", -] - -[[package]] -name = "cargo-component-macro" -version = "0.1.0" -source = "git+https://github.com/bytecodealliance/cargo-component#86ccf3e9e57885784d5a32dcbb162813d5c820ba" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-bindgen-rust-lib", - "wit-component", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "hashbrown" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - -[[package]] -name = "idna" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "indexmap" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" -dependencies = [ - "equivalent", - "hashbrown", - "serde", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f478948fd84d9f8e86967bf432640e46adfb5a4bd4f14ef7e864ab38220534ae" - -[[package]] -name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[package]] -name = "proc-macro2" -version = "1.0.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "pulldown-cmark" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a1a2f1f0a7ecff9c31abbe177637be0e97a0aef46cf8738ece09327985d998" -dependencies = [ - "bitflags 1.3.2", - "memchr", - "unicase", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "semver" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" - -[[package]] -name = "serde" -version = "1.0.188" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.188" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.105" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "smallvec" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" - -[[package]] -name = "spdx" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71" -dependencies = [ - "smallvec", -] - -[[package]] -name = "syn" -version = "2.0.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - -[[package]] -name = "unicase" -version = "2.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" -dependencies = [ - "version_check", -] - -[[package]] -name = "unicode-bidi" -version = "0.3.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" - -[[package]] -name = "unicode-ident" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" - -[[package]] -name = "unicode-normalization" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "url" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasm-encoder" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ba64e81215916eaeb48fee292f29401d69235d62d8b8fd92a7b2844ec5ae5f7" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-metadata" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08dc59d1fa569150851542143ca79438ca56845ccb31696c70225c638e063471" -dependencies = [ - "anyhow", - "indexmap", - "serde", - "serde_json", - "spdx", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.112.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e986b010f47fcce49cf8ea5d5f9e5d2737832f12b53ae8ae785bbe895d0877bf" -dependencies = [ - "indexmap", - "semver", -] - -[[package]] -name = "wit-bindgen" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8a3e8e965dc50e6eb4410d9a11720719fadc6a1713803ea5f3be390b81c8279" -dependencies = [ - "bitflags 2.4.0", - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77255512565dfbd0b61de466e854918041d1da53c7bc049d6188c6e02643dc1e" -dependencies = [ - "anyhow", - "wit-component", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "399c60e6ea8598d1380e792f13d557007834f0fb799fea6503408cbc5debb4ae" -dependencies = [ - "anyhow", - "heck", - "wasm-metadata", - "wit-bindgen-core", - "wit-bindgen-rust-lib", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-lib" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd9fb7a43c7dc28b0b727d6ae01bf369981229b7539e768fba2b7a4df13feeeb" -dependencies = [ - "heck", - "wit-bindgen-core", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44cea5ed784da06da0e55836a6c160e7502dbe28771c2368a595e8606243bf22" -dependencies = [ - "anyhow", - "proc-macro2", - "syn", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-bindgen-rust-lib", - "wit-component", -] - -[[package]] -name = "wit-component" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d9f2d16dd55d1a372dcfd4b7a466ea876682a5a3cb97e71ec9eef04affa876" -dependencies = [ - "anyhow", - "bitflags 2.4.0", - "indexmap", - "log", - "serde", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", + "wit-bindgen-rt", ] [[package]] -name = "wit-parser" -version = "0.11.0" +name = "wit-bindgen-rt" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e8b849bea13cc2315426b16efe6eb6813466d78f5fde69b0bb150c9c40e0dc" +checksum = "3b0780cf7046630ed70f689a098cd8d56c5c3b22f2a7379bbdb088879963ff96" dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "pulldown-cmark", - "semver", - "unicode-xid", - "url", + "bitflags", ] diff --git a/component-model/examples/tutorial/calculator/Cargo.toml b/component-model/examples/tutorial/calculator/Cargo.toml index 56945ca2..96f97db7 100644 --- a/component-model/examples/tutorial/calculator/Cargo.toml +++ b/component-model/examples/tutorial/calculator/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -cargo-component-bindings = { git = "https://github.com/bytecodealliance/cargo-component" } +wit-bindgen-rt = { version = "0.24.0", features = ["bitflags"] } [lib] crate-type = ["cdylib"] @@ -12,6 +12,9 @@ crate-type = ["cdylib"] [package.metadata.component] package = "docs:calculator" +[package.metadata.component.target.dependencies] +"docs:adder" = { path = "../adder/wit" } # directory containing the WIT package + [package.metadata.component.target] path = "../wit/calculator.wit" world = "calculator" diff --git a/component-model/examples/tutorial/calculator/src/bindings.rs b/component-model/examples/tutorial/calculator/src/bindings.rs new file mode 100644 index 00000000..fd7d8cc3 --- /dev/null +++ b/component-model/examples/tutorial/calculator/src/bindings.rs @@ -0,0 +1,233 @@ +// Generated by `wit-bindgen` 0.24.0. DO NOT EDIT! +// Options used: +#[allow(dead_code)] +pub mod docs { + #[allow(dead_code)] + pub mod adder { + #[allow(dead_code, clippy::all)] + pub mod add { + #[used] + #[doc(hidden)] + #[cfg(target_arch = "wasm32")] + static __FORCE_SECTION_REF: fn() = + super::super::super::__link_custom_section_describing_imports; + use super::super::super::_rt; + #[allow(unused_unsafe, clippy::all)] + pub fn add(a: u32, b: u32) -> u32 { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "docs:adder/add")] + extern "C" { + #[link_name = "add"] + fn wit_import(_: i32, _: i32) -> i32; + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i32) -> i32 { + unreachable!() + } + let ret = wit_import(_rt::as_i32(&a), _rt::as_i32(&b)); + ret as u32 + } + } + } + } +} +#[allow(dead_code)] +pub mod exports { + #[allow(dead_code)] + pub mod docs { + #[allow(dead_code)] + pub mod calculator { + #[allow(dead_code, clippy::all)] + pub mod calculate { + #[used] + #[doc(hidden)] + #[cfg(target_arch = "wasm32")] + static __FORCE_SECTION_REF: fn() = + super::super::super::super::__link_custom_section_describing_imports; + use super::super::super::super::_rt; + #[repr(u8)] + #[derive(Clone, Copy, Eq, PartialEq)] + pub enum Op { + Add, + } + impl ::core::fmt::Debug for Op { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + match self { + Op::Add => f.debug_tuple("Op::Add").finish(), + } + } + } + + impl Op { + pub(crate) unsafe fn _lift(val: u8) -> Op { + if !cfg!(debug_assertions) { + return ::core::mem::transmute(val); + } + + match val { + 0 => Op::Add, + + _ => panic!("invalid enum discriminant"), + } + } + } + + #[doc(hidden)] + #[allow(non_snake_case)] + pub unsafe fn _export_eval_expression_cabi( + arg0: i32, + arg1: i32, + arg2: i32, + ) -> i32 { + #[cfg(target_arch = "wasm32")] + _rt::run_ctors_once(); + let result0 = + T::eval_expression(Op::_lift(arg0 as u8), arg1 as u32, arg2 as u32); + _rt::as_i32(result0) + } + pub trait Guest { + fn eval_expression(op: Op, x: u32, y: u32) -> u32; + } + #[doc(hidden)] + + macro_rules! __export_docs_calculator_calculate_cabi{ + ($ty:ident with_types_in $($path_to_types:tt)*) => (const _: () = { + + #[export_name = "docs:calculator/calculate#eval-expression"] + unsafe extern "C" fn export_eval_expression(arg0: i32,arg1: i32,arg2: i32,) -> i32 { + $($path_to_types)*::_export_eval_expression_cabi::<$ty>(arg0, arg1, arg2) + } + };); + } + #[doc(hidden)] + pub(crate) use __export_docs_calculator_calculate_cabi; + } + } + } +} +mod _rt { + + pub fn as_i32(t: T) -> i32 { + t.as_i32() + } + + pub trait AsI32 { + fn as_i32(self) -> i32; + } + + impl<'a, T: Copy + AsI32> AsI32 for &'a T { + fn as_i32(self) -> i32 { + (*self).as_i32() + } + } + + impl AsI32 for i32 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for u32 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for i16 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for u16 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for i8 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for u8 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for char { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for usize { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + #[cfg(target_arch = "wasm32")] + pub fn run_ctors_once() { + wit_bindgen_rt::run_ctors_once(); + } +} + +/// Generates `#[no_mangle]` functions to export the specified type as the +/// root implementation of all generated traits. +/// +/// For more information see the documentation of `wit_bindgen::generate!`. +/// +/// ```rust +/// # macro_rules! export{ ($($t:tt)*) => (); } +/// # trait Guest {} +/// struct MyType; +/// +/// impl Guest for MyType { +/// // ... +/// } +/// +/// export!(MyType); +/// ``` +#[allow(unused_macros)] +#[doc(hidden)] + +macro_rules! __export_calculator_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::calculate::__export_docs_calculator_calculate_cabi!($ty with_types_in $($path_to_types_root)*::exports::docs::calculator::calculate); + ) +} +#[doc(inline)] +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; 290] = *b"\ +\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xa1\x01\x01A\x02\x01\ +A\x04\x01B\x02\x01@\x02\x01ay\x01by\0y\x04\0\x03add\x01\0\x03\x01\x0edocs:adder/\ +add\x05\0\x01B\x04\x01m\x01\x03add\x04\0\x02op\x03\0\0\x01@\x03\x02op\x01\x01xy\x01\ +yy\0y\x04\0\x0feval-expression\x01\x02\x04\x01\x19docs:calculator/calculate\x05\x01\ +\x04\x01\x1adocs:calculator/calculator\x04\0\x0b\x10\x01\0\x0acalculator\x03\0\0\ +\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070.202.0\x10wit-bind\ +gen-rust\x060.24.0"; + +#[inline(never)] +#[doc(hidden)] +#[cfg(target_arch = "wasm32")] +pub fn __link_custom_section_describing_imports() { + wit_bindgen_rt::maybe_link_cabi_realloc(); +} diff --git a/component-model/examples/tutorial/calculator/src/lib.rs b/component-model/examples/tutorial/calculator/src/lib.rs index fed827f0..9ea02477 100644 --- a/component-model/examples/tutorial/calculator/src/lib.rs +++ b/component-model/examples/tutorial/calculator/src/lib.rs @@ -1,9 +1,10 @@ -cargo_component_bindings::generate!(); +#[allow(warnings)] +mod bindings; use bindings::exports::docs::calculator::calculate::{Guest, Op}; // Bring the imported add function into scope -use bindings::docs::calculator::add::add; +use bindings::docs::adder::add::add; struct Component; @@ -14,3 +15,5 @@ impl Guest for Component { } } } + +bindings::export!(Component with_types_in bindings); diff --git a/component-model/examples/tutorial/command/Cargo.lock b/component-model/examples/tutorial/command/Cargo.lock index 39dbab4e..fdd9bab7 100644 --- a/component-model/examples/tutorial/command/Cargo.lock +++ b/component-model/examples/tutorial/command/Cargo.lock @@ -56,42 +56,12 @@ version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "bitflags" version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" -[[package]] -name = "cargo-component-bindings" -version = "0.1.0" -source = "git+https://github.com/bytecodealliance/cargo-component#86ccf3e9e57885784d5a32dcbb162813d5c820ba" -dependencies = [ - "cargo-component-macro", - "wit-bindgen", -] - -[[package]] -name = "cargo-component-macro" -version = "0.1.0" -source = "git+https://github.com/bytecodealliance/cargo-component#86ccf3e9e57885784d5a32dcbb162813d5c820ba" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-bindgen-rust-lib", - "wit-component", -] - [[package]] name = "clap" version = "4.4.1" @@ -144,90 +114,15 @@ name = "command" version = "0.1.0" dependencies = [ "anyhow", - "cargo-component-bindings", "clap", + "wit-bindgen-rt", ] -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "hashbrown" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" - [[package]] name = "heck" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - -[[package]] -name = "idna" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "indexmap" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" -dependencies = [ - "equivalent", - "hashbrown", - "serde", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f478948fd84d9f8e86967bf432640e46adfb5a4bd4f14ef7e864ab38220534ae" [[package]] name = "once_cell" @@ -235,12 +130,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - [[package]] name = "proc-macro2" version = "1.0.66" @@ -250,17 +139,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "pulldown-cmark" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a1a2f1f0a7ecff9c31abbe177637be0e97a0aef46cf8738ece09327985d998" -dependencies = [ - "bitflags 1.3.2", - "memchr", - "unicase", -] - [[package]] name = "quote" version = "1.0.33" @@ -270,64 +148,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "semver" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" - -[[package]] -name = "serde" -version = "1.0.188" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.188" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.105" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "smallvec" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" - -[[package]] -name = "spdx" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71" -dependencies = [ - "smallvec", -] - [[package]] name = "strsim" version = "0.10.0" @@ -345,120 +165,18 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - -[[package]] -name = "unicase" -version = "2.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" -dependencies = [ - "version_check", -] - -[[package]] -name = "unicode-bidi" -version = "0.3.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" - [[package]] name = "unicode-ident" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" -[[package]] -name = "unicode-normalization" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "url" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - [[package]] name = "utf8parse" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasm-encoder" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ba64e81215916eaeb48fee292f29401d69235d62d8b8fd92a7b2844ec5ae5f7" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-metadata" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08dc59d1fa569150851542143ca79438ca56845ccb31696c70225c638e063471" -dependencies = [ - "anyhow", - "indexmap", - "serde", - "serde_json", - "spdx", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.112.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e986b010f47fcce49cf8ea5d5f9e5d2737832f12b53ae8ae785bbe895d0877bf" -dependencies = [ - "indexmap", - "semver", -] - [[package]] name = "windows-sys" version = "0.48.0" @@ -526,95 +244,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] -name = "wit-bindgen" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8a3e8e965dc50e6eb4410d9a11720719fadc6a1713803ea5f3be390b81c8279" -dependencies = [ - "bitflags 2.4.0", - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77255512565dfbd0b61de466e854918041d1da53c7bc049d6188c6e02643dc1e" -dependencies = [ - "anyhow", - "wit-component", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "399c60e6ea8598d1380e792f13d557007834f0fb799fea6503408cbc5debb4ae" -dependencies = [ - "anyhow", - "heck", - "wasm-metadata", - "wit-bindgen-core", - "wit-bindgen-rust-lib", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-lib" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd9fb7a43c7dc28b0b727d6ae01bf369981229b7539e768fba2b7a4df13feeeb" -dependencies = [ - "heck", - "wit-bindgen-core", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.11.0" +name = "wit-bindgen-rt" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44cea5ed784da06da0e55836a6c160e7502dbe28771c2368a595e8606243bf22" +checksum = "3b0780cf7046630ed70f689a098cd8d56c5c3b22f2a7379bbdb088879963ff96" dependencies = [ - "anyhow", - "proc-macro2", - "syn", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-bindgen-rust-lib", - "wit-component", -] - -[[package]] -name = "wit-component" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d9f2d16dd55d1a372dcfd4b7a466ea876682a5a3cb97e71ec9eef04affa876" -dependencies = [ - "anyhow", - "bitflags 2.4.0", - "indexmap", - "log", - "serde", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e8b849bea13cc2315426b16efe6eb6813466d78f5fde69b0bb150c9c40e0dc" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "pulldown-cmark", - "semver", - "unicode-xid", - "url", + "bitflags", ] diff --git a/component-model/examples/tutorial/command/Cargo.toml b/component-model/examples/tutorial/command/Cargo.toml index 1588b3fe..1e03e53e 100644 --- a/component-model/examples/tutorial/command/Cargo.toml +++ b/component-model/examples/tutorial/command/Cargo.toml @@ -7,9 +7,12 @@ edition = "2021" [dependencies] anyhow = "1" -cargo-component-bindings = { git = "https://github.com/bytecodealliance/cargo-component" } +wit-bindgen-rt = { version = "0.24.0", features = ["bitflags"] } clap = { version = "4.3.19", features = ["derive"] } [package.metadata.component.target] path = "../wit/calculator.wit" world = "app" + +[package.metadata.component.target.dependencies] +"docs:adder" = { path = "../adder/wit" } diff --git a/component-model/examples/tutorial/command/src/bindings.rs b/component-model/examples/tutorial/command/src/bindings.rs new file mode 100644 index 00000000..5521ce81 --- /dev/null +++ b/component-model/examples/tutorial/command/src/bindings.rs @@ -0,0 +1,151 @@ +// Generated by `wit-bindgen` 0.24.0. DO NOT EDIT! +// Options used: +#[allow(dead_code)] +pub mod docs { + #[allow(dead_code)] + pub mod calculator { + #[allow(dead_code, clippy::all)] + pub mod calculate { + #[used] + #[doc(hidden)] + #[cfg(target_arch = "wasm32")] + static __FORCE_SECTION_REF: fn() = + super::super::super::__link_custom_section_describing_imports; + use super::super::super::_rt; + #[repr(u8)] + #[derive(Clone, Copy, Eq, PartialEq)] + pub enum Op { + Add, + } + impl ::core::fmt::Debug for Op { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + match self { + Op::Add => f.debug_tuple("Op::Add").finish(), + } + } + } + + impl Op { + pub(crate) unsafe fn _lift(val: u8) -> Op { + if !cfg!(debug_assertions) { + return ::core::mem::transmute(val); + } + + match val { + 0 => Op::Add, + + _ => panic!("invalid enum discriminant"), + } + } + } + + #[allow(unused_unsafe, clippy::all)] + pub fn eval_expression(op: Op, x: u32, y: u32) -> u32 { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "docs:calculator/calculate")] + extern "C" { + #[link_name = "eval-expression"] + fn wit_import(_: i32, _: i32, _: i32) -> i32; + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i32, _: i32) -> i32 { + unreachable!() + } + let ret = wit_import(op.clone() as i32, _rt::as_i32(&x), _rt::as_i32(&y)); + ret as u32 + } + } + } + } +} +mod _rt { + + pub fn as_i32(t: T) -> i32 { + t.as_i32() + } + + pub trait AsI32 { + fn as_i32(self) -> i32; + } + + impl<'a, T: Copy + AsI32> AsI32 for &'a T { + fn as_i32(self) -> i32 { + (*self).as_i32() + } + } + + impl AsI32 for i32 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for u32 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for i16 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for u16 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for i8 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for u8 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for char { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for usize { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } +} + +#[cfg(target_arch = "wasm32")] +#[link_section = "component-type:wit-bindgen:0.24.0:app:encoded world"] +#[doc(hidden)] +pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 234] = *b"\ +\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07q\x01A\x02\x01A\x02\x01\ +B\x04\x01m\x01\x03add\x04\0\x02op\x03\0\0\x01@\x03\x02op\x01\x01xy\x01yy\0y\x04\0\ +\x0feval-expression\x01\x02\x03\x01\x19docs:calculator/calculate\x05\0\x04\x01\x13\ +docs:calculator/app\x04\0\x0b\x09\x01\0\x03app\x03\0\0\0G\x09producers\x01\x0cpr\ +ocessed-by\x02\x0dwit-component\x070.202.0\x10wit-bindgen-rust\x060.24.0"; + +#[inline(never)] +#[doc(hidden)] +#[cfg(target_arch = "wasm32")] +pub fn __link_custom_section_describing_imports() { + wit_bindgen_rt::maybe_link_cabi_realloc(); +} diff --git a/component-model/examples/tutorial/command/src/main.rs b/component-model/examples/tutorial/command/src/main.rs index 1211ede7..075fb912 100644 --- a/component-model/examples/tutorial/command/src/main.rs +++ b/component-model/examples/tutorial/command/src/main.rs @@ -1,4 +1,6 @@ -cargo_component_bindings::generate!(); +#[allow(warnings)] +mod bindings; + use clap::Parser; use std::{fmt, thread::sleep}; diff --git a/component-model/examples/tutorial/wit/calculator.wit b/component-model/examples/tutorial/wit/calculator.wit index f46b6fb5..c78a3ff3 100644 --- a/component-model/examples/tutorial/wit/calculator.wit +++ b/component-model/examples/tutorial/wit/calculator.wit @@ -1,25 +1,17 @@ -package docs:calculator@0.1.0 +package docs:calculator; interface calculate { enum op { add, } - eval-expression: func(op: op, x: u32, y: u32) -> u32 -} - -interface add { - add: func(a: u32, b: u32) -> u32 -} - -world adder { - export add + eval-expression: func(op: op, x: u32, y: u32) -> u32; } world calculator { - export calculate - import add + export calculate; + import docs:adder/add; } world app { - import calculate + import calculate; } \ No newline at end of file diff --git a/component-model/src/tutorial.md b/component-model/src/tutorial.md index d1eb61c7..f8fbefed 100644 --- a/component-model/src/tutorial.md +++ b/component-model/src/tutorial.md @@ -15,8 +15,9 @@ Wasm components, we will compose them into a single runnable component, and test ## The calculator interface -For tutorial purposes, we are going to define all our interfaces in one WIT package (in fact, one -`.wit` file). This file defines: +For tutorial purposes, we are going to define all our interfaces in 2 separate wit files because in a real world use case a component is granular and will have its own wit file. +These files are `adder/wit/world.wit` and `wit/calculator.wit`.These files define: + * An interface for the calculator itself. We'll use this later to carry out calculations. It contains an evaluate function, and an enum that delineates the operations that can be involved in @@ -33,32 +34,38 @@ For tutorial purposes, we are going to define all our interfaces in one WIT pack the component will take in command line arguments and pass them to the "eval-expression" function of the calculator component. +```wit +//adder/wit/world.wit +package docs:adder; + +interface add { + add: func(a: u32, b: u32) -> u32; +} + +world adder { + export add; +} +``` + + ```wit // calculator.wit -package docs:calculator@0.1.0 +package docs:calculator; interface calculate { enum op { add, } - eval-expression: func(op: op, x: u32, y: u32) -> u32 -} - -interface add { - add: func(a: u32, b: u32) -> u32 -} - -world adder { - export add + eval-expression: func(op: op, x: u32, y: u32) -> u32; } world calculator { - export calculate - import add + export calculate; + import docs:adder/add; } world app { - import calculate + import calculate; } ``` @@ -67,14 +74,14 @@ world app { Reference the [language guide](language-support.md) and [authoring components documentation](creating-and-consuming/authoring.md) to create a component that implements the -`adder` world of `calculator.wit`. For reference, see the completed +`adder` world of `adder/wit/world.wit`. For reference, see the completed [example](https://github.com/bytecodealliance/component-docs/tree/main/component-model/examples/tutorial/adder/). ## Create a `calculator` component Reference the [language guide](language-support.md) and [authoring components documentation](creating-and-consuming/authoring.md) to create a component that implements the -`calculator` world of `calculator.wit`. For reference, see the completed +`calculator` world of `wit/calculator.wit`. For reference, see the completed [example](https://github.com/bytecodealliance/component-docs/tree/main/component-model/examples/tutorial/calculator/). The component should import the `add` function from the `adder` world and call it if the `op` enum matches `add`. @@ -93,14 +100,19 @@ cargo component new command --command This component will implement the [`app`](https://github.com/bytecodealliance/component-docs/tree/main/component-model/examples/tutorial/wit/calculator.wit) world, which imports the `calculate` interface. In `Cargo.toml`, point `cargo-component` to the WIT file and -specify that it should pull in bindings for the `app` world: +specify that it should pull in bindings for the `app` world from the path to calculator.wit: ```toml [package.metadata.component.target] -path = "../path/to/calculator.wit" +path = "../wit/calculator.wit" world = "app" ``` +Since the calculator world imports the wit for adder, the command component needs to pull in the dependencies from the adder components wit as well. +```toml +[package.metadata.component.target.dependencies] +"docs:adder" = { path = "../adder/wit" } +``` Now, implement a command line application that: 1. takes in three arguments: two operands and the name of an operator ("1 2 add") @@ -133,7 +145,7 @@ Now it all adds up! Run the command component with the `wasmtime` CLI, ensuring the `wasmtime` command line do not include component model support. ```sh -wasmtime run --wasm component-model command.wasm 1 2 add +wasmtime run command.wasm 1 2 add 1 + 2 = 3 ``` From 515661a5fa163ca6b534df6397a8a14796146919 Mon Sep 17 00:00:00 2001 From: ritesh089 Date: Fri, 10 May 2024 09:09:30 -0400 Subject: [PATCH 2/8] Update component-model/src/tutorial.md Co-authored-by: itowlson --- component-model/src/tutorial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component-model/src/tutorial.md b/component-model/src/tutorial.md index 11062eb8..9257faa6 100644 --- a/component-model/src/tutorial.md +++ b/component-model/src/tutorial.md @@ -15,7 +15,7 @@ Wasm components, we will compose them into a single runnable component, and test ## The calculator interface -For tutorial purposes, we are going to define all our interfaces in 2 separate wit files because in a real world use case a component is granular and will have its own wit file. +For tutorial purposes, we are going to put our "calculator engine" and "addition operation" interfaces into two separate WIT packages, each containing one WIT file. This may seem excessive, but the reason is to illustrate real-world use cases where components come from different authors and packages. These files are `adder/wit/world.wit` and `wit/calculator.wit`.These files define: From d810c3599d391e1a911cbbfb6889dac1d2754625 Mon Sep 17 00:00:00 2001 From: rrai35 Date: Mon, 20 May 2024 11:42:10 -0400 Subject: [PATCH 3/8] feat(wit): Moving wit outside the packages --- component-model/examples/tutorial/README.md | 11 ++--- .../examples/tutorial/adder/Cargo.toml | 4 ++ .../examples/tutorial/adder/src/bindings.rs | 20 ++++----- .../examples/tutorial/calculator/Cargo.toml | 4 +- .../tutorial/calculator/src/bindings.rs | 26 ++++++------ .../examples/tutorial/command/Cargo.lock | 14 ++----- .../examples/tutorial/command/Cargo.toml | 6 +-- .../examples/tutorial/command/src/bindings.rs | 13 +++--- .../examples/tutorial/command/src/main.rs | 1 - .../{adder/wit => wit/adder}/world.wit | 2 +- .../{calculator.wit => calculator/world.wit} | 4 +- component-model/src/tutorial.md | 42 +++++++++---------- 12 files changed, 72 insertions(+), 75 deletions(-) rename component-model/examples/tutorial/{adder/wit => wit/adder}/world.wit (77%) rename component-model/examples/tutorial/wit/{calculator.wit => calculator/world.wit} (75%) diff --git a/component-model/examples/tutorial/README.md b/component-model/examples/tutorial/README.md index 63b3acac..3beb5eb6 100644 --- a/component-model/examples/tutorial/README.md +++ b/component-model/examples/tutorial/README.md @@ -6,7 +6,7 @@ add an `op` enum that delineates each operator. The following example interface has an `add` operation: ```wit adder -package docs:adder; +package docs:adder@0.1.0; interface add { @@ -19,8 +19,8 @@ world adder { ``` -```wit -package docs:calculator; +```wit calculator +package docs:calculator@0.1.0; interface calculate { enum op { @@ -50,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 ``` diff --git a/component-model/examples/tutorial/adder/Cargo.toml b/component-model/examples/tutorial/adder/Cargo.toml index 3ef5ceac..d710b687 100644 --- a/component-model/examples/tutorial/adder/Cargo.toml +++ b/component-model/examples/tutorial/adder/Cargo.toml @@ -13,3 +13,7 @@ crate-type = ["cdylib"] package = "docs:adder" [package.metadata.component.dependencies] + +[package.metadata.component.target] +path = "../wit/adder" +world = "adder" diff --git a/component-model/examples/tutorial/adder/src/bindings.rs b/component-model/examples/tutorial/adder/src/bindings.rs index fb474c09..762a1ff2 100644 --- a/component-model/examples/tutorial/adder/src/bindings.rs +++ b/component-model/examples/tutorial/adder/src/bindings.rs @@ -27,17 +27,17 @@ pub mod exports { } #[doc(hidden)] - macro_rules! __export_docs_adder_add_cabi{ + macro_rules! __export_docs_adder_add_0_1_0_cabi{ ($ty:ident with_types_in $($path_to_types:tt)*) => (const _: () = { - #[export_name = "docs:adder/add#add"] + #[export_name = "docs:adder/add@0.1.0#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_adder_add_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::adder::add::__export_docs_adder_add_cabi!($ty with_types_in $($path_to_types_root)*::exports::docs::adder::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; 191] = *b"\ -\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07D\x01A\x02\x01A\x02\x01\ -B\x02\x01@\x02\x01ay\x01by\0y\x04\0\x03add\x01\0\x04\x01\x0edocs:adder/add\x05\0\ -\x04\x01\x10docs:adder/adder\x04\0\x0b\x0b\x01\0\x05adder\x03\0\0\0G\x09producer\ -s\x01\x0cprocessed-by\x02\x0dwit-component\x070.202.0\x10wit-bindgen-rust\x060.2\ -4.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/adder@0.1.0\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)] diff --git a/component-model/examples/tutorial/calculator/Cargo.toml b/component-model/examples/tutorial/calculator/Cargo.toml index 3c327ecf..6f6f7179 100644 --- a/component-model/examples/tutorial/calculator/Cargo.toml +++ b/component-model/examples/tutorial/calculator/Cargo.toml @@ -13,10 +13,10 @@ crate-type = ["cdylib"] package = "docs:calculator" [package.metadata.component.target.dependencies] -"docs:adder" = { path = "../adder/wit" } # directory containing the WIT package +"docs:adder" = { path = "../wit/adder" } # directory containing the WIT package [package.metadata.component.target] -path = "../wit/calculator.wit" +path = "../wit/calculator" world = "calculator" [package.metadata.component.dependencies] diff --git a/component-model/examples/tutorial/calculator/src/bindings.rs b/component-model/examples/tutorial/calculator/src/bindings.rs index fd7d8cc3..ee0f5171 100644 --- a/component-model/examples/tutorial/calculator/src/bindings.rs +++ b/component-model/examples/tutorial/calculator/src/bindings.rs @@ -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:adder/add")] + #[link(wasm_import_module = "docs:adder/add@0.1.0")] extern "C" { #[link_name = "add"] fn wit_import(_: i32, _: i32) -> i32; @@ -92,17 +92,17 @@ pub mod exports { } #[doc(hidden)] - macro_rules! __export_docs_calculator_calculate_cabi{ + macro_rules! __export_docs_calculator_calculate_0_1_0_cabi{ ($ty:ident with_types_in $($path_to_types:tt)*) => (const _: () = { - #[export_name = "docs:calculator/calculate#eval-expression"] + #[export_name = "docs:calculator/calculate@0.1.0#eval-expression"] unsafe extern "C" fn export_eval_expression(arg0: i32,arg1: i32,arg2: i32,) -> i32 { $($path_to_types)*::_export_eval_expression_cabi::<$ty>(arg0, arg1, arg2) } };); } #[doc(hidden)] - pub(crate) use __export_docs_calculator_calculate_cabi; + pub(crate) use __export_docs_calculator_calculate_0_1_0_cabi; } } } @@ -207,7 +207,7 @@ mod _rt { macro_rules! __export_calculator_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::calculate::__export_docs_calculator_calculate_cabi!($ty with_types_in $($path_to_types_root)*::exports::docs::calculator::calculate); + $($path_to_types_root)*::exports::docs::calculator::calculate::__export_docs_calculator_calculate_0_1_0_cabi!($ty with_types_in $($path_to_types_root)*::exports::docs::calculator::calculate); ) } #[doc(inline)] @@ -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; 290] = *b"\ -\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xa1\x01\x01A\x02\x01\ -A\x04\x01B\x02\x01@\x02\x01ay\x01by\0y\x04\0\x03add\x01\0\x03\x01\x0edocs:adder/\ -add\x05\0\x01B\x04\x01m\x01\x03add\x04\0\x02op\x03\0\0\x01@\x03\x02op\x01\x01xy\x01\ -yy\0y\x04\0\x0feval-expression\x01\x02\x04\x01\x19docs:calculator/calculate\x05\x01\ -\x04\x01\x1adocs:calculator/calculator\x04\0\x0b\x10\x01\0\x0acalculator\x03\0\0\ -\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070.202.0\x10wit-bind\ -gen-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/\ +add@0.1.0\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/calculator@0.1.0\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)] diff --git a/component-model/examples/tutorial/command/Cargo.lock b/component-model/examples/tutorial/command/Cargo.lock index 03464b52..a5dffccc 100644 --- a/component-model/examples/tutorial/command/Cargo.lock +++ b/component-model/examples/tutorial/command/Cargo.lock @@ -123,12 +123,6 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - [[package]] name = "proc-macro2" version = "1.0.78" @@ -140,9 +134,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -238,9 +232,9 @@ checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" [[package]] name = "windows_x86_64_msvc" -version = "0.48.5" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "wit-bindgen-rt" diff --git a/component-model/examples/tutorial/command/Cargo.toml b/component-model/examples/tutorial/command/Cargo.toml index 1e03e53e..98ef4596 100644 --- a/component-model/examples/tutorial/command/Cargo.toml +++ b/component-model/examples/tutorial/command/Cargo.toml @@ -3,16 +3,14 @@ name = "command" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] anyhow = "1" wit-bindgen-rt = { version = "0.24.0", features = ["bitflags"] } clap = { version = "4.3.19", features = ["derive"] } [package.metadata.component.target] -path = "../wit/calculator.wit" +path = "../wit/calculator" world = "app" [package.metadata.component.target.dependencies] -"docs:adder" = { path = "../adder/wit" } +"docs:adder" = { path = "../wit/adder" } diff --git a/component-model/examples/tutorial/command/src/bindings.rs b/component-model/examples/tutorial/command/src/bindings.rs index 5521ce81..1dbe7d85 100644 --- a/component-model/examples/tutorial/command/src/bindings.rs +++ b/component-model/examples/tutorial/command/src/bindings.rs @@ -43,7 +43,7 @@ pub mod docs { pub fn eval_expression(op: Op, x: u32, y: u32) -> u32 { unsafe { #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "docs:calculator/calculate")] + #[link(wasm_import_module = "docs:calculator/calculate@0.1.0")] extern "C" { #[link_name = "eval-expression"] fn wit_import(_: i32, _: i32, _: i32) -> i32; @@ -136,12 +136,13 @@ mod _rt { #[cfg(target_arch = "wasm32")] #[link_section = "component-type:wit-bindgen:0.24.0:app:encoded world"] #[doc(hidden)] -pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 234] = *b"\ -\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07q\x01A\x02\x01A\x02\x01\ +pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 246] = *b"\ +\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07}\x01A\x02\x01A\x02\x01\ B\x04\x01m\x01\x03add\x04\0\x02op\x03\0\0\x01@\x03\x02op\x01\x01xy\x01yy\0y\x04\0\ -\x0feval-expression\x01\x02\x03\x01\x19docs:calculator/calculate\x05\0\x04\x01\x13\ -docs:calculator/app\x04\0\x0b\x09\x01\0\x03app\x03\0\0\0G\x09producers\x01\x0cpr\ -ocessed-by\x02\x0dwit-component\x070.202.0\x10wit-bindgen-rust\x060.24.0"; +\x0feval-expression\x01\x02\x03\x01\x1fdocs:calculator/calculate@0.1.0\x05\0\x04\ +\x01\x19docs:calculator/app@0.1.0\x04\0\x0b\x09\x01\0\x03app\x03\0\0\0G\x09produ\ +cers\x01\x0cprocessed-by\x02\x0dwit-component\x070.202.0\x10wit-bindgen-rust\x06\ +0.24.0"; #[inline(never)] #[doc(hidden)] diff --git a/component-model/examples/tutorial/command/src/main.rs b/component-model/examples/tutorial/command/src/main.rs index 87f7d4a0..055fffbe 100644 --- a/component-model/examples/tutorial/command/src/main.rs +++ b/component-model/examples/tutorial/command/src/main.rs @@ -1,4 +1,3 @@ -#[allow(warnings)] mod bindings; use clap::Parser; diff --git a/component-model/examples/tutorial/adder/wit/world.wit b/component-model/examples/tutorial/wit/adder/world.wit similarity index 77% rename from component-model/examples/tutorial/adder/wit/world.wit rename to component-model/examples/tutorial/wit/adder/world.wit index ab60731f..328f7f49 100644 --- a/component-model/examples/tutorial/adder/wit/world.wit +++ b/component-model/examples/tutorial/wit/adder/world.wit @@ -1,4 +1,4 @@ -package docs:adder; +package docs:adder@0.1.0; interface add { add: func(a: u32, b: u32) -> u32; diff --git a/component-model/examples/tutorial/wit/calculator.wit b/component-model/examples/tutorial/wit/calculator/world.wit similarity index 75% rename from component-model/examples/tutorial/wit/calculator.wit rename to component-model/examples/tutorial/wit/calculator/world.wit index 583c6c45..c775b841 100644 --- a/component-model/examples/tutorial/wit/calculator.wit +++ b/component-model/examples/tutorial/wit/calculator/world.wit @@ -1,4 +1,4 @@ -package docs:calculator; +package docs:calculator@0.1.0; interface calculate { enum op { @@ -9,7 +9,7 @@ interface calculate { world calculator { export calculate; - import docs:adder/add; + import docs:adder/add@0.1.0; } world app { diff --git a/component-model/src/tutorial.md b/component-model/src/tutorial.md index 9257faa6..50fba53f 100644 --- a/component-model/src/tutorial.md +++ b/component-model/src/tutorial.md @@ -18,25 +18,12 @@ Wasm components, we will compose them into a single runnable component, and test For tutorial purposes, we are going to put our "calculator engine" and "addition operation" interfaces into two separate WIT packages, each containing one WIT file. This may seem excessive, but the reason is to illustrate real-world use cases where components come from different authors and packages. These files are `adder/wit/world.wit` and `wit/calculator.wit`.These files define: - -* An interface for the calculator itself. We'll use this later to carry out calculations. It - contains an evaluate function, and an enum that delineates the operations that can be involved in - a calculation. In this tutorial, the only operation is `add`. -* Interfaces for the various operations the calculator might need to carry out as part of a - calculation. For the tutorial, again, the only interface we define is for the "add" operation. -* A world describing the calculator component. This world exports the calculator interface, meaning - that other components can call it to perform calculations. It imports the operation interfaces - (such as "add"), meaning it relies on other components to perform those operations. -* A world describing each operator component. Again, there's just the "adder" world right now, and - this exports the "add" interface, meaning that components such as the calculator can call it when +* A world describing an world that exports the "add" interface. Again, components such as the calculator can call it when they need to add numbers. -* A world describing the "primary" app component, which imports the "calculate" interface. This is - the component will take in command line arguments and pass them to the "eval-expression" function - of the calculator component. ```wit -//adder/wit/world.wit -package docs:adder; +// wit/adder/world.wit +package docs:adder@0.1.0; interface add { add: func(a: u32, b: u32) -> u32; @@ -47,10 +34,23 @@ world adder { } ``` +* An interface for the calculator itself. We'll use this later to carry out calculations. It + contains an evaluate function, and an enum that delineates the operations that can be involved in + a calculation. In this tutorial, the only operation is `add`. +* Interfaces for the various operations the calculator might need to carry out as part of a + calculation. For the tutorial, again, the only import we define is for the "add" operation from + the "docs:adder" world defined previously. +* A world describing the calculator component. This world exports the calculator interface, meaning + that other components can call it to perform calculations. It imports the operation interfaces + (such as "add"), meaning it relies on other components to perform those operations. +* A world describing the "primary" app component, which imports the "calculate" interface. This is + the component will take in command line arguments and pass them to the "eval-expression" function + of the calculator component. + ```wit -// calculator.wit -package docs:calculator; +// wit/calculator/world.wit +package docs:calculator@0.1.0; interface calculate { enum op { @@ -61,7 +61,7 @@ interface calculate { world calculator { export calculate; - import docs:adder/add; + import docs:adder/add@0.1.0; } world app { @@ -100,7 +100,7 @@ cargo component new command --command This component will implement the [`app`](https://github.com/bytecodealliance/component-docs/tree/main/component-model/examples/tutorial/wit/calculator.wit) world, which imports the `calculate` interface. In `Cargo.toml`, point `cargo-component` to the WIT file and -specify that it should pull in bindings for the `app` world from the path to calculator.wit: +specify that it should pull in bindings for the `app` world from the path to `calculator.wit`: ```toml [package.metadata.component.target] @@ -145,7 +145,7 @@ Now it all adds up! Run the final component with the `wasmtime` CLI, ensuring yo the `wasmtime` command line do not include component model support. ```sh -wasmtime run command.wasm 1 2 add +wasmtime run final.wasm 1 2 add 1 + 2 = 3 ``` From ceda48908fb840d99398ec5e06707ce182e2412b Mon Sep 17 00:00:00 2001 From: ritesh089 Date: Tue, 28 May 2024 10:17:00 -0400 Subject: [PATCH 4/8] Update component-model/src/tutorial.md Co-authored-by: Kate Goldenring --- component-model/src/tutorial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component-model/src/tutorial.md b/component-model/src/tutorial.md index 50fba53f..067b6a5f 100644 --- a/component-model/src/tutorial.md +++ b/component-model/src/tutorial.md @@ -16,7 +16,7 @@ Wasm components, we will compose them into a single runnable component, and test ## The calculator interface For tutorial purposes, we are going to put our "calculator engine" and "addition operation" interfaces into two separate WIT packages, each containing one WIT file. This may seem excessive, but the reason is to illustrate real-world use cases where components come from different authors and packages. -These files are `adder/wit/world.wit` and `wit/calculator.wit`.These files define: +These files can be found in the component book repository in the [`wit` directory](https://github.com/bytecodealliance/component-docs/tree/main/component-model/examples/tutorial/wit) under `wit/adder/world.wit` and `wit/calculator/world.wit`. These files define: * A world describing an world that exports the "add" interface. Again, components such as the calculator can call it when they need to add numbers. From a45c4d4c2a1ac8c56833da4da4b4a737fc61b98d Mon Sep 17 00:00:00 2001 From: ritesh089 Date: Tue, 28 May 2024 10:18:12 -0400 Subject: [PATCH 5/8] Update component-model/src/tutorial.md Co-authored-by: Kate Goldenring --- component-model/src/tutorial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component-model/src/tutorial.md b/component-model/src/tutorial.md index 067b6a5f..484be2d7 100644 --- a/component-model/src/tutorial.md +++ b/component-model/src/tutorial.md @@ -81,7 +81,7 @@ documentation](creating-and-consuming/authoring.md) to create a component that i Reference the [language guide](language-support.md) and [authoring components documentation](creating-and-consuming/authoring.md) to create a component that implements the -`calculator` world of `wit/calculator.wit`. For reference, see the completed +`calculator` world of `wit/calculator/world.wit`. For reference, see the completed [example](https://github.com/bytecodealliance/component-docs/tree/main/component-model/examples/tutorial/calculator/). The component should import the `add` function from the `adder` world and call it if the `op` enum matches `add`. From 8d173c2d97d7c81aad88080790c0322be3b5793e Mon Sep 17 00:00:00 2001 From: ritesh089 Date: Tue, 28 May 2024 10:18:34 -0400 Subject: [PATCH 6/8] Update component-model/src/tutorial.md Co-authored-by: Kate Goldenring --- component-model/src/tutorial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component-model/src/tutorial.md b/component-model/src/tutorial.md index 484be2d7..8c1dd26e 100644 --- a/component-model/src/tutorial.md +++ b/component-model/src/tutorial.md @@ -104,7 +104,7 @@ specify that it should pull in bindings for the `app` world from the path to `ca ```toml [package.metadata.component.target] -path = "../wit/calculator.wit" +path = "../wit/calculator/world.wit" world = "app" ``` Since the calculator world imports the wit for adder, the command component needs to pull in the dependencies from the adder components wit as well. From 0b75a71de229237c86b39a82ddd915a740072c6f Mon Sep 17 00:00:00 2001 From: ritesh089 Date: Tue, 28 May 2024 10:19:45 -0400 Subject: [PATCH 7/8] Update component-model/src/tutorial.md Co-authored-by: Kate Goldenring --- component-model/src/tutorial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component-model/src/tutorial.md b/component-model/src/tutorial.md index 8c1dd26e..bbaba7ae 100644 --- a/component-model/src/tutorial.md +++ b/component-model/src/tutorial.md @@ -111,7 +111,7 @@ Since the calculator world imports the wit for adder, the command component need ```toml [package.metadata.component.target.dependencies] -"docs:adder" = { path = "../adder/wit" } +"docs:adder" = { path = "../wit/adder" } ``` Now, implement a command line application that: From 4ebfc4412a0aa0ba9e09380927c3456c33fc108e Mon Sep 17 00:00:00 2001 From: ritesh089 Date: Tue, 28 May 2024 10:20:16 -0400 Subject: [PATCH 8/8] Update component-model/src/tutorial.md Co-authored-by: Kate Goldenring --- component-model/src/tutorial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component-model/src/tutorial.md b/component-model/src/tutorial.md index bbaba7ae..68dc04b4 100644 --- a/component-model/src/tutorial.md +++ b/component-model/src/tutorial.md @@ -107,7 +107,7 @@ specify that it should pull in bindings for the `app` world from the path to `ca path = "../wit/calculator/world.wit" world = "app" ``` -Since the calculator world imports the wit for adder, the command component needs to pull in the dependencies from the adder components wit as well. +Since the calculator world imports the `add` interface, the command component needs to pull in the `adder` WIT as a dependency, as well. ```toml [package.metadata.component.target.dependencies]