From 66cd03cdca8fa3e36ceffbf93cb49b6035c961d8 Mon Sep 17 00:00:00 2001 From: Zhang Tianyang Date: Sat, 3 Aug 2024 19:15:11 +0800 Subject: [PATCH] wasm: support new sandbox controller api and flag parser Signed-off-by: Zhang Tianyang --- wasm/Cargo.lock | 446 ++++++++++++++++++++++++++++++++++++++------ wasm/Cargo.toml | 16 +- wasm/build.rs | 23 +++ wasm/src/args.rs | 59 ++++++ wasm/src/main.rs | 39 +++- wasm/src/sandbox.rs | 10 +- wasm/src/version.rs | 29 +++ 7 files changed, 549 insertions(+), 73 deletions(-) create mode 100644 wasm/build.rs create mode 100644 wasm/src/args.rs create mode 100644 wasm/src/version.rs diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index 5281c1e9..1b950358 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -52,6 +52,70 @@ version = "0.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9d4ee0d472d1cd2e28c97dfa124b3d8d992e10eb0a035f33f5d12e3a177ba3b" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + +[[package]] +name = "anstyle-parse" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "anyhow" version = "1.0.66" @@ -82,13 +146,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.68" +version = "0.1.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" +checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" dependencies = [ "proc-macro2", "quote", - "syn 2.0.13", + "syn 2.0.72", ] [[package]] @@ -180,6 +244,12 @@ version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bincode" version = "1.3.3" @@ -206,7 +276,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.13", + "syn 2.0.72", ] [[package]] @@ -230,6 +300,18 @@ dependencies = [ "generic-array", ] +[[package]] +name = "built" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "236e6289eda5a812bc6b53c3b024039382a2895fbbeef2d748b2931546d392c4" +dependencies = [ + "cargo-lock", + "chrono", + "git2", + "semver", +] + [[package]] name = "bumpalo" version = "3.13.0" @@ -321,6 +403,19 @@ dependencies = [ "winx", ] +[[package]] +name = "cargo-lock" +version = "9.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e11c675378efb449ed3ce8de78d75d0d80542fc98487c26aba28eb3b82feac72" +dependencies = [ + "petgraph 0.6.3", + "semver", + "serde", + "toml 0.7.8", + "url", +] + [[package]] name = "cc" version = "1.1.6" @@ -352,6 +447,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "cgroups-rs" version = "0.2.11" @@ -377,6 +478,18 @@ dependencies = [ "thiserror", ] +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "windows-targets 0.52.6", +] + [[package]] name = "clang-sys" version = "1.6.1" @@ -388,6 +501,46 @@ dependencies = [ "libloading", ] +[[package]] +name = "clap" +version = "4.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fbb260a053428790f3de475e304ff84cdbc4face759ea7a3e64c1edd938a7fc" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64b17d7ea74e9f833c7dbf2cbe4fb12ff26783eda4782a8975b72f895c9b4d99" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim 0.11.1", +] + +[[package]] +name = "clap_derive" +version = "4.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.72", +] + +[[package]] +name = "clap_lex" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" + [[package]] name = "cmake" version = "0.1.50" @@ -397,6 +550,12 @@ dependencies = [ "cc", ] +[[package]] +name = "colorchoice" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" + [[package]] name = "command-fds" version = "0.2.2" @@ -410,11 +569,12 @@ dependencies = [ [[package]] name = "containerd-sandbox" version = "0.1.0" -source = "git+https://github.com/kuasar-io/rust-extensions.git#6ae99540b754cd28c5389d5d6fdeff6ec7290ec5" +source = "git+https://github.com/kuasar-io/rust-extensions.git#3c942d70efcfb83351167acbbe3a06245d4b5644" dependencies = [ "anyhow", "async-stream", "async-trait", + "base64 0.22.1", "futures", "go-flag", "libc", @@ -438,7 +598,7 @@ dependencies = [ [[package]] name = "containerd-shim" version = "0.3.0" -source = "git+https://github.com/kuasar-io/rust-extensions.git#6ae99540b754cd28c5389d5d6fdeff6ec7290ec5" +source = "git+https://github.com/kuasar-io/rust-extensions.git#3c942d70efcfb83351167acbbe3a06245d4b5644" dependencies = [ "async-trait", "cgroups-rs 0.2.11", @@ -449,7 +609,7 @@ dependencies = [ "lazy_static", "libc", "log", - "nix 0.25.1", + "nix 0.28.0", "oci-spec", "page_size", "pin-project-lite", @@ -469,7 +629,7 @@ dependencies = [ [[package]] name = "containerd-shim-protos" version = "0.2.0" -source = "git+https://github.com/kuasar-io/rust-extensions.git#6ae99540b754cd28c5389d5d6fdeff6ec7290ec5" +source = "git+https://github.com/kuasar-io/rust-extensions.git#3c942d70efcfb83351167acbbe3a06245d4b5644" dependencies = [ "async-trait", "protobuf 3.2.0", @@ -691,7 +851,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim", + "strsim 0.10.0", "syn 1.0.109", ] @@ -840,6 +1000,12 @@ dependencies = [ "termcolor", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "errno" version = "0.3.1" @@ -1024,7 +1190,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.13", + "syn 2.0.72", ] [[package]] @@ -1106,7 +1272,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" dependencies = [ "fallible-iterator", - "indexmap", + "indexmap 1.9.3", "stable_deref_trait", ] @@ -1116,6 +1282,19 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "git2" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b903b73e45dc0c6c596f2d37eccece7c1c8bb6e4407b001096387c63d0d93724" +dependencies = [ + "bitflags 2.3.3", + "libc", + "libgit2-sys", + "log", + "url", +] + [[package]] name = "glob" version = "0.3.1" @@ -1143,7 +1322,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap", + "indexmap 1.9.3", "slab", "tokio", "tokio-util", @@ -1165,6 +1344,12 @@ dependencies = [ "ahash", ] +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + [[package]] name = "heck" version = "0.3.3" @@ -1180,6 +1365,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -1306,6 +1497,29 @@ dependencies = [ "tokio-io-timeout", ] +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "id-arena" version = "2.2.1" @@ -1339,6 +1553,16 @@ dependencies = [ "serde", ] +[[package]] +name = "indexmap" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3fc2e30ba82dd1b3911c8de1ffc143c74a914a14e99514d7637e3099df5ea0" +dependencies = [ + "equivalent", + "hashbrown 0.14.5", +] + [[package]] name = "instant" version = "0.1.12" @@ -1411,6 +1635,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itertools" version = "0.10.5" @@ -1484,9 +1714,21 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" -version = "0.2.147" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "libgit2-sys" +version = "0.17.0+1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10472326a8a6477c3c20a64547b0059e4b0d086869eee31e6d7da728a8eb7224" +dependencies = [ + "cc", + "libc", + "libz-sys", + "pkg-config", +] [[package]] name = "libloading" @@ -1498,6 +1740,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "libz-sys" +version = "1.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c15da26e5af7e25c90b37a2d75cdbf940cf4a55316de9d84c679c9b8bfabf82e" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linux-raw-sys" version = "0.1.4" @@ -1580,15 +1834,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "memoffset" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" -dependencies = [ - "autocfg", -] - [[package]] name = "memoffset" version = "0.8.0" @@ -1699,16 +1944,15 @@ dependencies = [ [[package]] name = "nix" -version = "0.26.2" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" +checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.3.3", "cfg-if 1.0.0", + "cfg_aliases", "libc", - "memoffset 0.7.1", - "pin-utils", - "static_assertions", + "memoffset 0.9.0", ] [[package]] @@ -1759,7 +2003,7 @@ checksum = "03b4680b86d9cfafba8fc491dc9b6df26b68cf40e9e6cd73909194759a63c385" dependencies = [ "crc32fast", "hashbrown 0.13.2", - "indexmap", + "indexmap 1.9.3", "memchr", ] @@ -1843,7 +2087,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7" dependencies = [ "fixedbitset 0.2.0", - "indexmap", + "indexmap 1.9.3", ] [[package]] @@ -1853,7 +2097,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4" dependencies = [ "fixedbitset 0.4.2", - "indexmap", + "indexmap 1.9.3", ] [[package]] @@ -1886,7 +2130,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.13", + "syn 2.0.72", ] [[package]] @@ -1949,7 +2193,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "059a34f111a9dee2ce1ac2826a68b24601c4298cfeb1a587c3cb493d5ab46f52" dependencies = [ "libc", - "nix 0.26.2", + "nix 0.28.0", ] [[package]] @@ -1988,9 +2232,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -2149,7 +2393,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d39b14605eaa1f6a340aec7f320b34064feb26c93aec35d6a9a2272a8ddfa49" dependencies = [ "anyhow", - "indexmap", + "indexmap 1.9.3", "log", "protobuf 3.2.0", "protobuf-support", @@ -2189,9 +2433,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.26" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -2484,6 +2728,15 @@ dependencies = [ "untrusted", ] +[[package]] +name = "semver" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" +dependencies = [ + "serde", +] + [[package]] name = "serde" version = "1.0.159" @@ -2501,7 +2754,7 @@ checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" dependencies = [ "proc-macro2", "quote", - "syn 2.0.13", + "syn 2.0.72", ] [[package]] @@ -2515,6 +2768,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -2656,16 +2918,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] -name = "static_assertions" -version = "1.1.0" +name = "strsim" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "strsim" -version = "0.10.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" @@ -2680,9 +2942,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.13" +version = "2.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c9da457c5285ac1f936ebd076af6dac17a61cfe7826f2076b4d015cf47bc8ec" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" dependencies = [ "proc-macro2", "quote", @@ -2788,7 +3050,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.13", + "syn 2.0.72", ] [[package]] @@ -2870,7 +3132,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.13", + "syn 2.0.72", ] [[package]] @@ -2930,6 +3192,40 @@ dependencies = [ "serde", ] +[[package]] +name = "toml" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.19.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +dependencies = [ + "indexmap 2.3.0", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + [[package]] name = "tonic" version = "0.7.2" @@ -2983,7 +3279,7 @@ checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" dependencies = [ "futures-core", "futures-util", - "indexmap", + "indexmap 1.9.3", "pin-project", "pin-project-lite", "rand", @@ -3192,6 +3488,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "uuid" version = "1.3.0" @@ -3201,6 +3503,12 @@ dependencies = [ "getrandom", ] +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.4" @@ -3315,7 +3623,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.13", + "syn 2.0.72", "wasm-bindgen-shared", ] @@ -3349,7 +3657,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.13", + "syn 2.0.72", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3375,8 +3683,10 @@ version = "0.1.0" dependencies = [ "anyhow", "async-trait", + "built", "cap-std", "cgroups-rs 0.3.3", + "clap", "containerd-sandbox", "containerd-shim", "env_logger 0.9.3", @@ -3401,7 +3711,7 @@ checksum = "dbe80d95a88e9ac87b6aaf7bc9acd1fdfcd92045db2bf41a2262f623e2406a92" dependencies = [ "proc-macro2", "quote", - "syn 2.0.13", + "syn 2.0.72", ] [[package]] @@ -3463,7 +3773,7 @@ version = "0.102.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48134de3d7598219ab9eaf6b91b15d8e50d31da76b8519fe4ecfcec2cf35104b" dependencies = [ - "indexmap", + "indexmap 1.9.3", "url", ] @@ -3477,7 +3787,7 @@ dependencies = [ "async-trait", "bincode", "cfg-if 1.0.0", - "indexmap", + "indexmap 1.9.3", "libc", "log", "object 0.30.4", @@ -3523,7 +3833,7 @@ dependencies = [ "rustix 0.36.14", "serde", "sha2", - "toml", + "toml 0.5.11", "windows-sys 0.45.0", "zstd", ] @@ -3595,7 +3905,7 @@ dependencies = [ "anyhow", "cranelift-entity", "gimli 0.27.3", - "indexmap", + "indexmap 1.9.3", "log", "object 0.30.4", "serde", @@ -3674,7 +3984,7 @@ dependencies = [ "anyhow", "cc", "cfg-if 1.0.0", - "indexmap", + "indexmap 1.9.3", "libc", "log", "mach", @@ -3857,6 +4167,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.45.0" @@ -4062,6 +4381,15 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "winnow" +version = "0.5.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] + [[package]] name = "winreg" version = "0.50.0" @@ -4090,7 +4418,7 @@ checksum = "f887c3da527a51b321076ebe6a7513026a4757b6d4d144259946552d6fc728b3" dependencies = [ "anyhow", "id-arena", - "indexmap", + "indexmap 1.9.3", "log", "pulldown-cmark", "unicode-xid", diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index 6842506d..52b4a7f3 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -9,24 +9,28 @@ wasmtime = ["cap-std", "wasi-cap-std-sync", "dep:wasmtime", "wasmtime-wasi"] wasmedge = ["wasmedge-sdk"] wasmedge_wasi_nn = ["wasmedge-sdk/wasi_nn"] +[build-dependencies] +built = { version = "0.7.0", features = ["cargo-lock", "dependency-tree", "git2", "chrono", "semver"] } + [dependencies] env_logger = "0.9.0" anyhow = { version = "=1.0.66", default-features = false, features = ["std"] } tokio = "1.13.0" -futures = { version = "0.3.21"} -containerd-sandbox = {git="https://github.com/kuasar-io/rust-extensions.git"} -async-trait = "0.1.51" +futures = { version = "0.3.21" } +containerd-sandbox = { git = "https://github.com/kuasar-io/rust-extensions.git" } +async-trait = "0.1.81" nix = "0.25" -containerd-shim = {git="https://github.com/kuasar-io/rust-extensions.git", features=["async"]} +containerd-shim = { git = "https://github.com/kuasar-io/rust-extensions.git", features = ["async"] } oci-spec = "0.5.4" signal-hook-tokio = { version = "0.3.1", features = ["futures-v0_3"] } log = { version = "0.4.17", features = ["std"] } time = "0.3.5" cgroups-rs = "0.3.2" - wasmedge-sdk = { version = "0.13.2", optional = true } +clap = { version = "4.5.4", features = ["derive"] } +built = { version = "0.7.0", features = ["cargo-lock", "dependency-tree", "git2", "chrono", "semver"] } -cap-std = { version = "1.0.14", 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/build.rs b/wasm/build.rs new file mode 100644 index 00000000..71002877 --- /dev/null +++ b/wasm/build.rs @@ -0,0 +1,23 @@ +/* +Copyright 2024 The Kuasar Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +use std::process::exit; + +fn main() { + if let Err(e) = built::write_built_file() { + eprint!("Failed to acquire build-time information: {:?}", e); + exit(-1) + } +} diff --git a/wasm/src/args.rs b/wasm/src/args.rs new file mode 100644 index 00000000..942aca2b --- /dev/null +++ b/wasm/src/args.rs @@ -0,0 +1,59 @@ +/* +Copyright 2024 The Kuasar Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +use clap::Parser; + +#[derive(Parser, Debug)] +#[command(author, about, long_about = None)] +pub struct Args { + /// Version info + #[arg(short, long)] + pub version: bool, + + /// Sandboxer working directory, default is `/run/kuasar-wasm` + #[arg(short, long, value_name = "DIR", default_value = "/run/kuasar-wasm")] + pub dir: String, + + /// Address for sandboxer's server, default is `/run/wasm-sandboxer.sock` + #[arg( + short, + long, + value_name = "FILE", + default_value = "/run/wasm-sandboxer.sock" + )] + pub listen: String, + + // log_level is optional and should not have default value if not given, since + // it can be defined in configuration file. + /// Logging level for sandboxer [trace, debug, info, warn, error, fatal, panic] + #[arg(long, value_name = "STRING")] + pub log_level: Option, +} + +#[cfg(test)] +mod tests { + use clap::Parser; + + use crate::args::Args; + + #[test] + fn test_args_parse_default() { + let args = Args::parse(); + assert!(!args.version); + assert_eq!(args.dir, "/run/kuasar-wasm"); + assert_eq!(args.listen, "/run/wasm-sandboxer.sock"); + assert!(args.log_level.is_none()); + } +} diff --git a/wasm/src/main.rs b/wasm/src/main.rs index 581dddce..9341de26 100644 --- a/wasm/src/main.rs +++ b/wasm/src/main.rs @@ -14,9 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ +use std::str::FromStr; + +use clap::Parser; use containerd_shim::asynchronous::monitor::monitor_notify_by_pid; use futures::StreamExt; -use log::{debug, error, warn}; +use log::{debug, error, warn, LevelFilter}; use nix::{ errno::Errno, libc, @@ -30,26 +33,48 @@ use signal_hook_tokio::Signals; use crate::sandbox::WasmSandboxer; +mod args; mod sandbox; mod utils; +mod version; #[cfg(feature = "wasmedge")] mod wasmedge; #[cfg(feature = "wasmtime")] mod wasmtime; #[tokio::main] -async fn main() -> anyhow::Result<()> { - env_logger::builder().format_timestamp_micros().init(); +async fn main() { + let args = args::Args::parse(); + if args.version { + version::print_version_info(); + return; + } + + // Update args log level if it not presents args but in config. + let log_level = + LevelFilter::from_str(&args.log_level.unwrap_or_default()).unwrap_or(LevelFilter::Info); + env_logger::Builder::from_default_env() + .format_timestamp_micros() + .filter_module("containerd_sandbox", log_level) + .filter_module("wasm_sandboxer", log_level) + .init(); + + // TODO: Support recovery + tokio::spawn(async move { let signals = Signals::new([libc::SIGPIPE, libc::SIGCHLD]).expect("new signal failed"); handle_signals(signals).await; }); let sandboxer = WasmSandboxer::default(); - containerd_sandbox::run("kuasar-wasm-sandboxer", sandboxer) - .await - .unwrap(); - Ok(()) + containerd_sandbox::run( + "kuasar-wasm-sandboxer-wasmedge", + &args.listen, + &args.dir, + sandboxer, + ) + .await + .unwrap(); } async fn handle_signals(signals: Signals) { diff --git a/wasm/src/sandbox.rs b/wasm/src/sandbox.rs index 84354869..0e7ac6fe 100644 --- a/wasm/src/sandbox.rs +++ b/wasm/src/sandbox.rs @@ -87,6 +87,12 @@ impl Sandboxer for WasmSandboxer { Ok(()) } + async fn update(&self, id: &str, data: SandboxData) -> Result<()> { + let sandbox = self.sandbox(id).await?; + sandbox.lock().await.data = data; + Ok(()) + } + async fn sandbox(&self, id: &str) -> Result>> { Ok(self .sandboxes @@ -134,7 +140,9 @@ impl WasmSandbox { async fn start(&mut self) -> Result<()> { let task = self.start_task_service().await?; let task_address = format!("unix://{}/task.sock", self.base_dir); - self.data.task_address.clone_from(&task_address); + self.data + .task_address + .clone_from(&format!("ttrpc+{}", task_address)); let task_service = create_task(Arc::new(Box::new(task))); let mut server = Server::new().register_service(task_service); server = server diff --git a/wasm/src/version.rs b/wasm/src/version.rs new file mode 100644 index 00000000..2ac1d905 --- /dev/null +++ b/wasm/src/version.rs @@ -0,0 +1,29 @@ +/* +Copyright 2024 The Kuasar Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +pub mod built_info { + // The file has been placed there by the build script. + include!(concat!(env!("OUT_DIR"), "/built.rs")); +} + +pub fn print_version_info() { + if let Some(v) = built_info::GIT_VERSION { + match built_info::GIT_DIRTY { + Some(true) => println!("Version: {}-dirty", v), + _ => println!("Version: {}", v), + } + } + println!("Build Time: {}", built_info::BUILT_TIME_UTC) +}