From f6933de5592912becbb71f00542dead238224417 Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Wed, 24 Jul 2024 20:32:59 -0400 Subject: [PATCH] update wasm related dependencies, make it easier to create components on the guest --- .vscode/settings.json | 6 +- Cargo.lock | 485 +++++++++++++++++-------------- Cargo.toml | 7 +- README.md | 25 +- common-api/Cargo.lock | 350 ++++++++++++++++++++++ common-api/Cargo.toml | 7 +- common-api/api-derive/Cargo.toml | 14 + common-api/api-derive/src/lib.rs | 101 +++++++ common-api/src/component.rs | 10 +- common-api/src/lib.rs | 4 + common-api/src/math.rs | 40 +++ common-api/wit/ecs.wit | 3 +- src/main.rs | 42 +-- witguest/Cargo.toml | 4 +- witguest/src/bindings.rs | 175 ++++++----- witguest/src/lib.rs | 43 +-- 16 files changed, 957 insertions(+), 359 deletions(-) create mode 100644 common-api/Cargo.lock mode change 100755 => 100644 common-api/Cargo.toml create mode 100644 common-api/api-derive/Cargo.toml create mode 100644 common-api/api-derive/src/lib.rs create mode 100644 common-api/src/math.rs diff --git a/.vscode/settings.json b/.vscode/settings.json index 786d4d3..8bd55ba 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,7 @@ { - "nixEnvSelector.nixFile": "${workspaceFolder}/shell.nix" + "nixEnvSelector.nixFile": "${workspaceFolder}/shell.nix", + "rust-analyzer.showUnlinkedFileNotification": false, + "rust-analyzer.check.extraArgs": [ + "--target-dir=target/analyzer" + ], } \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index ebb6b6c..334d451 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,6 +50,15 @@ version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" +[[package]] +name = "api-derive" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "arbitrary" version = "1.3.2" @@ -90,7 +99,7 @@ dependencies = [ "cfg-if", "libc", "miniz_oxide", - "object", + "object 0.32.2", "rustc-demangle", ] @@ -100,15 +109,6 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - [[package]] name = "bitflags" version = "1.3.2" @@ -261,10 +261,17 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cobs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" + [[package]] name = "common-api" version = "0.1.0" dependencies = [ + "api-derive", "bytemuck", "thiserror", "wit-bindgen", @@ -296,21 +303,32 @@ dependencies = [ [[package]] name = "cranelift-bforest" -version = "0.106.2" +version = "0.110.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b57d4f3ffc28bbd6ef1ca7b50b20126717232f97487efe027d135d9d87eb29c" +checksum = "effa84ab2023f7138045ece6b326588c17447ca22e66db71ec15cb0a6c0c4ad2" dependencies = [ "cranelift-entity", ] [[package]] -name = "cranelift-codegen" -version = "0.106.2" +name = "cranelift-bitset" +version = "0.110.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1f7d0ac7fd53f2c29db3ff9a063f6ff5a8be2abaa8f6942aceb6e1521e70df7" +checksum = "38a1dfc50dca188a15d938867c4400589530bcb0138f7022aae6d059d1d8c309" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-codegen" +version = "0.110.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "821c20c639350158ecca928dc2a244d0d1c9cef2377a378fc62a445a286eb1ca" dependencies = [ "bumpalo", "cranelift-bforest", + "cranelift-bitset", "cranelift-codegen-meta", "cranelift-codegen-shared", "cranelift-control", @@ -320,49 +338,51 @@ dependencies = [ "hashbrown 0.14.3", "log", "regalloc2", + "rustc-hash", "smallvec", "target-lexicon", ] [[package]] name = "cranelift-codegen-meta" -version = "0.106.2" +version = "0.110.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b40bf21460a600178956cb7fd900a7408c6587fbb988a8063f7215361801a1da" +checksum = "064473f2fd59b44fa2c9aaa60de1f9c44db5e13521e28bc85d2b92ee535ef625" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.106.2" +version = "0.110.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d792ecc1243b7ebec4a7f77d9ed428ef27456eeb1f8c780587a6f5c38841be19" +checksum = "d0f39b9ebfd2febdc2acfb9a0fca110665bcd5a6839502576307735ed07b2177" [[package]] name = "cranelift-control" -version = "0.106.2" +version = "0.110.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cea2808043df964b73ad7582e09afbbe06a31f3fb9db834d53e74b4e16facaeb" +checksum = "94e125c189c3a1ca8dfe209fc6f46edba058a6d24e0b92aff69459a15f4711e7" dependencies = [ "arbitrary", ] [[package]] name = "cranelift-entity" -version = "0.106.2" +version = "0.110.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1930946836da6f514da87625cd1a0331f3908e0de454628c24a0b97b130c4d4" +checksum = "ea62eb109baec2247e1a6fa7b74c0f584b1e76e289cfd7017385b4b031fc8450" dependencies = [ + "cranelift-bitset", "serde", "serde_derive", ] [[package]] name = "cranelift-frontend" -version = "0.106.2" +version = "0.110.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5482a5fcdf98f2f31b21093643bdcfe9030866b8be6481117022e7f52baa0f2b" +checksum = "722b089357aacb6c7528b2e59a5fe00917d61ce63448b25a3e477a5b7819fac8" dependencies = [ "cranelift-codegen", "log", @@ -372,15 +392,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.106.2" +version = "0.110.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f6e1869b6053383bdb356900e42e33555b4c9ebee05699469b7c53cdafc82ea" +checksum = "c4b5005a48288e7fc2a2991a377831c534e26929b063c379c018060727785a9b" [[package]] name = "cranelift-native" -version = "0.106.2" +version = "0.110.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91446e8045f1c4bc164b7bba68e2419c623904580d4b730877a663c6da38964" +checksum = "3ae2d48f38081a9e679ad795bd36bb29bedeb5552fc1c195185bf9885fa1b16e" dependencies = [ "cranelift-codegen", "libc", @@ -389,9 +409,9 @@ dependencies = [ [[package]] name = "cranelift-wasm" -version = "0.106.2" +version = "0.110.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8b17979b862d3b0d52de6ae3294ffe4d86c36027b56ad0443a7c8c8f921d14f" +checksum = "25abc7b3ec5aab50546ee9a29073223d2602b49b3d73ce312bf481fadba01255" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -399,7 +419,7 @@ dependencies = [ "itertools", "log", "smallvec", - "wasmparser 0.201.0", + "wasmparser 0.212.0", "wasmtime-types", ] @@ -513,6 +533,12 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +[[package]] +name = "embedded-io" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" + [[package]] name = "encoding_rs" version = "0.8.34" @@ -712,6 +738,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" dependencies = [ "ahash", + "serde", ] [[package]] @@ -719,9 +746,12 @@ name = "heck" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hermit-abi" @@ -866,6 +896,12 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + [[package]] name = "libredox" version = "0.1.3" @@ -929,10 +965,10 @@ dependencies = [ ] [[package]] -name = "mach" -version = "0.3.2" +name = "mach2" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" dependencies = [ "libc", ] @@ -958,15 +994,6 @@ dependencies = [ "rustix", ] -[[package]] -name = "memoffset" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" -dependencies = [ - "autocfg", -] - [[package]] name = "miniz_oxide" version = "0.7.2" @@ -1002,6 +1029,15 @@ name = "object" version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "object" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce" dependencies = [ "crc32fast", "hashbrown 0.14.3", @@ -1068,6 +1104,17 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "postcard" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a55c51ee6c0db07e68448e336cf8ea4131a620edefebf9893e759b2d793420f8" +dependencies = [ + "cobs", + "embedded-io", + "serde", +] + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -1075,10 +1122,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] -name = "proc-macro2" -version = "1.0.79" +name = "prettyplease" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" dependencies = [ "unicode-ident", ] @@ -1228,6 +1285,9 @@ name = "semver" version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" +dependencies = [ + "serde", +] [[package]] name = "serde" @@ -1318,6 +1378,9 @@ name = "smallvec" version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +dependencies = [ + "serde", +] [[package]] name = "socket2" @@ -1352,9 +1415,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "syn" -version = "2.0.58" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" dependencies = [ "proc-macro2", "quote", @@ -1383,6 +1446,15 @@ version = "0.12.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.58" @@ -1540,12 +1612,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" - [[package]] name = "unicode-width" version = "0.1.11" @@ -1643,27 +1709,28 @@ checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "wasm-encoder" -version = "0.201.0" +version = "0.212.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9c7d2731df60006819b013f64ccc2019691deccf6e11a1804bc850cd6748f1a" +checksum = "501940df4418b8929eb6d52f1aade1fdd15a5b86c92453cb696e3c906bd3fc33" dependencies = [ "leb128", ] [[package]] name = "wasm-encoder" -version = "0.202.0" +version = "0.214.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfd106365a7f5f7aa3c1916a98cbb3ad477f5ff96ddb130285a91c6e7429e67a" +checksum = "ff694f02a8d7a50b6922b197ae03883fbf18cdb2ae9fbee7b6148456f5f44041" dependencies = [ "leb128", + "wasmparser 0.214.0", ] [[package]] name = "wasm-metadata" -version = "0.202.0" +version = "0.214.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "094aea3cb90e09f16ee25a4c0e324b3e8c934e7fd838bfa039aef5352f44a917" +checksum = "865c5bff5f7a3781b5f92ea4cfa99bb38267da097441cdb09080de1568ef3075" dependencies = [ "anyhow", "indexmap", @@ -1671,73 +1738,89 @@ dependencies = [ "serde_derive", "serde_json", "spdx", - "wasm-encoder 0.202.0", - "wasmparser 0.202.0", + "wasm-encoder 0.214.0", + "wasmparser 0.214.0", ] [[package]] name = "wasmparser" -version = "0.201.0" +version = "0.212.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84e5df6dba6c0d7fafc63a450f1738451ed7a0b52295d83e868218fa286bf708" +checksum = "8d28bc49ba1e5c5b61ffa7a2eace10820443c4b7d1c0b144109261d14570fdf8" dependencies = [ + "ahash", "bitflags 2.5.0", + "hashbrown 0.14.3", "indexmap", "semver", + "serde", ] [[package]] name = "wasmparser" -version = "0.202.0" +version = "0.214.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6998515d3cf3f8b980ef7c11b29a9b1017d4cf86b99ae93b546992df9931413" +checksum = "5309c1090e3e84dad0d382f42064e9933fdaedb87e468cc239f0eabea73ddcb6" dependencies = [ + "ahash", "bitflags 2.5.0", + "hashbrown 0.14.3", "indexmap", "semver", ] [[package]] name = "wasmprinter" -version = "0.201.0" +version = "0.212.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a67e66da702706ba08729a78e3c0079085f6bfcb1a62e4799e97bbf728c2c265" +checksum = "dfac65326cc561112af88c3028f6dfdb140acff67ede33a8e86be2dc6b8956f7" dependencies = [ "anyhow", - "wasmparser 0.201.0", + "termcolor", + "wasmparser 0.212.0", ] [[package]] name = "wasmtime" -version = "19.0.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e300c0e3f19dc9064e3b17ce661088646c70dbdde36aab46470ed68ba58db7d" +checksum = "8945e69ec96e5d36cbe1aa2e88e28f988562dd3b5133578c44aae20ea2bcdb40" dependencies = [ "addr2line", "anyhow", "async-trait", - "bincode", + "bitflags 2.5.0", "bumpalo", + "cc", "cfg-if", "encoding_rs", "fxprof-processed-profile", "gimli", + "hashbrown 0.14.3", "indexmap", "ittapi", "libc", + "libm", "log", - "object", + "mach2", + "memfd", + "object 0.36.1", "once_cell", "paste", + "postcard", + "psm", "rayon", "rustix", "semver", "serde", "serde_derive", "serde_json", + "smallvec", + "sptr", "target-lexicon", - "wasm-encoder 0.201.0", - "wasmparser 0.201.0", + "wasm-encoder 0.212.0", + "wasmparser 0.212.0", + "wasmtime-asm-macros", "wasmtime-cache", "wasmtime-component-macro", "wasmtime-component-util", @@ -1746,8 +1829,8 @@ dependencies = [ "wasmtime-fiber", "wasmtime-jit-debug", "wasmtime-jit-icache-coherence", - "wasmtime-runtime", "wasmtime-slab", + "wasmtime-versioned-export-macros", "wasmtime-winch", "wat", "windows-sys 0.52.0", @@ -1755,24 +1838,24 @@ dependencies = [ [[package]] name = "wasmtime-asm-macros" -version = "19.0.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "110aa598e02a136fb095ca70fa96367fc16bab55256a131e66f9b58f16c73daf" +checksum = "964c3b3342547a51e0d2702eae3a2d2be215d16b55a14e2e786b11c4931b7f08" dependencies = [ "cfg-if", ] [[package]] name = "wasmtime-cache" -version = "19.0.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4e660537b0ac2fc76917fb0cc9d403d2448b6983a84e59c51f7fea7b7dae024" +checksum = "ba2577db54531c36d875a89c5baf92dd860dd0cc256063ba710f28f36c4e9148" dependencies = [ "anyhow", "base64", - "bincode", "directories-next", "log", + "postcard", "rustix", "serde", "serde_derive", @@ -1784,9 +1867,9 @@ dependencies = [ [[package]] name = "wasmtime-component-macro" -version = "19.0.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "091f32ce586251ac4d07019388fb665b010d9518ffe47be1ddbabb162eed6007" +checksum = "0e9a60f3dfc8a825214be6e3e8e4fab280ea9d46ea2f4db11d958e754be021ae" dependencies = [ "anyhow", "proc-macro2", @@ -1794,20 +1877,20 @@ dependencies = [ "syn", "wasmtime-component-util", "wasmtime-wit-bindgen", - "wit-parser 0.201.0", + "wit-parser 0.212.0", ] [[package]] name = "wasmtime-component-util" -version = "19.0.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dd17dc1ebc0b28fd24b6b9d07638f55b82ae908918ff08fd221f8b0fefa9125" +checksum = "2bd9555175ad59d13fd353c2a6d9bc92f47f3496fc2b92e84eaa9e6edf048f3c" [[package]] name = "wasmtime-cranelift" -version = "19.0.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e923262451a4b5b39fe02f69f1338d56356db470e289ea1887346b9c7f592738" +checksum = "b7ab12460e903933b1122d0c7ca5eb1a6160574870a5b110891a4cc96ef6ec3a" dependencies = [ "anyhow", "cfg-if", @@ -1819,52 +1902,36 @@ dependencies = [ "cranelift-wasm", "gimli", "log", - "object", + "object 0.36.1", "target-lexicon", "thiserror", - "wasmparser 0.201.0", - "wasmtime-cranelift-shared", + "wasmparser 0.212.0", "wasmtime-environ", "wasmtime-versioned-export-macros", ] -[[package]] -name = "wasmtime-cranelift-shared" -version = "19.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "508898cbbea0df81a5d29cfc1c7c72431a1bc4c9e89fd9514b4c868474c05c7a" -dependencies = [ - "anyhow", - "cranelift-codegen", - "cranelift-control", - "cranelift-native", - "gimli", - "object", - "target-lexicon", - "wasmtime-environ", -] - [[package]] name = "wasmtime-environ" -version = "19.0.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7e3f2aa72dbb64c19708646e1ff97650f34e254598b82bad5578ea9c80edd30" +checksum = "9e52faba13550fed76d5ffe75ec7cada73109b9324c4dabcaf18b3165107010d" dependencies = [ "anyhow", - "bincode", "cpp_demangle", + "cranelift-bitset", "cranelift-entity", "gimli", "indexmap", "log", - "object", + "object 0.36.1", + "postcard", "rustc-demangle", + "semver", "serde", "serde_derive", "target-lexicon", - "thiserror", - "wasm-encoder 0.201.0", - "wasmparser 0.201.0", + "wasm-encoder 0.212.0", + "wasmparser 0.212.0", "wasmprinter", "wasmtime-component-util", "wasmtime-types", @@ -1872,9 +1939,9 @@ dependencies = [ [[package]] name = "wasmtime-fiber" -version = "19.0.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9235b643527bcbac808216ed342e1fba324c95f14a62762acfa6f2e6ca5edbd6" +checksum = "9ad6a540bc919350909817c3d72383007dd9386d60b74d0d728761284627feb1" dependencies = [ "anyhow", "cc", @@ -1887,11 +1954,11 @@ dependencies = [ [[package]] name = "wasmtime-jit-debug" -version = "19.0.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92de34217bf7f0464262adf391a9950eba440f9dfc7d3b0e3209302875c6f65f" +checksum = "f71632cb3d01bc456b010689c554caf0f36e9040ffd357f097fdb8d42d09f710" dependencies = [ - "object", + "object 0.36.1", "once_cell", "rustix", "wasmtime-versioned-export-macros", @@ -1899,69 +1966,41 @@ dependencies = [ [[package]] name = "wasmtime-jit-icache-coherence" -version = "19.0.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c22ca2ef4d87b23d400660373453e274b2251bc2d674e3102497f690135e04b0" -dependencies = [ - "cfg-if", - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "wasmtime-runtime" -version = "19.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1806ee242ca4fd183309b7406e4e83ae7739b7569f395d56700de7c7ef9f5eb8" +checksum = "7fddf3e2980fb1d123d1fcac55189e417fdd3dba4f62139b5a0a1f9efe5669d5" dependencies = [ "anyhow", - "cc", "cfg-if", - "encoding_rs", - "indexmap", "libc", - "log", - "mach", - "memfd", - "memoffset", - "paste", - "psm", - "rustix", - "sptr", - "wasm-encoder 0.201.0", - "wasmtime-asm-macros", - "wasmtime-environ", - "wasmtime-fiber", - "wasmtime-jit-debug", - "wasmtime-versioned-export-macros", - "wasmtime-wmemcheck", "windows-sys 0.52.0", ] [[package]] name = "wasmtime-slab" -version = "19.0.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20c58bef9ce877fd06acb58f08d003af17cb05cc51225b455e999fbad8e584c0" +checksum = "f3ac25f8f80a3c5cda4ea68472057b23fa309956ae9784c0f1347439e624840e" [[package]] name = "wasmtime-types" -version = "19.0.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cebe297aa063136d9d2e5b347c1528868aa43c2c8d0e1eb0eec144567e38fe0f" +checksum = "44a0fba5f60b030c635abafdcaf2e9ad883163676bd02a0f0ebaed9393453f28" dependencies = [ + "anyhow", "cranelift-entity", "serde", "serde_derive", - "thiserror", - "wasmparser 0.201.0", + "smallvec", + "wasmparser 0.212.0", ] [[package]] name = "wasmtime-versioned-export-macros" -version = "19.0.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffaafa5c12355b1a9ee068e9295d50c4ca0a400c721950cdae4f5b54391a2da5" +checksum = "85b40c6d9c8f56ea0cbeacb80f40075a91687163b693b7cda39b48efe3c974d2" dependencies = [ "proc-macro2", "quote", @@ -1970,9 +2009,9 @@ dependencies = [ [[package]] name = "wasmtime-wasi" -version = "19.0.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b95961546319d4019625920756967a929879d1d46c4e5f89a74e9f4405655b0c" +checksum = "5a58bb8744f2e76c93e3bfb559646be80c1ebe1191b6e426f2d1b4571ad2a4c7" dependencies = [ "anyhow", "async-trait", @@ -2001,39 +2040,33 @@ dependencies = [ [[package]] name = "wasmtime-winch" -version = "19.0.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d618b4e90d3f259b1b77411ce573c9f74aade561957102132e169918aabdc863" +checksum = "0027b71a418208a21c46988393ceda01dc64842d1b3a601ca0517da270c317b5" dependencies = [ "anyhow", "cranelift-codegen", "gimli", - "object", + "object 0.36.1", "target-lexicon", - "wasmparser 0.201.0", - "wasmtime-cranelift-shared", + "wasmparser 0.212.0", + "wasmtime-cranelift", "wasmtime-environ", "winch-codegen", ] [[package]] name = "wasmtime-wit-bindgen" -version = "19.0.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c7a253c8505edd7493603e548bff3af937b0b7dbf2b498bd5ff2131b651af72" +checksum = "8cec1424f842d187b8244284e565f71b77bef8993452e8524f71216172978ac8" dependencies = [ "anyhow", - "heck", + "heck 0.4.1", "indexmap", - "wit-parser 0.201.0", + "wit-parser 0.212.0", ] -[[package]] -name = "wasmtime-wmemcheck" -version = "19.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9a8c62e9df8322b2166d2a6f096fbec195ddb093748fd74170dcf25ef596769" - [[package]] name = "wast" version = "35.0.2" @@ -2045,31 +2078,31 @@ dependencies = [ [[package]] name = "wast" -version = "202.0.0" +version = "214.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fbcb11204515c953c9b42ede0a46a1c5e17f82af05c4fae201a8efff1b0f4fe" +checksum = "694bcdb24c49c8709bd8713768b71301a11e823923eee355d530f1d8d0a7f8e9" dependencies = [ "bumpalo", "leb128", "memchr", "unicode-width", - "wasm-encoder 0.202.0", + "wasm-encoder 0.214.0", ] [[package]] name = "wat" -version = "1.202.0" +version = "1.214.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4de4b15a47135c56a3573406e9977b9518787a6154459b4842a9b9d3d1684848" +checksum = "347249eb56773fa728df2656cfe3a8c19437ded61a922a0b5e0839d9790e278e" dependencies = [ - "wast 202.0.0", + "wast 214.0.0", ] [[package]] name = "wiggle" -version = "19.0.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "899d3fe5fbacd02f114cacdaa1cca9040280c4153c71833a77b9609c60ccf72b" +checksum = "4e5319ed83c2ac543c5f69e77b3548020ac1c1cc1f590ad627c77ed4d827a811" dependencies = [ "anyhow", "async-trait", @@ -2082,12 +2115,12 @@ dependencies = [ [[package]] name = "wiggle-generate" -version = "19.0.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2df5887f452cff44ffe1e1aba69b7fafe812deed38498446fa7a46b55e962cd5" +checksum = "fe9a96d7bf758f59a0cb086d94ae24269cb7f1ffd3c24058871769884e8e9026" dependencies = [ "anyhow", - "heck", + "heck 0.4.1", "proc-macro2", "quote", "shellexpand", @@ -2097,9 +2130,9 @@ dependencies = [ [[package]] name = "wiggle-macro" -version = "19.0.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acdb12de36507498abaa3a042f895a43ee00a2f6125b6901b9a27edf72bfdbe7" +checksum = "caa70aa74de29f1438f083e39005d854812c72c48d876060e9e6df9686fb677b" dependencies = [ "proc-macro2", "quote", @@ -2123,6 +2156,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -2131,9 +2173,9 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "winch-codegen" -version = "0.17.2" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d15869abc9e3bb29c017c003dbe007a08e9910e8ff9023a962aa13c1b2ee6af" +checksum = "56a6aa28dbe4633a9934f27f18e262fd4886c02be3c6de0ee4ad3a1cb32a7758" dependencies = [ "anyhow", "cranelift-codegen", @@ -2141,7 +2183,8 @@ dependencies = [ "regalloc2", "smallvec", "target-lexicon", - "wasmparser 0.201.0", + "wasmparser 0.212.0", + "wasmtime-cranelift", "wasmtime-environ", ] @@ -2307,9 +2350,9 @@ dependencies = [ [[package]] name = "wit-bindgen" -version = "0.24.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb4e7653763780be47e38f479e9aa83c768aa6a3b2ed086dc2826fdbbb7e7f5" +checksum = "89178260ed223de8a5a81f9cff961481dfbbd55b25c17e4dd0b4c8e4b8ae646d" dependencies = [ "wit-bindgen-rt", "wit-bindgen-rust-macro", @@ -2317,32 +2360,35 @@ dependencies = [ [[package]] name = "wit-bindgen-core" -version = "0.24.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b67e11c950041849a10828c7600ea62a4077c01e8af72e8593253575428f91b" +checksum = "5e3fd9b11c16b9888c1bd159130b1b3487da913c45dbd34d408bfdf81f8a865a" dependencies = [ "anyhow", - "wit-parser 0.202.0", + "heck 0.5.0", + "wit-parser 0.214.0", ] [[package]] name = "wit-bindgen-rt" -version = "0.24.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b0780cf7046630ed70f689a098cd8d56c5c3b22f2a7379bbdb088879963ff96" +checksum = "d7a37bd9274cb2d4754b915d624447ec0dce9105d174361841c0826efc79ceb9" dependencies = [ "bitflags 2.5.0", ] [[package]] name = "wit-bindgen-rust" -version = "0.24.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30acbe8fb708c3a830a33c4cb705df82659bf831b492ec6ca1a17a369cfeeafb" +checksum = "0f195cd3774ff22f9bbd582a4ab97667c0a47d36ed8ed0c9ed357afe811b564b" dependencies = [ "anyhow", - "heck", + "heck 0.5.0", "indexmap", + "prettyplease", + "syn", "wasm-metadata", "wit-bindgen-core", "wit-component", @@ -2350,11 +2396,12 @@ dependencies = [ [[package]] name = "wit-bindgen-rust-macro" -version = "0.24.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b1b06eae85feaecdf9f2854f7cac124e00d5a6e5014bfb02eb1ecdeb5f265b9" +checksum = "683e47441b5d0a82fc4304619dcc0672bc84ef47de2c85cd493c37cb29de062f" dependencies = [ "anyhow", + "prettyplease", "proc-macro2", "quote", "syn", @@ -2364,9 +2411,9 @@ dependencies = [ [[package]] name = "wit-component" -version = "0.202.0" +version = "0.214.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c836b1fd9932de0431c1758d8be08212071b6bba0151f7bac826dbc4312a2a9" +checksum = "fd9fd46f0e783bf80f1ab7291f9d442fa5553ff0e96cdb71964bd8859b734b55" dependencies = [ "anyhow", "bitflags 2.5.0", @@ -2375,17 +2422,17 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "wasm-encoder 0.202.0", + "wasm-encoder 0.214.0", "wasm-metadata", - "wasmparser 0.202.0", - "wit-parser 0.202.0", + "wasmparser 0.214.0", + "wit-parser 0.214.0", ] [[package]] name = "wit-parser" -version = "0.201.0" +version = "0.212.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "196d3ecfc4b759a8573bf86a9b3f8996b304b3732e4c7de81655f875f6efdca6" +checksum = "ceeb0424aa8679f3fcf2d6e3cfa381f3d6fa6179976a2c05a6249dd2bb426716" dependencies = [ "anyhow", "id-arena", @@ -2396,14 +2443,14 @@ dependencies = [ "serde_derive", "serde_json", "unicode-xid", - "wasmparser 0.201.0", + "wasmparser 0.212.0", ] [[package]] name = "wit-parser" -version = "0.202.0" +version = "0.214.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "744237b488352f4f27bca05a10acb79474415951c450e52ebd0da784c1df2bcc" +checksum = "681d526d6ea42e28f9afe9eae2b50e0b0a627aef8822c75eb04078db84d03e57" dependencies = [ "anyhow", "id-arena", @@ -2414,7 +2461,7 @@ dependencies = [ "serde_derive", "serde_json", "unicode-xid", - "wasmparser 0.202.0", + "wasmparser 0.214.0", ] [[package]] @@ -2423,7 +2470,7 @@ version = "0.1.0" dependencies = [ "bytemuck", "common-api", - "wit-bindgen", + "wit-bindgen-rt", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 1435cec..71d0f0b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ -workspace = { members = [ "common-api","witguest"] } +workspace = { members = [ "common-api", "witguest"] } + [package] name = "wittest" version = "0.1.0" @@ -9,8 +10,8 @@ edition = "2021" [dependencies] async-trait = "0.1.80" tokio = { version = "1.37.0", features = ["full"] } -wasmtime = "19.0.2" -wasmtime-wasi = "19.0.2" +wasmtime = "23.0.1" +wasmtime-wasi = "23.0.1" lyra-ecs = { path = "./lyra-engine/lyra-ecs" } slab = "0.4.9" thiserror = "1.0.58" diff --git a/README.md b/README.md index 4c590b9..f865d73 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,26 @@ # lyra-wasm-scripting-test -A test zone for implementing WASM scripting into the Lyra engine \ No newline at end of file +A test zone for implementing WASM scripting into the Lyra engine + +## Building + +Install the `wasm32-wasip1` target: +``` +rustup target add wasm32-wasip1 +``` + +Install `wasm-tools`: +``` +cargo install wasm-tools +``` + +Install [`cargo-component`](https://github.com/bytecodealliance/cargo-component): +``` +cargo install wasm-tools +``` + +Build the `witguest` project: +``` +cd witguest +cargo component build +``` \ No newline at end of file diff --git a/common-api/Cargo.lock b/common-api/Cargo.lock new file mode 100644 index 0000000..d36af0a --- /dev/null +++ b/common-api/Cargo.lock @@ -0,0 +1,350 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" + +[[package]] +name = "api-derive" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytemuck" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" + +[[package]] +name = "common-api" +version = "0.1.0" +dependencies = [ + "bytemuck", + "thiserror", + "wit-bindgen", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[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 = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown", + "serde", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[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.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "proc-macro2" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + +[[package]] +name = "semver" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" + +[[package]] +name = "serde" +version = "1.0.198" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.198" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.116" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "spdx" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29ef1a0fa1e39ac22972c8db23ff89aea700ab96aa87114e1fb55937a631a0c9" +dependencies = [ + "smallvec", +] + +[[package]] +name = "syn" +version = "2.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "wasm-encoder" +version = "0.202.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfd106365a7f5f7aa3c1916a98cbb3ad477f5ff96ddb130285a91c6e7429e67a" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-metadata" +version = "0.202.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "094aea3cb90e09f16ee25a4c0e324b3e8c934e7fd838bfa039aef5352f44a917" +dependencies = [ + "anyhow", + "indexmap", + "serde", + "serde_derive", + "serde_json", + "spdx", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.202.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6998515d3cf3f8b980ef7c11b29a9b1017d4cf86b99ae93b546992df9931413" +dependencies = [ + "bitflags", + "indexmap", + "semver", +] + +[[package]] +name = "wit-bindgen" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb4e7653763780be47e38f479e9aa83c768aa6a3b2ed086dc2826fdbbb7e7f5" +dependencies = [ + "wit-bindgen-rt", + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b67e11c950041849a10828c7600ea62a4077c01e8af72e8593253575428f91b" +dependencies = [ + "anyhow", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rt" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0780cf7046630ed70f689a098cd8d56c5c3b22f2a7379bbdb088879963ff96" +dependencies = [ + "bitflags", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30acbe8fb708c3a830a33c4cb705df82659bf831b492ec6ca1a17a369cfeeafb" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b1b06eae85feaecdf9f2854f7cac124e00d5a6e5014bfb02eb1ecdeb5f265b9" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.202.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c836b1fd9932de0431c1758d8be08212071b6bba0151f7bac826dbc4312a2a9" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.202.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "744237b488352f4f27bca05a10acb79474415951c450e52ebd0da784c1df2bcc" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] diff --git a/common-api/Cargo.toml b/common-api/Cargo.toml old mode 100755 new mode 100644 index 9b6dfc5..18546d4 --- a/common-api/Cargo.toml +++ b/common-api/Cargo.toml @@ -6,9 +6,10 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bytemuck = "1.15.0" +bytemuck = { version = "1.15.0", features = ["derive"] } thiserror = "1.0.58" #bytemuck = "1.15.0" #wasmtime = "19.0.2" -wit-bindgen = "0.24.0" -#wit-bindgen = { version = "0.24.0", default-features = false, features = ["realloc"] } \ No newline at end of file +wit-bindgen = "0.28.0" +#wit-bindgen = { version = "0.24.0", default-features = false, features = ["realloc"] } +api-derive = { path = "./api-derive" } \ No newline at end of file diff --git a/common-api/api-derive/Cargo.toml b/common-api/api-derive/Cargo.toml new file mode 100644 index 0000000..18ff2be --- /dev/null +++ b/common-api/api-derive/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "api-derive" +version = "0.1.0" +edition = "2021" + +[lib] +proc-macro = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +proc-macro2 = "1.0.81" +quote = "1.0.36" +syn = "2.0.60" diff --git a/common-api/api-derive/src/lib.rs b/common-api/api-derive/src/lib.rs new file mode 100644 index 0000000..f19231b --- /dev/null +++ b/common-api/api-derive/src/lib.rs @@ -0,0 +1,101 @@ +use quote::quote; +use syn::{parse_macro_input, Token}; + +enum ComponentSerializationMethod { + Bytemuck +} + +struct HostComponentDeriveInput { + pub type_path: syn::Path, + host_type_name: Option, + serialize_method: Option, +} + +impl syn::parse::Parse for HostComponentDeriveInput { + fn parse(input: syn::parse::ParseStream) -> syn::Result { + let type_path: syn::Path = input.parse()?; + + let mut s = Self { + type_path, + host_type_name: None, + serialize_method: None, + }; + + while input.peek(Token![,]) { + let _: Token![,] = input.parse()?; + //println!("Peeked a , ({:?})", input); + + if input.peek(syn::Ident) { + let ident: syn::Ident = input.parse()?; + let ident_str = ident.to_string(); + + match ident_str.as_str() { + "host_type" => { + let _eq: syn::Token![=] = input.parse()?; + let ident: syn::LitStr = input.parse()?; + s.host_type_name = Some(ident.value()); + }, + "serialize" => { + let _eq: syn::Token![=] = input.parse()?; + let ident: syn::Ident = input.parse()?; + let ident_str = ident.to_string().to_lowercase(); + + match ident_str.as_str() { + "bytemuck" => { + s.serialize_method = Some(ComponentSerializationMethod::Bytemuck); + }, + _ => return Err(syn::Error::new(ident.span(), + format!("unknown component serialization method `{}`", + ident_str))), + } + }, + _ => return Err(syn::Error::new(ident.span(), + format!("unknown macro usage `{}`", ident_str))), + } + } + } + + Ok(s) + } +} + +#[proc_macro] +pub fn bytemuck_component_impl(input: proc_macro::TokenStream) -> proc_macro::TokenStream { + let input = parse_macro_input!(input as HostComponentDeriveInput); + + let type_path = input.type_path; + let host_type_name = input.host_type_name.unwrap_or(type_path.segments.last().unwrap().ident.to_string()); + let ser_method = match input.serialize_method.unwrap_or(ComponentSerializationMethod::Bytemuck) { + ComponentSerializationMethod::Bytemuck => quote!(Bytemuck), + }; + + quote! { + impl common_api::Component for #type_path { + const SERIALIZATION: common_api::ComponentSerializationMethod = common_api::ComponentSerializationMethod::#ser_method; + + fn host_name() -> Option<&'static str> { + Some(#host_type_name) + } + + fn component_info() -> common_api::bindings::lyra::api::ecs::ComponentInfo { + common_api::bindings::lyra::api::ecs::ComponentInfo::of::() + } + + fn to_bytes(&self) -> Result, common_api::ComponentSerializationError> { + Ok(common_api::bytemuck::bytes_of(self).to_vec()) + } + + fn to_bytes_into(&self, target: &mut Vec) -> Result<(), common_api::ComponentSerializationError> { + let bytes = self.to_bytes()?; + target.extend(bytes.into_iter()); + Ok(()) + } + + fn from_bytes(bytes: &[u8]) -> Result { + common_api::bytemuck::try_from_bytes::(&bytes) + .map_err(|e| common_api::ComponentSerializationError::Bytemuck(e)) + .cloned() + } + } + }.into() +} \ No newline at end of file diff --git a/common-api/src/component.rs b/common-api/src/component.rs index ae68f2b..cf78e36 100644 --- a/common-api/src/component.rs +++ b/common-api/src/component.rs @@ -6,6 +6,7 @@ impl ComponentInfo { pub fn of() -> Self { let layout = Layout::new::(); Self { + host_name: C::host_name().map(|s| s.to_string()), size: layout.size() as _, alignment: layout.align() as _, type_id: WasmTypeId::of::(), @@ -33,6 +34,7 @@ pub enum ComponentSerializationError { pub trait Component: Sized + 'static { const SERIALIZATION: ComponentSerializationMethod; + fn host_name() -> Option<&'static str>; fn component_info() -> ComponentInfo; fn to_bytes(&self) -> Result, ComponentSerializationError>; fn to_bytes_into(&self, target: &mut Vec) -> Result<(), ComponentSerializationError>; @@ -40,12 +42,16 @@ pub trait Component: Sized + 'static { fn from_bytes(bytes: &[u8]) -> Result; } -#[macro_export] +/* #[macro_export] macro_rules! bytemuck_component_impl { ($type:ident) => { impl common_api::Component for $type { const SERIALIZATION: common_api::ComponentSerializationMethod = common_api::ComponentSerializationMethod::Bytemuck; + fn host_name() -> Option<&'static str> { + Some(stringify!($type)) + } + fn component_info() -> common_api::bindings::lyra::api::ecs::ComponentInfo { common_api::bindings::lyra::api::ecs::ComponentInfo::of::<$type>() } @@ -67,4 +73,4 @@ macro_rules! bytemuck_component_impl { } } }; -} \ No newline at end of file +} */ \ No newline at end of file diff --git a/common-api/src/lib.rs b/common-api/src/lib.rs index 6134ae0..2e0cf92 100755 --- a/common-api/src/lib.rs +++ b/common-api/src/lib.rs @@ -8,6 +8,10 @@ pub use component::*; mod bundle; pub use bundle::*; +pub mod math; + +pub use api_derive as macros; + pub mod bindings { wit_bindgen::generate!({ world: "api", diff --git a/common-api/src/math.rs b/common-api/src/math.rs new file mode 100644 index 0000000..9ff83fb --- /dev/null +++ b/common-api/src/math.rs @@ -0,0 +1,40 @@ +use api_derive::bytemuck_component_impl; + +use crate as common_api; + +#[repr(C)] +#[derive(Debug, Clone, Copy, PartialEq, bytemuck::Pod, bytemuck::Zeroable)] +pub struct Vec3 { + x: f32, + y: f32, + z: f32, +} + +impl Vec3 { + pub fn new(x: f32, y: f32, z: f32) -> Self { + Self { + x, y, z + } + } +} + +bytemuck_component_impl!(Vec3); + +#[repr(C)] +#[derive(Debug, Clone, Copy, PartialEq, bytemuck::Pod, bytemuck::Zeroable)] +pub struct Vec4 { + x: f32, + y: f32, + z: f32, + w: f32, +} + +impl Vec4 { + pub fn new(x: f32, y: f32, z: f32, w: f32) -> Self { + Self { + x, y, z, w + } + } +} + +bytemuck_component_impl!(Vec4); \ No newline at end of file diff --git a/common-api/wit/ecs.wit b/common-api/wit/ecs.wit index e547541..6871e3f 100644 --- a/common-api/wit/ecs.wit +++ b/common-api/wit/ecs.wit @@ -16,6 +16,7 @@ interface ecs { } record component-info { + host-name: option, /// The size of the component in memory. size: u64, /// The alignment of the component in memory. @@ -24,7 +25,7 @@ interface ecs { /// /// This must be unique between component types since its used to identify the components /// in spawning and querying. - type-id: wasm-type-id, // a u128 + type-id: wasm-type-id, } resource ecs-dynamic-view { diff --git a/src/main.rs b/src/main.rs index fce7164..9b97d68 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,7 +64,7 @@ wasmtime::component::bindgen!({ async: true, with: { - "lyra:api": lyra::api, + //"lyra:api": lyra::api, } }); @@ -110,9 +110,8 @@ impl WasiView for Imports { #[async_trait] impl ExampleImports for Imports { - async fn host_print(&mut self, msg: String) -> wasmtime::Result<()> { + async fn host_print(&mut self, msg: String) { println!("{}", msg); - Ok(()) } } @@ -124,13 +123,13 @@ pub enum WasmError { #[async_trait] impl wasm_ecs::HostEcsWorld for Imports { - async fn new(&mut self) -> wasmtime::Result> { + async fn new(&mut self) -> WasmResource { let entry = WorldEntry { world: lyra_ecs::World::new(), views: Slab::new(), }; let world = self.world_slab.insert(entry); - Ok(WasmResource::new_own(world as _)) + WasmResource::new_own(world as _) } async fn spawn( @@ -138,11 +137,12 @@ impl wasm_ecs::HostEcsWorld for Imports { this: WasmResource, mut components: Vec, infos: Vec, - ) -> wasmtime::Result { + ) -> wasm_ecs::Entity { let world_entry = self .world_slab .get_mut(this.rep() as _) - .ok_or(WasmError::InvalidResourceHandle("EcsWorld"))?; + .ok_or(WasmError::InvalidResourceHandle("EcsWorld")) + .unwrap(); let world = &mut world_entry.world; // add the components in the tightly packed `components` buffer into the dynamic bundle @@ -152,20 +152,20 @@ impl wasm_ecs::HostEcsWorld for Imports { // SAFETY: The components are tightly packed, adding the offset to the pointer will // get the next component in the buffer. let data_ptr = unsafe { NonNull::new_unchecked(components.as_mut_ptr().add(offset)) }; - bundle.push_unknown(data_ptr, info.into()); + bundle.push_unknown(data_ptr, info.clone().into()); offset += info.size as usize; } let en = world.spawn(bundle); - Ok(en.into()) + en.into() } async fn view( &mut self, this: wasmtime::component::Resource, infos: Vec, - ) -> wasmtime::Result> { + ) -> wasmtime::component::Resource { ::new(self, this, infos).await } @@ -195,7 +195,7 @@ impl wasm_ecs::HostEcsDynamicView for Imports { &mut self, world: WasmResource, infos: Vec, - ) -> wasmtime::Result> { + ) -> wasmtime::component::Resource { // Create a dynamic view for querying for the components let mut view = DynamicViewState::new(); for info in infos.clone() { @@ -213,16 +213,17 @@ impl wasm_ecs::HostEcsDynamicView for Imports { let world_entry = self .world_slab .get_mut(world.rep() as _) - .ok_or(WasmError::InvalidResourceHandle("EcsWorld"))?; + .ok_or(WasmError::InvalidResourceHandle("EcsWorld")) + .unwrap(); world_entry.views.insert(view_index); - Ok(WasmResource::new_own(view_index as _)) + WasmResource::new_own(view_index as _) } async fn next( &mut self, view: WasmResource, - ) -> wasmtime::Result>> { + ) -> Option> { let view_entry = self.world_views_slab.get_mut(view.rep() as _).unwrap(); let world_entry = self.world_slab.get(view_entry.world_index).unwrap(); let view = &mut view_entry.view; @@ -253,9 +254,9 @@ impl wasm_ecs::HostEcsDynamicView for Imports { offset += comp_size; } - Ok(Some(row_buf)) + Some(row_buf) } else { - Ok(None) + None } } @@ -290,7 +291,10 @@ async fn main() -> wasmtime::Result<()> { // Configure the linker let mut linker = wasmtime::component::Linker::new(&engine); - wasmtime_wasi::bindings::Imports::add_to_linker(&mut linker, |s| s)?; + + //wasmtime_wasi::preview0::add_to_linker_sync(&mut linker, |s| s)?; + //wasmtime_wasi::bindings::Imports::add_to_linker(&mut linker, |s| s)?; + wasmtime_wasi::add_to_linker_async(&mut linker)?; Example::add_to_linker(&mut linker, |s| s)?; Api::add_to_linker(&mut linker, |s| s)?; @@ -310,12 +314,12 @@ async fn main() -> wasmtime::Result<()> { ); // Load the component from disk - let bytes = std::fs::read("target/wasm32-wasi/debug/witguest.wasm")?; + let bytes = std::fs::read("target/wasm32-wasip1/debug/witguest.wasm")?; let component = wasmtime::component::Component::new(&engine, bytes)?; // Instantiate the component println!("creating example"); - let (example, _instance) = Example::instantiate_async(&mut store, &component, &linker).await?; + let example = Example::instantiate_async(&mut store, &component, &linker).await?; example.call_on_init(&mut store).await?.unwrap(); println!("Guest is done"); diff --git a/witguest/Cargo.toml b/witguest/Cargo.toml index 8a6c42a..60c76db 100644 --- a/witguest/Cargo.toml +++ b/witguest/Cargo.toml @@ -6,10 +6,10 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -wit-bindgen = { version = "0.24.0", default-features = false, features = ["realloc"] } +#wit-bindgen = { version = "0.28.0", default-features = false, features = ["realloc"] } +wit-bindgen-rt = { version = "0.28.0", features = ["bitflags"] } common-api = { path = "../common-api" } bytemuck = { version = "1.15.0", features = ["derive"] } -#bytemuck = { version = "1.15.0", features = ["derive"] } [lib] crate-type = ["cdylib"] diff --git a/witguest/src/bindings.rs b/witguest/src/bindings.rs index de75a9b..33e6a51 100644 --- a/witguest/src/bindings.rs +++ b/witguest/src/bindings.rs @@ -1,81 +1,118 @@ -// Generated by `wit-bindgen` 0.18.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.25.0. DO NOT EDIT! +// Options used: #[allow(unused_unsafe, clippy::all)] -pub fn host_print(msg: &str,){ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - unsafe { - let vec0 = msg; - let ptr0 = vec0.as_ptr() as i32; - let len0 = vec0.len() as i32; - +pub fn host_print(msg: &str) { + unsafe { + let vec0 = msg; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "$root")] + extern "C" { + #[link_name = "host-print"] + fn wit_import(_: *mut u8, _: usize); + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: *mut u8, _: usize) { + unreachable!() + } + wit_import(ptr0.cast_mut(), len0); + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub unsafe fn _export_on_init_cabi() -> i32 { #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "$root")] - extern "C" { - #[link_name = "host-print"] - fn wit_import(_: i32, _: i32, ); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: i32, ){ unreachable!() } - wit_import(ptr0, len0); - } -} -const _: () = { - - #[doc(hidden)] - #[export_name = "on-init"] - #[allow(non_snake_case)] - unsafe extern "C" fn __export_on_init() -> i32 { - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - - // Before executing any other code, use this function to run all static - // constructors, if they have not yet been run. This is a hack required - // to work around wasi-libc ctors calling import functions to initialize - // the environment. - // - // This functionality will be removed once rust 1.69.0 is stable, at which - // point wasi-libc will no longer have this behavior. - // - // See - // https://github.com/bytecodealliance/preview2-prototyping/issues/99 - // for more details. - #[cfg(target_arch="wasm32")] - wit_bindgen::rt::run_ctors_once(); - - let result0 = <_GuestImpl as Guest>::on_init(); + _rt::run_ctors_once(); + let result0 = T::on_init(); let result1 = match result0 { - Ok(_) => { 0i32 }, - Err(_) => { 1i32 }, - };result1 - } -}; -use super::Component as _GuestImpl; -pub trait Guest { - fn on_init() -> Result<(),()>; + Ok(_) => 0i32, + Err(_) => 1i32, + }; + result1 } -pub mod component { - pub mod witguest { - - #[allow(clippy::all)] - pub mod math { - #[used] - #[doc(hidden)] - #[cfg(target_arch = "wasm32")] - static __FORCE_SECTION_REF: fn() = super::super::super::__link_section; - +pub trait Guest { + fn on_init() -> Result<(), ()>; +} +#[doc(hidden)] + +macro_rules! __export_world_example_cabi{ + ($ty:ident with_types_in $($path_to_types:tt)*) => (const _: () = { + + #[export_name = "on-init"] + unsafe extern "C" fn export_on_init() -> i32 { + $($path_to_types)*::_export_on_init_cabi::<$ty>() + } + };); +} +#[doc(hidden)] +pub(crate) use __export_world_example_cabi; +#[allow(dead_code)] +pub mod component { + #[allow(dead_code)] + pub mod witguest { + #[allow(dead_code, clippy::all)] + pub mod math { + #[used] + #[doc(hidden)] + #[cfg(target_arch = "wasm32")] + static __FORCE_SECTION_REF: fn() = + super::super::super::__link_custom_section_describing_imports; + } + } +} +mod _rt { + + #[cfg(target_arch = "wasm32")] + pub fn run_ctors_once() { + wit_bindgen_rt::run_ctors_once(); } - - } } -#[cfg(target_arch = "wasm32")] -#[link_section = "component-type:example"] +/// 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)] -pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 261] = [0, 97, 115, 109, 13, 0, 1, 0, 0, 25, 22, 119, 105, 116, 45, 99, 111, 109, 112, 111, 110, 101, 110, 116, 45, 101, 110, 99, 111, 100, 105, 110, 103, 4, 0, 7, 136, 1, 1, 65, 2, 1, 65, 7, 1, 66, 2, 1, 114, 3, 1, 120, 118, 1, 121, 118, 1, 122, 118, 4, 0, 4, 118, 101, 99, 51, 3, 0, 0, 3, 1, 23, 99, 111, 109, 112, 111, 110, 101, 110, 116, 58, 119, 105, 116, 103, 117, 101, 115, 116, 47, 109, 97, 116, 104, 5, 0, 1, 64, 1, 3, 109, 115, 103, 115, 1, 0, 3, 0, 10, 104, 111, 115, 116, 45, 112, 114, 105, 110, 116, 1, 1, 1, 106, 0, 0, 1, 64, 0, 0, 2, 4, 0, 7, 111, 110, 45, 105, 110, 105, 116, 1, 3, 4, 1, 26, 99, 111, 109, 112, 111, 110, 101, 110, 116, 58, 119, 105, 116, 103, 117, 101, 115, 116, 47, 101, 120, 97, 109, 112, 108, 101, 4, 0, 11, 13, 1, 0, 7, 101, 120, 97, 109, 112, 108, 101, 3, 0, 0, 0, 70, 9, 112, 114, 111, 100, 117, 99, 101, 114, 115, 1, 12, 112, 114, 111, 99, 101, 115, 115, 101, 100, 45, 98, 121, 2, 13, 119, 105, 116, 45, 99, 111, 109, 112, 111, 110, 101, 110, 116, 6, 48, 46, 50, 49, 46, 48, 16, 119, 105, 116, 45, 98, 105, 110, 100, 103, 101, 110, 45, 114, 117, 115, 116, 6, 48, 46, 49, 56, 46, 48]; + +macro_rules! __export_example_impl { + ($ty:ident) => (self::export!($ty with_types_in self);); + ($ty:ident with_types_in $($path_to_types_root:tt)*) => ( + $($path_to_types_root)*::__export_world_example_cabi!($ty with_types_in $($path_to_types_root)*); + ) +} +#[doc(inline)] +pub(crate) use __export_example_impl as export; + +#[cfg(target_arch = "wasm32")] +#[link_section = "component-type:wit-bindgen:0.25.0:example:encoded world"] +#[doc(hidden)] +pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 262] = *b"\ +\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\x88\x01\x01A\x02\x01\ +A\x07\x01B\x02\x01r\x03\x01xv\x01yv\x01zv\x04\0\x04vec3\x03\0\0\x03\x01\x17compo\ +nent:witguest/math\x05\0\x01@\x01\x03msgs\x01\0\x03\0\x0ahost-print\x01\x01\x01j\ +\0\0\x01@\0\0\x02\x04\0\x07on-init\x01\x03\x04\x01\x1acomponent:witguest/example\ +\x04\0\x0b\x0d\x01\0\x07example\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0d\ +wit-component\x070.208.1\x10wit-bindgen-rust\x060.25.0"; #[inline(never)] #[doc(hidden)] #[cfg(target_arch = "wasm32")] -pub fn __link_section() {} +pub fn __link_custom_section_describing_imports() { + wit_bindgen_rt::maybe_link_cabi_realloc(); +} diff --git a/witguest/src/lib.rs b/witguest/src/lib.rs index bd01e46..36288b2 100644 --- a/witguest/src/lib.rs +++ b/witguest/src/lib.rs @@ -2,44 +2,7 @@ mod bindings; use bindings::Guest; -use common_api::{bytemuck_component_impl, World}; - -#[repr(C)] -#[derive(Debug, Clone, Copy, PartialEq, bytemuck::Pod, bytemuck::Zeroable)] -struct Vec3 { - x: f32, - y: f32, - z: f32, -} - -impl Vec3 { - pub fn new(x: f32, y: f32, z: f32) -> Self { - Self { - x, y, z - } - } -} - -bytemuck_component_impl!(Vec3); - -#[repr(C)] -#[derive(Debug, Clone, Copy, PartialEq, bytemuck::Pod, bytemuck::Zeroable)] -struct Vec4 { - x: f32, - y: f32, - z: f32, - w: f32, -} - -impl Vec4 { - pub fn new(x: f32, y: f32, z: f32, w: f32) -> Self { - Self { - x, y, z, w - } - } -} - -bytemuck_component_impl!(Vec4); +use common_api::{World, math::{Vec3, Vec4}}; struct Component; @@ -59,4 +22,6 @@ impl Guest for Component { Ok(()) } -} \ No newline at end of file +} + +bindings::export!(Component with_types_in bindings); \ No newline at end of file