From a4fbcbd43d8621015880ecfac1025245e0f66f1b Mon Sep 17 00:00:00 2001 From: Kate Goldenring Date: Fri, 15 Mar 2024 14:30:49 -0700 Subject: [PATCH] fix: bring documentation and tutorials up to date with latest tooling Signed-off-by: Kate Goldenring --- .../examples/example-host/Cargo.lock | 417 ++++++++++-------- .../examples/example-host/Cargo.toml | 5 +- .../examples/example-host/src/add.rs | 20 +- component-model/examples/tutorial/README.md | 2 +- .../src/creating-and-consuming/composing.md | 2 +- .../src/creating-and-consuming/running.md | 6 +- component-model/src/implementations/jco.md | 1 - .../src/implementations/wasmtime.md | 1 - .../src/language-support/javascript.md | 21 +- .../src/language-support/python.md | 114 +++-- component-model/src/language-support/rust.md | 8 +- component-model/src/runtimes/wasmtime.md | 6 +- component-model/src/tutorial.md | 2 +- 13 files changed, 367 insertions(+), 238 deletions(-) delete mode 100644 component-model/src/implementations/jco.md delete mode 100644 component-model/src/implementations/wasmtime.md diff --git a/component-model/examples/example-host/Cargo.lock b/component-model/examples/example-host/Cargo.lock index fe2db91..d3568cf 100644 --- a/component-model/examples/example-host/Cargo.lock +++ b/component-model/examples/example-host/Cargo.lock @@ -70,7 +70,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" dependencies = [ - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -80,7 +80,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" dependencies = [ "anstyle", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -324,7 +324,7 @@ dependencies = [ "cap-primitives", "cap-std", "io-lifetimes 2.0.2", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -352,7 +352,7 @@ dependencies = [ "ipnet", "maybe-owned", "rustix 0.38.21", - "windows-sys", + "windows-sys 0.48.0", "winx", ] @@ -481,16 +481,18 @@ dependencies = [ [[package]] name = "cranelift-bforest" -version = "0.101.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "0.105.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16d5521e2abca66bbb1ddeecbb6f6965c79160352ae1579b39f8c86183895c24" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.101.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "0.105.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef40a4338a47506e832ac3e53f7f1375bc59351f049a8379ff736dd02565bd95" dependencies = [ "bumpalo", "cranelift-bforest", @@ -509,29 +511,33 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.101.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "0.105.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24cd5d85985c070f73dfca07521d09086362d1590105ba44b0932bf33513b61" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.101.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "0.105.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0584c4363e3aa0a3c7cb98a778fbd5326a3709f117849a727da081d4051726c" [[package]] name = "cranelift-control" -version = "0.101.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "0.105.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f25ecede098c6553fdba362a8e4c9ecb8d40138363bff47f9712db75be7f0571" dependencies = [ "arbitrary", ] [[package]] name = "cranelift-entity" -version = "0.101.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "0.105.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea081a42f25dc4c5b248b87efdd87dcd3842a1050a37524ec5391e6172058cb" dependencies = [ "serde", "serde_derive", @@ -539,8 +545,9 @@ dependencies = [ [[package]] name = "cranelift-frontend" -version = "0.101.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "0.105.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9796e712f5af797e247784f7518e6b0a83a8907d73d51526982d86ecb3a58b68" dependencies = [ "cranelift-codegen", "log", @@ -550,13 +557,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.101.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "0.105.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4a66ccad5782f15c80e9dd5af0df4acfe6e3eee98e8f7354a2e5c8ec3104bdd" [[package]] name = "cranelift-native" -version = "0.101.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "0.105.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "285e80df1d9b79ded9775b285df68b920a277b84f88a7228d2f5bc31fcdc58eb" dependencies = [ "cranelift-codegen", "libc", @@ -565,8 +574,9 @@ dependencies = [ [[package]] name = "cranelift-wasm" -version = "0.101.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "0.105.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4135b0ab01fd16aa8f8821196e9e2fe15953552ccaef8ba5153be0ced04ef757" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -718,7 +728,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -734,7 +744,6 @@ dependencies = [ "anyhow", "async-std", "clap", - "wasi-cap-std-sync", "wasmtime", "wasmtime-wasi", ] @@ -768,7 +777,7 @@ checksum = "0b0377f1edc77dbd1118507bc7a66e4ab64d2b90c66f90726dc801e73a8c68f9" dependencies = [ "cfg-if", "rustix 0.38.21", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -788,7 +797,7 @@ checksum = "dd738b84894214045e8414eaded76359b4a5773f0a0a56b16575110739cdcf39" dependencies = [ "io-lifetimes 2.0.2", "rustix 0.38.21", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1006,7 +1015,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d3c230ee517ee76b1cc593b52939ff68deda3fae9e41eca426c6b4993df51c4" dependencies = [ "io-lifetimes 2.0.2", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1017,7 +1026,7 @@ checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ "hermit-abi", "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1049,9 +1058,9 @@ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "ittapi" -version = "0.3.5" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a5c0b993601cad796222ea076565c5d9f337d35592f8622c753724f06d7271" +checksum = "6b996fe614c41395cdaedf3cf408a9534851090959d90d54a535f675550b64b1" dependencies = [ "anyhow", "ittapi-sys", @@ -1060,9 +1069,9 @@ dependencies = [ [[package]] name = "ittapi-sys" -version = "0.3.5" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7b5e473765060536a660eed127f758cf1a810c73e49063264959c60d1727d9" +checksum = "52f5385394064fa2c886205dba02598013ce83d3e92d33dbdc0c52fe0e7bf4fc" dependencies = [ "cc", ] @@ -1183,7 +1192,7 @@ checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" dependencies = [ "libc", "wasi", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1274,7 +1283,7 @@ dependencies = [ "libc", "log", "pin-project-lite", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1416,7 +1425,7 @@ dependencies = [ "io-lifetimes 1.0.11", "libc", "linux-raw-sys 0.3.8", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1431,7 +1440,7 @@ dependencies = [ "libc", "linux-raw-sys 0.4.10", "once_cell", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1541,7 +1550,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1596,7 +1605,7 @@ dependencies = [ "fd-lock", "io-lifetimes 2.0.2", "rustix 0.38.21", - "windows-sys", + "windows-sys 0.48.0", "winx", ] @@ -1654,7 +1663,7 @@ dependencies = [ "num_cpus", "pin-project-lite", "socket2 0.5.5", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1672,7 +1681,6 @@ version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -1785,12 +1793,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] -name = "wasi-cap-std-sync" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +name = "wasi-common" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95e022c29ad56af4cc0a8a8f0e0191abf9e0a0c4a68d25dfe088c39c9a8e3d2c" dependencies = [ "anyhow", - "async-trait", + "bitflags 2.4.1", "cap-fs-ext", "cap-rand", "cap-std", @@ -1798,31 +1807,15 @@ dependencies = [ "fs-set-times", "io-extras", "io-lifetimes 2.0.2", + "log", "once_cell", "rustix 0.38.21", "system-interface", - "tracing", - "wasi-common", - "windows-sys", -] - -[[package]] -name = "wasi-common" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" -dependencies = [ - "anyhow", - "bitflags 2.4.1", - "cap-rand", - "cap-std", - "io-extras", - "log", - "rustix 0.38.21", "thiserror", "tracing", "wasmtime", "wiggle", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -1893,28 +1886,38 @@ checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" [[package]] name = "wasm-encoder" -version = "0.35.0" +version = "0.41.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "972f97a5d8318f908dded23594188a90bcd09365986b1163e66d70170e5287ae" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-encoder" +version = "0.201.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca90ba1b5b0a70d3d49473c5579951f3bddc78d47b59256d2f9d4922b150aca" +checksum = "b9c7d2731df60006819b013f64ccc2019691deccf6e11a1804bc850cd6748f1a" dependencies = [ "leb128", ] [[package]] name = "wasmparser" -version = "0.115.0" +version = "0.121.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e06c0641a4add879ba71ccb3a1e4278fd546f76f1eafb21d8f7b07733b547cd5" +checksum = "9dbe55c8f9d0dbd25d9447a5a889ff90c0cc3feaa7395310d3d826b2c703eaab" dependencies = [ + "bitflags 2.4.1", "indexmap", "semver", ] [[package]] name = "wasmprinter" -version = "0.2.70" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e74458a9bc5cc9c7108abfa0fe4dc88d5abf1f3baf194df3264985f17d559b5e" +checksum = "60e73986a6b7fdfedb7c5bf9e7eb71135486507c8fbc4c0c42cffcb6532988b7" dependencies = [ "anyhow", "wasmparser", @@ -1922,9 +1925,11 @@ dependencies = [ [[package]] name = "wasmtime" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8106d7d22d63d1bcb940e22dcc7b03e46f0fc8bfbaf2fd7b6cb8f448f9449774" dependencies = [ + "addr2line", "anyhow", "async-trait", "bincode", @@ -1932,19 +1937,21 @@ dependencies = [ "cfg-if", "encoding_rs", "fxprof-processed-profile", + "gimli", "indexmap", + "ittapi", "libc", "log", "object", "once_cell", "paste", - "psm", "rayon", + "rustix 0.38.21", "serde", "serde_derive", "serde_json", "target-lexicon", - "wasm-encoder", + "wasm-encoder 0.41.2", "wasmparser", "wasmtime-cache", "wasmtime-component-macro", @@ -1952,25 +1959,28 @@ dependencies = [ "wasmtime-cranelift", "wasmtime-environ", "wasmtime-fiber", - "wasmtime-jit", + "wasmtime-jit-debug", + "wasmtime-jit-icache-coherence", "wasmtime-runtime", "wasmtime-winch", "wat", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] name = "wasmtime-asm-macros" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0cf02cea951ace34ee3b0e64b7f446c3519d1c95ad75bc5330f405e275ee8f" dependencies = [ "cfg-if", ] [[package]] name = "wasmtime-cache" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3249204a71d728d53fb3eea18afd0473f87e520445707a4d567ac4da0bb3eb5d" dependencies = [ "anyhow", "base64", @@ -1982,14 +1992,15 @@ dependencies = [ "serde_derive", "sha2", "toml", - "windows-sys", + "windows-sys 0.52.0", "zstd", ] [[package]] name = "wasmtime-component-macro" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d3786c0531565ec6c9852c0e46299f06cb6e4b58d36e30f3c234cfa69bde376" dependencies = [ "anyhow", "proc-macro2", @@ -2002,13 +2013,15 @@ dependencies = [ [[package]] name = "wasmtime-component-util" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81eae2ec98027ee0b3950da83bc320120a23087ac4d39b3d59201cb5ebf52777" [[package]] name = "wasmtime-cranelift" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "595abdb067acdc812ab0f21d8d46d5aa4022392aa7c3e0632c20bff9ec49ffb4" dependencies = [ "anyhow", "cfg-if", @@ -2031,8 +2044,9 @@ dependencies = [ [[package]] name = "wasmtime-cranelift-shared" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c24c1fdea167b992d82ebe76471fd1cbe7b0b406bc72f9250f86353000134e" dependencies = [ "anyhow", "cranelift-codegen", @@ -2046,20 +2060,24 @@ dependencies = [ [[package]] name = "wasmtime-environ" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3279d510005358141550d8a90a5fc989d7e81748e5759d582fe6bfdcbf074a04" dependencies = [ "anyhow", + "bincode", + "cpp_demangle", "cranelift-entity", "gimli", "indexmap", "log", "object", + "rustc-demangle", "serde", "serde_derive", "target-lexicon", "thiserror", - "wasm-encoder", + "wasm-encoder 0.41.2", "wasmparser", "wasmprinter", "wasmtime-component-util", @@ -2068,47 +2086,24 @@ dependencies = [ [[package]] name = "wasmtime-fiber" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b1df665f2117741d1265f5663b0d93068b18120c2c4b18b9faed49d00d92c31" dependencies = [ + "anyhow", "cc", "cfg-if", "rustix 0.38.21", "wasmtime-asm-macros", "wasmtime-versioned-export-macros", - "windows-sys", -] - -[[package]] -name = "wasmtime-jit" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" -dependencies = [ - "addr2line", - "anyhow", - "bincode", - "cfg-if", - "cpp_demangle", - "gimli", - "ittapi", - "log", - "object", - "rustc-demangle", - "rustix 0.38.21", - "serde", - "serde_derive", - "target-lexicon", - "wasmtime-environ", - "wasmtime-jit-debug", - "wasmtime-jit-icache-coherence", - "wasmtime-runtime", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] name = "wasmtime-jit-debug" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63f307739370736e5b0cd2b45910ff96bcda6d5d68b2c4384bcedb0af4f3b321" dependencies = [ "object", "once_cell", @@ -2118,18 +2113,20 @@ dependencies = [ [[package]] name = "wasmtime-jit-icache-coherence" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "866634605089b4632b32226b54aa3670d72e1849f9fc425c7e50b3749c2e6df3" dependencies = [ "cfg-if", "libc", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] name = "wasmtime-runtime" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e11185c88cadf595d228f5ae4ff9b4badbf9ca98dcb37b0310c36e31fa74867f" dependencies = [ "anyhow", "cc", @@ -2142,23 +2139,24 @@ dependencies = [ "memfd", "memoffset", "paste", - "rand", + "psm", "rustix 0.38.21", "sptr", - "wasm-encoder", + "wasm-encoder 0.41.2", "wasmtime-asm-macros", "wasmtime-environ", "wasmtime-fiber", "wasmtime-jit-debug", "wasmtime-versioned-export-macros", "wasmtime-wmemcheck", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] name = "wasmtime-types" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f32377cbd827bee06fcb2f6bf97b0477fdcc86888bbe6db7b9cab8e644082e0a" dependencies = [ "cranelift-entity", "serde", @@ -2169,8 +2167,9 @@ dependencies = [ [[package]] name = "wasmtime-versioned-export-macros" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ab8d7566d206c42f8cf1d4ac90c5e40d3582e8eabad9b3b67e9e73c61fc47a1" dependencies = [ "proc-macro2", "quote", @@ -2179,8 +2178,9 @@ dependencies = [ [[package]] name = "wasmtime-wasi" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca912bda309188bd25ab7652c6654b34aacdf43047c716ee1cb685a28079078" dependencies = [ "anyhow", "async-trait", @@ -2195,7 +2195,6 @@ dependencies = [ "futures", "io-extras", "io-lifetimes 2.0.2", - "libc", "log", "once_cell", "rustix 0.38.21", @@ -2204,17 +2203,17 @@ dependencies = [ "tokio", "tracing", "url", - "wasi-cap-std-sync", "wasi-common", "wasmtime", "wiggle", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] name = "wasmtime-winch" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba5a97bfccc241d1769cef75eb16f472a893982704d5f3c9c71c431c1484344a" dependencies = [ "anyhow", "cranelift-codegen", @@ -2229,8 +2228,9 @@ dependencies = [ [[package]] name = "wasmtime-wit-bindgen" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "faf2c76781a27e07802669f6f0e11eb4441546407eb65be60c3d862200988b92" dependencies = [ "anyhow", "heck", @@ -2240,8 +2240,9 @@ dependencies = [ [[package]] name = "wasmtime-wmemcheck" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3847d969bd203b8cd239f89581e52432a0f00b8c5c9bc917be2fccd7542c4f2f" [[package]] name = "wast" @@ -2254,23 +2255,24 @@ dependencies = [ [[package]] name = "wast" -version = "66.0.2" +version = "201.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93cb43b0ac6dd156f2c375735ccfd72b012a7c0a6e6d09503499b8d3cb6e6072" +checksum = "1ef6e1ef34d7da3e2b374fd2b1a9c0227aff6cad596e1b24df9b58d0f6222faa" dependencies = [ + "bumpalo", "leb128", "memchr", "unicode-width", - "wasm-encoder", + "wasm-encoder 0.201.0", ] [[package]] name = "wat" -version = "1.0.77" +version = "1.201.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e367582095d2903caeeea9acbb140e1db9c7677001efa4347c3687fd34fe7072" +checksum = "453d5b37a45b98dee4f4cb68015fc73634d7883bbef1c65e6e9c78d454cf3f32" dependencies = [ - "wast 66.0.2", + "wast 201.0.0", ] [[package]] @@ -2285,8 +2287,9 @@ dependencies = [ [[package]] name = "wiggle" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a7ecd6e1ffba1278cfd24a001a13da11d86801e0ad9342f11a370ce0df50e14" dependencies = [ "anyhow", "async-trait", @@ -2299,8 +2302,9 @@ dependencies = [ [[package]] name = "wiggle-generate" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c5490497a35d67040d4f2fd2491fbcad6dd225c5bd24681c2cd52a2f40a55ce" dependencies = [ "anyhow", "heck", @@ -2313,8 +2317,9 @@ dependencies = [ [[package]] name = "wiggle-macro" -version = "14.0.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "18.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83f31d1c1a0d87842f1a2bf40bd230e25ba790c450f0d0ddb84524fd6955958" dependencies = [ "proc-macro2", "quote", @@ -2346,8 +2351,9 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "winch-codegen" -version = "0.12.2" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +version = "0.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e0bd4d6cac8d69525d475d0ce1e0801eb6f314d42e764a52bd497ed3cb9c371" dependencies = [ "anyhow", "cranelift-codegen", @@ -2365,7 +2371,16 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.4", ] [[package]] @@ -2374,13 +2389,28 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +dependencies = [ + "windows_aarch64_gnullvm 0.52.4", + "windows_aarch64_msvc 0.52.4", + "windows_i686_gnu 0.52.4", + "windows_i686_msvc 0.52.4", + "windows_x86_64_gnu 0.52.4", + "windows_x86_64_gnullvm 0.52.4", + "windows_x86_64_msvc 0.52.4", ] [[package]] @@ -2389,42 +2419,84 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" + [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" + [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" + [[package]] name = "winx" version = "0.36.2" @@ -2432,14 +2504,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "357bb8e2932df531f83b052264b050b81ba0df90ee5a59b2d1d3949f344f81e5" dependencies = [ "bitflags 2.4.1", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] name = "wit-parser" -version = "0.12.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ace9943d89bbf3dbbc71b966da0e7302057b311f36a4ac3d65ddfef17b52cf" +checksum = "316b36a9f0005f5aa4b03c39bc3728d045df136f8c13a73b7db4510dec725e08" dependencies = [ "anyhow", "id-arena", @@ -2455,7 +2527,8 @@ dependencies = [ [[package]] name = "witx" version = "0.9.1" -source = "git+https://github.com/bytecodealliance/wasmtime?rev=2ade3ad#2ade3adec68caabdf35e778d67fe6343156ce16d" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e366f27a5cabcddb2706a78296a40b8fcc451e1a6aba2fc1d94b4a01bdaaef4b" dependencies = [ "anyhow", "log", diff --git a/component-model/examples/example-host/Cargo.toml b/component-model/examples/example-host/Cargo.toml index 6e49669..25d5bdb 100644 --- a/component-model/examples/example-host/Cargo.toml +++ b/component-model/examples/example-host/Cargo.toml @@ -6,7 +6,6 @@ edition = "2021" [dependencies] async-std = { version = "1.12.0", features = ["attributes"] } clap = { version = "4.3.19", features = ["derive"] } -wasmtime = { git = "https://github.com/bytecodealliance/wasmtime", rev = "2ade3ad", features = ["component-model"] } -wasmtime-wasi = { git = "https://github.com/bytecodealliance/wasmtime", rev = "2ade3ad" } -wasi-cap-std-sync = { git = "https://github.com/bytecodealliance/wasmtime", rev = "2ade3ad" } +wasmtime = "18.0.1" +wasmtime-wasi = { version = "18.0.1" } anyhow = "1.0.72" diff --git a/component-model/examples/example-host/src/add.rs b/component-model/examples/example-host/src/add.rs index 712ab58..8ab5b27 100644 --- a/component-model/examples/example-host/src/add.rs +++ b/component-model/examples/example-host/src/add.rs @@ -2,7 +2,7 @@ use anyhow::Context; use std::path::PathBuf; use wasmtime::component::*; use wasmtime::{Config, Engine, Store}; -use wasmtime_wasi::preview2::{command, Table, WasiCtx, WasiCtxBuilder, WasiView}; +use wasmtime_wasi::preview2::{command, WasiCtx, WasiCtxBuilder, WasiView}; wasmtime::component::bindgen!({ path: "add.wit", @@ -34,13 +34,13 @@ pub async fn add(path: PathBuf, x: i32, y: i32) -> wasmtime::Result { } struct ServerWasiView { - table: Table, + table: ResourceTable, ctx: WasiCtx, } impl ServerWasiView { fn new() -> Self { - let table = Table::new(); + let table = ResourceTable::new(); let ctx = WasiCtxBuilder::new().inherit_stdio().build(); Self { table, ctx } @@ -48,19 +48,11 @@ impl ServerWasiView { } impl WasiView for ServerWasiView { - fn table(&self) -> &Table { - &self.table - } - - fn table_mut(&mut self) -> &mut Table { + fn table(&mut self) -> &mut ResourceTable { &mut self.table } - fn ctx(&self) -> &WasiCtx { - &self.ctx - } - - fn ctx_mut(&mut self) -> &mut WasiCtx { + fn ctx(&mut self) -> &mut WasiCtx { &mut self.ctx } -} +} \ No newline at end of file diff --git a/component-model/examples/tutorial/README.md b/component-model/examples/tutorial/README.md index d16920a..c5c1d1b 100644 --- a/component-model/examples/tutorial/README.md +++ b/component-model/examples/tutorial/README.md @@ -46,6 +46,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/src/creating-and-consuming/composing.md b/component-model/src/creating-and-consuming/composing.md index a91f84e..5d7365a 100644 --- a/component-model/src/creating-and-consuming/composing.md +++ b/component-model/src/creating-and-consuming/composing.md @@ -55,7 +55,7 @@ The [`wasm-tools` suite](https://github.com/bytecodealliance/wasm-tools) include To compose a component with the components it directly depends on, run: -``` +```sh wasm-tools compose path/to/component.wasm -d path/to/dep1.wasm -d path/to/dep2.wasm -o composed.wasm ``` diff --git a/component-model/src/creating-and-consuming/running.md b/component-model/src/creating-and-consuming/running.md index 41d65ba..eb27bda 100644 --- a/component-model/src/creating-and-consuming/running.md +++ b/component-model/src/creating-and-consuming/running.md @@ -6,12 +6,10 @@ You can "run" a component by calling one of its exports. In some cases, this req You must use a recent version of `wasmtime` ([`v14.0.0` or greater](https://github.com/bytecodealliance/wasmtime/releases)), as earlier releases of the `wasmtime` command line do not include component model support. -> If you build the `wasmtime` CLI from source, you must pass `--features component-model` to the build command. - To run your component, run: ```sh -wasmtime run --wasm component-model +wasmtime run ``` ## Running components with custom exports @@ -28,6 +26,6 @@ If you're writing a library-style component - that is, one that exports a custom 5. Compose your command component with your library component by running `wasm-tools compose -d -o main.wasm`. -6. Run the composed component using `wasmtime run --wasm component-model main.wasm` +6. Run the composed component using `wasmtime run main.wasm` See [Composing Components](./composing.md) for more details. diff --git a/component-model/src/implementations/jco.md b/component-model/src/implementations/jco.md deleted file mode 100644 index 0e95fda..0000000 --- a/component-model/src/implementations/jco.md +++ /dev/null @@ -1 +0,0 @@ -# jco diff --git a/component-model/src/implementations/wasmtime.md b/component-model/src/implementations/wasmtime.md deleted file mode 100644 index 900d059..0000000 --- a/component-model/src/implementations/wasmtime.md +++ /dev/null @@ -1 +0,0 @@ -# Wasmtime diff --git a/component-model/src/language-support/javascript.md b/component-model/src/language-support/javascript.md index de0062a..a9141a0 100644 --- a/component-model/src/language-support/javascript.md +++ b/component-model/src/language-support/javascript.md @@ -3,17 +3,26 @@ [`jco`](https://github.com/bytecodealliance/jco) is a fully native JS tool for working with the emerging WebAssembly Components specification in JavaScript. -### Building a Component with `jco` +## Building a Component with `jco` -A component can be created from a JS module using `jco componentize`. First, install `jco` and -`componentize-js`: +A component can be created from a JS module using `jco componentize`. First, install `jco` and `componentize-js`: ```sh $ npm install @bytecodealliance/jco $ npm install @bytecodealliance/componentize-js ``` -Create a JavaScript module that implements the `add` function in [`add.wit`](https://github.com/bytecodealliance/component-docs/tree/main/component-model/examples/example-host/add.wit): +Next, create or download the WIT world you would like to target. For this example we will use an [`example` +world](https://github.com/bytecodealliance/component-docs/tree/main/component-model/examples/example-host/add.wit) with an `add` function: + +```wit +package example:component; +world example { + export add: func(x: s32, y: s32) -> s32; +} +``` + +Create a JavaScript module that implements the `add` function in the `example` world. ```js export function add(x, y) { @@ -24,7 +33,7 @@ export function add(x, y) { Now, use `jco` to create a component from the JS module: ```sh -$ jco componentize add.js --wit add.wit -n example -o add.wasm +$ jco componentize add.js --wit add.wit --world-name example --out add.wasm OK Successfully written add.wasm with imports (). ``` @@ -36,7 +45,7 @@ $ cargo run --release -- 1 2 ../path/to/add.wasm 1 + 2 = 3 ``` -### Running a Component from JavaScript Applications +## Running a Component from JavaScript Applications As the JavaScript runtime cannot yet execute Wasm components, a component must be transpiled into JavaScript and a core module and then executed. `jco` automates this transpilation: diff --git a/component-model/src/language-support/python.md b/component-model/src/language-support/python.md index b9aed72..40006f8 100644 --- a/component-model/src/language-support/python.md +++ b/component-model/src/language-support/python.md @@ -1,30 +1,51 @@ # Python Tooling -### Building a Component with `componentize-py` +## Building a Component with `componentize-py` [`componentize-py`](https://github.com/dicej/componentize-py) is a tool that converts a Python application to a WebAssembly component. -Create a Python program that implements the `add` function in the [`example` -world](https://github.com/bytecodealliance/component-docs/tree/main/component-model/examples/example-host/add.wit). Note that it imports the bindings that will be created by -`componentize-py`: +First, install [Python 3.10 or later](https://www.python.org/) and [pip](https://pypi.org/project/pip/) if you don't already have them. Then, install `componentize-py`: ```sh -$ cat<> guest.py +pip install componentize-py +``` + +Next, create or download the WIT world you would like to target. For this example we will use an [`example` +world](https://github.com/bytecodealliance/component-docs/tree/main/component-model/examples/example-host/add.wit) with an `add` function: + +```wit +package example:component; + +world example { + export add: func(x: s32, y: s32) -> s32; +} +``` + +If you want to generate bindings produced for the WIT world (for an IDE or typechecker), you can generate them using the `bindings` subcommand. Specify the path to the WIT interface with the world you are targeting: + +```sh +$ componentize-py --wit-path /path/to/examples/example-host/add.wit --world example bindings . +``` + +> Note: you do not need to generate the bindings in order to `componentize` in the next step. `componentize` will generate bindings on-the-fly and bundle them into the produced component. + +You can see that bindings were created in an `example` package which contains an `Example` protocol with an `add` method that we can implement: + +```sh +$ cat<> app.py import example class Example(example.Example): - def add(x: int, y: int) -> int: + def add(self, x: int, y: int) -> int: return x + y EOT ``` -[Install `componentize-py`](https://github.com/dicej/componentize-py#installing-from-pypi) and -generate a component from `guest.py`. +We now can compile our application to a Wasm component using the `componentize` subcommand: ```sh -$ pip install componentize-py -$ componentize-py -d /path/to/examples/example-host/add.wit -w example componentize guest -o add.wasm +$ componentize-py --wit-path /path/to/examples/example-host/add.wit --world example componentize app -o add.wasm Component built successfully ``` @@ -36,41 +57,78 @@ $ cargo run --release -- 1 2 ../path/to/add.wasm 1 + 2 = 3 ``` -### Running components from Python Applications +See [`componentize-py`'s examples](https://github.com/bytecodealliance/componentize-py/tree/main/examples) to try out build HTTP, CLI, and TCP components from Python applications. + + +### Building a Component that Exports an Interface + +The [sample `add.wit` file](https://github.com/bytecodealliance/component-docs/tree/main/component-model/examples/example-host/add.wit) exports a function. However, to use your component from another component, it must export an interface. That being said, you rarely find WIT that does not contain an interface. (Most WITs you'll see in the wild do use interfaces; we've been simplifying by exporting a function.) Let's expand our example world to export an interface rather than directly export the function. + +```wit +// add-interface.wit +package example:component; + +interface add { + add: func(a: u32, b: u32) -> u32; +} + +world example { + export add; +} +``` + +If you peek at the bindings, you'll notice that we now implement a class for the `add` interface rather than for the `example` world. This is a consistent pattern. As you export more interfaces from your world, you implement more classes. Our add example gets the slight update of: -Wasm components can also be invoked from Python applications. This walks through the tooling needed -to call the `app.wasm` component from the previous section from a Python application. First, install -`wasmtime-py`, being sure to use a version [this PR has -merged](https://github.com/bytecodealliance/wasmtime-py/pull/171) or working off that branch. +```py +# app.py +import example + +class Add(example.Example): + def add(self, a: int, b: int) -> int: + return a + b +``` -> Note: be sure to use at least Python 3.11 +Once again, compile an application to a Wasm component using the `componentize` subcommand: ```sh -$ git clone https://github.com/dicej/wasmtime-py -$ (cd wasmtime-py && python ci/download-wasmtime.py && python ci/build-rust.py && pip install .) +$ componentize-py --wit-path add-interface.wit --world example componentize app -o add.wasm +Component built successfully ``` -Now, generate the bindings to be able to call the component from a Python host application. +## Running components from Python Applications + +Wasm components can also be invoked from Python applications. This walks through using tooling +to call the [`app.wasm` component from the examples](../../examples/example-host/add.wasm). + +> Note: `wasmtime-py` does not currently support running components build with `componentize-py`. This is because `wasmtime-py` does not yet support [resources](../design/wit.md#resources), which components built with `componentize-py` always use, since `componentize-py` unconditionally imports most of the `wasi:cli` world. + +First, install [Python 3.11 or later](https://www.python.org/) and [pip](https://pypi.org/project/pip/) if you don't already have them. Then, install [`wasmtime-py`](https://github.com/bytecodealliance/wasmtime-py): ```sh -$ python3 -m wasmtime.bindgen add.wasm --out-dir add +$ pip install wasmtime ``` -The generated package `add` has all of the requisite exports/imports for the component and is -annotated with types to assist with type-checking and self-documentation as much as possible. +First, generate the bindings to be able to call the component from a Python host application. + +```sh +# Get an add component that does not import the WASI CLI world +$ wget https://github.com/bytecodealliance/component-docs/raw/main/component-model/examples/example-host/add.wasm +$ python3 -m wasmtime.bindgen add.wasm --out-dir add +``` -Now, create a Python program to run the component. Note that imports for WASI preview 2 are -explicitly set to null. This is because when creating a component from a Python module, -`componentize-py` pulls in extra WASI Preview 2 imports, even if they are not used by the component. -Currently, language toolchains are likely to pull in more than a component declares in WAT. +The generated package `add` has all of the requisite exports/imports for the +component and is annotated with types to assist with type-checking and +self-documentation as much as possible. Inside the package is a `Root` class +with an `add` function that calls the component's exported `add` function. We +can now write a Python program that calls `add`: ```py -from add import Root, RootImports +from add import Root from wasmtime import Store def main(): store = Store() - component = Root(store, RootImports(poll=None, monotonic_clock=None, wall_clock=None, streams=None, filesystem=None, random=None, environment=None, preopens=None, exit=None, stdin=None, stdout=None, stderr=None)) + component = Root(store) print("1 + 2 = ", component.add(store, 1, 2)) if __name__ == '__main__': diff --git a/component-model/src/language-support/rust.md b/component-model/src/language-support/rust.md index 59249d8..5f805f5 100644 --- a/component-model/src/language-support/rust.md +++ b/component-model/src/language-support/rust.md @@ -73,7 +73,7 @@ The application uses [`wasmtime`](https://github.com/bytecodealliance/wasmtime) Rust bindings, bring in WASI worlds, and execute the component. ```sh -$ cd examples/add-host +$ cd examples/example-host $ cargo run --release -- 1 2 ../add/target/wasm32-wasi/release/add.wasm 1 + 2 = 3 ``` @@ -215,9 +215,9 @@ You can write Rust in this project, just as you normally would, including import To run your command component: -``` +```sh cargo component build -wasmtime run --wasm component-model ./target/wasm32-wasi/debug/.wasm +wasmtime run ./target/wasm32-wasi/debug/.wasm ``` > **WARNING:** If your program prints to standard out or error, you may not see the printed output! Some versions of `wasmtime` have a bug where they don't flush output streams before exiting. To work around this, add a `std::thread::sleep()` with a 10 millisecond delay before exiting `main`. @@ -273,6 +273,6 @@ fn main() { 6. Run the composed component: ```sh -$ wasmtime run --wasm component-model ./my-composed-command.wasm +$ wasmtime run ./my-composed-command.wasm 1 + 1 = 579 # might need to go back and do some work on the calculator implementation ``` diff --git a/component-model/src/runtimes/wasmtime.md b/component-model/src/runtimes/wasmtime.md index 6386013..c828e06 100644 --- a/component-model/src/runtimes/wasmtime.md +++ b/component-model/src/runtimes/wasmtime.md @@ -3,12 +3,14 @@ [Wasmtime](https://github.com/bytecodealliance/wasmtime/) is the reference implementation of the Component Model. It supports running components that implement the [`wasi:cli/command` world](https://github.com/WebAssembly/wasi-cli/blob/main/wit/command.wit) and serving components the implement the [`wasi:http/proxy` world](https://github.com/WebAssembly/wasi-http/blob/main/wit/proxy.wit). ## Running command components with Wasmtime -To run a command component with wasmtime, execute: +To run a command component with Wasmtime, execute: ```sh -wasmtime run --wasm component-model +wasmtime run ``` +> If you are using an older version of `wasmtime`, you may need to add the `--wasm component-model` flag to specify that you are running a component rather than a core module. + By default, Wasmtime denies the component access to all system resources. For example, the component cannot access the file system or environment variables. See the [Wasmtime guide](https://docs.wasmtime.dev/) for information on granting access, and for other Wasmtime features. ## Running HTTP components with Wasmtime diff --git a/component-model/src/tutorial.md b/component-model/src/tutorial.md index 6ac5ad0..819c765 100644 --- a/component-model/src/tutorial.md +++ b/component-model/src/tutorial.md @@ -133,7 +133,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 --wasm component-model final.wasm 1 2 add +wasmtime run final.wasm 1 2 add 1 + 2 = 3 ```