From 16410b9615f6a0a8c1eb3d2803fa08fb20728043 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 6 Dec 2022 13:06:15 -0600 Subject: [PATCH] Remove the wasmtime-rust host from this repository (#439) This bindings generator has been moved to the `wasmtime` crate upstream as part of https://github.com/bytecodealliance/wasmtime/pull/5317. This is another step along the road of #395. The Wasmtime-hosted tests are all removed here as well but may get re-added in the future for testing as necessary. --- Cargo.lock | 1097 +---------------- Cargo.toml | 3 - crates/gen-host-wasmtime-rust/Cargo.toml | 27 - crates/gen-host-wasmtime-rust/build.rs | 4 - crates/gen-host-wasmtime-rust/src/lib.rs | 750 ----------- .../gen-host-wasmtime-rust/tests/codegen.rs | 37 - .../gen-host-wasmtime-rust/tests/runtime.rs | 107 -- crates/host-wasmtime-rust-macro/Cargo.toml | 21 - crates/host-wasmtime-rust-macro/src/lib.rs | 45 - crates/host-wasmtime-rust/Cargo.toml | 19 - crates/host-wasmtime-rust/src/lib.rs | 89 -- crates/test-helpers/macros/src/lib.rs | 47 - src/bin/wit-bindgen.rs | 13 - tests/runtime/flavorful/host.rs | 163 --- tests/runtime/invalid/host.rs | 123 -- tests/runtime/lists/host.rs | 136 -- tests/runtime/many_arguments/host.rs | 60 - tests/runtime/numbers/host.rs | 185 --- tests/runtime/records/host.rs | 111 -- tests/runtime/results/host.rs | 161 --- tests/runtime/smoke/host.async.rs | 42 - tests/runtime/smoke/host.rs | 35 - tests/runtime/smw_functions/exports.wit | 12 - tests/runtime/smw_functions/ignore_host.rs | 127 -- tests/runtime/smw_functions/imports.wit | 9 - tests/runtime/smw_functions/wasm.js | 83 -- tests/runtime/smw_lists/exports.wit | 7 - tests/runtime/smw_lists/ignore_host.rs | 88 -- tests/runtime/smw_lists/imports.wit | 5 - tests/runtime/smw_lists/wasm.js | 77 -- tests/runtime/smw_strings/exports.wit | 7 - tests/runtime/smw_strings/ignore_host.rs | 75 -- tests/runtime/smw_strings/imports.wit | 4 - tests/runtime/smw_strings/wasm.js | 40 - tests/runtime/unions/host.rs | 309 ----- tests/runtime/variants/host.rs | 118 -- 36 files changed, 8 insertions(+), 4228 deletions(-) delete mode 100644 crates/gen-host-wasmtime-rust/Cargo.toml delete mode 100644 crates/gen-host-wasmtime-rust/build.rs delete mode 100644 crates/gen-host-wasmtime-rust/src/lib.rs delete mode 100644 crates/gen-host-wasmtime-rust/tests/codegen.rs delete mode 100644 crates/gen-host-wasmtime-rust/tests/runtime.rs delete mode 100644 crates/host-wasmtime-rust-macro/Cargo.toml delete mode 100644 crates/host-wasmtime-rust-macro/src/lib.rs delete mode 100644 crates/host-wasmtime-rust/Cargo.toml delete mode 100644 crates/host-wasmtime-rust/src/lib.rs delete mode 100644 tests/runtime/flavorful/host.rs delete mode 100644 tests/runtime/invalid/host.rs delete mode 100644 tests/runtime/lists/host.rs delete mode 100644 tests/runtime/many_arguments/host.rs delete mode 100644 tests/runtime/numbers/host.rs delete mode 100644 tests/runtime/records/host.rs delete mode 100644 tests/runtime/results/host.rs delete mode 100644 tests/runtime/smoke/host.async.rs delete mode 100644 tests/runtime/smoke/host.rs delete mode 100644 tests/runtime/smw_functions/exports.wit delete mode 100644 tests/runtime/smw_functions/ignore_host.rs delete mode 100644 tests/runtime/smw_functions/imports.wit delete mode 100644 tests/runtime/smw_functions/wasm.js delete mode 100644 tests/runtime/smw_lists/exports.wit delete mode 100644 tests/runtime/smw_lists/ignore_host.rs delete mode 100644 tests/runtime/smw_lists/imports.wit delete mode 100644 tests/runtime/smw_lists/wasm.js delete mode 100644 tests/runtime/smw_strings/exports.wit delete mode 100644 tests/runtime/smw_strings/ignore_host.rs delete mode 100644 tests/runtime/smw_strings/imports.wit delete mode 100644 tests/runtime/smw_strings/wasm.js delete mode 100644 tests/runtime/unions/host.rs delete mode 100644 tests/runtime/variants/host.rs diff --git a/Cargo.lock b/Cargo.lock index 1f51862b..9fe8ba5f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,23 +43,6 @@ version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" -[[package]] -name = "arrayvec" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" - -[[package]] -name = "async-trait" -version = "0.1.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e805d94e6b5001b651426cf4cd446b1ab5f319d27bab5c644f61de0a804360c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "atty" version = "0.2.14" @@ -98,30 +81,12 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" -[[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" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "block-buffer" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" -dependencies = [ - "generic-array", -] - [[package]] name = "bstr" version = "0.2.17" @@ -131,32 +96,11 @@ dependencies = [ "memchr", ] -[[package]] -name = "bumpalo" -version = "3.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" - -[[package]] -name = "byteorder" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" - -[[package]] -name = "bytes" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" - [[package]] name = "cc" version = "1.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4" -dependencies = [ - "jobserver", -] [[package]] name = "cfg-if" @@ -201,78 +145,6 @@ dependencies = [ "os_str_bytes", ] -[[package]] -name = "cpp_demangle" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eeaa953eaad386a53111e47172c2fedba671e5684c8dd601a5f474f4f118710f" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "cpufeatures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" -dependencies = [ - "libc", -] - -[[package]] -name = "cranelift-bforest" -version = "0.91.0" -source = "git+https://github.com/bytecodealliance/wasmtime#28cf995fd3f9926a95036758c78390f54a0289ae" -dependencies = [ - "cranelift-entity", -] - -[[package]] -name = "cranelift-codegen" -version = "0.91.0" -source = "git+https://github.com/bytecodealliance/wasmtime#28cf995fd3f9926a95036758c78390f54a0289ae" -dependencies = [ - "arrayvec", - "bumpalo", - "cranelift-bforest", - "cranelift-codegen-meta", - "cranelift-codegen-shared", - "cranelift-egraph", - "cranelift-entity", - "cranelift-isle", - "gimli", - "log", - "regalloc2", - "smallvec", - "target-lexicon", -] - -[[package]] -name = "cranelift-codegen-meta" -version = "0.91.0" -source = "git+https://github.com/bytecodealliance/wasmtime#28cf995fd3f9926a95036758c78390f54a0289ae" -dependencies = [ - "cranelift-codegen-shared", -] - -[[package]] -name = "cranelift-codegen-shared" -version = "0.91.0" -source = "git+https://github.com/bytecodealliance/wasmtime#28cf995fd3f9926a95036758c78390f54a0289ae" - -[[package]] -name = "cranelift-egraph" -version = "0.91.0" -source = "git+https://github.com/bytecodealliance/wasmtime#28cf995fd3f9926a95036758c78390f54a0289ae" -dependencies = [ - "cranelift-entity", - "fxhash", - "hashbrown", - "indexmap", - "log", - "smallvec", -] - [[package]] name = "cranelift-entity" version = "0.91.0" @@ -281,47 +153,6 @@ dependencies = [ "serde", ] -[[package]] -name = "cranelift-frontend" -version = "0.91.0" -source = "git+https://github.com/bytecodealliance/wasmtime#28cf995fd3f9926a95036758c78390f54a0289ae" -dependencies = [ - "cranelift-codegen", - "log", - "smallvec", - "target-lexicon", -] - -[[package]] -name = "cranelift-isle" -version = "0.91.0" -source = "git+https://github.com/bytecodealliance/wasmtime#28cf995fd3f9926a95036758c78390f54a0289ae" - -[[package]] -name = "cranelift-native" -version = "0.91.0" -source = "git+https://github.com/bytecodealliance/wasmtime#28cf995fd3f9926a95036758c78390f54a0289ae" -dependencies = [ - "cranelift-codegen", - "libc", - "target-lexicon", -] - -[[package]] -name = "cranelift-wasm" -version = "0.91.0" -source = "git+https://github.com/bytecodealliance/wasmtime#28cf995fd3f9926a95036758c78390f54a0289ae" -dependencies = [ - "cranelift-codegen", - "cranelift-entity", - "cranelift-frontend", - "itertools", - "log", - "smallvec", - "wasmparser", - "wasmtime-types", -] - [[package]] name = "crc32fast" version = "1.3.2" @@ -331,40 +162,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crossbeam-channel" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-deque" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" -dependencies = [ - "cfg-if", - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a" -dependencies = [ - "autocfg", - "cfg-if", - "crossbeam-utils", - "memoffset 0.7.1", - "scopeguard", -] - [[package]] name = "crossbeam-utils" version = "0.8.14" @@ -374,112 +171,12 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "digest" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" -dependencies = [ - "block-buffer", - "crypto-common", -] - -[[package]] -name = "directories-next" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "339ee130d97a610ea5a5872d2bbb130fdf68884ff09d3028b81bec8a1ac23bbc" -dependencies = [ - "cfg-if", - "dirs-sys-next", -] - -[[package]] -name = "dirs-sys-next" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" -dependencies = [ - "libc", - "redox_users", - "winapi", -] - -[[package]] -name = "either" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" - -[[package]] -name = "encoding_rs" -version = "0.8.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "env_logger" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] - -[[package]] -name = "errno" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" -dependencies = [ - "errno-dragonfly", - "libc", - "winapi", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "fallible-iterator" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" -[[package]] -name = "file-per-thread-logger" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21e16290574b39ee41c71aeb90ae960c504ebaf1e2a1c87bd52aa56ed6e1a02f" -dependencies = [ - "env_logger", - "log", -] - [[package]] name = "filetime" version = "0.2.18" @@ -489,7 +186,7 @@ dependencies = [ "cfg-if", "libc", "redox_syscall", - "windows-sys 0.42.0", + "windows-sys", ] [[package]] @@ -544,25 +241,6 @@ dependencies = [ "slab", ] -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - -[[package]] -name = "generic-array" -version = "0.14.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" -dependencies = [ - "typenum", - "version_check", -] - [[package]] name = "getrandom" version = "0.2.8" @@ -581,7 +259,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" dependencies = [ "fallible-iterator", - "indexmap", "stable_deref_trait", ] @@ -625,12 +302,6 @@ dependencies = [ "libc", ] -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "id-arena" version = "2.2.1" @@ -676,60 +347,6 @@ dependencies = [ "serde", ] -[[package]] -name = "io-lifetimes" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ce5ef949d49ee85593fc4d3f3f95ad61657076395cbbce23e2121fc5542074" - -[[package]] -name = "io-lifetimes" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7d367024b3f3414d8e01f437f704f41a9f64ab36f9067fa73e526ad4c763c87" -dependencies = [ - "libc", - "windows-sys 0.42.0", -] - -[[package]] -name = "itertools" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] - -[[package]] -name = "ittapi" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c4f6ff06169ce7048dac5150b1501c7e3716a929721aeb06b87e51a43e42f4" -dependencies = [ - "anyhow", - "ittapi-sys", - "log", -] - -[[package]] -name = "ittapi-sys" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87e078cce01485f418bae3beb34dd604aaedf2065502853c7da17fbce8e64eda" -dependencies = [ - "cc", -] - -[[package]] -name = "jobserver" -version = "0.1.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "068b1ee6743e4d11fb9c6a1e6064b3693a1b600e7f5f5988047d98b3dc9fb90b" -dependencies = [ - "libc", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -748,28 +365,6 @@ version = "0.2.137" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" -[[package]] -name = "linux-raw-sys" -version = "0.0.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" - -[[package]] -name = "linux-raw-sys" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f9f08d8963a6c613f4b1a78f4f4a4dbfadf8e6545b2d72861731e4858b8b47f" - -[[package]] -name = "lock_api" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.17" @@ -779,57 +374,12 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "mach" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" -dependencies = [ - "libc", -] - -[[package]] -name = "matchers" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" -dependencies = [ - "regex-automata", -] - [[package]] name = "memchr" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" -[[package]] -name = "memfd" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b20a59d985586e4a5aef64564ac77299f8586d8be6cf9106a5a40207e8908efb" -dependencies = [ - "rustix 0.36.3", -] - -[[package]] -name = "memoffset" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" -dependencies = [ - "autocfg", -] - -[[package]] -name = "memoffset" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" -dependencies = [ - "autocfg", -] - [[package]] name = "miniz_oxide" version = "0.5.4" @@ -839,28 +389,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" -dependencies = [ - "libc", - "log", - "wasi", - "windows-sys 0.42.0", -] - -[[package]] -name = "num_cpus" -version = "1.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "object" version = "0.29.0" @@ -885,35 +413,6 @@ version = "6.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-sys 0.42.0", -] - -[[package]] -name = "paste" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" - [[package]] name = "percent-encoding" version = "2.2.0" @@ -932,12 +431,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - [[package]] name = "proc-macro-error" version = "1.0.4" @@ -971,15 +464,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "psm" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5787f7cda34e3033a72192c018bc5883100330f362ef279a8cbccfce8bb4e874" -dependencies = [ - "cc", -] - [[package]] name = "pulldown-cmark" version = "0.8.0" @@ -1000,59 +484,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rayon" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e060280438193c554f654141c9ea9417886713b7acd75974c85b18a69a88e0b" -dependencies = [ - "crossbeam-deque", - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cac410af5d00ab6884528b4ab69d1e8e146e8d471201800fa1b4524126de6ad3" -dependencies = [ - "crossbeam-channel", - "crossbeam-deque", - "crossbeam-utils", - "num_cpus", -] - [[package]] name = "redox_syscall" version = "0.2.16" @@ -1062,29 +493,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "redox_users" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" -dependencies = [ - "getrandom", - "redox_syscall", - "thiserror", -] - -[[package]] -name = "regalloc2" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91b2eab54204ea0117fe9a060537e0b07a4e72f7c7d182361ecc346cab2240e5" -dependencies = [ - "fxhash", - "log", - "slice-group-by", - "smallvec", -] - [[package]] name = "regex" version = "1.7.0" @@ -1096,15 +504,6 @@ dependencies = [ "regex-syntax", ] -[[package]] -name = "regex-automata" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" -dependencies = [ - "regex-syntax", -] - [[package]] name = "regex-syntax" version = "0.6.28" @@ -1117,34 +516,6 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" -[[package]] -name = "rustix" -version = "0.35.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "727a1a6d65f786ec22df8a81ca3121107f235970dc1705ed681d3e6e8b9cd5f9" -dependencies = [ - "bitflags", - "errno", - "io-lifetimes 0.7.5", - "libc", - "linux-raw-sys 0.0.46", - "windows-sys 0.42.0", -] - -[[package]] -name = "rustix" -version = "0.36.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b1fbb4dfc4eb1d390c02df47760bb19a84bb80b301ecc947ab5406394d8223e" -dependencies = [ - "bitflags", - "errno", - "io-lifetimes 1.0.1", - "libc", - "linux-raw-sys 0.1.3", - "windows-sys 0.42.0", -] - [[package]] name = "same-file" version = "1.0.6" @@ -1154,12 +525,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - [[package]] name = "serde" version = "1.0.147" @@ -1180,64 +545,13 @@ dependencies = [ "syn", ] -[[package]] -name = "sha2" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sharded-slab" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "signal-hook-registry" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" -dependencies = [ - "autocfg", -] - -[[package]] -name = "slice-group-by" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03b634d87b960ab1a38c4fe143b508576f075e7c978bfad18217645ebfdfa2ec" - -[[package]] -name = "smallvec" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" - -[[package]] -name = "socket2" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" +checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" dependencies = [ - "libc", - "winapi", + "autocfg", ] [[package]] @@ -1306,17 +620,6 @@ dependencies = [ "wit-parser", ] -[[package]] -name = "test-log" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38f0c854faeb68a048f0f2dc410c5ddae3bf83854ef0e4977d58306a5edef50e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "test-rust-wasm" version = "0.3.0" @@ -1369,99 +672,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" -[[package]] -name = "tokio" -version = "1.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76ce4a75fb488c605c54bf610f221cea8b0dafb53333c1a67e8ee199dcd2ae3" -dependencies = [ - "autocfg", - "bytes", - "libc", - "memchr", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "winapi", -] - -[[package]] -name = "tokio-macros" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "toml" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" -dependencies = [ - "serde", -] - -[[package]] -name = "tracing" -version = "0.1.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" -dependencies = [ - "cfg-if", - "pin-project-lite", - "tracing-attributes", - "tracing-core", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tracing-core" -version = "0.1.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" -dependencies = [ - "once_cell", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70" -dependencies = [ - "matchers", - "once_cell", - "regex", - "sharded-slab", - "thread_local", - "tracing", - "tracing-core", -] - -[[package]] -name = "typenum" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" - [[package]] name = "unicase" version = "2.6.0" @@ -1581,102 +791,11 @@ dependencies = [ "wasmparser", ] -[[package]] -name = "wasmtime" -version = "4.0.0" -source = "git+https://github.com/bytecodealliance/wasmtime#28cf995fd3f9926a95036758c78390f54a0289ae" -dependencies = [ - "anyhow", - "async-trait", - "bincode", - "cfg-if", - "encoding_rs", - "indexmap", - "libc", - "log", - "object", - "once_cell", - "paste", - "psm", - "rayon", - "serde", - "target-lexicon", - "wasmparser", - "wasmtime-cache", - "wasmtime-component-macro", - "wasmtime-component-util", - "wasmtime-cranelift", - "wasmtime-environ", - "wasmtime-fiber", - "wasmtime-jit", - "wasmtime-runtime", - "wat", - "windows-sys 0.36.1", -] - -[[package]] -name = "wasmtime-asm-macros" -version = "4.0.0" -source = "git+https://github.com/bytecodealliance/wasmtime#28cf995fd3f9926a95036758c78390f54a0289ae" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "wasmtime-cache" -version = "4.0.0" -source = "git+https://github.com/bytecodealliance/wasmtime#28cf995fd3f9926a95036758c78390f54a0289ae" -dependencies = [ - "anyhow", - "base64", - "bincode", - "directories-next", - "file-per-thread-logger", - "log", - "rustix 0.35.13", - "serde", - "sha2", - "toml", - "windows-sys 0.36.1", - "zstd", -] - -[[package]] -name = "wasmtime-component-macro" -version = "4.0.0" -source = "git+https://github.com/bytecodealliance/wasmtime#28cf995fd3f9926a95036758c78390f54a0289ae" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasmtime-component-util", -] - [[package]] name = "wasmtime-component-util" version = "4.0.0" source = "git+https://github.com/bytecodealliance/wasmtime#28cf995fd3f9926a95036758c78390f54a0289ae" -[[package]] -name = "wasmtime-cranelift" -version = "4.0.0" -source = "git+https://github.com/bytecodealliance/wasmtime#28cf995fd3f9926a95036758c78390f54a0289ae" -dependencies = [ - "anyhow", - "cranelift-codegen", - "cranelift-entity", - "cranelift-frontend", - "cranelift-native", - "cranelift-wasm", - "gimli", - "log", - "object", - "target-lexicon", - "thiserror", - "wasmparser", - "wasmtime-environ", -] - [[package]] name = "wasmtime-environ" version = "4.0.0" @@ -1698,89 +817,6 @@ dependencies = [ "wasmtime-types", ] -[[package]] -name = "wasmtime-fiber" -version = "4.0.0" -source = "git+https://github.com/bytecodealliance/wasmtime#28cf995fd3f9926a95036758c78390f54a0289ae" -dependencies = [ - "cc", - "cfg-if", - "rustix 0.35.13", - "wasmtime-asm-macros", - "windows-sys 0.36.1", -] - -[[package]] -name = "wasmtime-jit" -version = "4.0.0" -source = "git+https://github.com/bytecodealliance/wasmtime#28cf995fd3f9926a95036758c78390f54a0289ae" -dependencies = [ - "addr2line", - "anyhow", - "bincode", - "cfg-if", - "cpp_demangle", - "gimli", - "ittapi", - "log", - "object", - "rustc-demangle", - "serde", - "target-lexicon", - "thiserror", - "wasmtime-environ", - "wasmtime-jit-debug", - "wasmtime-jit-icache-coherence", - "wasmtime-runtime", - "windows-sys 0.36.1", -] - -[[package]] -name = "wasmtime-jit-debug" -version = "4.0.0" -source = "git+https://github.com/bytecodealliance/wasmtime#28cf995fd3f9926a95036758c78390f54a0289ae" -dependencies = [ - "object", - "once_cell", - "rustix 0.35.13", -] - -[[package]] -name = "wasmtime-jit-icache-coherence" -version = "3.0.0" -source = "git+https://github.com/bytecodealliance/wasmtime#28cf995fd3f9926a95036758c78390f54a0289ae" -dependencies = [ - "cfg-if", - "libc", - "windows-sys 0.36.1", -] - -[[package]] -name = "wasmtime-runtime" -version = "4.0.0" -source = "git+https://github.com/bytecodealliance/wasmtime#28cf995fd3f9926a95036758c78390f54a0289ae" -dependencies = [ - "anyhow", - "cc", - "cfg-if", - "encoding_rs", - "indexmap", - "libc", - "log", - "mach", - "memfd", - "memoffset 0.6.5", - "paste", - "rand", - "rustix 0.35.13", - "thiserror", - "wasmtime-asm-macros", - "wasmtime-environ", - "wasmtime-fiber", - "wasmtime-jit-debug", - "windows-sys 0.36.1", -] - [[package]] name = "wasmtime-types" version = "4.0.0" @@ -1844,19 +880,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" -dependencies = [ - "windows_aarch64_msvc 0.36.1", - "windows_i686_gnu 0.36.1", - "windows_i686_msvc 0.36.1", - "windows_x86_64_gnu 0.36.1", - "windows_x86_64_msvc 0.36.1", -] - [[package]] name = "windows-sys" version = "0.42.0" @@ -1864,12 +887,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ "windows_aarch64_gnullvm", - "windows_aarch64_msvc 0.42.0", - "windows_i686_gnu 0.42.0", - "windows_i686_msvc 0.42.0", - "windows_x86_64_gnu 0.42.0", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", "windows_x86_64_gnullvm", - "windows_x86_64_msvc 0.42.0", + "windows_x86_64_msvc", ] [[package]] @@ -1878,48 +901,24 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" -[[package]] -name = "windows_aarch64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" - [[package]] name = "windows_aarch64_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" -[[package]] -name = "windows_i686_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" - [[package]] name = "windows_i686_gnu" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" -[[package]] -name = "windows_i686_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" - [[package]] name = "windows_i686_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" -[[package]] -name = "windows_x86_64_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" - [[package]] name = "windows_x86_64_gnu" version = "0.42.0" @@ -1932,12 +931,6 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" -[[package]] -name = "windows_x86_64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" - [[package]] name = "windows_x86_64_msvc" version = "0.42.0" @@ -1956,7 +949,6 @@ dependencies = [ "wit-bindgen-gen-guest-rust", "wit-bindgen-gen-guest-teavm-java", "wit-bindgen-gen-host-js", - "wit-bindgen-gen-host-wasmtime-rust", "wit-bindgen-gen-markdown", "wit-component", ] @@ -1983,7 +975,6 @@ dependencies = [ "wit-bindgen-gen-guest-rust", "wit-bindgen-gen-guest-teavm-java", "wit-bindgen-gen-host-js", - "wit-bindgen-gen-host-wasmtime-rust", "wit-bindgen-gen-markdown", "wit-bindgen-guest-rust", "wit-component", @@ -2041,25 +1032,6 @@ dependencies = [ "wit-component", ] -[[package]] -name = "wit-bindgen-gen-host-wasmtime-rust" -version = "0.3.0" -dependencies = [ - "anyhow", - "clap", - "heck", - "test-helpers", - "test-log", - "tokio", - "tracing", - "tracing-subscriber", - "wasmtime", - "wit-bindgen-core", - "wit-bindgen-gen-rust-lib", - "wit-bindgen-host-wasmtime-rust", - "wit-component", -] - [[package]] name = "wit-bindgen-gen-markdown" version = "0.3.0" @@ -2098,30 +1070,6 @@ dependencies = [ "wit-bindgen-rust-macro-shared", ] -[[package]] -name = "wit-bindgen-host-wasmtime-rust" -version = "0.3.0" -dependencies = [ - "anyhow", - "async-trait", - "bitflags", - "tracing", - "wasmtime", - "wit-bindgen-host-wasmtime-rust-macro", -] - -[[package]] -name = "wit-bindgen-host-wasmtime-rust-macro" -version = "0.3.0" -dependencies = [ - "proc-macro2", - "syn", - "wit-bindgen-core", - "wit-bindgen-gen-host-wasmtime-rust", - "wit-bindgen-rust-macro-shared", - "wit-component", -] - [[package]] name = "wit-bindgen-rust-macro-shared" version = "0.3.0" @@ -2159,32 +1107,3 @@ dependencies = [ "pulldown-cmark", "unicode-xid", ] - -[[package]] -name = "zstd" -version = "0.11.2+zstd.1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" -dependencies = [ - "zstd-safe", -] - -[[package]] -name = "zstd-safe" -version = "5.0.2+zstd.1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" -dependencies = [ - "libc", - "zstd-sys", -] - -[[package]] -name = "zstd-sys" -version = "2.0.2+zstd.1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24faa29d97c8ddca9b37b680e3bd2d5439d864a9cac3a0640d086b71c908bb83" -dependencies = [ - "cc", - "libc", -] diff --git a/Cargo.toml b/Cargo.toml index 370e6e50..3d389e83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,11 +39,9 @@ wit-bindgen-gen-guest-c = { path = 'crates/gen-guest-c', version = '0.3.0' } wit-bindgen-gen-guest-rust = { path = "crates/gen-guest-rust", version = "0.3.0" } wit-bindgen-gen-guest-teavm-java = { path = 'crates/gen-guest-teavm-java', version = '0.3.0' } wit-bindgen-gen-host-js = { path = 'crates/gen-host-js', version = '0.3.0' } -wit-bindgen-gen-host-wasmtime-rust = { path = 'crates/gen-host-wasmtime-rust', version = '0.3.0' } wit-bindgen-gen-markdown = { path = 'crates/gen-markdown', version = '0.3.0' } wit-bindgen-gen-rust-lib = { path = 'crates/gen-rust-lib', version = '0.3.0' } wit-bindgen-guest-rust = { path = 'crates/guest-rust', version = '0.3.0', default-features = false } -wit-bindgen-host-wasmtime-rust = { path = 'crates/host-wasmtime-rust', version = '0.3.0' } wit-bindgen-rust-macro-shared = { path = 'crates/rust-macro-shared', version = '0.3.0' } [[bin]] @@ -55,7 +53,6 @@ anyhow = { workspace = true } clap = { workspace = true } wit-bindgen-core = { path = 'crates/bindgen-core' } wit-bindgen-gen-guest-rust = { path = 'crates/gen-guest-rust', features = ['clap'] } -wit-bindgen-gen-host-wasmtime-rust = { path = 'crates/gen-host-wasmtime-rust', features = ['clap'] } wit-bindgen-gen-host-js = { path = 'crates/gen-host-js', features = ['clap'] } wit-bindgen-gen-guest-c = { path = 'crates/gen-guest-c', features = ['clap'] } wit-bindgen-gen-markdown = { path = 'crates/gen-markdown', features = ['clap'] } diff --git a/crates/gen-host-wasmtime-rust/Cargo.toml b/crates/gen-host-wasmtime-rust/Cargo.toml deleted file mode 100644 index 0d8b3c09..00000000 --- a/crates/gen-host-wasmtime-rust/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -[package] -name = "wit-bindgen-gen-host-wasmtime-rust" -authors = ["Alex Crichton "] -version.workspace = true -edition.workspace = true - -[lib] -test = false -doctest = false - -[dependencies] -wit-bindgen-core = { workspace = true } -wit-bindgen-gen-rust-lib = { workspace = true } -heck = { workspace = true } -wit-component = { workspace = true } -clap = { workspace = true, optional = true } - -[dev-dependencies] -anyhow = { workspace = true } -test-helpers = { path = '../test-helpers' } -wasmtime = { workspace = true } -wit-bindgen-host-wasmtime-rust = { workspace = true, features = ['tracing'] } - -tokio = { version = "1", features = ["full"] } -tracing = { version = "0.1.26" } -tracing-subscriber = { version = "0.3", default-features = false, features = ["env-filter", "fmt"]} -test-log = { version = "0.2", default-features = false, features = ['trace'] } diff --git a/crates/gen-host-wasmtime-rust/build.rs b/crates/gen-host-wasmtime-rust/build.rs deleted file mode 100644 index d7c7fc24..00000000 --- a/crates/gen-host-wasmtime-rust/build.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn main() { - println!("cargo:rerun-if-changed=build.rs"); - // this build script is currently only here so OUT_DIR is set for testing. -} diff --git a/crates/gen-host-wasmtime-rust/src/lib.rs b/crates/gen-host-wasmtime-rust/src/lib.rs deleted file mode 100644 index 643fffeb..00000000 --- a/crates/gen-host-wasmtime-rust/src/lib.rs +++ /dev/null @@ -1,750 +0,0 @@ -use heck::*; -use std::collections::BTreeMap; -use std::fmt::Write as _; -use std::io::{Read, Write}; -use std::mem; -use std::process::{Command, Stdio}; -use wit_bindgen_core::{ - uwrite, uwriteln, wit_parser::*, Files, InterfaceGenerator as _, Source, TypeInfo, Types, - WorldGenerator, -}; -use wit_bindgen_gen_rust_lib::{to_rust_ident, FnSig, RustGenerator, TypeMode}; - -#[derive(Default)] -struct Wasmtime { - src: Source, - opts: Opts, - imports: Vec, - exports: Exports, -} - -#[derive(Default)] -struct Exports { - fields: BTreeMap, - funcs: Vec, -} - -#[derive(Default, Debug, Clone)] -#[cfg_attr(feature = "clap", derive(clap::Args))] -pub struct Opts { - /// Whether or not `rustfmt` is executed to format generated code. - #[cfg_attr(feature = "clap", arg(long))] - pub rustfmt: bool, - - /// Whether or not to emit `tracing` macro calls on function entry/exit. - #[cfg_attr(feature = "clap", arg(long))] - pub tracing: bool, - - /// Whether or not to use async rust functions and traits. - #[cfg_attr(feature = "clap", arg(long = "async"))] - pub async_: bool, -} - -impl Opts { - pub fn build(self) -> Box { - let mut r = Wasmtime::default(); - r.opts = self; - Box::new(r) - } -} - -impl WorldGenerator for Wasmtime { - fn import(&mut self, name: &str, iface: &Interface, _files: &mut Files) { - let mut gen = InterfaceGenerator::new(self, iface, TypeMode::Owned); - gen.types(); - gen.generate_from_error_impls(); - gen.generate_add_to_linker(name); - - let snake = to_rust_ident(name); - let module = &gen.src[..]; - - uwriteln!( - self.src, - " - #[allow(clippy::all)] - pub mod {snake} {{ - #[allow(unused_imports)] - use wit_bindgen_host_wasmtime_rust::{{wasmtime, anyhow}}; - - {module} - }} - " - ); - - self.imports.push(snake); // TODO - } - - fn export(&mut self, name: &str, iface: &Interface, _files: &mut Files) { - let mut gen = InterfaceGenerator::new(self, iface, TypeMode::AllBorrowed("'a")); - gen.types(); - gen.generate_from_error_impls(); - - let camel = name.to_upper_camel_case(); - uwriteln!(gen.src, "pub struct {camel} {{"); - for func in iface.functions.iter() { - uwriteln!( - gen.src, - "{}: wasmtime::component::Func,", - to_rust_ident(&func.name) - ); - } - uwriteln!(gen.src, "}}"); - - uwriteln!(gen.src, "impl {camel} {{"); - uwrite!( - gen.src, - " - pub fn new( - __exports: &mut wasmtime::component::ExportInstance<'_, '_>, - ) -> anyhow::Result<{camel}> {{ - " - ); - let fields = gen.extract_typed_functions(); - for (name, getter) in fields.iter() { - uwriteln!(gen.src, "let {name} = {getter};"); - } - uwriteln!(gen.src, "Ok({camel} {{"); - for (name, _) in fields.iter() { - uwriteln!(gen.src, "{name},"); - } - uwriteln!(gen.src, "}})"); - uwriteln!(gen.src, "}}"); - for func in iface.functions.iter() { - gen.define_rust_guest_export(Some(name), func); - } - uwriteln!(gen.src, "}}"); - - let snake = to_rust_ident(name); - let module = &gen.src[..]; - - uwriteln!( - self.src, - " - #[allow(clippy::all)] - pub mod {snake} {{ - #[allow(unused_imports)] - use wit_bindgen_host_wasmtime_rust::{{wasmtime, anyhow}}; - - {module} - }} - " - ); - - let getter = format!( - "\ - {snake}::{camel}::new( - &mut __exports.instance(\"{name}\") - .ok_or_else(|| anyhow::anyhow!(\"exported instance `{name}` not present\"))? - )?\ - " - ); - let prev = self - .exports - .fields - .insert(snake.clone(), (format!("{snake}::{camel}"), getter)); - assert!(prev.is_none()); - self.exports.funcs.push(format!( - " - pub fn {snake}(&self) -> &{snake}::{camel} {{ - &self.{snake} - }} - " - )); - } - - fn export_default(&mut self, _name: &str, iface: &Interface, _files: &mut Files) { - let mut gen = InterfaceGenerator::new(self, iface, TypeMode::AllBorrowed("'a")); - gen.types(); - let fields = gen.extract_typed_functions(); - for (name, getter) in fields { - let prev = gen - .gen - .exports - .fields - .insert(name, ("wasmtime::component::Func".to_string(), getter)); - assert!(prev.is_none()); - } - - for func in iface.functions.iter() { - let prev = mem::take(&mut gen.src); - gen.define_rust_guest_export(None, func); - let func = mem::replace(&mut gen.src, prev); - gen.gen.exports.funcs.push(func.to_string()); - } - - let src = gen.src; - self.src.push_str(&src); - } - - fn finish(&mut self, world: &World, files: &mut Files) { - let camel = world.name.to_upper_camel_case(); - uwriteln!(self.src, "pub struct {camel} {{"); - for (name, (ty, _)) in self.exports.fields.iter() { - uwriteln!(self.src, "{name}: {ty},"); - } - self.src.push_str("}\n"); - - let (async_, async__, send, await_) = if self.opts.async_ { - ("async", "_async", ":Send", ".await") - } else { - ("", "", "", "") - }; - - uwriteln!( - self.src, - " - impl {camel} {{ - /// Instantiates the provided `module` using the specified - /// parameters, wrapping up the result in a structure that - /// translates between wasm and the host. - pub {async_} fn instantiate{async__}( - mut store: impl wasmtime::AsContextMut, - component: &wasmtime::component::Component, - linker: &wasmtime::component::Linker, - ) -> anyhow::Result<(Self, wasmtime::component::Instance)> {{ - let instance = linker.instantiate{async__}(&mut store, component){await_}?; - Ok((Self::new(store, &instance)?, instance)) - }} - - /// Low-level creation wrapper for wrapping up the exports - /// of the `instance` provided in this structure of wasm - /// exports. - /// - /// This function will extract exports from the `instance` - /// defined within `store` and wrap them all up in the - /// returned structure which can be used to interact with - /// the wasm module. - pub fn new( - mut store: impl wasmtime::AsContextMut, - instance: &wasmtime::component::Instance, - ) -> anyhow::Result {{ - let mut store = store.as_context_mut(); - let mut exports = instance.exports(&mut store); - let mut __exports = exports.root(); - ", - ); - for (name, (_, get)) in self.exports.fields.iter() { - uwriteln!(self.src, "let {name} = {get};"); - } - uwriteln!(self.src, "Ok({camel} {{"); - for (name, _) in self.exports.fields.iter() { - uwriteln!(self.src, "{name},"); - } - uwriteln!(self.src, "}})"); - uwriteln!(self.src, "}}"); - - for func in self.exports.funcs.iter() { - self.src.push_str(func); - } - - uwriteln!(self.src, "}}"); - - let mut src = mem::take(&mut self.src); - if self.opts.rustfmt { - let mut child = Command::new("rustfmt") - .arg("--edition=2018") - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .spawn() - .expect("failed to spawn `rustfmt`"); - child - .stdin - .take() - .unwrap() - .write_all(src.as_bytes()) - .unwrap(); - src.as_mut_string().truncate(0); - child - .stdout - .take() - .unwrap() - .read_to_string(src.as_mut_string()) - .unwrap(); - let status = child.wait().unwrap(); - assert!(status.success()); - } - - files.push(&format!("{}.rs", world.name), src.as_bytes()); - } -} - -struct InterfaceGenerator<'a> { - src: Source, - gen: &'a mut Wasmtime, - iface: &'a Interface, - default_param_mode: TypeMode, - types: Types, -} - -impl<'a> InterfaceGenerator<'a> { - fn new( - gen: &'a mut Wasmtime, - iface: &'a Interface, - default_param_mode: TypeMode, - ) -> InterfaceGenerator<'a> { - let mut types = Types::default(); - types.analyze(iface); - InterfaceGenerator { - src: Source::default(), - gen, - iface, - types, - default_param_mode, - } - } - - fn print_result_ty(&mut self, results: &Results, mode: TypeMode) { - match results { - Results::Named(rs) => match rs.len() { - 0 => self.push_str("()"), - 1 => self.print_ty(&rs[0].1, mode), - _ => { - self.push_str("("); - for (i, (_, ty)) in rs.iter().enumerate() { - if i > 0 { - self.push_str(", ") - } - self.print_ty(ty, mode) - } - self.push_str(")"); - } - }, - Results::Anon(ty) => self.print_ty(ty, mode), - } - } - - fn special_case_host_error(&self, results: &Results) -> Option<&Result_> { - // We only support the wit_bindgen_host_wasmtime_rust::Error case when - // a function has just one result, which is itself a `result`, and the - // `e` is *not* a primitive (i.e. defined in std) type. - let mut i = results.iter_types(); - if i.len() == 1 { - match i.next().unwrap() { - Type::Id(id) => match &self.iface.types[*id].kind { - TypeDefKind::Result(r) => match r.err { - Some(Type::Id(_)) => Some(&r), - _ => None, - }, - _ => None, - }, - _ => None, - } - } else { - None - } - } - - fn generate_add_to_linker(&mut self, name: &str) { - let camel = name.to_upper_camel_case(); - - if self.gen.opts.async_ { - uwriteln!(self.src, "#[wit_bindgen_host_wasmtime_rust::async_trait]") - } - // Generate the `pub trait` which represents the host functionality for - // this import. - uwriteln!(self.src, "pub trait {camel}: Sized {{"); - for func in self.iface.functions.iter() { - let mut fnsig = FnSig::default(); - fnsig.async_ = self.gen.opts.async_; - fnsig.private = true; - fnsig.self_arg = Some("&mut self".to_string()); - - self.print_docs_and_params(func, TypeMode::Owned, &fnsig); - self.push_str(" -> "); - - if let Some(r) = self.special_case_host_error(&func.results).cloned() { - // Functions which have a single result `result` get special - // cased to use the host_wasmtime_rust::Error, making it possible - // for them to trap or use `?` to propogate their errors - self.push_str("wit_bindgen_host_wasmtime_rust::Result<"); - if let Some(ok) = r.ok { - self.print_ty(&ok, TypeMode::Owned); - } else { - self.push_str("()"); - } - self.push_str(","); - if let Some(err) = r.err { - self.print_ty(&err, TypeMode::Owned); - } else { - self.push_str("()"); - } - self.push_str(">"); - } else { - // All other functions get their return values wrapped in an anyhow::Result. - // Returning the anyhow::Error case can be used to trap. - self.push_str("anyhow::Result<"); - self.print_result_ty(&func.results, TypeMode::Owned); - self.push_str(">"); - } - - self.push_str(";\n"); - } - uwriteln!(self.src, "}}"); - - let where_clause = if self.gen.opts.async_ { - format!("T: Send, U: {camel} + Send") - } else { - format!("U: {camel}") - }; - uwriteln!( - self.src, - " - pub fn add_to_linker( - linker: &mut wasmtime::component::Linker, - get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static, - ) -> anyhow::Result<()> - where {where_clause}, - {{ - " - ); - uwriteln!(self.src, "let mut inst = linker.instance(\"{name}\")?;"); - for func in self.iface.functions.iter() { - uwrite!( - self.src, - "inst.{}(\"{}\", ", - if self.gen.opts.async_ { - "func_wrap_async" - } else { - "func_wrap" - }, - func.name - ); - self.generate_guest_import_closure(func); - uwriteln!(self.src, ")?;") - } - uwriteln!(self.src, "Ok(())"); - uwriteln!(self.src, "}}"); - } - - fn generate_guest_import_closure(&mut self, func: &Function) { - // Generate the closure that's passed to a `Linker`, the final piece of - // codegen here. - self.src - .push_str("move |mut caller: wasmtime::StoreContextMut<'_, T>, ("); - for (i, _param) in func.params.iter().enumerate() { - uwrite!(self.src, "arg{},", i); - } - self.src.push_str(") : ("); - for param in func.params.iter() { - // Lift is required to be impled for this type, so we can't use - // a borrowed type: - self.print_ty(¶m.1, TypeMode::Owned); - self.src.push_str(", "); - } - self.src.push_str(") |"); - if self.gen.opts.async_ { - self.src.push_str(" Box::new(async move { \n"); - } else { - self.src.push_str(" { \n"); - } - - if self.gen.opts.tracing { - self.src.push_str(&format!( - " - let span = wit_bindgen_host_wasmtime_rust::tracing::span!( - wit_bindgen_host_wasmtime_rust::tracing::Level::TRACE, - \"wit-bindgen guest import\", - module = \"{}\", - function = \"{}\", - ); - let _enter = span.enter(); - ", - self.iface.name, func.name, - )); - } - - self.src.push_str("let host = get(caller.data_mut());\n"); - - uwrite!(self.src, "let r = host.{}(", to_rust_ident(&func.name)); - for (i, _) in func.params.iter().enumerate() { - uwrite!(self.src, "arg{},", i); - } - if self.gen.opts.async_ { - uwrite!(self.src, ").await;\n"); - } else { - uwrite!(self.src, ");\n"); - } - - if self.special_case_host_error(&func.results).is_some() { - uwrite!( - self.src, - "match r {{ - Ok(a) => Ok((Ok(a),)), - Err(e) => match e.downcast() {{ - Ok(api_error) => Ok((Err(api_error),)), - Err(anyhow_error) => Err(anyhow_error), - }} - }}" - ); - } else if func.results.iter_types().len() == 1 { - uwrite!(self.src, "Ok((r?,))\n"); - } else { - uwrite!(self.src, "r\n"); - } - - if self.gen.opts.async_ { - // Need to close Box::new and async block - self.src.push_str("})"); - } else { - self.src.push_str("}"); - } - } - - fn extract_typed_functions(&mut self) -> Vec<(String, String)> { - let prev = mem::take(&mut self.src); - let mut ret = Vec::new(); - for func in self.iface.functions.iter() { - let snake = to_rust_ident(&func.name); - uwrite!(self.src, "*__exports.typed_func::<("); - for (_, ty) in func.params.iter() { - self.print_ty(ty, TypeMode::AllBorrowed("'_")); - self.push_str(", "); - } - self.src.push_str("), ("); - for ty in func.results.iter_types() { - self.print_ty(ty, TypeMode::Owned); - self.push_str(", "); - } - self.src.push_str(")>(\""); - self.src.push_str(&func.name); - self.src.push_str("\")?.func()"); - - ret.push((snake, mem::take(&mut self.src).to_string())); - } - self.src = prev; - return ret; - } - - fn define_rust_guest_export(&mut self, ns: Option<&str>, func: &Function) { - let (async_, async__, await_) = if self.gen.opts.async_ { - ("async", "_async", ".await") - } else { - ("", "", "") - }; - - self.rustdoc(&func.docs); - uwrite!( - self.src, - "pub {async_} fn {}(&self, mut store: S, ", - to_rust_ident(&func.name), - ); - for (i, param) in func.params.iter().enumerate() { - uwrite!(self.src, "arg{}: ", i); - self.print_ty(¶m.1, TypeMode::AllBorrowed("'_")); - self.push_str(","); - } - self.src.push_str(") -> anyhow::Result<"); - self.print_result_ty(&func.results, TypeMode::Owned); - - if self.gen.opts.async_ { - self.src - .push_str("> where ::Data: Send {\n"); - } else { - self.src.push_str("> {\n"); - } - - if self.gen.opts.tracing { - self.src.push_str(&format!( - " - let span = wit_bindgen_host_wasmtime_rust::tracing::span!( - wit_bindgen_host_wasmtime_rust::tracing::Level::TRACE, - \"wit-bindgen guest export\", - module = \"{}\", - function = \"{}\", - ); - let _enter = span.enter(); - ", - ns.unwrap_or("default"), - func.name, - )); - } - - self.src.push_str("let callee = unsafe {\n"); - self.src.push_str("wasmtime::component::TypedFunc::<("); - for (_, ty) in func.params.iter() { - self.print_ty(ty, TypeMode::AllBorrowed("'_")); - self.push_str(", "); - } - self.src.push_str("), ("); - for ty in func.results.iter_types() { - self.print_ty(ty, TypeMode::Owned); - self.push_str(", "); - } - uwriteln!( - self.src, - ")>::new_unchecked(self.{})", - to_rust_ident(&func.name) - ); - self.src.push_str("};\n"); - self.src.push_str("let ("); - for (i, _) in func.results.iter_types().enumerate() { - uwrite!(self.src, "ret{},", i); - } - uwrite!( - self.src, - ") = callee.call{async__}(store.as_context_mut(), (" - ); - for (i, _) in func.params.iter().enumerate() { - uwrite!(self.src, "arg{}, ", i); - } - uwriteln!(self.src, ")){await_}?;"); - - uwriteln!( - self.src, - "callee.post_return{async__}(store.as_context_mut()){await_}?;" - ); - - self.src.push_str("Ok("); - if func.results.iter_types().len() == 1 { - self.src.push_str("ret0"); - } else { - self.src.push_str("("); - for (i, _) in func.results.iter_types().enumerate() { - uwrite!(self.src, "ret{},", i); - } - self.src.push_str(")"); - } - self.src.push_str(")\n"); - - // End function body - self.src.push_str("}\n"); - } - - fn generate_from_error_impls(&mut self) { - for (id, ty) in self.iface.types.iter() { - if ty.name.is_none() { - continue; - } - let info = self.info(id); - if info.error { - for (name, mode) in self.modes_of(id) { - let name = name.to_upper_camel_case(); - if self.lifetime_for(&info, mode).is_some() { - continue; - } - self.push_str("impl From<"); - self.push_str(&name); - self.push_str("> for wit_bindgen_host_wasmtime_rust::Error<"); - self.push_str(&name); - self.push_str("> {\n"); - self.push_str("fn from(e: "); - self.push_str(&name); - self.push_str(") -> wit_bindgen_host_wasmtime_rust::Error::< "); - self.push_str(&name); - self.push_str("> {\n"); - self.push_str("wit_bindgen_host_wasmtime_rust::Error::new(e)\n"); - self.push_str("}\n"); - self.push_str("}\n"); - } - } - } - } -} - -impl<'a> RustGenerator<'a> for InterfaceGenerator<'a> { - fn iface(&self) -> &'a Interface { - self.iface - } - - fn default_param_mode(&self) -> TypeMode { - self.default_param_mode - } - - fn push_str(&mut self, s: &str) { - self.src.push_str(s); - } - - fn info(&self, ty: TypeId) -> TypeInfo { - self.types.get(ty) - } - - fn types_mut(&mut self) -> &mut Types { - &mut self.types - } - - fn print_borrowed_slice(&mut self, mutbl: bool, ty: &Type, lifetime: &'static str) { - self.print_rust_slice(mutbl, ty, lifetime); - } - - fn print_borrowed_str(&mut self, lifetime: &'static str) { - self.push_str("&"); - if lifetime != "'_" { - self.push_str(lifetime); - self.push_str(" "); - } - self.push_str(" str"); - } -} - -impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { - fn iface(&self) -> &'a Interface { - self.iface - } - - fn type_record(&mut self, id: TypeId, _name: &str, record: &Record, docs: &Docs) { - self.print_typedef_record(id, record, docs, true); - } - - fn type_tuple(&mut self, id: TypeId, _name: &str, tuple: &Tuple, docs: &Docs) { - self.print_typedef_tuple(id, tuple, docs); - } - - fn type_flags(&mut self, _id: TypeId, name: &str, flags: &Flags, docs: &Docs) { - self.rustdoc(docs); - self.src.push_str("wasmtime::component::flags!(\n"); - self.src - .push_str(&format!("{} {{\n", name.to_upper_camel_case())); - for flag in flags.flags.iter() { - // TODO wasmtime-component-macro doesnt support docs for flags rn - uwrite!( - self.src, - "#[component(name=\"{}\")] const {};\n", - flag.name, - flag.name.to_shouty_snake_case() - ); - } - self.src.push_str("}\n"); - self.src.push_str(");\n\n"); - } - - fn type_variant(&mut self, id: TypeId, _name: &str, variant: &Variant, docs: &Docs) { - self.print_typedef_variant(id, variant, docs, true); - } - - fn type_union(&mut self, id: TypeId, _name: &str, union: &Union, docs: &Docs) { - self.print_typedef_union(id, union, docs, true); - } - - fn type_option(&mut self, id: TypeId, _name: &str, payload: &Type, docs: &Docs) { - self.print_typedef_option(id, payload, docs); - } - - fn type_result(&mut self, id: TypeId, _name: &str, result: &Result_, docs: &Docs) { - self.print_typedef_result(id, result, docs); - } - - fn type_enum(&mut self, id: TypeId, name: &str, enum_: &Enum, docs: &Docs) { - self.print_typedef_enum(id, name, enum_, docs, - &["#[derive(wasmtime::component::ComponentType, wasmtime::component::Lift, wasmtime::component::Lower)]".to_owned(), - "#[component(enum)]".to_owned()], - Box::new(|case| format!("#[component(name = \"{}\")]", case.name)) - ); - } - - fn type_alias(&mut self, id: TypeId, _name: &str, ty: &Type, docs: &Docs) { - self.print_typedef_alias(id, ty, docs); - } - - fn type_list(&mut self, id: TypeId, _name: &str, ty: &Type, docs: &Docs) { - self.print_type_list(id, ty, docs); - } - - fn type_builtin(&mut self, _id: TypeId, name: &str, ty: &Type, docs: &Docs) { - self.rustdoc(docs); - self.src - .push_str(&format!("pub type {}", name.to_upper_camel_case())); - self.src.push_str(" = "); - self.print_ty(ty, TypeMode::Owned); - self.src.push_str(";\n"); - } -} diff --git a/crates/gen-host-wasmtime-rust/tests/codegen.rs b/crates/gen-host-wasmtime-rust/tests/codegen.rs deleted file mode 100644 index 2586e6c6..00000000 --- a/crates/gen-host-wasmtime-rust/tests/codegen.rs +++ /dev/null @@ -1,37 +0,0 @@ -#![allow(dead_code)] - -macro_rules! codegen_test { - ($name:ident $test:tt) => { - mod $name { - mod default { - wit_bindgen_host_wasmtime_rust::generate!($test); - - #[test] - fn works() {} - } - - mod async_ { - wit_bindgen_host_wasmtime_rust::generate!({ - path: $test, - async: true, - }); - - #[test] - fn works() {} - } - - mod tracing { - wit_bindgen_host_wasmtime_rust::generate!({ - path: $test, - tracing: true, - }); - - #[test] - fn works() {} - } - - } - }; -} - -test_helpers::codegen_tests!("*.wit"); diff --git a/crates/gen-host-wasmtime-rust/tests/runtime.rs b/crates/gen-host-wasmtime-rust/tests/runtime.rs deleted file mode 100644 index 1a8dc027..00000000 --- a/crates/gen-host-wasmtime-rust/tests/runtime.rs +++ /dev/null @@ -1,107 +0,0 @@ -use anyhow::Result; -use wasmtime::{ - component::{Component, Instance, Linker}, - Config, Engine, Store, -}; - -test_helpers::runtime_tests_wasmtime!(); - -fn default_config() -> Result { - // Create an engine with caching enabled to assist with iteration in this - // project. - let mut config = Config::new(); - config.cache_config_load_default()?; - config.wasm_backtrace_details(wasmtime::WasmBacktraceDetails::Enable); - config.wasm_component_model(true); - Ok(config) -} - -#[derive(Default)] -struct Context { - imports: I, - testwasi: TestWasi, -} - -fn instantiate( - wasm: &str, - add_imports: impl FnOnce(&mut Linker>) -> Result<()>, - mk_exports: impl FnOnce( - &mut Store>, - &Component, - &Linker>, - ) -> Result<(T, Instance)>, -) -> Result<(T, Store>)> { - let engine = Engine::new(&default_config()?)?; - let module = Component::from_file(&engine, wasm)?; - - let mut linker = Linker::new(&engine); - add_imports(&mut linker)?; - testwasi::add_to_linker(&mut linker, |cx| &mut cx.testwasi)?; - - let mut store = Store::new( - &engine, - Context { - imports: I::default(), - testwasi: TestWasi::default(), - }, - ); - let (exports, _instance) = mk_exports(&mut store, &module, &linker)?; - Ok((exports, store)) -} - -async fn instantiate_async( - wasm: &str, - add_imports: impl FnOnce(&mut Linker>) -> Result<()>, - mk_exports: F, -) -> Result<(T, Store>)> -where - F: for<'a> FnOnce( - &'a mut Store>, - &'a Component, - &'a Linker>, - ) -> std::pin::Pin< - Box> + 'a>, - >, -{ - let mut config = default_config()?; - config.async_support(true); - let engine = Engine::new(&config)?; - let module = Component::from_file(&engine, wasm)?; - - let mut linker = Linker::new(&engine); - add_imports(&mut linker)?; - testwasi::add_to_linker(&mut linker, |cx| &mut cx.testwasi)?; - - let mut store = Store::new( - &engine, - Context { - imports: I::default(), - testwasi: TestWasi::default(), - }, - ); - let (exports, _instance) = mk_exports(&mut store, &module, &linker).await?; - Ok((exports, store)) -} - -wit_bindgen_host_wasmtime_rust::generate!("../wasi_snapshot_preview1/testwasi.wit"); - -#[derive(Default)] -pub struct TestWasi; - -impl testwasi::Testwasi for TestWasi { - fn log(&mut self, bytes: Vec) -> Result<()> { - match std::str::from_utf8(&bytes) { - Ok(s) => print!("{}", s), - Err(_) => println!("\nbinary: {:?}", bytes), - } - Ok(()) - } - - fn log_err(&mut self, bytes: Vec) -> Result<()> { - match std::str::from_utf8(&bytes) { - Ok(s) => eprint!("{}", s), - Err(_) => eprintln!("\nbinary: {:?}", bytes), - } - Ok(()) - } -} diff --git a/crates/host-wasmtime-rust-macro/Cargo.toml b/crates/host-wasmtime-rust-macro/Cargo.toml deleted file mode 100644 index 1e85130b..00000000 --- a/crates/host-wasmtime-rust-macro/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "wit-bindgen-host-wasmtime-rust-macro" -authors = ["Alex Crichton "] -version.workspace = true -edition.workspace = true - -[lib] -proc-macro = true -doctest = false -test = false - -[dependencies] -proc-macro2 = "1.0" -syn = "1.0" -wit-bindgen-core = { workspace = true } -wit-bindgen-gen-host-wasmtime-rust = { workspace = true } -wit-component = { workspace = true } -wit-bindgen-rust-macro-shared = { workspace = true } - -[features] -tracing = [] diff --git a/crates/host-wasmtime-rust-macro/src/lib.rs b/crates/host-wasmtime-rust-macro/src/lib.rs deleted file mode 100644 index a4762520..00000000 --- a/crates/host-wasmtime-rust-macro/src/lib.rs +++ /dev/null @@ -1,45 +0,0 @@ -use proc_macro::TokenStream; -use syn::parse::{Parse, ParseStream, Result}; -use syn::Token; -use wit_bindgen_gen_host_wasmtime_rust::Opts; - -#[proc_macro] -pub fn generate(input: TokenStream) -> TokenStream { - wit_bindgen_rust_macro_shared::generate::(input, |opts| opts.build()) -} - -mod kw { - syn::custom_keyword!(tracing); -} - -enum Opt { - Tracing(bool), - Async(bool), -} - -impl Parse for Opt { - fn parse(input: ParseStream<'_>) -> Result { - let l = input.lookahead1(); - - if l.peek(kw::tracing) { - input.parse::()?; - input.parse::()?; - Ok(Opt::Tracing(input.parse::()?.value)) - } else if l.peek(Token![async]) { - input.parse::()?; - input.parse::()?; - Ok(Opt::Async(input.parse::()?.value)) - } else { - Err(l.error()) - } - } -} - -impl wit_bindgen_rust_macro_shared::Configure for Opt { - fn configure(self, opts: &mut Opts) { - match self { - Opt::Tracing(val) => opts.tracing = val, - Opt::Async(val) => opts.async_ = val, - } - } -} diff --git a/crates/host-wasmtime-rust/Cargo.toml b/crates/host-wasmtime-rust/Cargo.toml deleted file mode 100644 index 4ccb94b2..00000000 --- a/crates/host-wasmtime-rust/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "wit-bindgen-host-wasmtime-rust" -authors = ["Alex Crichton "] -version.workspace = true -edition.workspace = true - -[dependencies] -anyhow = { workspace = true } -bitflags = { workspace = true } -wasmtime = { workspace = true } -wit-bindgen-host-wasmtime-rust-macro = { path = "../host-wasmtime-rust-macro", version = "0.3.0" } -tracing-lib = { version = "0.1.26", optional = true, package = 'tracing' } -async-trait = "0.1.57" - -[features] -# Enables generated code to emit events via the `tracing` crate whenever wasm is -# entered and when native functions are called. Note that tracing is currently -# only done for imported functions. -tracing = ['tracing-lib', 'wit-bindgen-host-wasmtime-rust-macro/tracing'] diff --git a/crates/host-wasmtime-rust/src/lib.rs b/crates/host-wasmtime-rust/src/lib.rs deleted file mode 100644 index 4ca85473..00000000 --- a/crates/host-wasmtime-rust/src/lib.rs +++ /dev/null @@ -1,89 +0,0 @@ -pub use wit_bindgen_host_wasmtime_rust_macro::*; - -#[cfg(feature = "tracing-lib")] -pub use tracing_lib as tracing; -#[doc(hidden)] -pub use {anyhow, async_trait::async_trait, wasmtime}; - -pub type Result = std::result::Result>; - -pub struct Error { - err: anyhow::Error, - ty: std::marker::PhantomData, -} - -impl Error { - pub fn new(err: T) -> Error { - Error { - err: err.into(), - ty: std::marker::PhantomData, - } - } - - pub fn downcast(self) -> std::result::Result { - self.err.downcast::() - } - - pub fn downcast_ref(&self) -> Option<&T> { - self.err.downcast_ref::() - } - - pub fn downcast_mut(&mut self) -> Option<&mut T> { - self.err.downcast_mut::() - } -} - -impl Error { - pub fn trap(err: impl std::error::Error + Send + Sync + 'static) -> Error { - Error { - err: anyhow::Error::from(err), - ty: std::marker::PhantomData, - } - } - - pub fn into_inner(self) -> anyhow::Error { - self.err - } - - pub fn context(self, context: C) -> Error - where - C: std::fmt::Display + Send + Sync + 'static, - { - self.err.context(context).into() - } -} - -impl std::ops::Deref for Error { - type Target = dyn std::error::Error + Send + Sync + 'static; - fn deref(&self) -> &Self::Target { - self.err.deref() - } -} -impl std::ops::DerefMut for Error { - fn deref_mut(&mut self) -> &mut Self::Target { - self.err.deref_mut() - } -} - -impl std::fmt::Display for Error { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - self.err.fmt(f) - } -} - -impl std::fmt::Debug for Error { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - self.err.fmt(f) - } -} - -impl std::error::Error for Error {} - -impl From for Error { - fn from(err: anyhow::Error) -> Error { - Error { - err, - ty: std::marker::PhantomData, - } - } -} diff --git a/crates/test-helpers/macros/src/lib.rs b/crates/test-helpers/macros/src/lib.rs index 4b3807df..66c46abc 100644 --- a/crates/test-helpers/macros/src/lib.rs +++ b/crates/test-helpers/macros/src/lib.rs @@ -86,50 +86,3 @@ pub fn runtime_component_tests(input: TokenStream) -> TokenStream { (quote::quote!(#(#tests)*)).into() } - -#[proc_macro] -pub fn runtime_tests_wasmtime(_input: TokenStream) -> TokenStream { - let mut tests = Vec::new(); - let cwd = std::env::current_dir().unwrap(); - for entry in std::fs::read_dir(cwd.join("tests/runtime")).unwrap() { - let entry = entry.unwrap().path(); - if !entry.join("host.rs").exists() { - continue; - } - let name_str = entry.file_name().unwrap().to_str().unwrap(); - for (lang, name, _wasm, component) in WASMS { - if *name != name_str { - continue; - } - let name = quote::format_ident!("{}_{}", name_str, lang); - let host_file = entry.join("host.rs").to_str().unwrap().to_string(); - tests.push(quote::quote! { - mod #name { - include!(#host_file); - - #[test_log::test] - fn test() -> anyhow::Result<()> { - run(#component) - } - } - }); - - if entry.join("host.async.rs").exists() { - let host_file = entry.join("host.async.rs").to_str().unwrap().to_string(); - let name = quote::format_ident!("{}_async", name); - tests.push(quote::quote! { - mod #name { - include!(#host_file); - - #[test_log::test(tokio::test)] - async fn test() -> anyhow::Result<()> { - run_async(#component).await - } - } - }); - } - } - } - - (quote::quote!(#(#tests)*)).into() -} diff --git a/src/bin/wit-bindgen.rs b/src/bin/wit-bindgen.rs index 648d711e..696c1800 100644 --- a/src/bin/wit-bindgen.rs +++ b/src/bin/wit-bindgen.rs @@ -39,15 +39,6 @@ enum Category { #[derive(Debug, Parser)] enum HostGenerator { - /// Generates bindings for Rust hosts using the Wasmtime engine. - WasmtimeRust { - #[clap(flatten)] - opts: wit_bindgen_gen_host_wasmtime_rust::Opts, - #[clap(flatten)] - common: Common, - #[clap(flatten)] - world: WorldOpt, - }, /// Generates bindings for JavaScript hosts. Js { #[clap(flatten)] @@ -138,7 +129,6 @@ impl Opt { Category::Guest(GuestGenerator::Rust { common, .. }) | Category::Guest(GuestGenerator::C { common, .. }) | Category::Guest(GuestGenerator::TeavmJava { common, .. }) - | Category::Host(HostGenerator::WasmtimeRust { common, .. }) | Category::Markdown { common, .. } => common, Category::Host(HostGenerator::Js { component, .. }) => &component.common, } @@ -151,9 +141,6 @@ fn main() -> Result<()> { let mut files = Files::default(); match opt.category { - Category::Host(HostGenerator::WasmtimeRust { opts, world, .. }) => { - gen_world(opts.build(), world, &mut files)?; - } Category::Host(HostGenerator::Js { opts, component }) => { gen_component(opts.build()?, component, &mut files)?; } diff --git a/tests/runtime/flavorful/host.rs b/tests/runtime/flavorful/host.rs deleted file mode 100644 index fab7c7f9..00000000 --- a/tests/runtime/flavorful/host.rs +++ /dev/null @@ -1,163 +0,0 @@ -use anyhow::Result; -use wit_bindgen_host_wasmtime_rust::Result as HostResult; - -wit_bindgen_host_wasmtime_rust::generate!("../../tests/runtime/flavorful/world.wit"); - -#[derive(Default)] -pub struct MyImports { - errored: bool -} - -impl imports::Imports for MyImports { - fn f_list_in_record1(&mut self, ty: imports::ListInRecord1) -> Result<()> { - assert_eq!(ty.a, "list_in_record1"); - Ok(()) - } - - fn f_list_in_record2(&mut self) -> Result { - Ok(imports::ListInRecord2 { - a: "list_in_record2".to_string(), - }) - } - - fn f_list_in_record3(&mut self, a: imports::ListInRecord3) -> Result { - assert_eq!(a.a, "list_in_record3 input"); - Ok(imports::ListInRecord3 { - a: "list_in_record3 output".to_string(), - }) - } - - fn f_list_in_record4(&mut self, a: imports::ListInAlias) -> Result { - assert_eq!(a.a, "input4"); - Ok(imports::ListInRecord4 { - a: "result4".to_string(), - }) - } - - fn f_list_in_variant1( - &mut self, - a: imports::ListInVariant1V1, - b: imports::ListInVariant1V2, - c: imports::ListInVariant1V3, - ) -> Result<()> { - assert_eq!(a.unwrap(), "foo"); - assert_eq!(b.unwrap_err(), "bar"); - match c { - imports::ListInVariant1V3::String(s) => assert_eq!(s, "baz"), - imports::ListInVariant1V3::F32(_) => panic!(), - } - Ok(()) - } - - fn f_list_in_variant2(&mut self) -> Result> { - Ok(Some("list_in_variant2".to_string())) - } - - fn f_list_in_variant3(&mut self, a: imports::ListInVariant3) -> Result> { - assert_eq!(a.unwrap(), "input3"); - Ok(Some("output3".to_string())) - } - - fn errno_result(&mut self) -> HostResult<(), imports::MyErrno> { - if self.errored { - return Ok(()); - } - imports::MyErrno::A.to_string(); - format!("{:?}", imports::MyErrno::A); - fn assert_error() {} - assert_error::(); - self.errored = true; - Err(imports::MyErrno::B)? - } - - fn list_typedefs( - &mut self, - a: imports::ListTypedef, - b: imports::ListTypedef3, - ) -> Result<(imports::ListTypedef2, imports::ListTypedef3)> { - assert_eq!(a, "typedef1"); - assert_eq!(b.len(), 1); - assert_eq!(b[0], "typedef2"); - Ok((b"typedef3".to_vec(), vec!["typedef4".to_string()])) - } - - fn list_of_variants( - &mut self, - bools: Vec, - results: Vec>, - enums: Vec, - ) -> Result<(Vec, Vec>, Vec)> { - assert_eq!(bools, [true, false]); - assert_eq!(results, [Ok(()), Err(())]); - assert_eq!(enums, [imports::MyErrno::Success, imports::MyErrno::A]); - Ok(( - vec![false, true], - vec![Err(()), Ok(())], - vec![imports::MyErrno::A, imports::MyErrno::B], - )) - } -} - -fn run(wasm: &str) -> Result<()> { - let (exports, mut store) = crate::instantiate( - wasm, - |linker| imports::add_to_linker(linker, |cx| -> &mut MyImports { &mut cx.imports }), - |store, module, linker| Flavorful::instantiate(store, module, linker), - )?; - - exports.test_imports(&mut store)?; - - exports.f_list_in_record1( - &mut store, - ListInRecord1 { - a: "list_in_record1", - }, - )?; - assert_eq!(exports.f_list_in_record2(&mut store)?.a, "list_in_record2"); - - assert_eq!( - exports - .f_list_in_record3( - &mut store, - ListInRecord3Param { - a: "list_in_record3 input" - } - )? - .a, - "list_in_record3 output" - ); - - assert_eq!( - exports - .f_list_in_record4(&mut store, ListInAliasParam { a: "input4" })? - .a, - "result4" - ); - - exports.f_list_in_variant1( - &mut store, - Some("foo"), - Err("bar"), - ListInVariant1V3::String("baz"), - )?; - assert_eq!( - exports.f_list_in_variant2(&mut store)?, - Some("list_in_variant2".to_string()) - ); - assert_eq!( - exports.f_list_in_variant3(&mut store, Some("input3"))?, - Some("output3".to_string()) - ); - - assert!(exports.errno_result(&mut store)?.is_err()); - MyErrno::A.to_string(); - format!("{:?}", MyErrno::A); - fn assert_error() {} - assert_error::(); - - let (a, b) = exports.list_typedefs(&mut store, "typedef1", &["typedef2"])?; - assert_eq!(a, b"typedef3"); - assert_eq!(b.len(), 1); - assert_eq!(b[0], "typedef4"); - Ok(()) -} diff --git a/tests/runtime/invalid/host.rs b/tests/runtime/invalid/host.rs deleted file mode 100644 index 9942f7a7..00000000 --- a/tests/runtime/invalid/host.rs +++ /dev/null @@ -1,123 +0,0 @@ -wit_bindgen_host_wasmtime_rust::generate!("../../tests/runtime/invalid/world.wit"); - -use anyhow::{Context, Result}; -use imports::*; -use wasmtime::component::{Component, Linker}; -use wasmtime::{Engine, Store}; - -#[derive(Default)] -pub struct MyImports; - -impl Imports for MyImports { - // The following types are truncated when out-of-bounds - fn roundtrip_u8(&mut self, v: u8) -> Result { - Ok(v) - } - fn roundtrip_s8(&mut self, v: i8) -> Result { - Ok(v) - } - fn roundtrip_u16(&mut self, v: u16) -> Result { - Ok(v) - } - fn roundtrip_s16(&mut self, v: i16) -> Result { - Ok(v) - } - fn roundtrip_bool(&mut self, v: bool) -> Result { - Ok(v) - } - - // None of this should be reached and instead validation should prevent them - // from being called - fn roundtrip_char(&mut self, _: char) -> Result { - unreachable!() - } - fn roundtrip_enum(&mut self, _: imports::E) -> Result { - unreachable!() - } - fn unaligned1(&mut self, _: Vec) -> Result<()> { - unreachable!() - } - fn unaligned2(&mut self, _: Vec) -> Result<()> { - unreachable!() - } - fn unaligned3(&mut self, _: Vec) -> Result<()> { - unreachable!() - } - fn unaligned4(&mut self, _: Vec) -> Result<()> { - unreachable!() - } - fn unaligned5(&mut self, _: Vec) -> Result<()> { - unreachable!() - } - fn unaligned6(&mut self, _: Vec) -> Result<()> { - unreachable!() - } - fn unaligned7(&mut self, _: Vec) -> Result<()> { - unreachable!() - } - fn unaligned8(&mut self, _: Vec) -> Result<()> { - unreachable!() - } - fn unaligned9(&mut self, _: Vec) -> Result<()> { - unreachable!() - } - fn unaligned10(&mut self, _: Vec>) -> Result<()> { - unreachable!() - } -} - -fn run(wasm: &str) -> Result<()> { - let engine = Engine::new(&crate::default_config()?)?; - let module = Component::from_file(&engine, wasm)?; - - let mut linker = Linker::new(&engine); - imports::add_to_linker(&mut linker, |cx: &mut crate::Context| { - &mut cx.imports - })?; - crate::testwasi::add_to_linker(&mut linker, |cx| &mut cx.testwasi)?; - - let mut store = Store::new(&engine, Default::default()); - - let exports = Invalid::instantiate(&mut store, &module, &linker)?.0; - exports.invalid_bool(&mut store)?; - exports.invalid_u8(&mut store)?; - exports.invalid_s8(&mut store)?; - exports.invalid_u16(&mut store)?; - exports.invalid_s16(&mut store)?; - - let mk = |store: &mut Store<_>| Invalid::instantiate(store, &module, &linker).map(|p| p.0); - - assert_err( - mk(&mut store)?.invalid_char(&mut store), - "converted integer out of range for `char`", - )?; - assert_err( - mk(&mut store)?.invalid_enum(&mut store), - "unexpected discriminant: ", - )?; - assert_err(mk(&mut store)?.unaligned1(&mut store), "not aligned")?; - assert_err(mk(&mut store)?.unaligned2(&mut store), "not aligned")?; - assert_err(mk(&mut store)?.unaligned3(&mut store), "not aligned")?; - assert_err(mk(&mut store)?.unaligned4(&mut store), "not aligned")?; - assert_err(mk(&mut store)?.unaligned5(&mut store), "not aligned")?; - assert_err(mk(&mut store)?.unaligned6(&mut store), "not aligned")?; - assert_err(mk(&mut store)?.unaligned7(&mut store), "not aligned")?; - assert_err(mk(&mut store)?.unaligned8(&mut store), "not aligned")?; - assert_err(mk(&mut store)?.unaligned9(&mut store), "not aligned")?; - assert_err(mk(&mut store)?.unaligned10(&mut store), "not aligned")?; - - return Ok(()); - - fn assert_err(result: Result<()>, err: &str) -> Result<()> { - match result { - Ok(()) => anyhow::bail!("export didn't trap"), - Err(e) => { - if format!("{e:?}").contains(err) { - Ok(()) - } else { - Err(e).with_context(|| format!("expected trap containing \"{}\"", err)) - } - } - } - } -} diff --git a/tests/runtime/lists/host.rs b/tests/runtime/lists/host.rs deleted file mode 100644 index f4cf9801..00000000 --- a/tests/runtime/lists/host.rs +++ /dev/null @@ -1,136 +0,0 @@ -use anyhow::Result; - -wit_bindgen_host_wasmtime_rust::generate!("../../tests/runtime/lists/world.wit"); - -use imports::*; - -#[derive(Default)] -pub struct MyImports; - -impl Imports for MyImports { - fn empty_list_param(&mut self, a: Vec) -> Result<()> { - assert_eq!(a, []); - Ok(()) - } - - fn empty_string_param(&mut self, a: String) -> Result<()> { - assert_eq!(a, ""); - Ok(()) - } - - fn empty_list_result(&mut self) -> Result> { - Ok(Vec::new()) - } - - fn empty_string_result(&mut self) -> Result { - Ok(String::new()) - } - - fn list_param(&mut self, list: Vec) -> Result<()> { - assert_eq!(list, [1, 2, 3, 4]); - Ok(()) - } - - fn list_param2(&mut self, ptr: String) -> Result<()> { - assert_eq!(ptr, "foo"); - Ok(()) - } - - fn list_param3(&mut self, ptr: Vec) -> Result<()> { - assert_eq!(ptr.len(), 3); - assert_eq!(ptr[0], "foo"); - assert_eq!(ptr[1], "bar"); - assert_eq!(ptr[2], "baz"); - Ok(()) - } - - fn list_param4(&mut self, ptr: Vec>) -> Result<()> { - assert_eq!(ptr.len(), 2); - assert_eq!(ptr[0][0], "foo"); - assert_eq!(ptr[0][1], "bar"); - assert_eq!(ptr[1][0], "baz"); - Ok(()) - } - - fn list_result(&mut self) -> Result> { - Ok(vec![1, 2, 3, 4, 5]) - } - - fn list_result2(&mut self) -> Result { - Ok("hello!".to_string()) - } - - fn list_result3(&mut self) -> Result> { - Ok(vec!["hello,".to_string(), "world!".to_string()]) - } - - fn list_roundtrip(&mut self, list: Vec) -> Result> { - Ok(list.to_vec()) - } - - fn string_roundtrip(&mut self, s: String) -> Result { - Ok(s.to_string()) - } - - fn list_minmax8(&mut self, u: Vec, s: Vec) -> Result<(Vec, Vec)> { - assert_eq!(u, [u8::MIN, u8::MAX]); - assert_eq!(s, [i8::MIN, i8::MAX]); - Ok((u, s)) - } - - fn list_minmax16(&mut self, u: Vec, s: Vec) -> Result<(Vec, Vec)> { - assert_eq!(u, [u16::MIN, u16::MAX]); - assert_eq!(s, [i16::MIN, i16::MAX]); - Ok((u, s)) - } - - fn list_minmax32(&mut self, u: Vec, s: Vec) -> Result<(Vec, Vec)> { - assert_eq!(u, [u32::MIN, u32::MAX]); - assert_eq!(s, [i32::MIN, i32::MAX]); - Ok((u, s)) - } - - fn list_minmax64(&mut self, u: Vec, s: Vec) -> Result<(Vec, Vec)> { - assert_eq!(u, [u64::MIN, u64::MAX]); - assert_eq!(s, [i64::MIN, i64::MAX]); - Ok((u, s)) - } - - fn list_minmax_float(&mut self, u: Vec, s: Vec) -> Result<(Vec, Vec)> { - assert_eq!(u, [f32::MIN, f32::MAX, f32::NEG_INFINITY, f32::INFINITY]); - assert_eq!(s, [f64::MIN, f64::MAX, f64::NEG_INFINITY, f64::INFINITY]); - Ok((u, s)) - } -} - -fn run(wasm: &str) -> Result<()> { - let (exports, mut store) = crate::instantiate( - wasm, - |linker| imports::add_to_linker(linker, |cx| -> &mut MyImports { &mut cx.imports }), - |store, module, linker| Lists::instantiate(store, module, linker), - )?; - - let bytes = exports.allocated_bytes(&mut store)?; - exports.test_imports(&mut store)?; - exports.empty_list_param(&mut store, &[])?; - exports.empty_string_param(&mut store, "")?; - assert_eq!(exports.empty_list_result(&mut store)?, []); - assert_eq!(exports.empty_string_result(&mut store)?, ""); - exports.list_param(&mut store, &[1, 2, 3, 4])?; - exports.list_param2(&mut store, "foo")?; - exports.list_param3(&mut store, &["foo", "bar", "baz"])?; - exports.list_param4(&mut store, &[&["foo", "bar"], &["baz"]])?; - assert_eq!(exports.list_result(&mut store)?, [1, 2, 3, 4, 5]); - assert_eq!(exports.list_result2(&mut store)?, "hello!"); - assert_eq!(exports.list_result3(&mut store)?, ["hello,", "world!"]); - assert_eq!(exports.string_roundtrip(&mut store, "x")?, "x"); - assert_eq!(exports.string_roundtrip(&mut store, "")?, ""); - assert_eq!( - exports.string_roundtrip(&mut store, "hello ⚑ world")?, - "hello ⚑ world" - ); - // Ensure that we properly called `free` everywhere in all the glue that we - // needed to. - assert_eq!(bytes, exports.allocated_bytes(&mut store)?); - Ok(()) -} diff --git a/tests/runtime/many_arguments/host.rs b/tests/runtime/many_arguments/host.rs deleted file mode 100644 index 4f1b3be4..00000000 --- a/tests/runtime/many_arguments/host.rs +++ /dev/null @@ -1,60 +0,0 @@ -use anyhow::Result; - -wit_bindgen_host_wasmtime_rust::generate!("../../tests/runtime/many_arguments/world.wit"); - -#[derive(Default)] -pub struct MyImports {} - -impl imports::Imports for MyImports { - fn many_arguments( - &mut self, - a1: u64, - a2: u64, - a3: u64, - a4: u64, - a5: u64, - a6: u64, - a7: u64, - a8: u64, - a9: u64, - a10: u64, - a11: u64, - a12: u64, - a13: u64, - a14: u64, - a15: u64, - a16: u64, - ) -> Result<()> { - assert_eq!(a1, 1); - assert_eq!(a2, 2); - assert_eq!(a3, 3); - assert_eq!(a4, 4); - assert_eq!(a5, 5); - assert_eq!(a6, 6); - assert_eq!(a7, 7); - assert_eq!(a8, 8); - assert_eq!(a9, 9); - assert_eq!(a10, 10); - assert_eq!(a11, 11); - assert_eq!(a12, 12); - assert_eq!(a13, 13); - assert_eq!(a14, 14); - assert_eq!(a15, 15); - assert_eq!(a16, 16); - Ok(()) - } -} - -fn run(wasm: &str) -> Result<()> { - let (exports, mut store) = crate::instantiate( - wasm, - |linker| imports::add_to_linker(linker, |cx| -> &mut MyImports { &mut cx.imports }), - |store, module, linker| ManyArguments::instantiate(store, module, linker), - )?; - - exports.many_arguments( - &mut store, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - )?; - - Ok(()) -} diff --git a/tests/runtime/numbers/host.rs b/tests/runtime/numbers/host.rs deleted file mode 100644 index b911b888..00000000 --- a/tests/runtime/numbers/host.rs +++ /dev/null @@ -1,185 +0,0 @@ -use anyhow::Result; - -wit_bindgen_host_wasmtime_rust::generate!("../../tests/runtime/numbers/world.wit"); - -#[derive(Default)] -pub struct MyImports { - scalar: u32, -} - -impl imports::Imports for MyImports { - fn roundtrip_u8(&mut self, val: u8) -> Result { - Ok(val) - } - - fn roundtrip_s8(&mut self, val: i8) -> Result { - Ok(val) - } - - fn roundtrip_u16(&mut self, val: u16) -> Result { - Ok(val) - } - - fn roundtrip_s16(&mut self, val: i16) -> Result { - Ok(val) - } - - fn roundtrip_u32(&mut self, val: u32) -> Result { - Ok(val) - } - - fn roundtrip_s32(&mut self, val: i32) -> Result { - Ok(val) - } - - fn roundtrip_u64(&mut self, val: u64) -> Result { - Ok(val) - } - - fn roundtrip_s64(&mut self, val: i64) -> Result { - Ok(val) - } - - fn roundtrip_float32(&mut self, val: f32) -> Result { - Ok(val) - } - - fn roundtrip_float64(&mut self, val: f64) -> Result { - Ok(val) - } - - fn roundtrip_char(&mut self, val: char) -> Result { - Ok(val) - } - - fn set_scalar(&mut self, val: u32) -> Result<()> { - self.scalar = val; - Ok(()) - } - - fn get_scalar(&mut self) -> Result { - Ok(self.scalar) - } -} - -fn run(wasm: &str) -> Result<()> { - let (exports, mut store) = crate::instantiate( - wasm, - |linker| imports::add_to_linker(linker, |cx| -> &mut MyImports { &mut cx.imports }), - |store, module, linker| Numbers::instantiate(store, module, linker), - )?; - - exports.test_imports(&mut store)?; - assert_eq!(exports.roundtrip_u8(&mut store, 1)?, 1); - assert_eq!( - exports.roundtrip_u8(&mut store, u8::min_value())?, - u8::min_value() - ); - assert_eq!( - exports.roundtrip_u8(&mut store, u8::max_value())?, - u8::max_value() - ); - - assert_eq!(exports.roundtrip_s8(&mut store, 1)?, 1); - assert_eq!( - exports.roundtrip_s8(&mut store, i8::min_value())?, - i8::min_value() - ); - assert_eq!( - exports.roundtrip_s8(&mut store, i8::max_value())?, - i8::max_value() - ); - - assert_eq!(exports.roundtrip_u16(&mut store, 1)?, 1); - assert_eq!( - exports.roundtrip_u16(&mut store, u16::min_value())?, - u16::min_value() - ); - assert_eq!( - exports.roundtrip_u16(&mut store, u16::max_value())?, - u16::max_value() - ); - - assert_eq!(exports.roundtrip_s16(&mut store, 1)?, 1); - assert_eq!( - exports.roundtrip_s16(&mut store, i16::min_value())?, - i16::min_value() - ); - assert_eq!( - exports.roundtrip_s16(&mut store, i16::max_value())?, - i16::max_value() - ); - - assert_eq!(exports.roundtrip_u32(&mut store, 1)?, 1); - assert_eq!( - exports.roundtrip_u32(&mut store, u32::min_value())?, - u32::min_value() - ); - assert_eq!( - exports.roundtrip_u32(&mut store, u32::max_value())?, - u32::max_value() - ); - - assert_eq!(exports.roundtrip_s32(&mut store, 1)?, 1); - assert_eq!( - exports.roundtrip_s32(&mut store, i32::min_value())?, - i32::min_value() - ); - assert_eq!( - exports.roundtrip_s32(&mut store, i32::max_value())?, - i32::max_value() - ); - - assert_eq!(exports.roundtrip_u64(&mut store, 1)?, 1); - assert_eq!( - exports.roundtrip_u64(&mut store, u64::min_value())?, - u64::min_value() - ); - assert_eq!( - exports.roundtrip_u64(&mut store, u64::max_value())?, - u64::max_value() - ); - - assert_eq!(exports.roundtrip_s64(&mut store, 1)?, 1); - assert_eq!( - exports.roundtrip_s64(&mut store, i64::min_value())?, - i64::min_value() - ); - assert_eq!( - exports.roundtrip_s64(&mut store, i64::max_value())?, - i64::max_value() - ); - - assert_eq!(exports.roundtrip_float32(&mut store, 1.0)?, 1.0); - assert_eq!( - exports.roundtrip_float32(&mut store, f32::INFINITY)?, - f32::INFINITY - ); - assert_eq!( - exports.roundtrip_float32(&mut store, f32::NEG_INFINITY)?, - f32::NEG_INFINITY - ); - assert!(exports.roundtrip_float32(&mut store, f32::NAN)?.is_nan()); - - assert_eq!(exports.roundtrip_float64(&mut store, 1.0)?, 1.0); - assert_eq!( - exports.roundtrip_float64(&mut store, f64::INFINITY)?, - f64::INFINITY - ); - assert_eq!( - exports.roundtrip_float64(&mut store, f64::NEG_INFINITY)?, - f64::NEG_INFINITY - ); - assert!(exports.roundtrip_float64(&mut store, f64::NAN)?.is_nan()); - - assert_eq!(exports.roundtrip_char(&mut store, 'a')?, 'a'); - assert_eq!(exports.roundtrip_char(&mut store, ' ')?, ' '); - assert_eq!(exports.roundtrip_char(&mut store, '🚩')?, '🚩'); - - exports.set_scalar(&mut store, 2)?; - assert_eq!(exports.get_scalar(&mut store)?, 2); - exports.set_scalar(&mut store, 4)?; - assert_eq!(exports.get_scalar(&mut store)?, 4); - - Ok(()) -} diff --git a/tests/runtime/records/host.rs b/tests/runtime/records/host.rs deleted file mode 100644 index 35d42dc9..00000000 --- a/tests/runtime/records/host.rs +++ /dev/null @@ -1,111 +0,0 @@ -wit_bindgen_host_wasmtime_rust::generate!("../../tests/runtime/records/world.wit"); - -use anyhow::Result; - -#[derive(Default)] -pub struct MyImports; - -impl imports::Imports for MyImports { - fn multiple_results(&mut self) -> Result<(u8, u16)> { - Ok((4, 5)) - } - - fn swap_tuple(&mut self, a: (u8, u32)) -> Result<(u32, u8)> { - Ok((a.1, a.0)) - } - - fn roundtrip_flags1(&mut self, a: imports::F1) -> Result { - drop(format!("{:?}", a)); - drop(a & imports::F1::all()); - Ok(a) - } - - fn roundtrip_flags2(&mut self, a: imports::F2) -> Result { - Ok(a) - } - - fn roundtrip_flags3( - &mut self, - a: imports::Flag8, - b: imports::Flag16, - c: imports::Flag32, - d: imports::Flag64, - ) -> Result<( - imports::Flag8, - imports::Flag16, - imports::Flag32, - imports::Flag64, - )> { - Ok((a, b, c, d)) - } - - fn roundtrip_record1(&mut self, a: imports::R1) -> Result { - drop(format!("{:?}", a)); - Ok(a) - } - - fn tuple0(&mut self, _: ()) -> Result<()> { - Ok(()) - } - - fn tuple1(&mut self, a: (u8,)) -> Result<(u8,)> { - Ok((a.0,)) - } -} - -fn run(wasm: &str) -> Result<()> { - let (exports, mut store) = crate::instantiate( - wasm, - |linker| imports::add_to_linker(linker, |cx| -> &mut MyImports { &mut cx.imports }), - |store, module, linker| Records::instantiate(store, module, linker), - )?; - - exports.test_imports(&mut store)?; - assert_eq!(exports.multiple_results(&mut store,)?, (100, 200)); - assert_eq!(exports.swap_tuple(&mut store, (1u8, 2u32))?, (2u32, 1u8)); - assert_eq!(exports.roundtrip_flags1(&mut store, F1::A)?, F1::A); - assert_eq!( - exports.roundtrip_flags1(&mut store, F1::empty())?, - F1::empty() - ); - assert_eq!(exports.roundtrip_flags1(&mut store, F1::B)?, F1::B); - assert_eq!( - exports.roundtrip_flags1(&mut store, F1::A | F1::B)?, - F1::A | F1::B - ); - - assert_eq!(exports.roundtrip_flags2(&mut store, F2::C)?, F2::C); - assert_eq!( - exports.roundtrip_flags2(&mut store, F2::empty())?, - F2::empty() - ); - assert_eq!(exports.roundtrip_flags2(&mut store, F2::D)?, F2::D); - assert_eq!( - exports.roundtrip_flags2(&mut store, F2::C | F2::E)?, - F2::C | F2::E - ); - - let r = exports.roundtrip_record1( - &mut store, - R1 { - a: 8, - b: F1::empty(), - }, - )?; - assert_eq!(r.a, 8); - assert_eq!(r.b, F1::empty()); - - let r = exports.roundtrip_record1( - &mut store, - R1 { - a: 0, - b: F1::A | F1::B, - }, - )?; - assert_eq!(r.a, 0); - assert_eq!(r.b, F1::A | F1::B); - - assert_eq!(exports.tuple0(&mut store, ())?, ()); - assert_eq!(exports.tuple1(&mut store, (1,))?, (1,)); - Ok(()) -} diff --git a/tests/runtime/results/host.rs b/tests/runtime/results/host.rs deleted file mode 100644 index 2bf34ea9..00000000 --- a/tests/runtime/results/host.rs +++ /dev/null @@ -1,161 +0,0 @@ -use wit_bindgen_host_wasmtime_rust::Result as HostResult; -wit_bindgen_host_wasmtime_rust::generate!("../../tests/runtime/results/world.wit"); - -#[derive(Default)] -pub struct MyImports {} - -#[derive(Debug)] -struct MyTrap; -impl std::fmt::Display for MyTrap { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "my very own trap") - } -} -impl std::error::Error for MyTrap {} - -impl imports::Imports for MyImports { - // The interface error type is a String, which is a primitive, therefore - // we need to use an outer anyhow::Result for trapping, and an inner - // Result to represent the interface result. - fn string_error(&mut self, a: f32) -> anyhow::Result> { - if a == 0.0 { - Ok(Err("zero".to_owned())) - } else { - Ok(Ok(a)) - } - } - - // The interface error type is defined (as an enum), therefore - // wit-bindgen-host-wasmtime-rust will impl all the traits to make it a - // std::error::Error, as well as an `impl From for - // wit_bindgen_host_wasmtime_rust::Error`. This means we can use `?` to - // covert a Result<_, E> into a HostResult<_, E>. - // - // We expect a lot of wit interfaces to look like this one. - fn enum_error(&mut self, a: f64) -> HostResult { - if a == 0.0 { - Err(imports::E::A)? - } else { - Ok(a) - } - } - - // Same ideas as enum_error, but the interface error is defined as a - // record. - // - // Shows how you can trap in a HostResult func with an ordinary anyhow::Error. - fn record_error(&mut self, a: f64) -> HostResult { - if a == 0.0 { - Err(imports::E2 { - line: 420, - column: 0, - })? - } else if a == 1.0 { - Err(anyhow::Error::msg("a somewhat ergonomic trap"))? - } else { - Ok(a) - } - } - - // Same ideas as enum_error, but the interface error is defined as a - // variant. - // - // Shows how you can trap in a HostResult func with anything that impls - // std::error::Error - fn variant_error(&mut self, a: f64) -> HostResult { - if a == 0.0 { - Err(imports::E3::E2(imports::E2 { - line: 420, - column: 0, - }))? - } else if a == 1.0 { - Err(imports::E3::E1(imports::E::B))? - } else if a == 2.0 { - Err(wit_bindgen_host_wasmtime_rust::Error::trap(MyTrap))? - } else { - Ok(a) - } - } - - // Finally, another case where we can't impl Error on the error type, - // so we need a nested result. - // - // In this function body we show how the outer result does indeed trap - // execution. - fn empty_error(&mut self, a: u32) -> anyhow::Result> { - if a == 0 { - Ok(Err(())) - } else if a == 1 { - Err(anyhow::Error::msg("outer result trap")) - } else { - Ok(Ok(a)) - } - } -} - -fn run(wasm: &str) -> anyhow::Result<()> { - let create = || { - crate::instantiate( - wasm, - |linker| { - imports::add_to_linker( - linker, - |cx: &mut crate::Context| -> &mut MyImports { &mut cx.imports }, - ) - }, - |store, module, linker| Results::instantiate(store, module, linker), - ) - }; - - let (exports, mut store) = create()?; - - assert_eq!( - exports.string_error(&mut store, 0.0)?, - Err("zero".to_owned()) - ); - assert_eq!(exports.string_error(&mut store, 1.0)?, Ok(1.0)); - - assert_eq!(exports.enum_error(&mut store, 0.0)?, Err(E::A)); - assert_eq!(exports.enum_error(&mut store, 0.0)?, Err(E::A)); - - assert!(matches!( - exports.record_error(&mut store, 0.0)?, - Err(E2 { - line: 420, - column: 0 - }) - )); - let e = exports.record_error(&mut store, 1.0); - assert!(e.is_err()); - assert!(format!("{:?}", e.err().unwrap()).contains("a somewhat ergonomic trap")); - - let (exports, mut store) = create()?; - assert!(exports.record_error(&mut store, 2.0)?.is_ok()); - - assert!(matches!( - exports.variant_error(&mut store, 0.0)?, - Err(E3::E2(E2 { - line: 420, - column: 0 - })) - )); - assert!(matches!( - exports.variant_error(&mut store, 1.0)?, - Err(E3::E1(E::B)) - )); - let e = exports.variant_error(&mut store, 2.0); - assert!(e.is_err()); - assert!(format!("{:?}", e.err().unwrap()).contains("my very own trap")); - - let (exports, mut store) = create()?; - assert_eq!(exports.empty_error(&mut store, 0)?, Err(())); - - let e = exports.empty_error(&mut store, 1); - assert!(e.is_err()); - assert!(format!("{:?}", e.err().unwrap()).contains("outer result trap")); - - let (exports, mut store) = create()?; - assert_eq!(exports.empty_error(&mut store, 2)?, Ok(2)); - - Ok(()) -} diff --git a/tests/runtime/smoke/host.async.rs b/tests/runtime/smoke/host.async.rs deleted file mode 100644 index 5bd81332..00000000 --- a/tests/runtime/smoke/host.async.rs +++ /dev/null @@ -1,42 +0,0 @@ -use anyhow::Result; - -wit_bindgen_host_wasmtime_rust::generate!({ - path: "../../tests/runtime/smoke/world.wit", - async: true, -}); - -#[derive(Default)] -pub struct MyImports { - hit: bool, -} - -#[wit_bindgen_host_wasmtime_rust::async_trait] -impl imports::Imports for MyImports { - async fn thunk(&mut self) -> Result<()> { - self.hit = true; - println!("in the host"); - Ok(()) - } -} - -async fn run_async(wasm: &str) -> Result<()> { - let (exports, mut store) = crate::instantiate_async( - wasm, - |linker| { - imports::add_to_linker( - linker, - |cx: &mut crate::Context| -> &mut MyImports { &mut cx.imports }, - ) - }, - |store, module, linker| { - Box::pin(async { Smoke::instantiate_async(store, module, linker).await }) - }, - ) - .await?; - - exports.thunk(&mut store).await?; - - assert!(store.data().imports.hit); - - Ok(()) -} diff --git a/tests/runtime/smoke/host.rs b/tests/runtime/smoke/host.rs deleted file mode 100644 index 7071040b..00000000 --- a/tests/runtime/smoke/host.rs +++ /dev/null @@ -1,35 +0,0 @@ -use anyhow::Result; - -wit_bindgen_host_wasmtime_rust::generate!("../../tests/runtime/smoke/world.wit"); - -#[derive(Default)] -pub struct MyImports { - hit: bool, -} - -impl imports::Imports for MyImports { - fn thunk(&mut self) -> Result<()> { - self.hit = true; - println!("in the host"); - Ok(()) - } -} - -fn run(wasm: &str) -> Result<()> { - let (exports, mut store) = crate::instantiate( - wasm, - |linker| { - imports::add_to_linker( - linker, - |cx: &mut crate::Context| -> &mut MyImports { &mut cx.imports }, - ) - }, - |store, module, linker| Smoke::instantiate(store, module, linker), - )?; - - exports.thunk(&mut store)?; - - assert!(store.data().imports.hit); - - Ok(()) -} diff --git a/tests/runtime/smw_functions/exports.wit b/tests/runtime/smw_functions/exports.wit deleted file mode 100644 index 802fcdb2..00000000 --- a/tests/runtime/smw_functions/exports.wit +++ /dev/null @@ -1,12 +0,0 @@ -test-imports: func() - -f1: func() -f2: func(a: u32) -f3: func(a: u32, b: u32) - -f4: func() -> u32 - -// TODO: shoudl re-enable when re-implemented -//f5: func() -> tuple -// -//f6: func(a: u32, b: u32, c: u32) -> tuple diff --git a/tests/runtime/smw_functions/ignore_host.rs b/tests/runtime/smw_functions/ignore_host.rs deleted file mode 100644 index 21180790..00000000 --- a/tests/runtime/smw_functions/ignore_host.rs +++ /dev/null @@ -1,127 +0,0 @@ -use anyhow::Context; - -wit_bindgen_host_wasmtime_rust::export!("../../tests/runtime/smw_functions/imports.wit"); - -#[derive(Default)] -pub struct Host { - pub f1_called: bool, - pub f2_arg: u32, - pub f3_a: u32, - pub f3_b: u32, - pub f4_called: bool, - // pub f5_called: bool, - // pub f6_a: u32, - // pub f6_b: u32, - // pub f6_c: u32, -} - -impl imports::Imports for Host { - fn f1(&mut self) { - self.f1_called = true; - } - - fn f2(&mut self, arg: u32) { - self.f2_arg = arg; - } - - fn f3(&mut self, a: u32, b: u32) { - self.f3_a = a; - self.f3_b = b; - } - - fn f4(&mut self) -> u32 { - self.f4_called = true; - 1337 - } - - // fn f5(&mut self) -> (u32, u32) { - // self.f5_called = true; - // (1, 2) - // } - - // fn f6(&mut self, a: u32, b: u32, c: u32) -> (u32, u32, u32) { - // self.f6_a = a; - // self.f6_b = b; - // self.f6_c = c; - // (a + 1, b + 1, c + 1) - // } -} - -wit_bindgen_host_wasmtime_rust::import!("../../tests/runtime/smw_functions/exports.wit"); - -fn run(wasm: &str) -> anyhow::Result<()> { - let (exports, mut store) = crate::instantiate_smw( - wasm, - |linker| imports::add_to_linker(linker, |cx| -> &mut Host { &mut cx.imports }), - |store, module, linker| { - exports::Exports::instantiate(store, module, linker, |cx| &mut cx.exports) - }, - )?; - - // Test that the import instance called the functions we made available with - // the expected arguments. - - exports.test_imports(&mut store)?; - - assert!( - store.data().imports.f1_called, - "top-level JS imported and called `f1`", - ); - - assert_eq!( - store.data().imports.f2_arg, - 42, - "f2 should have been called with 42", - ); - - assert_eq!(store.data().imports.f3_a, 0); - assert_eq!(store.data().imports.f3_b, u32::MAX); - - assert!( - store.data().imports.f4_called, - "the top-level JS imported and called `f4`", - ); - - // assert!( - // store.data().imports.f5_called, - // "the top-level JS imported and called `f5`" - // ); - - // assert_eq!(store.data().imports.f6_a, 100); - // assert_eq!(store.data().imports.f6_b, 200); - // assert_eq!(store.data().imports.f6_c, 300); - - // Test that the export instance behaves as we expect it to. - - exports - .f1(&mut store) - .context("calling the `f1` export should succeed")?; - - exports - .f2(&mut store, 42) - .context("calling the `f2` export should succeed")?; - - exports - .f3(&mut store, 0, u32::MAX) - .context("calling the `f3` export should succeed")?; - - let a = exports - .f4(&mut store) - .context("calling the `f4` export should succeed")?; - assert_eq!(a, 1337); - - // let (a, b) = exports - // .f5(&mut store) - // .context("calling the `f5` export should succeed")?; - // assert_eq!(a, 1); - // assert_eq!(b, 2); - - // let (a, b, c) = exports - // .f6(&mut store, 100, 200, 300) - // .context("calling the `f6` export should succeed")?; - // assert_eq!(a, 101); - // assert_eq!(b, 201); - // assert_eq!(c, 301); - - Ok(()) -} diff --git a/tests/runtime/smw_functions/imports.wit b/tests/runtime/smw_functions/imports.wit deleted file mode 100644 index e3fe649c..00000000 --- a/tests/runtime/smw_functions/imports.wit +++ /dev/null @@ -1,9 +0,0 @@ -f1: func() -f2: func(a: u32) -f3: func(a: u32, b: u32) - -f4: func() -> u32 -// TODO: should re-enable when re-implemented -//f5: func() -> tuple -// -//f6: func(a: u32, b: u32, c: u32) -> tuple diff --git a/tests/runtime/smw_functions/wasm.js b/tests/runtime/smw_functions/wasm.js deleted file mode 100644 index 21adadfc..00000000 --- a/tests/runtime/smw_functions/wasm.js +++ /dev/null @@ -1,83 +0,0 @@ -import * as imports from "imports"; - -function assert(condition, message) { - if (!condition) { - throw new Error(message); - } -} - -function assertEq(a, b) { - assert(a == b, `assertEq failed: ${a} != ${b}`); -} - -export function test_imports() { - // const { f1, f2, f3, f4, f5, f6 } = imports; - const { f1, f2, f3, f4 } = imports; - - // - // Testing arguments. - // - - f1(); - - f2(42); - - // Min and max `u32`. - f3(0, 4294967295); - - // - // Testing returns. - // - - { - const a = f4(); - assertEq(a, 1337); - } - - // { - // const [a, b] = f5(); - // assertEq(a, 1); - // assertEq(b, 2); - // } - - // { - // const [a, b, c] = f6(100, 200, 300); - // assertEq(a, 101); - // assertEq(b, 201); - // assertEq(c, 301); - // } -} - -// -// Testing arguments. -// - -export function f1() {} - -export function f2(x) { - assertEq(x, 42); -} - -export function f3(a, b) { - assertEq(a, 0); - assertEq(b, 4294967295); -} - -// -// Testing returns. -// - -export function f4() { - return 1337; -} - -export function f5() { - return [1, 2]; -} - -export function f6(a, b, c) { - assertEq(a, 100); - assertEq(b, 200); - assertEq(c, 300); - return [a + 1, b + 1, c + 1]; -} diff --git a/tests/runtime/smw_lists/exports.wit b/tests/runtime/smw_lists/exports.wit deleted file mode 100644 index f87a89b6..00000000 --- a/tests/runtime/smw_lists/exports.wit +++ /dev/null @@ -1,7 +0,0 @@ -test-imports: func() - -f1: func(l: list) -f2: func() -> list -// TODO: should re-enable when re-implemented -// f3: func(a: list, b: list) -> tuple, list> -f4: func(l: list>) -> list> diff --git a/tests/runtime/smw_lists/ignore_host.rs b/tests/runtime/smw_lists/ignore_host.rs deleted file mode 100644 index fd62ceb5..00000000 --- a/tests/runtime/smw_lists/ignore_host.rs +++ /dev/null @@ -1,88 +0,0 @@ -use anyhow::Context; -use wit_bindgen_host_wasmtime_rust::Le; - -wit_bindgen_host_wasmtime_rust::export!("../../tests/runtime/smw_lists/imports.wit"); - -#[derive(Default)] -pub struct Host { - pub f1_l: Vec, - pub f2_called: bool, - // pub f3_a: Vec, - // pub f3_b: Vec, - pub f4_l: Vec>, -} - -impl imports::Imports for Host { - fn f1(&mut self, l: &[Le]) { - self.f1_l = l.iter().map(|le| le.get()).collect(); - } - - fn f2(&mut self) -> Vec { - self.f2_called = true; - vec![1, 2, 3] - } - - // fn f3(&mut self, a: &[Le], b: &[Le]) -> (Vec, Vec) { - // self.f3_a = a.iter().map(|le| le.get()).collect(); - // self.f3_b = b.iter().map(|le| le.get()).collect(); - // (vec![], vec![1, 2, 3]) - // } - - fn f4(&mut self, l: Vec<&[Le]>) -> Vec> { - self.f4_l = l - .into_iter() - .map(|xs| xs.iter().map(|le| le.get()).collect()) - .collect(); - vec![vec![], vec![4], vec![5, 6]] - } -} - -wit_bindgen_host_wasmtime_rust::import!("../../tests/runtime/smw_lists/exports.wit"); - -fn run(wasm: &str) -> anyhow::Result<()> { - let (exports, mut store) = crate::instantiate_smw( - wasm, - |linker| imports::add_to_linker(linker, |cx| -> &mut Host { &mut cx.imports }), - |store, module, linker| { - exports::Exports::instantiate(store, module, linker, |cx| &mut cx.exports) - }, - )?; - - // Test that the import instance called the functions we made available with - // the expected arguments. - - exports.test_imports(&mut store)?; - - assert_eq!(store.data().imports.f1_l, vec![1, 2, 3]); - - assert!(store.data().imports.f2_called); - - // assert_eq!(store.data().imports.f3_a, vec![]); - // assert_eq!(store.data().imports.f3_b, vec![1, 2, 3]); - - assert_eq!(store.data().imports.f4_l, vec![vec![], vec![1], vec![2, 3]]); - - // Test that the export instance behaves as we expect it to. - - exports - .f1(&mut store, &[1, 2, 3]) - .context("calling the `f1` export should succeed")?; - - let l = exports - .f2(&mut store) - .context("calling the `f2` export should succeed")?; - assert_eq!(l, vec![1, 2, 3]); - - // let (a, b) = exports - // .f3(&mut store, &[], &[1, 2, 3]) - // .context("calling the `f3` export should succeed")?; - // assert_eq!(a, vec![]); - // assert_eq!(b, vec![1, 2, 3]); - - let l = exports - .f4(&mut store, &[&[], &[1], &[2, 3]]) - .context("calling the `f4` export should succeed")?; - assert_eq!(l, vec![vec![], vec![4], vec![5, 6]]); - - Ok(()) -} diff --git a/tests/runtime/smw_lists/imports.wit b/tests/runtime/smw_lists/imports.wit deleted file mode 100644 index 19bf5db0..00000000 --- a/tests/runtime/smw_lists/imports.wit +++ /dev/null @@ -1,5 +0,0 @@ -f1: func(l: list) -f2: func() -> list -// TODO: should re-enable when re-implemented -// f3: func(a: list, b: list) -> tuple, list> -f4: func(l: list>) -> list> diff --git a/tests/runtime/smw_lists/wasm.js b/tests/runtime/smw_lists/wasm.js deleted file mode 100644 index e55cdf68..00000000 --- a/tests/runtime/smw_lists/wasm.js +++ /dev/null @@ -1,77 +0,0 @@ -import * as imports from "imports"; - -function assert(condition, message) { - if (!condition) { - throw new Error(message); - } -} - -function assertEq(a, b) { - assert(a == b, `assertEq failed: ${a} != ${b}`); -} - -export function test_imports() { - // const { f1, f2, f3, f4 } = imports; - const { f1, f2, f4 } = imports; - f1([1, 2, 3]); - - const l = f2(); - assertEq(l.length, 3); - assertEq(l[0], 1); - assertEq(l[1], 2); - assertEq(l[2], 3); - - // const [a, b] = f3([], [1, 2, 3]); - // assertEq(a.length, 0); - // assertEq(b.length, 3); - // assertEq(b[0], 1); - // assertEq(b[1], 2); - // assertEq(b[2], 3); - - const l2 = f4([[], [1], [2, 3]]); - assertEq(l2.length, 3); - assertEq(l2[0].length, 0); - assertEq(l2[1].length, 1); - assertEq(l2[1][0], 4); - assertEq(l2[2].length, 2); - assertEq(l2[2][0], 5); - assertEq(l2[2][1], 6); -} - -export function f1(l) { - assertEq(l.length, 3); - assertEq(l[0], 1); - assertEq(l[1], 2); - assertEq(l[2], 3); -} - -export function f2() { - return [1, 2, 3]; -} - -export function f3(a, b) { - assertEq(a.length, 0); - assertEq(b.length, 3); - assertEq(b[0], 1); - assertEq(b[1], 2); - assertEq(b[2], 3); - return [ - [], - [1, 2, 3] - ]; -} - -export function f4(l) { - assertEq(l.length, 3); - assertEq(l[0].length, 0); - assertEq(l[1].length, 1); - assertEq(l[1][0], 1); - assertEq(l[2].length, 2); - assertEq(l[2][0], 2); - assertEq(l[2][1], 3); - return [ - [], - [4], - [5, 6] - ]; -} diff --git a/tests/runtime/smw_strings/exports.wit b/tests/runtime/smw_strings/exports.wit deleted file mode 100644 index 9c1292ee..00000000 --- a/tests/runtime/smw_strings/exports.wit +++ /dev/null @@ -1,7 +0,0 @@ -test-imports: func() - -f1: func(s: string) -f2: func() -> string - -// TODO: should re-enable when fixed -//f3: func(a: string, b:string, c: string) -> tuple diff --git a/tests/runtime/smw_strings/ignore_host.rs b/tests/runtime/smw_strings/ignore_host.rs deleted file mode 100644 index 217b3f18..00000000 --- a/tests/runtime/smw_strings/ignore_host.rs +++ /dev/null @@ -1,75 +0,0 @@ -use anyhow::Context; - -wit_bindgen_host_wasmtime_rust::export!("../../tests/runtime/smw_strings/imports.wit"); - -#[derive(Default)] -pub struct Host { - pub f1_s: String, - pub f2_called: bool, - // pub f3_a: String, - // pub f3_b: String, - // pub f3_c: String, -} - -impl imports::Imports for Host { - fn f1(&mut self, s: &str) { - self.f1_s = s.to_string(); - } - - fn f2(&mut self) -> String { - self.f2_called = true; - "36 chambers".into() - } - - // fn f3(&mut self, a: &str, b: &str, c: &str) -> (String, String, String) { - // self.f3_a = a.into(); - // self.f3_b = b.into(); - // self.f3_c = c.into(); - // (a.into(), b.into(), c.into()) - // } -} - -wit_bindgen_host_wasmtime_rust::import!("../../tests/runtime/smw_strings/exports.wit"); - -fn run(wasm: &str) -> anyhow::Result<()> { - let (exports, mut store) = crate::instantiate_smw( - wasm, - |linker| imports::add_to_linker(linker, |cx| -> &mut Host { &mut cx.imports }), - |store, module, linker| { - exports::Exports::instantiate(store, module, linker, |cx| &mut cx.exports) - }, - )?; - - // Test that the import instance called the functions we made available with - // the expected arguments. - - exports.test_imports(&mut store)?; - - assert_eq!(store.data().imports.f1_s, "Hello, WIT!"); - - assert!(store.data().imports.f2_called, "JS should have called `f2`"); - - // assert_eq!(store.data().imports.f3_a, ""); - // assert_eq!(store.data().imports.f3_b, "🚀"); - // assert_eq!(store.data().imports.f3_c, "hello"); - - // Test that the export instance behaves as we expect it to. - - exports - .f1(&mut store, "Hello, WIT!") - .context("calling the `f1` export should succeed")?; - - let s = exports - .f2(&mut store) - .context("calling the `f2` export should succeed")?; - assert_eq!(s, "36 chambers"); - - // let (a, b, c) = exports - // .f3(&mut store, "", "🚀", "hello") - // .context("calling the `f3` export should succeed")?; - // assert_eq!(a, ""); - // assert_eq!(b, "🚀"); - // assert_eq!(c, "hello"); - - Ok(()) -} diff --git a/tests/runtime/smw_strings/imports.wit b/tests/runtime/smw_strings/imports.wit deleted file mode 100644 index 56c81b10..00000000 --- a/tests/runtime/smw_strings/imports.wit +++ /dev/null @@ -1,4 +0,0 @@ -f1: func(s: string) -f2: func() -> string -// TODO: should re-enable when fixed -//f3: func(a: string, b:string, c: string) -> tuple diff --git a/tests/runtime/smw_strings/wasm.js b/tests/runtime/smw_strings/wasm.js deleted file mode 100644 index 053be8f9..00000000 --- a/tests/runtime/smw_strings/wasm.js +++ /dev/null @@ -1,40 +0,0 @@ -import * as imports from "imports"; - -function assert(condition, message) { - if (!condition) { - throw new Error(message); - } -} - -function assertEq(a, b) { - assert(a == b, `assertEq failed: ${a} != ${b}`); -} - -export function test_imports() { - const { f1, f2 } = imports; - // const { f1, f2, f3 } = imports; - f1("Hello, WIT!"); - - const s = f2(); - assertEq(s, "36 chambers"); - - // const [a, b, c] = f3("", "🚀", "hello"); - // assertEq(a, ""); - // assertEq(b, "🚀"); - // assertEq(c, "hello"); -} - -export function f1(s) { - assertEq(s, "Hello, WIT!"); -} - -export function f2() { - return "36 chambers"; -} - -export function f3(a, b, c) { - assertEq(a, ""); - assertEq(b, "🚀"); - assertEq(c, "hello"); - return [a, b, c]; -} diff --git a/tests/runtime/unions/host.rs b/tests/runtime/unions/host.rs deleted file mode 100644 index b7d8d024..00000000 --- a/tests/runtime/unions/host.rs +++ /dev/null @@ -1,309 +0,0 @@ -use anyhow::Result; - -wit_bindgen_host_wasmtime_rust::generate!("../../tests/runtime/unions/world.wit"); - -#[derive(Default)] -pub struct MyImports; - -impl imports::Imports for MyImports { - fn add_one_integer(&mut self, num: imports::AllIntegers) -> Result { - use imports::AllIntegers; - Ok(match num { - AllIntegers::Bool(false) => AllIntegers::Bool(true), - AllIntegers::Bool(true) => AllIntegers::Bool(false), - AllIntegers::U8(n) => AllIntegers::U8(n.wrapping_add(1)), - AllIntegers::U16(n) => AllIntegers::U16(n.wrapping_add(1)), - AllIntegers::U32(n) => AllIntegers::U32(n.wrapping_add(1)), - AllIntegers::U64(n) => AllIntegers::U64(n.wrapping_add(1)), - AllIntegers::I8(n) => AllIntegers::I8(n.wrapping_add(1)), - AllIntegers::I16(n) => AllIntegers::I16(n.wrapping_add(1)), - AllIntegers::I32(n) => AllIntegers::I32(n.wrapping_add(1)), - AllIntegers::I64(n) => AllIntegers::I64(n.wrapping_add(1)), - }) - } - fn add_one_float(&mut self, num: imports::AllFloats) -> Result { - use imports::AllFloats; - Ok(match num { - AllFloats::F32(n) => AllFloats::F32(n + 1.0), - AllFloats::F64(n) => AllFloats::F64(n + 1.0), - }) - } - fn replace_first_char(&mut self, text: imports::AllText, c: char) -> Result { - use imports::AllText; - Ok(match text { - AllText::Char(_) => AllText::Char(c), - AllText::String(t) => AllText::String(format!("{}{}", c, &t[1..])), - }) - } - fn identify_integer(&mut self, num: imports::AllIntegers) -> Result { - use imports::AllIntegers; - Ok(match num { - AllIntegers::Bool { .. } => 0, - AllIntegers::U8 { .. } => 1, - AllIntegers::U16 { .. } => 2, - AllIntegers::U32 { .. } => 3, - AllIntegers::U64 { .. } => 4, - AllIntegers::I8 { .. } => 5, - AllIntegers::I16 { .. } => 6, - AllIntegers::I32 { .. } => 7, - AllIntegers::I64 { .. } => 8, - }) - } - fn identify_float(&mut self, num: imports::AllFloats) -> Result { - use imports::AllFloats; - Ok(match num { - AllFloats::F32 { .. } => 0, - AllFloats::F64 { .. } => 1, - }) - } - fn identify_text(&mut self, text: imports::AllText) -> Result { - use imports::AllText; - Ok(match text { - AllText::Char { .. } => 0, - AllText::String { .. } => 1, - }) - } - fn identify_duplicated(&mut self, dup: imports::DuplicatedS32) -> Result { - use imports::DuplicatedS32; - Ok(match dup { - DuplicatedS32::I320 { .. } => 0, - DuplicatedS32::I321 { .. } => 1, - DuplicatedS32::I322 { .. } => 2, - }) - } - fn add_one_duplicated( - &mut self, - dup: imports::DuplicatedS32, - ) -> Result { - use imports::DuplicatedS32; - Ok(match dup { - DuplicatedS32::I320(n) => DuplicatedS32::I320(n.wrapping_add(1)), - DuplicatedS32::I321(n) => DuplicatedS32::I321(n.wrapping_add(1)), - DuplicatedS32::I322(n) => DuplicatedS32::I322(n.wrapping_add(1)), - }) - } - fn identify_distinguishable_num(&mut self, num: imports::DistinguishableNum) -> Result { - use imports::DistinguishableNum; - Ok(match num { - DistinguishableNum::F64 { .. } => 0, - DistinguishableNum::I64 { .. } => 1, - }) - } - fn add_one_distinguishable_num( - &mut self, - num: imports::DistinguishableNum, - ) -> Result { - use imports::DistinguishableNum; - Ok(match num { - DistinguishableNum::F64(n) => DistinguishableNum::F64(n + 1.0), - DistinguishableNum::I64(n) => DistinguishableNum::I64(n.wrapping_add(1)), - }) - } -} - -fn run(wasm: &str) -> Result<()> { - let (exports, mut store) = crate::instantiate( - wasm, - |linker| imports::add_to_linker(linker, |cx| -> &mut MyImports { &mut cx.imports }), - |store, module, linker| Unions::instantiate(store, module, linker), - )?; - - exports.test_imports(&mut store)?; - - // Booleans - assert!(matches!( - exports.add_one_integer(&mut store, AllIntegers::Bool(false))?, - AllIntegers::Bool(true) - )); - assert!(matches!( - exports.add_one_integer(&mut store, AllIntegers::Bool(true))?, - AllIntegers::Bool(false) - )); - // Unsigned integers - assert!(matches!( - exports.add_one_integer(&mut store, AllIntegers::U8(0))?, - AllIntegers::U8(1) - )); - assert!(matches!( - exports.add_one_integer(&mut store, AllIntegers::U8(u8::MAX))?, - AllIntegers::U8(0) - )); - assert!(matches!( - exports.add_one_integer(&mut store, AllIntegers::U16(0))?, - AllIntegers::U16(1) - )); - assert!(matches!( - exports.add_one_integer(&mut store, AllIntegers::U16(u16::MAX))?, - AllIntegers::U16(0) - )); - assert!(matches!( - exports.add_one_integer(&mut store, AllIntegers::U32(0))?, - AllIntegers::U32(1) - )); - assert!(matches!( - exports.add_one_integer(&mut store, AllIntegers::U32(u32::MAX))?, - AllIntegers::U32(0) - )); - assert!(matches!( - exports.add_one_integer(&mut store, AllIntegers::U64(0))?, - AllIntegers::U64(1) - )); - assert!(matches!( - exports.add_one_integer(&mut store, AllIntegers::U64(u64::MAX))?, - AllIntegers::U64(0) - )); - // Signed integers - assert!(matches!( - exports.add_one_integer(&mut store, AllIntegers::I8(0))?, - AllIntegers::I8(1) - )); - assert!(matches!( - exports.add_one_integer(&mut store, AllIntegers::I8(i8::MAX))?, - AllIntegers::I8(i8::MIN) - )); - assert!(matches!( - exports.add_one_integer(&mut store, AllIntegers::I16(0))?, - AllIntegers::I16(1) - )); - assert!(matches!( - exports.add_one_integer(&mut store, AllIntegers::I16(i16::MAX))?, - AllIntegers::I16(i16::MIN) - )); - assert!(matches!( - exports.add_one_integer(&mut store, AllIntegers::I32(0))?, - AllIntegers::I32(1) - )); - assert!(matches!( - exports.add_one_integer(&mut store, AllIntegers::I32(i32::MAX))?, - AllIntegers::I32(i32::MIN) - )); - assert!(matches!( - exports.add_one_integer(&mut store, AllIntegers::I64(0))?, - AllIntegers::I64(1) - )); - assert!(matches!( - exports.add_one_integer(&mut store, AllIntegers::I64(i64::MAX))?, - AllIntegers::I64(i64::MIN) - )); - - // Floats - match exports.add_one_float(&mut store, AllFloats::F32(0.0))? { - AllFloats::F32(r) => assert_eq!(r, 1.0), - _ => panic!(), - } - match exports.add_one_float(&mut store, AllFloats::F32(420.0))? { - AllFloats::F32(r) => assert_eq!(r, 421.0), - _ => panic!(), - } - match exports.add_one_float(&mut store, AllFloats::F64(0.0))? { - AllFloats::F64(r) => assert_eq!(r, 1.0), - _ => panic!(), - } - match exports.add_one_float(&mut store, AllFloats::F64(420.0))? { - AllFloats::F64(r) => assert_eq!(r, 421.0), - _ => panic!(), - } - - // Text - assert!(matches!( - exports.replace_first_char(&mut store, AllTextParam::Char('a'), 'z')?, - AllTextResult::Char('z') - )); - match exports.replace_first_char(&mut store, AllTextParam::String("abc"), 'z')? { - AllTextResult::String(s) => assert_eq!(s, "zbc"), - _ => panic!(), - } - - // Identify Integers - assert_eq!( - exports.identify_integer(&mut store, AllIntegers::Bool(false))?, - 0 - ); - assert_eq!(exports.identify_integer(&mut store, AllIntegers::U8(0))?, 1); - assert_eq!( - exports.identify_integer(&mut store, AllIntegers::U16(0))?, - 2 - ); - assert_eq!( - exports.identify_integer(&mut store, AllIntegers::U32(0))?, - 3 - ); - assert_eq!( - exports.identify_integer(&mut store, AllIntegers::U64(0))?, - 4 - ); - assert_eq!(exports.identify_integer(&mut store, AllIntegers::I8(0))?, 5); - assert_eq!( - exports.identify_integer(&mut store, AllIntegers::I16(0))?, - 6 - ); - assert_eq!( - exports.identify_integer(&mut store, AllIntegers::I32(0))?, - 7 - ); - assert_eq!( - exports.identify_integer(&mut store, AllIntegers::I64(0))?, - 8 - ); - - // Identify floats - assert_eq!(exports.identify_float(&mut store, AllFloats::F32(0.0))?, 0); - assert_eq!(exports.identify_float(&mut store, AllFloats::F64(0.0))?, 1); - - // Identify text - assert_eq!( - exports.identify_text(&mut store, AllTextParam::Char('\0'))?, - 0 - ); - assert_eq!( - exports.identify_text(&mut store, AllTextParam::String(""))?, - 1 - ); - - // Identify Duplicated - assert_eq!( - exports.identify_duplicated(&mut store, DuplicatedS32::I320(0))?, - 0 - ); - assert_eq!( - exports.identify_duplicated(&mut store, DuplicatedS32::I321(0))?, - 1 - ); - assert_eq!( - exports.identify_duplicated(&mut store, DuplicatedS32::I322(0))?, - 2 - ); - - assert!(matches!( - exports.add_one_duplicated(&mut store, DuplicatedS32::I320(0))?, - DuplicatedS32::I320(1) - )); - assert!(matches!( - exports.add_one_duplicated(&mut store, DuplicatedS32::I321(0))?, - DuplicatedS32::I321(1) - )); - assert!(matches!( - exports.add_one_duplicated(&mut store, DuplicatedS32::I322(0))?, - DuplicatedS32::I322(1) - )); - - // Identify Distinguishable Num - assert_eq!( - exports.identify_distinguishable_num(&mut store, DistinguishableNum::F64(0.0))?, - 0 - ); - assert_eq!( - exports.identify_distinguishable_num(&mut store, DistinguishableNum::I64(0))?, - 1 - ); - - match exports.add_one_distinguishable_num(&mut store, DistinguishableNum::F64(0.0))? { - DistinguishableNum::F64(f) => assert_eq!(f, 1.0), - _ => panic!(), - }; - assert!(matches!( - exports.add_one_distinguishable_num(&mut store, DistinguishableNum::I64(0))?, - DistinguishableNum::I64(1), - )); - Ok(()) -} diff --git a/tests/runtime/variants/host.rs b/tests/runtime/variants/host.rs deleted file mode 100644 index 1024c87f..00000000 --- a/tests/runtime/variants/host.rs +++ /dev/null @@ -1,118 +0,0 @@ -wit_bindgen_host_wasmtime_rust::generate!("../../tests/runtime/variants/world.wit"); - -#[derive(Default)] -pub struct MyImports; - -impl imports::Imports for MyImports { - fn roundtrip_option(&mut self, a: Option) -> anyhow::Result> { - Ok(a.map(|x| x as u8)) - } - - fn roundtrip_result(&mut self, a: Result) -> anyhow::Result> { - Ok(match a { - Ok(a) => Ok(a.into()), - Err(b) => Err(b as u8), - }) - } - - fn roundtrip_enum(&mut self, a: imports::E1) -> anyhow::Result { - assert_eq!(a, a); - Ok(a) - } - - fn invert_bool(&mut self, a: bool) -> anyhow::Result { - Ok(!a) - } - - fn variant_casts(&mut self, a: imports::Casts) -> anyhow::Result { - Ok(a) - } - - fn variant_zeros(&mut self, a: imports::Zeros) -> anyhow::Result { - Ok(a) - } - - fn variant_typedefs( - &mut self, - _: Option, - _: bool, - _: Result, - ) -> anyhow::Result<()> { - Ok(()) - } - - fn variant_enums( - &mut self, - a: bool, - b: Result<(), ()>, - c: imports::MyErrno, - ) -> anyhow::Result<(bool, Result<(), ()>, imports::MyErrno)> { - assert_eq!(a, true); - assert_eq!(b, Ok(())); - assert_eq!(c, imports::MyErrno::Success); - Ok((false, Err(()), imports::MyErrno::A)) - } -} - -fn run(wasm: &str) -> anyhow::Result<()> { - let (exports, mut store) = crate::instantiate( - wasm, - |linker| imports::add_to_linker(linker, |cx| -> &mut MyImports { &mut cx.imports }), - |store, module, linker| Variants::instantiate(store, module, linker), - )?; - - exports.test_imports(&mut store)?; - - assert_eq!(exports.roundtrip_option(&mut store, Some(1.0))?, Some(1)); - assert_eq!(exports.roundtrip_option(&mut store, None)?, None); - assert_eq!(exports.roundtrip_option(&mut store, Some(2.0))?, Some(2)); - assert_eq!(exports.roundtrip_result(&mut store, Ok(2))?, Ok(2.0)); - assert_eq!(exports.roundtrip_result(&mut store, Ok(4))?, Ok(4.0)); - assert_eq!(exports.roundtrip_result(&mut store, Err(5.3))?, Err(5)); - - assert_eq!(exports.roundtrip_enum(&mut store, E1::A)?, E1::A); - assert_eq!(exports.roundtrip_enum(&mut store, E1::B)?, E1::B); - - assert_eq!(exports.invert_bool(&mut store, true)?, false); - assert_eq!(exports.invert_bool(&mut store, false)?, true); - - let (a1, a2, a3, a4, a5, a6) = exports.variant_casts( - &mut store, - (C1::A(1), C2::A(2), C3::A(3), C4::A(4), C5::A(5), C6::A(6.0)), - )?; - assert!(matches!(a1, C1::A(1))); - assert!(matches!(a2, C2::A(2))); - assert!(matches!(a3, C3::A(3))); - assert!(matches!(a4, C4::A(4))); - assert!(matches!(a5, C5::A(5))); - assert!(matches!(a6, C6::A(b) if b == 6.0)); - - let (a1, a2, a3, a4, a5, a6) = exports.variant_casts( - &mut store, - ( - C1::B(1), - C2::B(2.0), - C3::B(3.0), - C4::B(4.0), - C5::B(5.0), - C6::B(6.0), - ), - )?; - assert!(matches!(a1, C1::B(1))); - assert!(matches!(a2, C2::B(b) if b == 2.0)); - assert!(matches!(a3, C3::B(b) if b == 3.0)); - assert!(matches!(a4, C4::B(b) if b == 4.0)); - assert!(matches!(a5, C5::B(b) if b == 5.0)); - assert!(matches!(a6, C6::B(b) if b == 6.0)); - - let (a1, a2, a3, a4) = - exports.variant_zeros(&mut store, (Z1::A(1), Z2::A(2), Z3::A(3.0), Z4::A(4.0)))?; - assert!(matches!(a1, Z1::A(1))); - assert!(matches!(a2, Z2::A(2))); - assert!(matches!(a3, Z3::A(b) if b == 3.0)); - assert!(matches!(a4, Z4::A(b) if b == 4.0)); - - exports.variant_typedefs(&mut store, None, false, Err(()))?; - - Ok(()) -}