feat(plugins): upgrade wasmer to 3.1.1 (#2706)

upgrade wasmer to 3.1.1

- last version with wasmer-wasi
- refactor to satisfy &mut Store requirement to call wasm functions
This commit is contained in:
Thomas Linford 2023-09-27 22:15:54 +02:00 committed by GitHub
parent 8ac57d5cfc
commit 7c726c131c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 554 additions and 522 deletions

502
Cargo.lock generated
View file

@ -586,56 +586,57 @@ dependencies = [
[[package]]
name = "cranelift-bforest"
version = "0.82.3"
version = "0.86.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38faa2a16616c8e78a18d37b4726b98bfd2de192f2fdc8a39ddf568a408a0f75"
checksum = "529ffacce2249ac60edba2941672dfedf3d96558b415d0d8083cd007456e0f55"
dependencies = [
"cranelift-entity",
]
[[package]]
name = "cranelift-codegen"
version = "0.82.3"
version = "0.86.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26f192472a3ba23860afd07d2b0217dc628f21fcc72617aa1336d98e1671f33b"
checksum = "427d105f617efc8cb55f8d036a7fded2e227892d8780b4985e5551f8d27c4a92"
dependencies = [
"cranelift-bforest",
"cranelift-codegen-meta",
"cranelift-codegen-shared",
"cranelift-entity",
"cranelift-isle",
"gimli",
"log",
"regalloc",
"regalloc2",
"smallvec",
"target-lexicon",
]
[[package]]
name = "cranelift-codegen-meta"
version = "0.82.3"
version = "0.86.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f32ddb89e9b89d3d9b36a5b7d7ea3261c98235a76ac95ba46826b8ec40b1a24"
checksum = "551674bed85b838d45358e3eab4f0ffaa6790c70dc08184204b9a54b41cdb7d1"
dependencies = [
"cranelift-codegen-shared",
]
[[package]]
name = "cranelift-codegen-shared"
version = "0.82.3"
version = "0.86.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01fd0d9f288cc1b42d9333b7a776b17e278fc888c28e6a0f09b5573d45a150bc"
checksum = "2b3a63ae57498c3eb495360944a33571754241e15e47e3bcae6082f40fec5866"
[[package]]
name = "cranelift-entity"
version = "0.82.3"
version = "0.86.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e3bfe172b83167604601faf9dc60453e0d0a93415b57a9c4d1a7ae6849185cf"
checksum = "11aa8aa624c72cc1c94ea3d0739fa61248260b5b14d3646f51593a88d67f3e6e"
[[package]]
name = "cranelift-frontend"
version = "0.82.3"
version = "0.86.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a006e3e32d80ce0e4ba7f1f9ddf66066d052a8c884a110b91d05404d6ce26dce"
checksum = "544ee8f4d1c9559c9aa6d46e7aaeac4a13856d620561094f35527356c7d21bd0"
dependencies = [
"cranelift-codegen",
"log",
@ -644,13 +645,10 @@ dependencies = [
]
[[package]]
name = "crc32fast"
version = "1.3.2"
name = "cranelift-isle"
version = "0.86.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
dependencies = [
"cfg-if 1.0.0",
]
checksum = "ed16b14363d929b8c37e3c557d0a7396791b383ecc302141643c054343170aad"
[[package]]
name = "crossbeam"
@ -1153,6 +1151,15 @@ dependencies = [
"thread_local",
]
[[package]]
name = "fxhash"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
dependencies = [
"byteorder",
]
[[package]]
name = "generational-arena"
version = "0.2.8"
@ -1264,9 +1271,6 @@ name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
dependencies = [
"ahash",
]
[[package]]
name = "hashbrown"
@ -1325,6 +1329,12 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "id-arena"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005"
[[package]]
name = "ident_case"
version = "1.0.1"
@ -1386,7 +1396,6 @@ checksum = "e6012d540c5baa3589337a98ce73408de9b5a25ec9fc2c6fd6be8f0d39e0ca5a"
dependencies = [
"autocfg",
"hashbrown 0.11.2",
"serde",
]
[[package]]
@ -1514,9 +1523,9 @@ checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d"
[[package]]
name = "js-sys"
version = "0.3.58"
version = "0.3.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3fac17f7123a73ca62df411b1bf727ccc805daa070338fda671c86dac1bdc27"
checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a"
dependencies = [
"wasm-bindgen",
]
@ -1591,16 +1600,6 @@ version = "0.2.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
[[package]]
name = "libloading"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
dependencies = [
"cfg-if 1.0.0",
"winapi",
]
[[package]]
name = "libssh2-sys"
version = "0.2.23"
@ -1692,27 +1691,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "loupe"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b6a72dfa44fe15b5e76b94307eeb2ff995a8c5b283b55008940c02e0c5b634d"
dependencies = [
"indexmap",
"loupe-derive",
"rustversion",
]
[[package]]
name = "loupe-derive"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0fbfc88337168279f2e9ae06e157cfed4efd3316e14dc96ed074d4f2e6c5952"
dependencies = [
"quote",
"syn 1.0.96",
]
[[package]]
name = "mach"
version = "0.3.2"
@ -1997,17 +1975,14 @@ version = "0.28.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424"
dependencies = [
"crc32fast",
"hashbrown 0.11.2",
"indexmap",
"memchr",
]
[[package]]
name = "once_cell"
version = "1.12.0"
version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225"
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
[[package]]
name = "opaque-debug"
@ -2451,6 +2426,17 @@ dependencies = [
"syn 1.0.96",
]
[[package]]
name = "pulldown-cmark"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8"
dependencies = [
"bitflags",
"memchr",
"unicase",
]
[[package]]
name = "quote"
version = "1.0.27"
@ -2586,13 +2572,14 @@ dependencies = [
]
[[package]]
name = "regalloc"
version = "0.0.34"
name = "regalloc2"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62446b1d3ebf980bdc68837700af1d77b37bc430e524bf95319c6eada2a4cc02"
checksum = "d43a209257d978ef079f3d446331d0f1794f5e0fc19b306a199983857833a779"
dependencies = [
"fxhash",
"log",
"rustc-hash",
"slice-group-by",
"smallvec",
]
@ -2651,6 +2638,7 @@ checksum = "cec2b3485b07d96ddfd3134767b8a447b45ea4eb91448d0a35180ec0ffd5ed15"
dependencies = [
"bytecheck",
"hashbrown 0.12.3",
"indexmap",
"ptr_meta",
"rend",
"rkyv_derive",
@ -2696,12 +2684,6 @@ version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustc_version"
version = "0.2.3"
@ -2734,12 +2716,6 @@ dependencies = [
"windows-sys 0.45.0",
]
[[package]]
name = "rustversion"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8"
[[package]]
name = "ryu"
version = "1.0.10"
@ -2826,12 +2802,14 @@ dependencies = [
]
[[package]]
name = "serde_bytes"
version = "0.11.6"
name = "serde-wasm-bindgen"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "212e73464ebcde48d723aa02eb270ba62eff38a9b732df31f33f1b4e145f3a54"
checksum = "e3b4c031cd0d9014307d82b8abf653c0290fbdaeb4c02d00c63cf52f728628bf"
dependencies = [
"js-sys",
"serde",
"wasm-bindgen",
]
[[package]]
@ -3000,6 +2978,12 @@ version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32"
[[package]]
name = "slice-group-by"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7"
[[package]]
name = "smallvec"
version = "1.8.0"
@ -3569,6 +3553,15 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"
[[package]]
name = "unicase"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
dependencies = [
"version_check",
]
[[package]]
name = "unicode-bidi"
version = "0.3.8"
@ -3611,6 +3604,12 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
[[package]]
name = "unicode-xid"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "unsafe-any-ors"
version = "1.0.0"
@ -3747,9 +3746,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.81"
version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994"
checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342"
dependencies = [
"cfg-if 1.0.0",
"wasm-bindgen-macro",
@ -3757,17 +3756,40 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.81"
version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a"
checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd"
dependencies = [
"bumpalo",
"lazy_static",
"log",
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.15",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-downcast"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5dac026d43bcca6e7ce1c0956ba68f59edf6403e8e930a5d891be72c31a44340"
dependencies = [
"js-sys",
"once_cell",
"wasm-bindgen",
"wasm-bindgen-downcast-macros",
]
[[package]]
name = "wasm-bindgen-downcast-macros"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5020cfa87c7cecefef118055d44e3c1fc122c7ec25701d528ee458a0b45f38f"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.96",
"wasm-bindgen-shared",
]
[[package]]
@ -3784,9 +3806,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.81"
version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa"
checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@ -3794,22 +3816,22 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.81"
version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048"
checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.96",
"syn 2.0.15",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.81"
version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be"
checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
[[package]]
name = "wasm-encoder"
@ -3822,74 +3844,65 @@ dependencies = [
[[package]]
name = "wasmer"
version = "2.3.0"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea8d8361c9d006ea3d7797de7bd6b1492ffd0f91a22430cfda6c1658ad57bedf"
checksum = "840af6d21701220cb805dc7201af301cb99e9b4f646f48a41befbc1d949f0f90"
dependencies = [
"bytes",
"cfg-if 1.0.0",
"indexmap",
"js-sys",
"loupe",
"more-asserts",
"serde",
"serde-wasm-bindgen",
"target-lexicon",
"thiserror",
"wasm-bindgen",
"wasmer-artifact",
"wasm-bindgen-downcast",
"wasmer-compiler",
"wasmer-compiler-cranelift",
"wasmer-compiler-singlepass",
"wasmer-derive",
"wasmer-engine",
"wasmer-engine-dylib",
"wasmer-engine-universal",
"wasmer-types",
"wasmer-vm",
"wat",
"winapi",
]
[[package]]
name = "wasmer-artifact"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7aaf9428c29c1d8ad2ac0e45889ba8a568a835e33fd058964e5e500f2f7ce325"
dependencies = [
"enumset",
"loupe",
"thiserror",
"wasmer-compiler",
"wasmer-types",
]
[[package]]
name = "wasmer-compiler"
version = "2.3.0"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e67a6cd866aed456656db2cfea96c18baabbd33f676578482b85c51e1ee19d2c"
checksum = "b86fab98beaaace77380cb04e681773739473860d1b8499ea6b14f920923e0c5"
dependencies = [
"backtrace",
"cfg-if 1.0.0",
"enum-iterator",
"enumset",
"loupe",
"rkyv",
"serde",
"serde_bytes",
"lazy_static",
"leb128",
"memmap2",
"more-asserts",
"region",
"rustc-demangle",
"smallvec",
"target-lexicon",
"thiserror",
"wasmer-types",
"wasmer-vm",
"wasmparser",
"winapi",
]
[[package]]
name = "wasmer-compiler-cranelift"
version = "2.3.0"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48be2f9f6495f08649e4f8b946a2cbbe119faf5a654aa1457f9504a99d23dae0"
checksum = "015eef629fc84889540dc1686bd7fa524b93da9fd2d275b16c49dbe96268e58f"
dependencies = [
"cranelift-codegen",
"cranelift-entity",
"cranelift-frontend",
"gimli",
"loupe",
"more-asserts",
"rayon",
"smallvec",
@ -3901,16 +3914,16 @@ dependencies = [
[[package]]
name = "wasmer-compiler-singlepass"
version = "2.3.0"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29ca2a35204d8befa85062bc7aac259a8db8070b801b8a783770ba58231d729e"
checksum = "07e235ccc192d5f39147e8a430f48040dcfeebc1f1b0d979d2232ec1618d255c"
dependencies = [
"byteorder",
"dynasm",
"dynasmrt",
"enumset",
"gimli",
"lazy_static",
"loupe",
"more-asserts",
"rayon",
"smallvec",
@ -3920,9 +3933,9 @@ dependencies = [
[[package]]
name = "wasmer-derive"
version = "2.3.0"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00e50405cc2a2f74ff574584710a5f2c1d5c93744acce2ca0866084739284b51"
checksum = "1ff577b7c1cfcd3d7c5b3a09fe1a499b73f7c17084845ff71225c8250a6a63a9"
dependencies = [
"proc-macro-error",
"proc-macro2",
@ -3931,123 +3944,35 @@ dependencies = [
]
[[package]]
name = "wasmer-engine"
version = "2.3.0"
name = "wasmer-types"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f98f010978c244db431b392aeab0661df7ea0822343334f8f2a920763548e45"
checksum = "8b9600f9da966abae3be0b0a4560e7d1f2c88415a2d01ce362ac06063cb1c473"
dependencies = [
"backtrace",
"enum-iterator",
"enumset",
"lazy_static",
"loupe",
"memmap2",
"indexmap",
"more-asserts",
"rustc-demangle",
"serde",
"serde_bytes",
"rkyv",
"target-lexicon",
"thiserror",
"wasmer-artifact",
"wasmer-compiler",
"wasmer-types",
"wasmer-vm",
]
[[package]]
name = "wasmer-engine-dylib"
version = "2.3.0"
name = "wasmer-vbus"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0358af9c154724587731175553805648d9acb8f6657880d165e378672b7e53"
checksum = "72b42f76b9f09c68084de3a35fdf4907609f4b5005ecf3767fa1839a669dcbdb"
dependencies = [
"cfg-if 1.0.0",
"enum-iterator",
"enumset",
"leb128",
"libloading",
"loupe",
"object",
"rkyv",
"serde",
"tempfile",
"tracing",
"wasmer-artifact",
"wasmer-compiler",
"wasmer-engine",
"wasmer-object",
"wasmer-types",
"wasmer-vm",
"which",
]
[[package]]
name = "wasmer-engine-universal"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "440dc3d93c9ca47865a4f4edd037ea81bf983b5796b59b3d712d844b32dbef15"
dependencies = [
"cfg-if 1.0.0",
"enumset",
"leb128",
"loupe",
"region",
"rkyv",
"wasmer-compiler",
"wasmer-engine",
"wasmer-engine-universal-artifact",
"wasmer-types",
"wasmer-vm",
"winapi",
]
[[package]]
name = "wasmer-engine-universal-artifact"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68f1db3f54152657eb6e86c44b66525ff7801dad8328fe677da48dd06af9ad41"
dependencies = [
"enum-iterator",
"enumset",
"loupe",
"rkyv",
"thiserror",
"wasmer-artifact",
"wasmer-compiler",
"wasmer-types",
]
[[package]]
name = "wasmer-object"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d831335ff3a44ecf451303f6f891175c642488036b92ceceb24ac8623a8fa8b"
dependencies = [
"object",
"thiserror",
"wasmer-compiler",
"wasmer-types",
]
[[package]]
name = "wasmer-types"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39df01ea05dc0a9bab67e054c7cb01521e53b35a7bb90bd02eca564ed0b2667f"
dependencies = [
"backtrace",
"enum-iterator",
"indexmap",
"loupe",
"more-asserts",
"rkyv",
"serde",
"thiserror",
"wasmer-vfs",
]
[[package]]
name = "wasmer-vfs"
version = "2.3.0"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9302eae3edc53cb540c2d681e7f16d8274918c1ce207591f04fed351649e97c0"
checksum = "34bfbd243503d64aed4fc8a194657a561cae6c2d782dbcf649211d7f4db9e413"
dependencies = [
"libc",
"thiserror",
@ -4056,9 +3981,9 @@ dependencies = [
[[package]]
name = "wasmer-vm"
version = "2.3.0"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30d965fa61f4dc4cdb35a54daaf7ecec3563fbb94154a6c35433f879466247dd"
checksum = "9fc68a7f0a003e6cb63845b7510065097d289553201d64afb9a5e1744da3c6a0"
dependencies = [
"backtrace",
"cc",
@ -4068,27 +3993,36 @@ dependencies = [
"indexmap",
"lazy_static",
"libc",
"loupe",
"mach",
"memoffset",
"more-asserts",
"region",
"rkyv",
"scopeguard",
"serde",
"thiserror",
"wasmer-artifact",
"wasmer-types",
"winapi",
]
[[package]]
name = "wasmer-wasi"
version = "2.3.0"
name = "wasmer-vnet"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fadbe31e3c1b6f3e398ad172b169152ae1a743ae6efd5f9ffb34019983319d99"
checksum = "9bc4fe3b48ccc620901bdcdfac98d8a76ef3487412c221752814750c2e7db4c1"
dependencies = [
"bytes",
"thiserror",
"wasmer-vfs",
]
[[package]]
name = "wasmer-wasi"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e893ecd57c63db83b17dacfaee90f660e1d7f5b26d2f9d88ea6aa2e8c4bc301d"
dependencies = [
"bytes",
"cfg-if 1.0.0",
"derivative",
"generational-arena",
"getrandom 0.2.7",
"libc",
@ -4096,20 +4030,108 @@ dependencies = [
"tracing",
"wasm-bindgen",
"wasmer",
"wasmer-vbus",
"wasmer-vfs",
"wasmer-vnet",
"wasmer-wasi-local-networking",
"wasmer-wasi-types",
"winapi",
]
[[package]]
name = "wasmer-wasi-types"
version = "2.3.0"
name = "wasmer-wasi-local-networking"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22dc83aadbdf97388de3211cb6f105374f245a3cf2a5c65a16776e7a087a8468"
checksum = "bd65882d8cee793848776f26e979b7ff3e139d927947d87304c940c89527a730"
dependencies = [
"bytes",
"tracing",
"wasmer-vfs",
"wasmer-vnet",
]
[[package]]
name = "wasmer-wasi-types"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1afdec83c62d22bf7110b83d662a08f708332fd728a213399919a045a1061d4"
dependencies = [
"byteorder",
"time 0.2.27",
"wasmer",
"wasmer-derive",
"wasmer-types",
"wasmer-wit-bindgen-gen-core",
"wasmer-wit-bindgen-gen-rust-wasm",
"wasmer-wit-bindgen-rust",
"wasmer-wit-parser",
]
[[package]]
name = "wasmer-wit-bindgen-gen-core"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff8aa5be5ae5d61f5e151dc2c0e603093fe28395d2083b65ef7a3547844054fe"
dependencies = [
"anyhow",
"wasmer-wit-parser",
]
[[package]]
name = "wasmer-wit-bindgen-gen-rust"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "438bce7c4589842bf100cc9b312443a9b5fc6440e58ab0b8c114e460219c3c3b"
dependencies = [
"heck 0.3.3",
"wasmer-wit-bindgen-gen-core",
]
[[package]]
name = "wasmer-wit-bindgen-gen-rust-wasm"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "505f5168cfee591840e13e158a5c5e2f95d6df1df710839021564f36bee7bafc"
dependencies = [
"heck 0.3.3",
"wasmer-wit-bindgen-gen-core",
"wasmer-wit-bindgen-gen-rust",
]
[[package]]
name = "wasmer-wit-bindgen-rust"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "968747f1271f74aab9b70d9c5d4921db9bd13b4ec3ba5506506e6e7dc58c918c"
dependencies = [
"async-trait",
"bitflags",
"wasmer-wit-bindgen-rust-impl",
]
[[package]]
name = "wasmer-wit-bindgen-rust-impl"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd26fe00d08bd2119870b017d13413dfbd51e7750b6634d649fc7a7bbc057b85"
dependencies = [
"proc-macro2",
"syn 1.0.96",
"wasmer-wit-bindgen-gen-core",
"wasmer-wit-bindgen-gen-rust-wasm",
]
[[package]]
name = "wasmer-wit-parser"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f46c9a15086be8a2eb3790613902b9d3a9a687833b17cd021de263a20378585a"
dependencies = [
"anyhow",
"id-arena",
"pulldown-cmark",
"unicode-normalization",
"unicode-xid",
]
[[package]]

View file

@ -18,8 +18,8 @@ daemonize = "0.4.1"
serde_json = "1.0"
unicode-width = "0.1.8"
url = "2.2.2"
wasmer = "2.3.0"
wasmer-wasi = "2.3.0"
wasmer = "3.1.1"
wasmer-wasi = "3.1.1"
cassowary = "0.3.0"
zellij-utils = { path = "../zellij-utils/", version = "0.39.0" }
log = "0.4.17"
@ -36,7 +36,7 @@ semver = "0.11.0"
[dev-dependencies]
insta = "1.6.0"
tempfile = "3.2.0"
wasmer = { version = "2.3.0", features = [ "singlepass" ] }
wasmer = { version = "3.1.1", features = ["singlepass"] }
[features]
singlepass = ["wasmer/singlepass"]

View file

@ -911,11 +911,11 @@ fn init_session(
#[cfg(not(feature = "singlepass"))]
fn get_store() -> Store {
log::info!("Compiling plugins using Cranelift");
Store::new(&wasmer::Universal::new(wasmer::Cranelift::default()).engine())
Store::new(wasmer::Cranelift::default())
}
#[cfg(feature = "singlepass")]
fn get_store() -> Store {
log::info!("Compiling plugins using Singlepass");
Store::new(&wasmer::Universal::new(wasmer::Singlepass::default()).engine())
Store::new(wasmer::Singlepass::default())
}

View file

@ -9,6 +9,8 @@ use std::{
collections::{HashMap, HashSet},
fs,
path::PathBuf,
sync::{Arc, Mutex},
time::Duration,
};
use wasmer::Store;
@ -19,6 +21,7 @@ use crate::{pty::PtyInstruction, thread_bus::Bus, ClientId, ServerInstruction};
use wasm_bridge::WasmBridge;
use zellij_utils::{
async_std::{channel, future::timeout, task},
data::{Event, EventType, PermissionStatus, PermissionType, PluginCapabilities},
errors::{prelude::*, ContextType, PluginContext},
input::{
@ -142,6 +145,12 @@ pub(crate) fn plugin_thread_main(
let plugin_dir = data_dir.join("plugins/");
let plugin_global_data_dir = plugin_dir.join("data");
let store = Arc::new(Mutex::new(store));
// use this channel to ensure that tasks spawned from this thread terminate before exiting
// https://tokio.rs/tokio/topics/shutdown#waiting-for-things-to-finish-shutting-down
let (shutdown_send, shutdown_receive) = channel::bounded::<()>(1);
let mut wasm_bridge = WasmBridge::new(
plugins,
bus.senders.clone(),
@ -186,7 +195,7 @@ pub(crate) fn plugin_thread_main(
},
},
PluginInstruction::Update(updates) => {
wasm_bridge.update_plugins(updates)?;
wasm_bridge.update_plugins(updates, shutdown_send.clone())?;
},
PluginInstruction::Unload(pid) => {
wasm_bridge.unload_plugin(pid)?;
@ -229,7 +238,7 @@ pub(crate) fn plugin_thread_main(
}
},
PluginInstruction::Resize(pid, new_columns, new_rows) => {
wasm_bridge.resize_plugin(pid, new_columns, new_rows)?;
wasm_bridge.resize_plugin(pid, new_columns, new_rows, shutdown_send.clone())?;
},
PluginInstruction::AddClient(client_id) => {
wasm_bridge.add_client(client_id)?;
@ -286,7 +295,7 @@ pub(crate) fn plugin_thread_main(
)));
},
PluginInstruction::ApplyCachedEvents(plugin_id) => {
wasm_bridge.apply_cached_events(plugin_id)?;
wasm_bridge.apply_cached_events(plugin_id, shutdown_send.clone())?;
},
PluginInstruction::ApplyCachedWorkerMessages(plugin_id) => {
wasm_bridge.apply_cached_worker_messages(plugin_id)?;
@ -310,7 +319,7 @@ pub(crate) fn plugin_thread_main(
Some(client_id),
Event::CustomMessage(message, payload),
)];
wasm_bridge.update_plugins(updates)?;
wasm_bridge.update_plugins(updates, shutdown_send.clone())?;
},
PluginInstruction::PluginSubscribedToEvents(_plugin_id, _client_id, events) => {
for event in events {
@ -345,16 +354,28 @@ pub(crate) fn plugin_thread_main(
client_id,
Event::PermissionRequestResult(status),
)];
wasm_bridge.update_plugins(updates)?;
wasm_bridge.update_plugins(updates, shutdown_send.clone())?;
},
PluginInstruction::Exit => {
wasm_bridge.cleanup();
break;
},
}
}
info!("wasm main thread exits");
// first drop our sender, then call recv.
// once all senders are dropped or the timeout is reached, recv will return an error, that we ignore
drop(shutdown_send);
task::block_on(async {
let result = timeout(EXIT_TIMEOUT, shutdown_receive.recv()).await;
if let Err(err) = result {
log::error!("timeout waiting for plugin tasks to finish: {}", err);
}
});
wasm_bridge.cleanup();
fs::remove_dir_all(&plugin_global_data_dir)
.or_else(|err| {
if err.kind() == std::io::ErrorKind::NotFound {
@ -367,6 +388,8 @@ pub(crate) fn plugin_thread_main(
.context("failed to cleanup plugin data directory")
}
const EXIT_TIMEOUT: Duration = Duration::from_secs(3);
#[path = "./unit/plugin_tests.rs"]
#[cfg(test)]
mod plugin_tests;

View file

@ -1,3 +1,4 @@
use crate::get_store;
use crate::plugins::plugin_map::{PluginEnv, PluginMap, RunningPlugin, Subscriptions};
use crate::plugins::plugin_worker::{plugin_worker, RunningWorker};
use crate::plugins::zellij_exports::{wasi_write_object, zellij_exports};
@ -11,7 +12,7 @@ use std::{
sync::{Arc, Mutex},
};
use url::Url;
use wasmer::{ChainableNamedResolver, Instance, Module, Store};
use wasmer::{AsStoreRef, Instance, Module, Store};
use wasmer_wasi::{Pipe, WasiState};
use zellij_utils::prost::Message;
@ -51,7 +52,7 @@ pub struct PluginLoader<'a> {
senders: ThreadSenders,
plugin_id: PluginId,
client_id: ClientId,
store: Store,
store: Arc<Mutex<Store>>,
plugin: PluginConfig,
plugin_dir: &'a PathBuf,
tab_index: usize,
@ -72,7 +73,7 @@ impl<'a> PluginLoader<'a> {
plugin_dir: PathBuf,
plugin_cache: Arc<Mutex<HashMap<PathBuf, Module>>>,
senders: ThreadSenders,
store: Store,
store: Arc<Mutex<Store>>,
plugin_map: Arc<Mutex<PluginMap>>,
connected_clients: Arc<Mutex<Vec<ClientId>>>,
loading_indication: &mut LoadingIndication,
@ -98,7 +99,7 @@ impl<'a> PluginLoader<'a> {
&senders,
plugin_id,
first_client_id,
&store,
store,
&plugin_dir,
path_to_default_shell,
zellij_cwd,
@ -110,8 +111,9 @@ impl<'a> PluginLoader<'a> {
plugin_loader
.load_module_from_memory()
.and_then(|module| plugin_loader.create_plugin_environment(module))
.and_then(|(instance, plugin_env, subscriptions)| {
.and_then(|(store, instance, plugin_env, subscriptions)| {
plugin_loader.load_plugin_instance(
store,
&instance,
&plugin_env,
&plugin_map,
@ -134,7 +136,7 @@ impl<'a> PluginLoader<'a> {
plugin_dir: PathBuf,
plugin_cache: Arc<Mutex<HashMap<PathBuf, Module>>>,
senders: ThreadSenders,
store: Store,
store: Arc<Mutex<Store>>,
plugin_map: Arc<Mutex<PluginMap>>,
size: Size,
connected_clients: Arc<Mutex<Vec<ClientId>>>,
@ -153,7 +155,7 @@ impl<'a> PluginLoader<'a> {
&senders,
plugin_id,
client_id,
&store,
store.clone(),
plugin.clone(),
&plugin_dir,
tab_index,
@ -170,8 +172,9 @@ impl<'a> PluginLoader<'a> {
.or_else(|_e| plugin_loader.load_module_from_hd_cache())
.or_else(|_e| plugin_loader.compile_module())
.and_then(|module| plugin_loader.create_plugin_environment(module))
.and_then(|(instance, plugin_env, subscriptions)| {
.and_then(|(store, instance, plugin_env, subscriptions)| {
plugin_loader.load_plugin_instance(
store,
&instance,
&plugin_env,
&plugin_map,
@ -194,7 +197,7 @@ impl<'a> PluginLoader<'a> {
plugin_dir: PathBuf,
plugin_cache: Arc<Mutex<HashMap<PathBuf, Module>>>,
senders: ThreadSenders,
store: Store,
store: Arc<Mutex<Store>>,
plugin_map: Arc<Mutex<PluginMap>>,
connected_clients: Arc<Mutex<Vec<ClientId>>>,
loading_indication: &mut LoadingIndication,
@ -217,7 +220,7 @@ impl<'a> PluginLoader<'a> {
&senders,
plugin_id,
existing_client_id,
&store,
store.clone(),
&plugin_dir,
path_to_default_shell.clone(),
zellij_cwd.clone(),
@ -229,8 +232,9 @@ impl<'a> PluginLoader<'a> {
plugin_loader
.load_module_from_memory()
.and_then(|module| plugin_loader.create_plugin_environment(module))
.and_then(|(instance, plugin_env, subscriptions)| {
.and_then(|(store, instance, plugin_env, subscriptions)| {
plugin_loader.load_plugin_instance(
store,
&instance,
&plugin_env,
&plugin_map,
@ -247,7 +251,7 @@ impl<'a> PluginLoader<'a> {
plugin_dir: PathBuf,
plugin_cache: Arc<Mutex<HashMap<PathBuf, Module>>>,
senders: ThreadSenders,
store: Store,
store: Arc<Mutex<Store>>,
plugin_map: Arc<Mutex<PluginMap>>,
connected_clients: Arc<Mutex<Vec<ClientId>>>,
loading_indication: &mut LoadingIndication,
@ -274,7 +278,7 @@ impl<'a> PluginLoader<'a> {
&senders,
plugin_id,
first_client_id,
&store,
store.clone(),
&plugin_dir,
path_to_default_shell,
zellij_cwd,
@ -286,8 +290,9 @@ impl<'a> PluginLoader<'a> {
plugin_loader
.compile_module()
.and_then(|module| plugin_loader.create_plugin_environment(module))
.and_then(|(instance, plugin_env, subscriptions)| {
.and_then(|(store, instance, plugin_env, subscriptions)| {
plugin_loader.load_plugin_instance(
store,
&instance,
&plugin_env,
&plugin_map,
@ -307,7 +312,7 @@ impl<'a> PluginLoader<'a> {
senders: &ThreadSenders,
plugin_id: PluginId,
client_id: ClientId,
store: &Store,
store: Arc<Mutex<Store>>,
plugin: PluginConfig,
plugin_dir: &'a PathBuf,
tab_index: usize,
@ -353,7 +358,7 @@ impl<'a> PluginLoader<'a> {
senders: &ThreadSenders,
plugin_id: PluginId,
client_id: ClientId,
store: &Store,
store: Arc<Mutex<Store>>,
plugin_dir: &'a PathBuf,
path_to_default_shell: PathBuf,
zellij_cwd: PathBuf,
@ -403,7 +408,7 @@ impl<'a> PluginLoader<'a> {
senders: &ThreadSenders,
plugin_id: PluginId,
client_id: ClientId,
store: &Store,
store: Arc<Mutex<Store>>,
plugin_dir: &'a PathBuf,
path_to_default_shell: PathBuf,
zellij_cwd: PathBuf,
@ -434,7 +439,7 @@ impl<'a> PluginLoader<'a> {
senders,
plugin_id,
client_id,
store,
store.clone(),
plugin_config,
plugin_dir,
tab_index,
@ -483,7 +488,9 @@ impl<'a> PluginLoader<'a> {
);
let (_wasm_bytes, cached_path) = self.plugin_bytes_and_cache_path()?;
let timer = std::time::Instant::now();
let module = unsafe { Module::deserialize_from_file(&self.store, &cached_path)? };
let module = unsafe {
Module::deserialize_from_file(&self.store.lock().unwrap().as_store_ref(), &cached_path)?
};
log::info!(
"Loaded plugin '{}' from cache folder at '{}' in {:?}",
self.plugin_path.display(),
@ -518,7 +525,8 @@ impl<'a> PluginLoader<'a> {
.map_err(anyError::new)
.and_then(|_| {
// compile module
Module::new(&self.store, &wasm_bytes).map_err(anyError::new)
Module::new(&self.store.lock().unwrap().as_store_ref(), &wasm_bytes)
.map_err(anyError::new)
})
.and_then(|m| {
// serialize module to HD cache for faster loading in the future
@ -536,8 +544,8 @@ impl<'a> PluginLoader<'a> {
pub fn create_plugin_environment(
&mut self,
module: Module,
) -> Result<(Instance, PluginEnv, Arc<Mutex<Subscriptions>>)> {
let (instance, plugin_env, subscriptions) =
) -> Result<(Store, Instance, PluginEnv, Arc<Mutex<Subscriptions>>)> {
let (store, instance, plugin_env, subscriptions) =
self.create_plugin_instance_env_and_subscriptions(&module)?;
// Only do an insert when everything went well!
let cloned_plugin = self.plugin.clone();
@ -545,11 +553,11 @@ impl<'a> PluginLoader<'a> {
.lock()
.unwrap()
.insert(cloned_plugin.path, module);
Ok((instance, plugin_env, subscriptions))
Ok((store, instance, plugin_env, subscriptions))
}
pub fn create_plugin_instance_and_wasi_env_for_worker(
&mut self,
) -> Result<(Instance, PluginEnv)> {
) -> Result<(Store, Instance, PluginEnv)> {
let err_context = || {
format!(
"Failed to create instance and plugin env for worker {}",
@ -563,12 +571,13 @@ impl<'a> PluginLoader<'a> {
.get(&self.plugin.path)
.with_context(err_context)?
.clone();
let (instance, plugin_env, _subscriptions) =
let (store, instance, plugin_env, _subscriptions) =
self.create_plugin_instance_env_and_subscriptions(&module)?;
Ok((instance, plugin_env))
Ok((store, instance, plugin_env))
}
pub fn load_plugin_instance(
&mut self,
store: Store,
instance: &Instance,
plugin_env: &PluginEnv,
plugin_map: &Arc<Mutex<PluginMap>>,
@ -595,7 +604,7 @@ impl<'a> PluginLoader<'a> {
for (function_name, _exported_function) in instance.exports.iter().functions() {
if function_name.ends_with("_worker") {
let plugin_config = self.plugin.clone();
let (instance, plugin_env) =
let (mut store, instance, plugin_env) =
self.create_plugin_instance_and_wasi_env_for_worker()?;
let start_function_for_worker = instance
@ -603,30 +612,35 @@ impl<'a> PluginLoader<'a> {
.get_function("_start")
.with_context(err_context)?;
start_function_for_worker
.call(&[])
.call(&mut store, &[])
.with_context(err_context)?;
let worker =
RunningWorker::new(instance, &function_name, plugin_config, plugin_env);
RunningWorker::new(store, instance, &function_name, plugin_config, plugin_env);
let worker_sender = plugin_worker(worker);
workers.insert(function_name.into(), worker_sender);
}
}
start_function.call(&[]).with_context(err_context)?;
plugin_map.lock().unwrap().insert(
self.plugin_id,
self.client_id,
Arc::new(Mutex::new(RunningPlugin::new(
let plugin = Arc::new(Mutex::new(RunningPlugin::new(
store,
main_user_instance,
main_user_env,
self.size.rows,
self.size.cols,
))),
)));
plugin_map.lock().unwrap().insert(
self.plugin_id,
self.client_id,
plugin.clone(),
subscriptions.clone(),
workers,
);
start_function
.call(&mut plugin.lock().unwrap().store, &[])
.with_context(err_context)?;
let protobuf_plugin_configuration: ProtobufPluginConfiguration = self
.plugin
.userspace_configuration
@ -640,7 +654,9 @@ impl<'a> PluginLoader<'a> {
// &self.plugin.userspace_configuration.inner(),
)
.with_context(err_context)?;
load_function.call(&[]).with_context(err_context)?;
load_function
.call(&mut plugin.lock().unwrap().store, &[])
.with_context(err_context)?;
display_loading_stage!(
indicate_starting_plugin_success,
@ -660,6 +676,7 @@ impl<'a> PluginLoader<'a> {
self.senders,
self.plugin_id
);
Ok(())
}
pub fn clone_instance_for_other_clients(
@ -687,7 +704,7 @@ impl<'a> PluginLoader<'a> {
&self.senders.clone(),
self.plugin_id,
*client_id,
&self.store,
self.store.clone(),
&self.plugin_dir,
self.path_to_default_shell.clone(),
self.zellij_cwd.clone(),
@ -699,8 +716,9 @@ impl<'a> PluginLoader<'a> {
plugin_loader_for_client
.load_module_from_memory()
.and_then(|module| plugin_loader_for_client.create_plugin_environment(module))
.and_then(|(instance, plugin_env, subscriptions)| {
.and_then(|(store, instance, plugin_env, subscriptions)| {
plugin_loader_for_client.load_plugin_instance(
store,
&instance,
&plugin_env,
plugin_map,
@ -743,13 +761,15 @@ impl<'a> PluginLoader<'a> {
fn create_plugin_instance_env_and_subscriptions(
&self,
module: &Module,
) -> Result<(Instance, PluginEnv, Arc<Mutex<Subscriptions>>)> {
) -> Result<(Store, Instance, PluginEnv, Arc<Mutex<Subscriptions>>)> {
let err_context = || {
format!(
"Failed to create instance, plugin env and subscriptions for plugin {}",
self.plugin_id
)
};
let mut store = get_store();
let store_mut = &mut store;
let mut wasi_env = WasiState::new("Zellij")
.env("CLICOLOR_FORCE", "1")
.map_dir("/host", self.zellij_cwd.clone())
@ -762,10 +782,12 @@ impl<'a> PluginLoader<'a> {
&self.plugin.location.to_string(),
self.plugin_id,
)))
.finalize()
.finalize(store_mut)
})
.with_context(err_context)?;
let wasi = wasi_env.import_object(&module).with_context(err_context)?;
let wasi = wasi_env
.import_object(store_mut, &module)
.with_context(err_context)?;
let mut mut_plugin = self.plugin.clone();
mut_plugin.set_tab_index(self.tab_index);
let plugin_env = PluginEnv {
@ -774,7 +796,7 @@ impl<'a> PluginLoader<'a> {
plugin: mut_plugin,
permissions: Arc::new(Mutex::new(None)),
senders: self.senders.clone(),
wasi_env,
wasi_env: wasi_env.data_mut(store_mut).clone(),
plugin_own_data_dir: self.plugin_own_data_dir.clone(),
tab_index: self.tab_index,
path_to_default_shell: self.path_to_default_shell.clone(),
@ -785,10 +807,15 @@ impl<'a> PluginLoader<'a> {
};
let subscriptions = Arc::new(Mutex::new(HashSet::new()));
let zellij = zellij_exports(&self.store, &plugin_env, &subscriptions);
let instance =
Instance::new(&module, &zellij.chain_back(wasi)).with_context(err_context)?;
Ok((instance, plugin_env, subscriptions))
let mut zellij = zellij_exports(store_mut, &plugin_env, &subscriptions);
zellij.extend(&wasi);
let instance = Instance::new(store_mut, &module, &zellij).with_context(err_context)?;
wasi_env.initialize(store_mut, &instance)?;
Ok((store, instance, plugin_env, subscriptions))
}
}

View file

@ -5,7 +5,7 @@ use std::{
path::PathBuf,
sync::{Arc, Mutex},
};
use wasmer::Instance;
use wasmer::{Instance, Store};
use wasmer_wasi::WasiEnv;
use crate::{thread_bus::ThreadSenders, ClientId};
@ -228,6 +228,7 @@ pub enum AtomicEvent {
}
pub struct RunningPlugin {
pub store: Store,
pub instance: Instance,
pub plugin_env: PluginEnv,
pub rows: usize,
@ -237,8 +238,15 @@ pub struct RunningPlugin {
}
impl RunningPlugin {
pub fn new(instance: Instance, plugin_env: PluginEnv, rows: usize, columns: usize) -> Self {
pub fn new(
store: Store,
instance: Instance,
plugin_env: PluginEnv,
rows: usize,
columns: usize,
) -> Self {
RunningPlugin {
store,
instance,
plugin_env,
rows,

View file

@ -1,6 +1,6 @@
use crate::plugins::plugin_map::PluginEnv;
use crate::plugins::zellij_exports::wasi_write_object;
use wasmer::Instance;
use wasmer::{Instance, Store};
use zellij_utils::async_channel::{unbounded, Receiver, Sender};
use zellij_utils::async_std::task;
@ -14,23 +14,26 @@ pub struct RunningWorker {
pub name: String,
pub plugin_config: PluginConfig,
pub plugin_env: PluginEnv,
store: Store,
}
impl RunningWorker {
pub fn new(
store: Store,
instance: Instance,
name: &str,
plugin_config: PluginConfig,
plugin_env: PluginEnv,
) -> Self {
RunningWorker {
store,
instance,
name: name.into(),
plugin_config,
plugin_env,
}
}
pub fn send_message(&self, message: String, payload: String) -> Result<()> {
pub fn send_message(&mut self, message: String, payload: String) -> Result<()> {
let err_context = || format!("Failed to send message to worker");
let protobuf_message = ProtobufMessage {
name: message,
@ -44,7 +47,9 @@ impl RunningWorker {
.get_function(&self.name)
.with_context(err_context)?;
wasi_write_object(&self.plugin_env.wasi_env, &protobuf_bytes).with_context(err_context)?;
work_function.call(&[]).with_context(err_context)?;
work_function
.call(&mut self.store, &[])
.with_context(err_context)?;
Ok(())
}
}
@ -54,7 +59,7 @@ pub enum MessageToWorker {
Exit,
}
pub fn plugin_worker(worker: RunningWorker) -> Sender<MessageToWorker> {
pub fn plugin_worker(mut worker: RunningWorker) -> Sender<MessageToWorker> {
let (sender, receiver): (Sender<MessageToWorker>, Receiver<MessageToWorker>) = unbounded();
task::spawn({
async move {

File diff suppressed because it is too large Load diff

View file

@ -11,7 +11,8 @@ use std::{
str::FromStr,
sync::{Arc, Mutex},
};
use wasmer::{Instance, Module, Store, Value};
use wasmer::{Module, Store, Value};
use zellij_utils::async_channel::Sender;
use zellij_utils::async_std::task::{self, JoinHandle};
use zellij_utils::data::{PermissionStatus, PermissionType};
use zellij_utils::input::permission::PermissionCache;
@ -40,7 +41,7 @@ pub struct WasmBridge {
connected_clients: Arc<Mutex<Vec<ClientId>>>,
plugins: PluginsConfig,
senders: ThreadSenders,
store: Store,
store: Arc<Mutex<Store>>,
plugin_dir: PathBuf,
plugin_cache: Arc<Mutex<HashMap<PathBuf, Module>>>,
plugin_map: Arc<Mutex<PluginMap>>,
@ -66,7 +67,7 @@ impl WasmBridge {
pub fn new(
plugins: PluginsConfig,
senders: ThreadSenders,
store: Store,
store: Arc<Mutex<Store>>,
plugin_dir: PathBuf,
path_to_default_shell: PathBuf,
zellij_cwd: PathBuf,
@ -342,6 +343,7 @@ impl WasmBridge {
pid: PluginId,
new_columns: usize,
new_rows: usize,
shutdown_sender: Sender<()>,
) -> Result<()> {
let err_context = move || format!("failed to resize plugin {pid}");
@ -369,22 +371,29 @@ impl WasmBridge {
let running_plugin = running_plugin.clone();
let plugin_id = plugin_id;
let client_id = client_id;
let _s = shutdown_sender.clone();
async move {
let mut running_plugin = running_plugin.lock().unwrap();
let _s = _s; // guard to allow the task to complete before cleanup/shutdown
if running_plugin.apply_event_id(AtomicEvent::Resize, event_id) {
running_plugin.rows = new_rows;
running_plugin.columns = new_columns;
let rendered_bytes = running_plugin
.instance
.clone()
.exports
.get_function("render")
.map_err(anyError::new)
.and_then(|render| {
render
.call(&[
Value::I32(running_plugin.rows as i32),
Value::I32(running_plugin.columns as i32),
])
.call(
&mut running_plugin.store,
&[
Value::I32(new_rows as i32),
Value::I32(new_columns as i32),
],
)
.map_err(anyError::new)
})
.and_then(|_| wasi_read_string(&running_plugin.plugin_env.wasi_env))
@ -420,6 +429,7 @@ impl WasmBridge {
pub fn update_plugins(
&mut self,
mut updates: Vec<(Option<PluginId>, Option<ClientId>, Event)>,
shutdown_sender: Sender<()>,
) -> Result<()> {
let err_context = || "failed to update plugin state".to_string();
@ -459,17 +469,16 @@ impl WasmBridge {
let event = event.clone();
let plugin_id = *plugin_id;
let client_id = *client_id;
let _s = shutdown_sender.clone();
async move {
let running_plugin = running_plugin.lock().unwrap();
let mut running_plugin = running_plugin.lock().unwrap();
let mut plugin_bytes = vec![];
let _s = _s; // guard to allow the task to complete before cleanup/shutdown
match apply_event_to_plugin(
plugin_id,
client_id,
&running_plugin.instance,
&running_plugin.plugin_env,
&mut running_plugin,
&event,
running_plugin.rows,
running_plugin.columns,
&mut plugin_bytes,
) {
Ok(()) => {
@ -503,10 +512,14 @@ impl WasmBridge {
}
Ok(())
}
pub fn apply_cached_events(&mut self, plugin_ids: Vec<PluginId>) -> Result<()> {
pub fn apply_cached_events(
&mut self,
plugin_ids: Vec<PluginId>,
shutdown_sender: Sender<()>,
) -> Result<()> {
let mut applied_plugin_paths = HashSet::new();
for plugin_id in plugin_ids {
self.apply_cached_events_and_resizes_for_plugin(plugin_id)?;
self.apply_cached_events_and_resizes_for_plugin(plugin_id, shutdown_sender.clone())?;
if let Some(run_plugin) = self.run_plugin_of_plugin_id(plugin_id) {
applied_plugin_paths.insert(run_plugin.clone());
}
@ -544,7 +557,11 @@ impl WasmBridge {
.find(|((p_id, _run_plugin), _)| p_id == &plugin_id)
.map(|((_p_id, run_plugin), _)| run_plugin)
}
fn apply_cached_events_and_resizes_for_plugin(&mut self, plugin_id: PluginId) -> Result<()> {
fn apply_cached_events_and_resizes_for_plugin(
&mut self,
plugin_id: PluginId,
shutdown_sender: Sender<()>,
) -> Result<()> {
let err_context = || format!("Failed to apply cached events to plugin");
if let Some(events) = self.cached_events_for_pending_plugins.remove(&plugin_id) {
let all_connected_clients: Vec<ClientId> = self
@ -572,17 +589,16 @@ impl WasmBridge {
let senders = self.senders.clone();
let running_plugin = running_plugin.clone();
let client_id = *client_id;
let _s = shutdown_sender.clone();
async move {
let running_plugin = running_plugin.lock().unwrap();
let mut running_plugin = running_plugin.lock().unwrap();
let mut plugin_bytes = vec![];
let _s = _s; // guard to allow the task to complete before cleanup/shutdown
match apply_event_to_plugin(
plugin_id,
client_id,
&running_plugin.instance,
&running_plugin.plugin_env,
&mut running_plugin,
&event,
running_plugin.rows,
running_plugin.columns,
&mut plugin_bytes,
) {
Ok(()) => {
@ -601,7 +617,7 @@ impl WasmBridge {
}
}
if let Some((rows, columns)) = self.cached_resizes_for_pending_plugins.remove(&plugin_id) {
self.resize_plugin(plugin_id, columns, rows)?;
self.resize_plugin(plugin_id, columns, rows, shutdown_sender.clone())?;
}
self.apply_cached_worker_messages(plugin_id)?;
Ok(())
@ -716,15 +732,17 @@ impl WasmBridge {
status: PermissionStatus,
cache_path: Option<PathBuf>,
) -> Result<()> {
if let Some(running_plugin) = self
let err_context = || format!("Failed to write plugin permission {plugin_id}");
let running_plugin = self
.plugin_map
.lock()
.unwrap()
.get_running_plugin(plugin_id, client_id)
{
let err_context = || format!("Failed to write plugin permission {plugin_id}");
.ok_or_else(|| anyhow!("Failed to get running plugin"))?;
let mut running_plugin = running_plugin.lock().unwrap();
let permissions = if status == PermissionStatus::Granted {
permissions
} else {
@ -741,10 +759,7 @@ impl WasmBridge {
permissions,
);
permission_cache.write_to_file().with_context(err_context)?;
}
Ok(())
permission_cache.write_to_file().with_context(err_context)
}
}
@ -801,13 +816,15 @@ fn check_event_permission(
pub fn apply_event_to_plugin(
plugin_id: PluginId,
client_id: ClientId,
instance: &Instance,
plugin_env: &PluginEnv,
running_plugin: &mut RunningPlugin,
event: &Event,
rows: usize,
columns: usize,
plugin_bytes: &mut Vec<(PluginId, ClientId, Vec<u8>)>,
) -> Result<()> {
let instance = &running_plugin.instance;
let plugin_env = &running_plugin.plugin_env;
let rows = running_plugin.rows;
let columns = running_plugin.columns;
let err_context = || format!("Failed to apply event to plugin {plugin_id}");
match check_event_permission(plugin_env, event) {
(PermissionStatus::Granted, _) => {
@ -821,7 +838,9 @@ pub fn apply_event_to_plugin(
.with_context(err_context)?;
wasi_write_object(&plugin_env.wasi_env, &protobuf_event.encode_to_vec())
.with_context(err_context)?;
let update_return = update.call(&[]).with_context(err_context)?;
let update_return = update
.call(&mut running_plugin.store, &[])
.with_context(err_context)?;
let mut should_render = match update_return.get(0) {
Some(Value::I32(n)) => *n == 1,
_ => false,
@ -838,7 +857,10 @@ pub fn apply_event_to_plugin(
.map_err(anyError::new)
.and_then(|render| {
render
.call(&[Value::I32(rows as i32), Value::I32(columns as i32)])
.call(
&mut running_plugin.store,
&[Value::I32(rows as i32), Value::I32(columns as i32)],
)
.map_err(anyError::new)
})
.and_then(|_| wasi_read_string(&plugin_env.wasi_env))

View file

@ -14,7 +14,7 @@ use std::{
thread,
time::{Duration, Instant},
};
use wasmer::{imports, Function, ImportObject, Store, WasmerEnv};
use wasmer::{imports, AsStoreMut, Function, FunctionEnv, FunctionEnvMut, Imports};
use wasmer_wasi::WasiEnv;
use zellij_utils::data::{
CommandType, ConnectToSession, PermissionStatus, PermissionType, PluginPermission,
@ -64,20 +64,21 @@ macro_rules! apply_action {
}
pub fn zellij_exports(
store: &Store,
store: &mut impl AsStoreMut,
plugin_env: &PluginEnv,
subscriptions: &Arc<Mutex<Subscriptions>>,
) -> ImportObject {
) -> Imports {
let function_env = FunctionEnv::new(store, ForeignFunctionEnv::new(plugin_env, subscriptions));
imports! {
"zellij" => {
"host_run_plugin_command" => {
Function::new_native_with_env(store, ForeignFunctionEnv::new(plugin_env, subscriptions), host_run_plugin_command)
Function::new_typed_with_env(store, &function_env, host_run_plugin_command)
}
}
}
}
#[derive(WasmerEnv, Clone)]
#[derive(Clone)]
pub struct ForeignFunctionEnv {
pub plugin_env: PluginEnv,
pub subscriptions: Arc<Mutex<Subscriptions>>,
@ -92,7 +93,8 @@ impl ForeignFunctionEnv {
}
}
fn host_run_plugin_command(env: &ForeignFunctionEnv) {
fn host_run_plugin_command(env: FunctionEnvMut<ForeignFunctionEnv>) {
let env = env.data();
let err_context = || format!("failed to run plugin command {}", env.plugin_env.name());
wasi_read_bytes(&env.plugin_env.wasi_env)
.and_then(|bytes| {
@ -1102,17 +1104,13 @@ pub fn wasi_read_string(wasi_env: &WasiEnv) -> Result<String> {
let mut buf = vec![];
wasi_env
.state()
.fs
.stdout_mut()
.stdout()
.map_err(anyError::new)
.and_then(|stdout| {
stdout
.as_mut()
.ok_or(anyhow!("failed to get mutable reference to stdout"))
})
.and_then(|wasi_file| wasi_file.read_to_end(&mut buf).map_err(anyError::new))
.and_then(|stdout| stdout.ok_or(anyhow!("failed to get mutable reference to stdout")))
.and_then(|mut wasi_file| wasi_file.read_to_end(&mut buf).map_err(anyError::new))
.with_context(err_context)?;
let buf = String::from_utf8_lossy(&buf);
// https://stackoverflow.com/questions/66450942/in-rust-is-there-a-way-to-make-literal-newlines-in-r-using-windows-c
Ok(buf.replace("\n", "\n\r"))
}
@ -1120,15 +1118,10 @@ pub fn wasi_read_string(wasi_env: &WasiEnv) -> Result<String> {
pub fn wasi_write_string(wasi_env: &WasiEnv, buf: &str) -> Result<()> {
wasi_env
.state()
.fs
.stdin_mut()
.stdin()
.map_err(anyError::new)
.and_then(|stdin| {
stdin
.as_mut()
.ok_or(anyhow!("failed to get mutable reference to stdin"))
})
.and_then(|stdin| writeln!(stdin, "{}\r", buf).map_err(anyError::new))
.and_then(|stdin| stdin.ok_or(anyhow!("failed to get mutable reference to stdin")))
.and_then(|mut stdin| writeln!(stdin, "{}\r", buf).map_err(anyError::new))
.with_context(|| format!("failed to write string to WASI env '{wasi_env:?}'"))
}