diff --git a/.rustfmt.toml b/.rustfmt.toml index 6b8c82afc..7c074d766 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1,4 +1,4 @@ -edition = "2018" +edition = "2021" reorder_imports = false reorder_modules = false diff --git a/Cargo.lock b/Cargo.lock index 18bb7487f..36ee56ba1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,21 +21,47 @@ dependencies = [ "gimli 0.26.2", ] +[[package]] +name = "addr2line" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" +dependencies = [ + "gimli 0.27.1", +] + [[package]] name = "adler" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom 0.2.8", + "once_cell", + "version_check", +] + [[package]] name = "aho-corasick" -version = "0.7.19" +version = "0.7.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" dependencies = [ "memchr", ] +[[package]] +name = "ambient-authority" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8ad6edb4840b78c5c3d88de606b22252d552b55f3a4699fbb10fc070ec3049" + [[package]] name = "android_system_properties" version = "0.1.5" @@ -56,9 +82,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.66" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" +checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800" [[package]] name = "arguments-passing-test" @@ -88,6 +114,23 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + +[[package]] +name = "async-trait" +version = "0.1.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd7fce9ba8c3c042128ce72d8b2ddbf3a05747efb67ea0313c635e10bda47a2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "atty" version = "0.2.14" @@ -107,30 +150,30 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" -version = "0.3.66" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7" +checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca" dependencies = [ - "addr2line", + "addr2line 0.19.0", "cc", "cfg-if 1.0.0", "libc", "miniz_oxide", - "object", + "object 0.30.3", "rustc-demangle", ] [[package]] -name = "base-x" -version = "0.2.11" +name = "base64" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.13.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" [[package]] name = "beef" @@ -160,7 +203,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b64485778c4f16a6a5a9d335e80d449ac6c70cdd6a06d2af18a6f6f775a125b3" dependencies = [ "arrayref", - "arrayvec", + "arrayvec 0.5.2", "cc", "cfg-if 0.1.10", "constant_time_eq", @@ -168,6 +211,15 @@ dependencies = [ "digest 0.9.0", ] +[[package]] +name = "block-buffer" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +dependencies = [ + "generic-array 0.14.6", +] + [[package]] name = "boolinator" version = "2.4.0" @@ -176,9 +228,9 @@ checksum = "cfa8873f51c92e232f9bac4065cddef41b714152812bfc5f7672ba16d6ef8cd9" [[package]] name = "bumpalo" -version = "3.11.0" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" +checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" [[package]] name = "byteorder" @@ -188,9 +240,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" [[package]] name = "bytesize" @@ -218,15 +270,79 @@ dependencies = [ "serde", ] +[[package]] +name = "cap-fs-ext" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff40fd8a96d57a204080e5debd621342612f6d6b60901201a51f518baf72691d" +dependencies = [ + "cap-primitives", + "cap-std", + "io-lifetimes", + "windows-sys 0.45.0", +] + +[[package]] +name = "cap-primitives" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9554a7698c8db4b7777f01b2237de111c5ecea169efb1190004d9069ceb289aa" +dependencies = [ + "ambient-authority", + "fs-set-times", + "io-extras", + "io-lifetimes", + "ipnet", + "maybe-owned", + "rustix", + "windows-sys 0.45.0", + "winx", +] + +[[package]] +name = "cap-rand" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "103e94d97d73504c5fa6ffb47135d5627ce5ff84a4ad37e8219103ddc291de24" +dependencies = [ + "ambient-authority", + "rand", +] + +[[package]] +name = "cap-std" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7b68a8ac703cc7bed0a46666a04b386cca214844897a69f599dcd82ea59422c" +dependencies = [ + "cap-primitives", + "io-extras", + "io-lifetimes", + "ipnet", + "rustix", +] + +[[package]] +name = "cap-time-ext" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "472931750f90fbf0731c886c2937521e25772942577a182e7ace5bc561d10e3b" +dependencies = [ + "cap-primitives", + "once_cell", + "rustix", + "winx", +] + [[package]] name = "cargo-lock" version = "8.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "031718ddb8f78aa5def78a09e90defe30151d1f6c672f937af4dd916429ed996" dependencies = [ - "semver 1.0.14", + "semver 1.0.16", "serde", - "toml 0.5.9", + "toml 0.5.11", "url", ] @@ -247,7 +363,7 @@ checksum = "08a1ec454bc3eead8719cb56e15dbbfecdbc14e4b3a3ae4936cc6e31f5fc0d07" dependencies = [ "camino", "cargo-platform", - "semver 1.0.14", + "semver 1.0.16", "serde", "serde_json", "thiserror", @@ -265,9 +381,12 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.73" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +dependencies = [ + "jobserver", +] [[package]] name = "cfg-if" @@ -290,7 +409,7 @@ dependencies = [ "anyhow", "chrono", "reqwest", - "semver 1.0.14", + "semver 1.0.16", "serde", ] @@ -305,7 +424,7 @@ dependencies = [ "num-integer", "num-traits", "serde", - "time 0.1.44", + "time 0.1.45", "wasm-bindgen", "winapi", ] @@ -320,16 +439,41 @@ dependencies = [ "atty", "bitflags", "strsim 0.8.0", - "textwrap", + "textwrap 0.11.0", "unicode-width", "vec_map", ] +[[package]] +name = "clap" +version = "3.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" +dependencies = [ + "atty", + "bitflags", + "clap_lex", + "indexmap", + "once_cell", + "strsim 0.10.0", + "termcolor", + "textwrap 0.16.0", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "clipboard-win" -version = "4.4.2" +version = "4.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4ab1b92798304eedc095b53942963240037c0516452cb11aeba709d420b2219" +checksum = "7191c27c2357d9b7ef96baac1773290d4ca63b24205b82a3fd8a0637afcf0362" dependencies = [ "error-code", "str-buf", @@ -345,6 +489,16 @@ dependencies = [ "bitflags", ] +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -355,12 +509,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "const_fn" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" - [[package]] name = "constant_time_eq" version = "0.1.5" @@ -390,13 +538,40 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +[[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.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +dependencies = [ + "libc", +] + [[package]] name = "cranelift-bforest" version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45a9c21f8042b9857bda93f6c1910b9f9f24100187a3d3d52f214a34e3dc5818" dependencies = [ - "cranelift-entity", + "cranelift-entity 0.59.0", +] + +[[package]] +name = "cranelift-bforest" +version = "0.93.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7379abaacee0f14abf3204a7606118f0465785252169d186337bcb75030815a" +dependencies = [ + "cranelift-entity 0.93.1", ] [[package]] @@ -406,25 +581,55 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7853f77a6e4a33c67a69c40f5e1bb982bd2dc5c4a22e17e67b65bbccf9b33b2e" dependencies = [ "byteorder", - "cranelift-bforest", - "cranelift-codegen-meta", - "cranelift-codegen-shared", - "cranelift-entity", + "cranelift-bforest 0.59.0", + "cranelift-codegen-meta 0.59.0", + "cranelift-codegen-shared 0.59.0", + "cranelift-entity 0.59.0", "gimli 0.20.0", "log", "smallvec", - "target-lexicon", + "target-lexicon 0.10.0", "thiserror", ] +[[package]] +name = "cranelift-codegen" +version = "0.93.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9489fa336927df749631f1008007ced2871068544f40a202ce6d93fbf2366a7b" +dependencies = [ + "arrayvec 0.7.2", + "bumpalo", + "cranelift-bforest 0.93.1", + "cranelift-codegen-meta 0.93.1", + "cranelift-codegen-shared 0.93.1", + "cranelift-entity 0.93.1", + "cranelift-isle", + "gimli 0.26.2", + "hashbrown", + "log", + "regalloc2", + "smallvec", + "target-lexicon 0.12.5", +] + [[package]] name = "cranelift-codegen-meta" version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "084cd6d5fb0d1da28acd72c199471bfb09acc703ec8f3bf07b1699584272a3b9" dependencies = [ - "cranelift-codegen-shared", - "cranelift-entity", + "cranelift-codegen-shared 0.59.0", + "cranelift-entity 0.59.0", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.93.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05bbb67da91ec721ed57cef2f7c5ef7728e1cd9bde9ffd3ef8601022e73e3239" +dependencies = [ + "cranelift-codegen-shared 0.93.1", ] [[package]] @@ -433,21 +638,90 @@ version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "701b599783305a58c25027a4d73f2d6b599b2d8ef3f26677275f480b4d51e05d" +[[package]] +name = "cranelift-codegen-shared" +version = "0.93.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418ecb2f36032f6665dc1a5e2060a143dbab41d83b784882e97710e890a7a16d" + [[package]] name = "cranelift-entity" version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b88e792b28e1ebbc0187b72ba5ba880dad083abe9231a99d19604d10c9e73f38" +[[package]] +name = "cranelift-entity" +version = "0.93.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cf583f7b093f291005f9fb1323e2c37f6ee4c7909e39ce016b2e8360d461705" +dependencies = [ + "serde", +] + +[[package]] +name = "cranelift-frontend" +version = "0.93.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b66bf9e916f57fbbd0f7703ec6286f4624866bf45000111627c70d272c8dda1" +dependencies = [ + "cranelift-codegen 0.93.1", + "log", + "smallvec", + "target-lexicon 0.12.5", +] + +[[package]] +name = "cranelift-isle" +version = "0.93.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "649782a39ce99798dd6b4029e2bb318a2fbeaade1b4fa25330763c10c65bc358" + [[package]] name = "cranelift-native" version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32daf082da21c0c05d93394ff4842c2ab7c4991b1f3186a1d952f8ac660edd0b" dependencies = [ - "cranelift-codegen", + "cranelift-codegen 0.59.0", "raw-cpuid", - "target-lexicon", + "target-lexicon 0.10.0", +] + +[[package]] +name = "cranelift-native" +version = "0.93.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "937e021e089c51f9749d09e7ad1c4f255c2f8686cb8c3df63a34b3ec9921bc41" +dependencies = [ + "cranelift-codegen 0.93.1", + "libc", + "target-lexicon 0.12.5", +] + +[[package]] +name = "cranelift-wasm" +version = "0.93.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d850cf6775477747c9dfda9ae23355dd70512ffebc70cf82b85a5b111ae668b5" +dependencies = [ + "cranelift-codegen 0.93.1", + "cranelift-entity 0.93.1", + "cranelift-frontend", + "itertools", + "log", + "smallvec", + "wasmparser 0.100.0", + "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]] @@ -457,21 +731,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2801af0d36612ae591caa9568261fddce32ce6e08a7275ea334a06a4ad021a2c" dependencies = [ "cfg-if 1.0.0", - "crossbeam-channel 0.5.6", + "crossbeam-channel", "crossbeam-deque", "crossbeam-epoch", "crossbeam-queue", - "crossbeam-utils 0.8.11", -] - -[[package]] -name = "crossbeam-channel" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87" -dependencies = [ - "crossbeam-utils 0.7.2", - "maybe-uninit", + "crossbeam-utils", ] [[package]] @@ -481,7 +745,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" dependencies = [ "cfg-if 1.0.0", - "crossbeam-utils 0.8.11", + "crossbeam-utils", ] [[package]] @@ -492,52 +756,49 @@ checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" dependencies = [ "cfg-if 1.0.0", "crossbeam-epoch", - "crossbeam-utils 0.8.11", + "crossbeam-utils", ] [[package]] name = "crossbeam-epoch" -version = "0.9.10" +version = "0.9.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "045ebe27666471bb549370b4b0b3e51b07f56325befa4284db65fc89c02511b1" +checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a" dependencies = [ "autocfg", "cfg-if 1.0.0", - "crossbeam-utils 0.8.11", - "memoffset", - "once_cell", + "crossbeam-utils", + "memoffset 0.7.1", "scopeguard", ] [[package]] name = "crossbeam-queue" -version = "0.3.6" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd42583b04998a5363558e5f9291ee5a5ff6b49944332103f251e7479a82aa7" +checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add" dependencies = [ "cfg-if 1.0.0", - "crossbeam-utils 0.8.11", + "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.7.2" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" +checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" dependencies = [ - "autocfg", - "cfg-if 0.1.10", - "lazy_static", + "cfg-if 1.0.0", ] [[package]] -name = "crossbeam-utils" -version = "0.8.11" +name = "crypto-common" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ - "cfg-if 1.0.0", - "once_cell", + "generic-array 0.14.6", + "typenum", ] [[package]] @@ -552,9 +813,9 @@ dependencies = [ [[package]] name = "ctor" -version = "0.1.23" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdffe87e1d521a10f9696f833fe502293ea446d7f256c06128293a4119bdf4cb" +checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" dependencies = [ "quote", "syn", @@ -569,113 +830,128 @@ dependencies = [ ] [[package]] -name = "darling" -version = "0.10.2" +name = "cxx" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" +checksum = "bc831ee6a32dd495436e317595e639a587aa9907bef96fe6e6abc290ab6204e9" dependencies = [ - "darling_core 0.10.2", - "darling_macro 0.10.2", + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", ] [[package]] -name = "darling" -version = "0.14.1" +name = "cxx-build" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4529658bdda7fd6769b8614be250cdcfc3aeb0ee72fe66f9e41e5e5eb73eac02" +checksum = "94331d54f1b1a8895cd81049f7eaaaef9d05a7dcb4d1fd08bf3ff0806246789d" dependencies = [ - "darling_core 0.14.1", - "darling_macro 0.14.1", + "cc", + "codespan-reporting", + "once_cell", + "proc-macro2", + "quote", + "scratch", + "syn", ] [[package]] -name = "darling_core" -version = "0.10.2" +name = "cxxbridge-flags" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48dcd35ba14ca9b40d6e4b4b39961f23d835dbb8eed74565ded361d93e1feb8a" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" +checksum = "81bbeb29798b407ccd82a3324ade1a7286e0d29851475990b612670f6f5124d2" dependencies = [ - "fnv", - "ident_case", "proc-macro2", "quote", - "strsim 0.9.3", "syn", ] [[package]] -name = "darling_core" -version = "0.14.1" +name = "darling" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "649c91bc01e8b1eac09fb91e8dbc7d517684ca6be8ebc75bb9cafc894f9fdb6f" +checksum = "c0808e1bd8671fb44a113a14e13497557533369847788fa2ae912b6ebfce9fa8" dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim 0.10.0", - "syn", + "darling_core", + "darling_macro", ] [[package]] -name = "darling_macro" -version = "0.10.2" +name = "darling_core" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" +checksum = "001d80444f28e193f30c2f293455da62dcf9a6b29918a4253152ae2b1de592cb" dependencies = [ - "darling_core 0.10.2", + "fnv", + "ident_case", + "proc-macro2", "quote", + "strsim 0.10.0", "syn", ] [[package]] name = "darling_macro" -version = "0.14.1" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc69c5bfcbd2fc09a0f38451d2daf0e372e367986a83906d1b0dbc88134fb5" +checksum = "b36230598a2d5de7ec1c6f51f72d8a99a9208daff41de2084d06e3fd3ea56685" dependencies = [ - "darling_core 0.14.1", + "darling_core", "quote", "syn", ] [[package]] name = "defer-drop" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "828aca0e5e4341b0320a319209cbc6255b8b06254849ce8a5f33d33f7f2fa0f0" +checksum = "f613ec9fa66a6b28cdb1842b27f9adf24f39f9afc4dcdd9fdecee4aca7945c57" dependencies = [ - "crossbeam-channel 0.4.4", + "crossbeam-channel", "once_cell", ] [[package]] name = "derive_builder" -version = "0.9.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2658621297f2cf68762a6f7dc0bb7e1ff2cfd6583daef8ee0fed6f7ec468ec0" +checksum = "d07adf7be193b71cc36b193d0f5fe60b918a3a9db4dad0449f57bcfd519704a3" dependencies = [ - "darling 0.10.2", - "derive_builder_core", - "proc-macro2", - "quote", - "syn", + "derive_builder_macro", ] [[package]] name = "derive_builder_core" -version = "0.9.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2791ea3e372c8495c0bc2033991d76b512cd799d07491fbd6890124db9458bef" +checksum = "1f91d4cfa921f1c05904dc3c57b4a32c38aed3340cce209f3a6fd1478babafc4" dependencies = [ - "darling 0.10.2", + "darling", "proc-macro2", "quote", "syn", ] [[package]] -name = "diff" -version = "0.1.13" +name = "derive_builder_macro" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f0314b72bed045f3a68671b3c86328386762c93f82d98c65c3cb5e5f573dd68" +dependencies = [ + "derive_builder_core", + "syn", +] + +[[package]] +name = "diff" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" @@ -697,6 +973,35 @@ dependencies = [ "generic-array 0.14.6", ] +[[package]] +name = "digest" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "directories-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "339ee130d97a610ea5a5872d2bbb130fdf68884ff09d3028b81bec8a1ac23bbc" +dependencies = [ + "cfg-if 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-next" version = "2.0.0" @@ -708,10 +1013,10 @@ dependencies = [ ] [[package]] -name = "dirs-sys-next" -version = "0.1.2" +name = "dirs-sys" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" dependencies = [ "libc", "redox_users", @@ -719,10 +1024,15 @@ dependencies = [ ] [[package]] -name = "discard" -version = "1.0.4" +name = "dirs-sys-next" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] [[package]] name = "donkey" @@ -733,15 +1043,15 @@ dependencies = [ [[package]] name = "either" -version = "1.8.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "encoding_rs" -version = "0.8.31" +version = "0.8.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" +checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" dependencies = [ "cfg-if 1.0.0", ] @@ -752,19 +1062,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" -[[package]] -name = "env_logger" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] - [[package]] name = "env_logger" version = "0.9.3" @@ -793,9 +1090,9 @@ dependencies = [ [[package]] name = "erased-serde" -version = "0.3.23" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54558e0ba96fbe24280072642eceb9d7d442e32c7ec0ea9e7ecd7b4ea2cf4e11" +checksum = "e4ca605381c017ec7a5fef5e548f1cfaa419ed0f6df6367339300db74c92aa7d" dependencies = [ "serde", ] @@ -871,6 +1168,12 @@ dependencies = [ "synstructure", ] +[[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.8.0" @@ -882,29 +1185,39 @@ dependencies = [ [[package]] name = "fd-lock" -version = "3.0.6" +version = "3.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e11dcc7e4d79a8c89b9ab4c6f5c30b1fc4a83c420792da3542fd31179ed5f517" +checksum = "8ef1a30ae415c3a691a4f41afddc2dbcd6d70baf338368d85ebc1e8ed92cedb9" dependencies = [ "cfg-if 1.0.0", - "rustix 0.35.9", - "windows-sys 0.36.1", + "rustix", + "windows-sys 0.45.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 = "fluence-app-service" -version = "0.24.0" +version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01eec180e93188fa71a47432e298cc2725a7a247e3da6f51678443779d68dd02" +checksum = "967bc26939d9a5a0dd09bd8991c9b0df80eacb370723b8d1019184a9c0606936" dependencies = [ "log", "maplit", - "marine-min-it-version 0.2.0", - "marine-runtime 0.23.1", + "marine-min-it-version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "marine-runtime 0.23.2", "serde", "serde_derive", "serde_json", - "toml 0.5.9", + "toml 0.5.11", "wasmer-wasi-fl", ] @@ -915,12 +1228,13 @@ dependencies = [ "log", "maplit", "marine-min-it-version 0.2.1", - "marine-runtime 0.24.1", + "marine-runtime 0.25.0", + "marine-wasm-backend-traits", + "marine-wasmtime-backend", "serde", "serde_derive", "serde_json", - "toml 0.5.9", - "wasmer-wasi-fl", + "toml 0.5.11", ] [[package]] @@ -930,10 +1244,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4e11b54c84babd376e0844d4973fdf7313799c4b9531757015ea6736ef14b70" dependencies = [ "it-to-bytes", - "nom", + "nom 5.1.2", + "serde", + "variant_count", + "wast 8.0.0", +] + +[[package]] +name = "fluence-it-types" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d57951373d9ece94e8494a7b2f8a3772c56e290a7b7972a24eaecd7292b11083" +dependencies = [ + "it-to-bytes", + "nom 7.1.3", "serde", "variant_count", - "wast", + "wast 53.0.0", ] [[package]] @@ -966,44 +1293,55 @@ 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", + "rustix", + "windows-sys 0.45.0", +] + [[package]] name = "futures-channel" -version = "0.3.24" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" +checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5" dependencies = [ "futures-core", ] [[package]] name = "futures-core" -version = "0.3.24" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" +checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" [[package]] name = "futures-io" -version = "0.3.24" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68" +checksum = "bfb8371b6fb2aeb2d280374607aeabfc99d95c72edfe51692e42d3d7f0d08531" [[package]] name = "futures-sink" -version = "0.3.24" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" +checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364" [[package]] name = "futures-task" -version = "0.3.24" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" +checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366" [[package]] name = "futures-util" -version = "0.3.24" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" +checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" dependencies = [ "futures-core", "futures-io", @@ -1023,6 +1361,15 @@ dependencies = [ "thread_local", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + [[package]] name = "generational-arena" version = "0.2.8" @@ -1065,9 +1412,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if 1.0.0", "libc", @@ -1076,9 +1423,9 @@ dependencies = [ [[package]] name = "ghost" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb19fe8de3ea0920d282f7b77dd4227aea6b8b999b42cdf0ca41b2472b14443a" +checksum = "41973d4c45f7a35af8753ba3457cc99d406d863941fd7f52663cff54a5ab99b3" dependencies = [ "proc-macro2", "quote", @@ -1100,12 +1447,23 @@ name = "gimli" version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" +dependencies = [ + "fallible-iterator", + "indexmap", + "stable_deref_trait", +] + +[[package]] +name = "gimli" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "221996f774192f0f718773def8201c4ae31f02616a54ccfc2d358bb0e5cefdec" [[package]] name = "h2" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" +checksum = "5f9f29bc9dda355256b2916cf526ab02ce0aeaaaf2bad60d65ef3f12f11dd0f4" dependencies = [ "bytes", "fnv", @@ -1125,6 +1483,9 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] [[package]] name = "heck" @@ -1135,6 +1496,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -1146,9 +1513,18 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.1" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + +[[package]] +name = "hermit-abi" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +checksum = "856b5cb0902c2b6d65d5fd97dfa30f9b70c7538e770b98eab5ed52d8db923e01" [[package]] name = "hex" @@ -1198,9 +1574,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.20" +version = "0.14.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac" +checksum = "5e011372fa0b68db8350aa7a248930ecc7839bf46d8485577d69f117a75f164c" dependencies = [ "bytes", "futures-channel", @@ -1235,18 +1611,28 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.47" +version = "0.1.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c495f162af0bf17656d0014a0eded5f3cd2f365fdd204548c2869db89359dc7" +checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" dependencies = [ "android_system_properties", "core-foundation-sys", + "iana-time-zone-haiku", "js-sys", - "once_cell", "wasm-bindgen", "winapi", ] +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +dependencies = [ + "cxx", + "cxx-build", +] + [[package]] name = "id-arena" version = "2.2.1" @@ -1271,9 +1657,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.9.1" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ "autocfg", "hashbrown", @@ -1300,10 +1686,14 @@ dependencies = [ ] [[package]] -name = "io-lifetimes" -version = "0.7.3" +name = "io-extras" +version = "0.17.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ea37f355c05dde75b84bba2d767906ad522e97cd9e2eef2be7a4ab7fb442c06" +checksum = "d79107d6e60d78351e11f0a2dc9d0eaf304a7efb592e92603783afb8479c7d97" +dependencies = [ + "io-lifetimes", + "windows-sys 0.45.0", +] [[package]] name = "io-lifetimes" @@ -1333,44 +1723,44 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.5.0" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" +checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" [[package]] name = "is-terminal" -version = "0.4.4" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b6b32576413a8e69b90e952e4a026476040d81017b80445deda5f2d3921857" +checksum = "22e18b0a45d56fe973d6db23972bf5bc46f988a4a2385deac9cc29572f09daef" dependencies = [ - "hermit-abi 0.3.1", - "io-lifetimes 1.0.5", - "rustix 0.36.8", + "hermit-abi 0.3.0", + "io-lifetimes", + "rustix", "windows-sys 0.45.0", ] [[package]] name = "it-json-serde" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d7bc35c4e8bc44e236bc459a88a24a74326eedff6b073a435eb5537849bfd25" +version = "0.3.5" dependencies = [ "serde", "serde_derive", "serde_json", "thiserror", - "wasmer-interface-types-fl", + "wasmer-interface-types-fl 0.26.0", ] [[package]] name = "it-json-serde" version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d3f68d6c0e26f35c3d7f0176fcd14b2884c9e954ded51461a7a49f25a20b480" dependencies = [ "serde", "serde_derive", "serde_json", "thiserror", - "wasmer-interface-types-fl", + "wasmer-interface-types-fl 0.24.1", ] [[package]] @@ -1379,8 +1769,21 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59726dde6ea2df9ad15bb67341103879cb94f26642ee0e40bf9a426f8e69bec8" dependencies = [ - "fluence-it-types", - "it-memory-traits", + "fluence-it-types 0.3.2", + "it-memory-traits 0.3.1", + "log", + "paste", + "thiserror", +] + +[[package]] +name = "it-lilo" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89811f46f772c0a839ba49cef3e976ff7cc57d899328c739bf25e8d0d9491ac1" +dependencies = [ + "fluence-it-types 0.4.0", + "it-memory-traits 0.4.0", "log", "paste", "thiserror", @@ -1395,6 +1798,15 @@ dependencies = [ "thiserror", ] +[[package]] +name = "it-memory-traits" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d563f2a6baee17cf471b7951dfb96ab17fecc5e8947de39f1057cf3fb4cc906d" +dependencies = [ + "thiserror", +] + [[package]] name = "it-to-bytes" version = "0.1.0" @@ -1412,15 +1824,44 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.3" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" + +[[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.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" +checksum = "068b1ee6743e4d11fb9c6a1e6064b3693a1b600e7f5f5988047d98b3dc9fb90b" +dependencies = [ + "libc", +] [[package]] name = "js-sys" -version = "0.3.60" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" dependencies = [ "wasm-bindgen", ] @@ -1443,7 +1884,7 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe" dependencies = [ - "arrayvec", + "arrayvec 0.5.2", "bitflags", "cfg-if 1.0.0", "ryu", @@ -1465,10 +1906,13 @@ dependencies = [ ] [[package]] -name = "linux-raw-sys" -version = "0.0.46" +name = "link-cplusplus" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" +checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" +dependencies = [ + "cc", +] [[package]] name = "linux-raw-sys" @@ -1494,6 +1938,16 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "lock_api" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.17" @@ -1503,6 +1957,15 @@ 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 = "maplit" version = "1.0.2" @@ -1520,14 +1983,14 @@ dependencies = [ "cargo_metadata", "cargo_toml", "check-latest", - "clap", + "clap 2.34.0", "env_logger 0.10.0", "exitfailure", "log", "marine-it-generator 0.9.5", "marine-it-parser 0.11.1", "marine-module-info-parser 0.5.1", - "semver 1.0.14", + "semver 1.0.16", "serde", "serde_json", "termion", @@ -1547,32 +2010,32 @@ dependencies = [ [[package]] name = "marine-core" -version = "0.18.0" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b68e6db433b04a70ebfa7d4f65797863d45d3af0bbbb2865e39ab3de92803c2a" +checksum = "16160d8f2db5186ed94b09e6419096c595ad712346f9f384bd6936e0856b366a" dependencies = [ "anyhow", "boolinator", "bytesize", - "it-lilo", - "it-memory-traits", + "it-lilo 0.4.1", + "it-memory-traits 0.3.1", "log", - "marine-it-generator 0.9.4", + "marine-it-generator 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)", "marine-it-interfaces 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "marine-it-parser 0.11.0", - "marine-min-it-version 0.2.0", - "marine-module-info-parser 0.5.0", - "marine-module-interface 0.6.0", + "marine-it-parser 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)", + "marine-min-it-version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "marine-module-info-parser 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "marine-module-interface 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "marine-utils 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "multimap", "once_cell", "parity-wasm 0.45.0", "paste", "pwasm-utils", - "semver 1.0.14", + "semver 1.0.16", "serde", "thiserror", - "wasmer-interface-types-fl", + "wasmer-interface-types-fl 0.24.1", "wasmer-runtime-core-fl", "wasmer-runtime-fl", "wasmer-wasi-fl", @@ -1586,8 +2049,8 @@ dependencies = [ "boolinator", "bytes", "bytesize", - "it-lilo", - "it-memory-traits", + "it-lilo 0.5.0", + "it-memory-traits 0.4.0", "log", "marine-it-generator 0.9.5", "marine-it-interfaces 0.7.3", @@ -1596,52 +2059,51 @@ dependencies = [ "marine-module-info-parser 0.5.1", "marine-module-interface 0.6.1", "marine-utils 0.4.0", + "marine-wasm-backend-traits", + "marine-wasmtime-backend", "multimap", "once_cell", "parity-wasm 0.45.0", "paste", "pwasm-utils", "reqwest", - "semver 1.0.14", + "semver 1.0.16", "serde", "thiserror", "tokio", - "wasmer-interface-types-fl", - "wasmer-runtime-core-fl", - "wasmer-runtime-fl", - "wasmer-wasi-fl", + "wasmer-interface-types-fl 0.26.0", ] [[package]] name = "marine-it-generator" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f2cbca852ae9b00f95e48afcf9135ea3cc54b7364dff7adaf5dc57e4dab6668" +version = "0.9.5" dependencies = [ - "it-lilo", - "marine-it-parser 0.11.0", + "it-lilo 0.5.0", + "marine-it-parser 0.11.1", "marine-macro-impl", "once_cell", "serde", "serde_json", "thiserror", "walrus", - "wasmer-interface-types-fl", + "wasmer-interface-types-fl 0.26.0", ] [[package]] name = "marine-it-generator" version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd47a34f51b0767bb28b3aea97d0a89716952ebe11bcf151e09a7d7c2e5eb12" dependencies = [ - "it-lilo", - "marine-it-parser 0.11.1", + "it-lilo 0.4.1", + "marine-it-parser 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)", "marine-macro-impl", "once_cell", "serde", "serde_json", "thiserror", "walrus", - "wasmer-interface-types-fl", + "wasmer-interface-types-fl 0.24.1", ] [[package]] @@ -1649,7 +2111,7 @@ name = "marine-it-interfaces" version = "0.7.3" dependencies = [ "multimap", - "wasmer-interface-types-fl", + "wasmer-interface-types-fl 0.26.0", ] [[package]] @@ -1659,42 +2121,42 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e57037e5bf10449d7603ea7ff1012aae3a6f77e266e4a1cc1decabeb5e0f9924" dependencies = [ "multimap", - "wasmer-interface-types-fl", + "wasmer-interface-types-fl 0.24.1", ] [[package]] name = "marine-it-parser" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e52c1e59b84546be07004851c242a5644487211b62c242c69ceff57f9112aa0" +version = "0.11.1" dependencies = [ "anyhow", "itertools", - "marine-it-interfaces 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "marine-module-interface 0.6.0", - "nom", - "semver 1.0.14", + "marine-it-interfaces 0.7.3", + "marine-module-interface 0.6.1", + "marine-wasm-backend-traits", + "nom 7.1.3", + "semver 1.0.16", "serde", "thiserror", "walrus", - "wasmer-interface-types-fl", - "wasmer-runtime-core-fl", + "wasmer-interface-types-fl 0.26.0", ] [[package]] name = "marine-it-parser" version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e9902762a0575a992c8d6bea77d1a34f485b89ce1db438f28d9babd2ac72f3" dependencies = [ "anyhow", "itertools", - "marine-it-interfaces 0.7.3", - "marine-module-interface 0.6.1", - "nom", - "semver 1.0.14", + "marine-it-interfaces 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", + "marine-module-interface 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "nom 5.1.2", + "semver 1.0.16", "serde", "thiserror", "walrus", - "wasmer-interface-types-fl", + "wasmer-interface-types-fl 0.24.1", "wasmer-runtime-core-fl", ] @@ -1706,10 +2168,10 @@ dependencies = [ "boolinator", "bytesize", "console_error_panic_hook", - "fluence-it-types", + "fluence-it-types 0.4.0", "it-json-serde 0.3.5", - "it-lilo", - "it-memory-traits", + "it-lilo 0.5.0", + "it-memory-traits 0.4.0", "itertools", "log", "maplit", @@ -1719,17 +2181,17 @@ dependencies = [ "marine-rs-sdk", "marine-utils 0.4.0", "multimap", - "nom", + "nom 7.1.3", "once_cell", "paste", - "semver 1.0.14", + "semver 1.0.16", "serde", "serde_derive", "serde_json", "thiserror", - "toml 0.5.9", + "toml 0.5.11", "wasm-bindgen", - "wasmer-interface-types-fl", + "wasmer-interface-types-fl 0.26.0", "web-sys", ] @@ -1758,46 +2220,46 @@ dependencies = [ [[package]] name = "marine-min-it-version" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af8d201133f1ca6af9d9bc68a2fe03e16e7c5672456e1aa2c7785976f544265d" +version = "0.2.1" dependencies = [ "once_cell", - "semver 1.0.14", + "semver 1.0.16", ] [[package]] name = "marine-min-it-version" version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d23211d31dc45b0941666e867e717c951d3f446c27ddbf148b4fa62c4de1f159" dependencies = [ "once_cell", - "semver 1.0.14", + "semver 1.0.16", ] [[package]] name = "marine-module-info-parser" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "923184474998c2deadf603f95cd1d3a215f98428c90c0daff4ba98aa2de888f8" +version = "0.5.1" dependencies = [ "anyhow", "chrono", "marine-rs-sdk-main", - "semver 1.0.14", + "marine-wasm-backend-traits", + "semver 1.0.16", "serde", "thiserror", "walrus", - "wasmer-runtime-core-fl", ] [[package]] name = "marine-module-info-parser" version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06c2fa2dd89f704680d957aabdb6f0babdf5b041744739db5e5b36965b1b8ed1" dependencies = [ "anyhow", "chrono", "marine-rs-sdk-main", - "semver 1.0.14", + "semver 1.0.16", "serde", "thiserror", "walrus", @@ -1806,34 +2268,34 @@ dependencies = [ [[package]] name = "marine-module-interface" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ee2b9e4ac777a57359380fca1b1b5f71ff7ffa83a3b2a4aefd56fae4854296" +version = "0.6.1" dependencies = [ "anyhow", "itertools", - "marine-it-interfaces 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "nom", - "semver 1.0.14", + "marine-it-interfaces 0.7.3", + "nom 7.1.3", + "semver 1.0.16", "serde", "thiserror", "walrus", - "wasmer-interface-types-fl", + "wasmer-interface-types-fl 0.26.0", ] [[package]] name = "marine-module-interface" version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "311dad103f02acae6371adbeecbb18e01a0daf3fac7b9947ee020581f38841fa" dependencies = [ "anyhow", "itertools", - "marine-it-interfaces 0.7.3", - "nom", - "semver 1.0.14", + "marine-it-interfaces 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", + "nom 5.1.2", + "semver 1.0.16", "serde", "thiserror", "walrus", - "wasmer-interface-types-fl", + "wasmer-interface-types-fl 0.24.1", ] [[package]] @@ -1865,7 +2327,7 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f83cec3d030da1e06b72d241f76e7ff0b701aafe942ddf4ea8a9e053352d9935" dependencies = [ - "fluence-app-service 0.22.2", + "fluence-app-service 0.22.3", "marine-build-rs-generator", "marine-test-macro", "serde", @@ -1875,16 +2337,16 @@ dependencies = [ [[package]] name = "marine-runtime" -version = "0.25.0" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93f57e7471e12d4f758f57dc54241fe8a750d2be03725260326f85f18cc0625d" +checksum = "ed92c1e296d3790a78347a49d5519f02ab866d8bc7a2140075c09de6b5562a8c" dependencies = [ "bytesize", - "it-json-serde 0.3.4", + "it-json-serde 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "itertools", "log", - "marine-core 0.18.0", - "marine-module-interface 0.6.0", + "marine-core 0.18.1", + "marine-module-interface 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "marine-rs-sdk", "marine-rs-sdk-main", "marine-utils 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1894,8 +2356,8 @@ dependencies = [ "serde_json", "serde_with", "thiserror", - "toml 0.5.9", - "wasmer-interface-types-fl", + "toml 0.5.11", + "wasmer-interface-types-fl 0.24.1", "wasmer-runtime-core-fl", "wasmer-runtime-fl", "wasmer-wasi-fl", @@ -1908,6 +2370,7 @@ dependencies = [ "bytesize", "env_logger 0.9.3", "it-json-serde 0.3.5", + "it-memory-traits 0.4.0", "itertools", "log", "marine-core 0.19.0", @@ -1915,7 +2378,10 @@ dependencies = [ "marine-rs-sdk", "marine-rs-sdk-main", "marine-utils 0.4.0", + "marine-wasm-backend-traits", + "marine-wasmtime-backend", "once_cell", + "parking_lot 0.12.1", "pretty_assertions", "safe-transmute", "serde", @@ -1923,11 +2389,8 @@ dependencies = [ "serde_json", "serde_with", "thiserror", - "toml 0.5.9", - "wasmer-interface-types-fl", - "wasmer-runtime-core-fl", - "wasmer-runtime-fl", - "wasmer-wasi-fl", + "toml 0.5.11", + "wasmer-interface-types-fl 0.26.0", ] [[package]] @@ -1958,10 +2421,10 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50aa0bc3097682e7a8c90bd19b7d7dac13392b910865008fe27848de62ade756" dependencies = [ - "darling 0.14.1", - "fluence-app-service 0.22.2", + "darling", + "fluence-app-service 0.22.3", "itertools", - "marine-it-parser 0.11.0", + "marine-it-parser 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro-error", "proc-macro2", "quote", @@ -1991,17 +2454,54 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cff7a23a7f3925a712c34dfb9cd87994012d7743f016fd1533e12ab5a8335ca" [[package]] -name = "maybe-uninit" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" +name = "marine-wasm-backend-traits" +version = "0.1.0" +dependencies = [ + "anyhow", + "it-memory-traits 0.4.0", + "multimap", + "paste", + "thiserror", + "wasmer-interface-types-fl 0.26.0", + "wasmparser 0.101.1", +] [[package]] -name = "memchr" -version = "2.5.0" +name = "marine-wasmtime-backend" +version = "0.1.0" +dependencies = [ + "anyhow", + "it-memory-traits 0.4.0", + "log", + "marine-wasm-backend-traits", + "multimap", + "paste", + "wasmer-interface-types-fl 0.26.0", + "wasmtime", + "wasmtime-wasi", +] + +[[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.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b20a59d985586e4a5aef64564ac77299f8586d8be6cf9106a5a40207e8908efb" +dependencies = [ + "rustix", +] + [[package]] name = "memmap" version = "0.7.0" @@ -2021,31 +2521,46 @@ 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 = "mime" version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" -version = "0.5.4" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" +checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" dependencies = [ "adler", ] [[package]] name = "mio" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" +checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" dependencies = [ "libc", "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.36.1", + "windows-sys 0.42.0", ] [[package]] @@ -2054,12 +2569,13 @@ version = "0.20.0" dependencies = [ "anyhow", "check-latest", - "clap", + "clap 2.34.0", "env_logger 0.9.3", - "fluence-app-service 0.23.1", + "fluence-app-service 0.24.0", "itertools", "log", "marine-rs-sdk-main", + "marine-wasm-backend-traits", "rustop", "rustyline", "rustyline-derive", @@ -2067,7 +2583,6 @@ dependencies = [ "serde_json", "termion", "uuid", - "wasmer-wasi-fl", ] [[package]] @@ -2088,9 +2603,9 @@ dependencies = [ [[package]] name = "native-tls" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" dependencies = [ "lazy_static", "libc", @@ -2128,26 +2643,27 @@ dependencies = [ [[package]] name = "nix" -version = "0.19.1" +version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ccba0cfe4fdf15982d1674c69b1fd80bad427d293849982668dfe454bd61f2" +checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" dependencies = [ "bitflags", - "cc", "cfg-if 1.0.0", "libc", ] [[package]] name = "nix" -version = "0.24.2" +version = "0.25.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc" +checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4" dependencies = [ + "autocfg", "bitflags", "cfg-if 1.0.0", "libc", - "memoffset", + "memoffset 0.6.5", + "pin-utils", ] [[package]] @@ -2161,6 +2677,16 @@ dependencies = [ "version_check", ] +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "num-integer" version = "0.1.45" @@ -2182,20 +2708,11 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" -dependencies = [ - "hermit-abi 0.1.19", - "libc", -] - -[[package]] -name = "num_threads" -version = "0.1.6" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" dependencies = [ + "hermit-abi 0.2.6", "libc", ] @@ -2210,21 +2727,33 @@ name = "object" version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" +dependencies = [ + "crc32fast", + "hashbrown", + "indexmap", + "memchr", +] + +[[package]] +name = "object" +version = "0.30.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea86265d3d3dcb6a27fc51bd29a4bf387fae9d2986b823079d4986af253eb439" dependencies = [ "memchr", ] [[package]] name = "once_cell" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" +checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" [[package]] name = "openssl" -version = "0.10.41" +version = "0.10.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0" +checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1" dependencies = [ "bitflags", "cfg-if 1.0.0", @@ -2254,9 +2783,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.75" +version = "0.9.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f" +checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7" dependencies = [ "autocfg", "cc", @@ -2265,6 +2794,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "os_str_bytes" +version = "6.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" + [[package]] name = "output_vt100" version = "0.1.3" @@ -2302,15 +2837,25 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e" dependencies = [ - "lock_api", - "parking_lot_core", + "lock_api 0.3.4", + "parking_lot_core 0.7.3", +] + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api 0.4.9", + "parking_lot_core 0.9.7", ] [[package]] name = "parking_lot_core" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3" +checksum = "b93f386bb233083c799e6e642a9d73db98c24a5deeb95ffc85bf281255dffc98" dependencies = [ "cfg-if 0.1.10", "cloudabi", @@ -2320,11 +2865,24 @@ dependencies = [ "winapi", ] +[[package]] +name = "parking_lot_core" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall 0.2.16", + "smallvec", + "windows-sys 0.45.0", +] + [[package]] name = "paste" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" +checksum = "d01a5bd0424d00070b0098dd17ebca6f961a959dead1dbcbbbc1d1cd8d3deeba" [[package]] name = "percent-encoding" @@ -2346,21 +2904,27 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" [[package]] name = "polyplets" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18e540cb5c893983c540b95c09df91fa4976bf133d7d1c20cdf24faefad0274e" +checksum = "6c051f220264e391afae06b6dceda199d523ee1dc7ae8e8cba4119a378dd411f" dependencies = [ "marine-macro", "marine-rs-sdk-main", "serde", ] +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + [[package]] name = "pretty_assertions" version = "1.3.0" @@ -2396,12 +2960,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" - [[package]] name = "proc-macro2" version = "1.0.51" @@ -2418,6 +2976,15 @@ dependencies = [ "marine-rs-sdk", ] +[[package]] +name = "psm" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5787f7cda34e3033a72192c018bc5883100330f362ef279a8cbccfce8bb4e874" +dependencies = [ + "cc", +] + [[package]] name = "pwasm-utils" version = "0.19.0" @@ -2431,9 +2998,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.21" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" dependencies = [ "proc-macro2", ] @@ -2448,6 +3015,36 @@ dependencies = [ "nibble_vec", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.8", +] + [[package]] name = "raw-cpuid" version = "7.0.4" @@ -2461,25 +3058,23 @@ dependencies = [ [[package]] name = "rayon" -version = "1.5.3" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d" +checksum = "6db3a213adf02b3bcfd2d3846bb41cb22857d131789e01df434fb7e7bc0759b7" dependencies = [ - "autocfg", - "crossbeam-deque", "either", "rayon-core", ] [[package]] name = "rayon-core" -version = "1.9.3" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" +checksum = "356a0625f1954f730c0201cdab48611198dc6ce21f4acff55089b5a78e6e835b" dependencies = [ - "crossbeam-channel 0.5.6", + "crossbeam-channel", "crossbeam-deque", - "crossbeam-utils 0.8.11", + "crossbeam-utils", "num_cpus", ] @@ -2537,16 +3132,28 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom 0.2.7", + "getrandom 0.2.8", "redox_syscall 0.2.16", "thiserror", ] +[[package]] +name = "regalloc2" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300d4fbfb40c1c66a78ba3ddd41c1110247cf52f97b87d0f2fc9209bd49b030c" +dependencies = [ + "fxhash", + "log", + "slice-group-by", + "smallvec", +] + [[package]] name = "regex" -version = "1.6.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" dependencies = [ "aho-corasick", "memchr", @@ -2555,9 +3162,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.27" +version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" [[package]] name = "remove_dir_all" @@ -2570,11 +3177,11 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.13" +version = "0.11.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68cc60575865c7831548863cc02356512e3f1dc2f3f82cb837d7fc4cc8f3c97c" +checksum = "21eed90ec8570952d53b772ecf8f206aa1ec9a3d76b2521c56c42973f2d91ee9" dependencies = [ - "base64", + "base64 0.21.0", "bytes", "encoding_rs", "futures-core", @@ -2620,20 +3227,6 @@ dependencies = [ "semver 0.9.0", ] -[[package]] -name = "rustix" -version = "0.35.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72c825b8aa8010eb9ee99b75f05e10180b9278d161583034d7574c9d617aeada" -dependencies = [ - "bitflags", - "errno", - "io-lifetimes 0.7.3", - "libc", - "linux-raw-sys 0.0.46", - "windows-sys 0.36.1", -] - [[package]] name = "rustix" version = "0.36.8" @@ -2642,9 +3235,11 @@ checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644" dependencies = [ "bitflags", "errno", - "io-lifetimes 1.0.5", + "io-lifetimes", + "itoa", "libc", - "linux-raw-sys 0.1.4", + "linux-raw-sys", + "once_cell", "windows-sys 0.45.0", ] @@ -2656,15 +3251,15 @@ checksum = "cac77bea4e5c89acb455a2fe072bc19334cb130691af6e1bed4625d3f5396e89" [[package]] name = "rustversion" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" +checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70" [[package]] name = "rustyline" -version = "10.0.0" +version = "10.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d1cd5ae51d3f7bf65d7969d579d502168ef578f289452bd8ccc91de28fda20e" +checksum = "c1e83c32c3f3c33b08496e0d1df9ea8c64d39adb8eb36a1ebb1440c690697aef" dependencies = [ "bitflags", "cfg-if 1.0.0", @@ -2674,7 +3269,7 @@ dependencies = [ "libc", "log", "memchr", - "nix 0.24.2", + "nix 0.25.1", "radix_trie", "scopeguard", "skim", @@ -2697,9 +3292,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" +checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" [[package]] name = "safe-transmute" @@ -2709,12 +3304,11 @@ checksum = "98a01dab6acf992653be49205bdd549f32f17cb2803e8eacf1560bf97259aae8" [[package]] name = "schannel" -version = "0.1.20" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" +checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" dependencies = [ - "lazy_static", - "windows-sys 0.36.1", + "windows-sys 0.42.0", ] [[package]] @@ -2723,11 +3317,17 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "scratch" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2" + [[package]] name = "security-framework" -version = "2.7.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" +checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" dependencies = [ "bitflags", "core-foundation", @@ -2738,9 +3338,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.6.1" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" dependencies = [ "core-foundation-sys", "libc", @@ -2757,9 +3357,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.14" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" +checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a" dependencies = [ "serde", ] @@ -2791,9 +3391,9 @@ dependencies = [ [[package]] name = "serde_bytes" -version = "0.11.7" +version = "0.11.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfc50e8183eeeb6178dcb167ae34a8051d63535023ae38b5d8d12beae193d37b" +checksum = "416bda436f9aab92e02c8e10d49a15ddd339cea90b6e340fe51ed97abb548294" dependencies = [ "serde", ] @@ -2811,9 +3411,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.89" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db" +checksum = "7434af0dc1cbd59268aa98b4c22c131c0584d2232f6fb166efb993e2832e896a" dependencies = [ "itoa", "ryu", @@ -2843,52 +3443,57 @@ dependencies = [ [[package]] name = "serde_with" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25bf4a5a814902cd1014dbccfa4d4560fb8432c779471e96e035602519f82eef" +checksum = "30d904179146de381af4c93d3af6ca4984b3152db687dacb9c3c35e86f39809c" dependencies = [ - "base64", + "base64 0.13.1", "chrono", "hex", "indexmap", "serde", "serde_json", "serde_with_macros", - "time 0.3.14", + "time 0.3.17", ] [[package]] name = "serde_with_macros" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3452b4c0f6c1e357f73fdb87cd1efabaa12acf328c7a528e252893baeb3f4aa" +checksum = "a1966009f3c05f095697c537312f5415d1e3ed31ce0a56942bac4c771c5c335e" dependencies = [ - "darling 0.14.1", + "darling", "proc-macro2", "quote", "syn", ] [[package]] -name = "sha1" -version = "0.6.1" +name = "sha2" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" dependencies = [ - "sha1_smol", + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.10.6", ] [[package]] -name = "sha1_smol" -version = "1.0.0" +name = "shellexpand" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" +checksum = "7ccc8076840c4da029af4f87e4e8daeb0fca6b87bbb02e10cb60b791450e11e4" +dependencies = [ + "dirs", +] [[package]] name = "shlex" -version = "0.1.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" +checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" [[package]] name = "shrek" @@ -2899,27 +3504,27 @@ dependencies = [ [[package]] name = "skim" -version = "0.9.4" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b9d19f904221fab15163486d2ce116cb86e60296470bb4e956d6687f04ebbb4" +checksum = "cebed5f897cd6c0d80fbe30adb36c0abf7400e93043a63ae56458495642b3485" dependencies = [ "atty", "beef", "bitflags", "chrono", - "clap", + "clap 3.2.23", "crossbeam", "defer-drop", "derive_builder", - "env_logger 0.8.4", + "env_logger 0.9.3", "fuzzy-matcher", "lazy_static", "log", - "nix 0.19.1", + "nix 0.25.1", "rayon", "regex", "shlex", - "time 0.2.27", + "time 0.3.17", "timer", "tuikit", "unicode-width", @@ -2935,11 +3540,17 @@ dependencies = [ "autocfg", ] +[[package]] +name = "slice-group-by" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03b634d87b960ab1a38c4fe143b508576f075e7c978bfad18217645ebfdfa2ec" + [[package]] name = "smallvec" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "socket2" @@ -2952,13 +3563,10 @@ dependencies = [ ] [[package]] -name = "standback" -version = "0.2.17" +name = "stable_deref_trait" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" -dependencies = [ - "version_check", -] +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "static_assertions" @@ -2966,55 +3574,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "stdweb" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" -dependencies = [ - "discard", - "rustc_version", - "stdweb-derive", - "stdweb-internal-macros", - "stdweb-internal-runtime", - "wasm-bindgen", -] - -[[package]] -name = "stdweb-derive" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" -dependencies = [ - "proc-macro2", - "quote", - "serde", - "serde_derive", - "syn", -] - -[[package]] -name = "stdweb-internal-macros" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" -dependencies = [ - "base-x", - "proc-macro2", - "quote", - "serde", - "serde_derive", - "serde_json", - "sha1", - "syn", -] - -[[package]] -name = "stdweb-internal-runtime" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" - [[package]] name = "str-buf" version = "1.0.6" @@ -3027,12 +3586,6 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" -[[package]] -name = "strsim" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" - [[package]] name = "strsim" version = "0.10.0" @@ -3047,9 +3600,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.108" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d56e159d99e6c2b93995d171050271edb50ecc5288fbc7cc17de8fdce4e58c14" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" dependencies = [ "proc-macro2", "quote", @@ -3068,12 +3621,34 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "system-interface" +version = "0.25.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f355df185d945435f24c51fda9bf01bea6acb6c0b753e1241e5cc05413a659d4" +dependencies = [ + "bitflags", + "cap-fs-ext", + "cap-std", + "fd-lock", + "io-lifetimes", + "rustix", + "windows-sys 0.45.0", + "winx", +] + [[package]] name = "target-lexicon" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab0e7238dcc7b40a7be719a25365910f6807bd864f4cce6b2e6b873658e2b19d" +[[package]] +name = "target-lexicon" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9410d0f6853b1d94f0e519fb95df60f29d2c1eff2d921ffdf01a4c8a3b54f12d" + [[package]] name = "tempfile" version = "3.3.0" @@ -3101,9 +3676,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.3" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" dependencies = [ "winapi-util", ] @@ -3136,20 +3711,26 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "textwrap" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" + [[package]] name = "thiserror" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" +checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" +checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" dependencies = [ "proc-macro2", "quote", @@ -3167,9 +3748,9 @@ dependencies = [ [[package]] name = "time" -version = "0.1.44" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" dependencies = [ "libc", "wasi 0.10.0+wasi-snapshot-preview1", @@ -3178,52 +3759,29 @@ dependencies = [ [[package]] name = "time" -version = "0.2.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242" -dependencies = [ - "const_fn", - "libc", - "standback", - "stdweb", - "time-macros", - "version_check", - "winapi", -] - -[[package]] -name = "time" -version = "0.3.14" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c3f9a28b618c3a6b9251b6908e9c99e04b9e5c02e6581ccbb67d59c34ef7f9b" +checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376" dependencies = [ "itoa", - "libc", - "num_threads", "serde", + "time-core", + "time-macros", ] [[package]] -name = "time-macros" -version = "0.1.1" +name = "time-core" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1" -dependencies = [ - "proc-macro-hack", - "time-macros-impl", -] +checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" [[package]] -name = "time-macros-impl" -version = "0.1.2" +name = "time-macros" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" +checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2" dependencies = [ - "proc-macro-hack", - "proc-macro2", - "quote", - "standback", - "syn", + "time-core", ] [[package]] @@ -3246,15 +3804,15 @@ dependencies = [ [[package]] name = "tinyvec_macros" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.22.0" +version = "1.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76ce4a75fb488c605c54bf610f221cea8b0dafb53333c1a67e8ee199dcd2ae3" +checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af" dependencies = [ "autocfg", "bytes", @@ -3265,14 +3823,14 @@ dependencies = [ "pin-project-lite", "socket2", "tokio-macros", - "winapi", + "windows-sys 0.42.0", ] [[package]] name = "tokio-macros" -version = "1.8.0" +version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484" +checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" dependencies = [ "proc-macro2", "quote", @@ -3281,9 +3839,9 @@ dependencies = [ [[package]] name = "tokio-native-tls" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" dependencies = [ "native-tls", "tokio", @@ -3305,9 +3863,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.9" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" dependencies = [ "serde", ] @@ -3354,49 +3912,62 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.36" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if 1.0.0", + "log", "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tracing-core" -version = "0.1.29" +version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" +checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" dependencies = [ "once_cell", ] [[package]] name = "try-lock" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" +checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "tuikit" -version = "0.4.6" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "667c8e002675e76d98358d8869021793a472d28e3a50fbd750284a1d211abd09" +checksum = "5e19c6ab038babee3d50c8c12ff8b910bdb2196f62278776422f50390d8e53d8" dependencies = [ "bitflags", "lazy_static", "log", - "nix 0.24.2", + "nix 0.24.3", "term", "unicode-width", ] [[package]] name = "typenum" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" [[package]] name = "typetag" @@ -3424,42 +3995,42 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.8" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" +checksum = "d54675592c1dbefd78cbd98db9bacd89886e1ca50692a0692baefffdeb92dd58" [[package]] name = "unicode-ident" -version = "1.0.3" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" [[package]] name = "unicode-normalization" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" dependencies = [ "tinyvec", ] [[package]] name = "unicode-segmentation" -version = "1.9.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "unicode-width" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] name = "unicode-xid" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "url" @@ -3480,11 +4051,11 @@ checksum = "936e4b492acfd135421d8dca4b1aa80a7bfc26e702ef3af710e0752684df5372" [[package]] name = "uuid" -version = "1.2.2" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c" +checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" dependencies = [ - "getrandom 0.2.7", + "getrandom 0.2.8", ] [[package]] @@ -3523,11 +4094,11 @@ checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" [[package]] name = "vte" -version = "0.9.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e7745610024d50ab1ebfa41f8f8ee361c567f7ab51032f93cc1cc4cbf0c547a" +checksum = "1aae21c12ad2ec2d168c236f369c38ff332bc1134f7246350dca641437365045" dependencies = [ - "arrayvec", + "arrayvec 0.7.2", "utf8parse", "vte_generate_state_changes", ] @@ -3562,7 +4133,7 @@ version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a6e5bd22c71e77d60140b0bd5be56155a37e5bd14e24f5f87298040d0cc40d7" dependencies = [ - "heck", + "heck 0.3.3", "proc-macro2", "quote", "syn", @@ -3596,6 +4167,49 @@ 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 = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e90aedcb27963f120aaa7d27216c463f7e8a4f8277434dac88c836a856325dd" +dependencies = [ + "anyhow", + "async-trait", + "cap-fs-ext", + "cap-rand", + "cap-std", + "cap-time-ext", + "fs-set-times", + "io-extras", + "io-lifetimes", + "is-terminal", + "once_cell", + "rustix", + "system-interface", + "tracing", + "wasi-common", + "windows-sys 0.42.0", +] + +[[package]] +name = "wasi-common" +version = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae6ce6df8b37388a7772aacb9c5d4e9384f97f0abb1984983f892471c952e5be" +dependencies = [ + "anyhow", + "bitflags", + "cap-rand", + "cap-std", + "io-extras", + "rustix", + "thiserror", + "tracing", + "wasmtime", + "wiggle", + "windows-sys 0.42.0", +] + [[package]] name = "wasi-test" version = "0.1.0" @@ -3606,9 +4220,9 @@ dependencies = [ [[package]] name = "wasm-bindgen" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -3616,9 +4230,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" dependencies = [ "bumpalo", "log", @@ -3631,9 +4245,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.32" +version = "0.4.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa76fb221a1f8acddf5b54ace85912606980ad661ac7a503b4570ffd3a624dad" +checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -3643,9 +4257,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3653,9 +4267,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", @@ -3666,9 +4280,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" [[package]] name = "wasm-build-rs" @@ -3678,6 +4292,24 @@ dependencies = [ "marine-rs-sdk-test", ] +[[package]] +name = "wasm-encoder" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a584273ccc2d9311f1dd19dc3fb26054661fa3e373d53ede5d1144ba07a9acd" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-encoder" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c3e4bc09095436c8e7584d86d33e6c3ee67045af8fb262cbb9cc321de553428" +dependencies = [ + "leb128", +] + [[package]] name = "wasm-failing" version = "0.1.0" @@ -3727,9 +4359,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "532fb6cef712d9cd1ec68f9fc561447df33313393926f9bdb91fc3d67eed918f" dependencies = [ "byteorder", - "cranelift-codegen", - "cranelift-entity", - "cranelift-native", + "cranelift-codegen 0.59.0", + "cranelift-entity 0.59.0", + "cranelift-native 0.59.0", "libc", "nix 0.15.0", "rayon", @@ -3737,7 +4369,7 @@ dependencies = [ "serde-bench", "serde_bytes", "serde_derive", - "target-lexicon", + "target-lexicon 0.10.0", "wasmer-clif-fork-frontend", "wasmer-clif-fork-wasm", "wasmer-runtime-core-fl", @@ -3752,10 +4384,10 @@ version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c23f2824f354a00a77e4b040eef6e1d4c595a8a3e9013bad65199cc8dade9a5a" dependencies = [ - "cranelift-codegen", + "cranelift-codegen 0.59.0", "log", "smallvec", - "target-lexicon", + "target-lexicon 0.10.0", ] [[package]] @@ -3764,8 +4396,8 @@ version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a35e21d3aebc51cc6ebc0e830cf8458a9891c3482fb3c65ad18d408102929ae5" dependencies = [ - "cranelift-codegen", - "cranelift-entity", + "cranelift-codegen 0.59.0", + "cranelift-entity 0.59.0", "log", "thiserror", "wasmer-clif-fork-frontend", @@ -3778,19 +4410,40 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba2a3bf176a65a5a1a136be5b9440395c2ba4493a3a07ea70cac553fe924185d" dependencies = [ - "fluence-it-types", - "it-lilo", - "it-memory-traits", + "fluence-it-types 0.3.2", + "it-lilo 0.4.1", + "it-memory-traits 0.3.1", "it-to-bytes", "itertools", "log", - "nom", + "nom 5.1.2", "safe-transmute", - "semver 1.0.14", + "semver 1.0.16", "serde", "serde_json", "thiserror", - "wast", + "wast 8.0.0", +] + +[[package]] +name = "wasmer-interface-types-fl" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b3d15a6608fcdd309d6b4439616629ad84dbf28a21dba5bce447254a040b8a8" +dependencies = [ + "fluence-it-types 0.4.0", + "it-lilo 0.5.0", + "it-memory-traits 0.4.0", + "it-to-bytes", + "itertools", + "log", + "nom 7.1.3", + "safe-transmute", + "semver 1.0.16", + "serde", + "serde_json", + "thiserror", + "wast 53.0.0", ] [[package]] @@ -3810,14 +4463,14 @@ dependencies = [ "libc", "nix 0.15.0", "page_size", - "parking_lot", + "parking_lot 0.10.2", "rustc_version", "serde", "serde-bench", "serde_bytes", "serde_derive", "smallvec", - "target-lexicon", + "target-lexicon 0.10.0", "wasmparser 0.51.4", "winapi", ] @@ -3839,14 +4492,14 @@ dependencies = [ "libc", "nix 0.15.0", "page_size", - "parking_lot", + "parking_lot 0.10.2", "rustc_version", "serde", "serde-bench", "serde_bytes", "serde_derive", "smallvec", - "target-lexicon", + "target-lexicon 0.10.0", "wasmparser 0.51.4", "winapi", ] @@ -3879,7 +4532,7 @@ dependencies = [ "log", "serde", "thiserror", - "time 0.1.44", + "time 0.1.45", "typetag", "wasmer-runtime-core-fl", "winapi", @@ -3909,6 +4562,220 @@ version = "0.77.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b35c86d22e720a07d954ebbed772d01180501afe7d03d464f413bb5f8914a8d6" +[[package]] +name = "wasmparser" +version = "0.100.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64b20236ab624147dfbb62cf12a19aaf66af0e41b8398838b66e997d07d269d4" +dependencies = [ + "indexmap", + "url", +] + +[[package]] +name = "wasmparser" +version = "0.101.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf2f22ef84ac5666544afa52f326f13e16f3d019d2e61e704fd8091c9358b130" +dependencies = [ + "indexmap", + "url", +] + +[[package]] +name = "wasmtime" +version = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6e89f9819523447330ffd70367ef4a18d8c832e24e8150fe054d1d912841632" +dependencies = [ + "anyhow", + "bincode", + "cfg-if 1.0.0", + "indexmap", + "libc", + "log", + "object 0.29.0", + "once_cell", + "paste", + "psm", + "rayon", + "serde", + "target-lexicon 0.12.5", + "wasmparser 0.100.0", + "wasmtime-cache", + "wasmtime-cranelift", + "wasmtime-environ", + "wasmtime-jit", + "wasmtime-runtime", + "wat", + "windows-sys 0.42.0", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bd3a5e46c198032da934469f3a6e48649d1f9142438e4fd4617b68a35644b8a" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "wasmtime-cache" +version = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b389ae9b678b9c3851091a4804f4182d688d27aff7abc9aa37fa7be37d8ecffa" +dependencies = [ + "anyhow", + "base64 0.13.1", + "bincode", + "directories-next", + "file-per-thread-logger", + "log", + "rustix", + "serde", + "sha2", + "toml 0.5.11", + "windows-sys 0.42.0", + "zstd", +] + +[[package]] +name = "wasmtime-cranelift" +version = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59b2c92a08c0db6efffd88fdc97d7aa9c7c63b03edb0971dbca745469f820e8c" +dependencies = [ + "anyhow", + "cranelift-codegen 0.93.1", + "cranelift-entity 0.93.1", + "cranelift-frontend", + "cranelift-native 0.93.1", + "cranelift-wasm", + "gimli 0.26.2", + "log", + "object 0.29.0", + "target-lexicon 0.12.5", + "thiserror", + "wasmparser 0.100.0", + "wasmtime-environ", +] + +[[package]] +name = "wasmtime-environ" +version = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a6db9fc52985ba06ca601f2ff0ff1f526c5d724c7ac267b47326304b0c97883" +dependencies = [ + "anyhow", + "cranelift-entity 0.93.1", + "gimli 0.26.2", + "indexmap", + "log", + "object 0.29.0", + "serde", + "target-lexicon 0.12.5", + "thiserror", + "wasmparser 0.100.0", + "wasmtime-types", +] + +[[package]] +name = "wasmtime-jit" +version = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b77e3a52cd84d0f7f18554afa8060cfe564ccac61e3b0802d3fd4084772fa5f6" +dependencies = [ + "addr2line 0.17.0", + "anyhow", + "bincode", + "cfg-if 1.0.0", + "cpp_demangle", + "gimli 0.26.2", + "ittapi", + "log", + "object 0.29.0", + "rustc-demangle", + "serde", + "target-lexicon 0.12.5", + "wasmtime-environ", + "wasmtime-jit-debug", + "wasmtime-jit-icache-coherence", + "wasmtime-runtime", + "windows-sys 0.42.0", +] + +[[package]] +name = "wasmtime-jit-debug" +version = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0245e8a9347017c7185a72e215218a802ff561545c242953c11ba00fccc930f" +dependencies = [ + "object 0.29.0", + "once_cell", + "rustix", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67d412e9340ab1c83867051d8d1d7c90aa8c9afc91da086088068e2734e25064" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "windows-sys 0.42.0", +] + +[[package]] +name = "wasmtime-runtime" +version = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d594e791b5fdd4dbaf8cf7ae62f2e4ff85018ce90f483ca6f42947688e48827d" +dependencies = [ + "anyhow", + "cc", + "cfg-if 1.0.0", + "indexmap", + "libc", + "log", + "mach", + "memfd", + "memoffset 0.6.5", + "paste", + "rand", + "rustix", + "wasmtime-asm-macros", + "wasmtime-environ", + "wasmtime-jit-debug", + "windows-sys 0.42.0", +] + +[[package]] +name = "wasmtime-types" +version = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6688d6f96d4dbc1f89fab626c56c1778936d122b5f4ae7a57c2eb42b8d982e2" +dependencies = [ + "cranelift-entity 0.93.1", + "serde", + "thiserror", + "wasmparser 0.100.0", +] + +[[package]] +name = "wasmtime-wasi" +version = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38e749611f4ea64f19ad4da2324c86043f49ad946e6cc4ce057308d1319b2ba6" +dependencies = [ + "anyhow", + "wasi-cap-std-sync", + "wasi-common", + "wasmtime", + "wiggle", +] + [[package]] name = "wast" version = "8.0.0" @@ -3918,16 +4785,100 @@ dependencies = [ "leb128", ] +[[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 = "52.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15942180f265280eede7bc38b239e9770031d1821c02d905284216c645316430" +dependencies = [ + "leb128", + "memchr", + "unicode-width", + "wasm-encoder 0.22.1", +] + +[[package]] +name = "wast" +version = "53.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8244fa24196b1d8fd3ca4a96a3a164c40f846498c5deab6caf414c67340ca4af" +dependencies = [ + "leb128", + "memchr", + "unicode-width", + "wasm-encoder 0.23.0", +] + +[[package]] +name = "wat" +version = "1.0.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37212100d4cbe6f0f6ff6e707f1e5a5b5b675f0451231ed9e4235e234e127ed3" +dependencies = [ + "wast 52.0.3", +] + [[package]] name = "web-sys" -version = "0.3.60" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" +checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" dependencies = [ "js-sys", "wasm-bindgen", ] +[[package]] +name = "wiggle" +version = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba2420f80af94fc0e6f54ec45de6f6eb5b06b9b9ad2d1bd1923ed8a1288031b4" +dependencies = [ + "anyhow", + "async-trait", + "bitflags", + "thiserror", + "tracing", + "wasmtime", + "wiggle-macro", +] + +[[package]] +name = "wiggle-generate" +version = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93b0e0ff7e9d9c0b390475c07eedfeddb4e4259baba00032dacfe079616b689a" +dependencies = [ + "anyhow", + "heck 0.4.1", + "proc-macro2", + "quote", + "shellexpand", + "syn", + "witx", +] + +[[package]] +name = "wiggle-macro" +version = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "750332a587ddc8372d260ea1792a276b1c908cd93782e2da30c19db075d4d7a8" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wiggle-generate", +] + [[package]] name = "winapi" version = "0.3.9" @@ -3961,15 +4912,17 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" -version = "0.36.1" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ - "windows_aarch64_msvc 0.36.1", - "windows_i686_gnu 0.36.1", - "windows_i686_msvc 0.36.1", - "windows_x86_64_gnu 0.36.1", - "windows_x86_64_msvc 0.36.1", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] [[package]] @@ -3988,12 +4941,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" dependencies = [ "windows_aarch64_gnullvm", - "windows_aarch64_msvc 0.42.1", - "windows_i686_gnu 0.42.1", - "windows_i686_msvc 0.42.1", - "windows_x86_64_gnu 0.42.1", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", "windows_x86_64_gnullvm", - "windows_x86_64_msvc 0.42.1", + "windows_x86_64_msvc", ] [[package]] @@ -4002,48 +4955,24 @@ version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" -[[package]] -name = "windows_aarch64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" - [[package]] name = "windows_aarch64_msvc" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" -[[package]] -name = "windows_i686_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" - [[package]] name = "windows_i686_gnu" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" -[[package]] -name = "windows_i686_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" - [[package]] name = "windows_i686_msvc" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" -[[package]] -name = "windows_x86_64_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" - [[package]] name = "windows_x86_64_gnu" version = "0.42.1" @@ -4056,12 +4985,6 @@ version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" -[[package]] -name = "windows_x86_64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" - [[package]] name = "windows_x86_64_msvc" version = "0.42.1" @@ -4070,9 +4993,9 @@ checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" [[package]] name = "winnow" -version = "0.3.0" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efdd927d1a3d5d98abcfc4cf8627371862ee6abfe52a988050621c50c66b4493" +checksum = "ee7b2c67f962bf5042bfd8b6a916178df33a26eec343ae064cb8e069f638fa6f" dependencies = [ "memchr", ] @@ -4086,8 +5009,61 @@ dependencies = [ "winapi", ] +[[package]] +name = "winx" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "129cd8ee937d535e1a239d9d3c9c0525af0454bc0967d9211a251be062513520" +dependencies = [ + "bitflags", + "io-lifetimes", + "windows-sys 0.45.0", +] + +[[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 = "yansi" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" + +[[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.6+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68a3f9792c0c3dc6c165840a75f47ae1f4da402c2d006881129579f6597e801b" +dependencies = [ + "cc", + "libc", + "pkg-config", +] diff --git a/Cargo.toml b/Cargo.toml index 2436708e3..1fec72b39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,8 @@ members = [ "crates/min-it-version", "crates/module-info-parser", "crates/module-interface", + "crates/wasm-backend-traits", + "crates/wasmtime-backend", "crates/utils", "examples/call_parameters", "examples/failing", @@ -40,6 +42,12 @@ members = [ "tools/repl", ] +[workspace.dependencies] +wasmer-it = { package = "wasmer-interface-types-fl", version = "0.26.0" } +it-memory-traits ="0.4.0" +it-lilo = "0.5.0" +fluence-it-types = { version = "0.4.0", features = ["impls"] } + [profile.release] opt-level = 3 debug = false diff --git a/core/Cargo.toml b/core/Cargo.toml index 9321b5b1d..4c8cabc44 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -4,7 +4,7 @@ description = "Core of Marine, the Fluence Wasm Runtime" version = "0.19.0" authors = ["Fluence Labs"] license = "Apache-2.0" -edition = "2018" +edition = "2021" [lib] name = "marine_core" @@ -17,15 +17,13 @@ marine-it-parser = { path = "../crates/it-parser", version = "0.11.1" } marine-it-generator = { path = "../crates/it-generator", version = "0.9.5" } marine-module-interface = { path = "../crates/module-interface", version = "0.6.1" } marine-utils = { path = "../crates/utils", version = "0.4.0" } -marine-min-it-version = { path = "../crates/min-it-version", version = "0.2.1" } +marine-min-it-version = { path = "../crates/min-it-version", version = "0.2.1" } +marine-wasm-backend-traits = {path = "../crates/wasm-backend-traits", version = "0.1.0"} +marine-wasmtime-backend = { path = "../crates/wasmtime-backend", version = "0.1.0"} -wasmer-runtime = { package = "wasmer-runtime-fl", version = "=0.17.1" } -# dynamicfunc-fat-closures allows using state inside DynamicFunc -wasmer-core = { package = "wasmer-runtime-core-fl", version = "=0.17.1", features = ["dynamicfunc-fat-closures"] } -wasmer-it = { package = "wasmer-interface-types-fl", version = "0.24.1"} -wasmer-wasi = { package = "wasmer-wasi-fl", version = "0.17.1" } -it-lilo = "0.4.1" -it-memory-traits = "0.3.1" +wasmer-it = { workspace = true, default-features = false } +it-lilo = { workspace = true} +it-memory-traits = { workspace = true } bytesize = "1.1.0" multimap = "0.8.3" diff --git a/core/src/config.rs b/core/src/config.rs index cca8e6163..c8f015d32 100644 --- a/core/src/config.rs +++ b/core/src/config.rs @@ -18,9 +18,8 @@ use super::IValue; use super::IType; use crate::HostImportError; -use wasmer_wasi::WasiVersion; -use wasmer_runtime::ImportObject; -use wasmer_core::vm::Ctx; +use marine_wasm_backend_traits::WasiParameters; +use marine_wasm_backend_traits::WasmBackend; use std::path::PathBuf; use std::collections::HashMap; @@ -29,12 +28,21 @@ use std::collections::HashSet; // 65536*1600 ~ 100 Mb (Wasm page size is 64 Kb) const DEFAULT_HEAP_PAGES_COUNT: u32 = 1600; -pub type HostExportedFunc = Box) -> Option + 'static>; -pub type ErrorHandler = Option Option + 'static>>; +pub type ErrorHandler = + Option Option + Sync + Send + 'static>>; +pub type HostExportedFunc = Box< + dyn for<'c> Fn(&mut ::Caller<'c>, Vec) -> Option + + Sync + + Send + + 'static, +>; -pub struct HostImportDescriptor { +pub type RawImportCreator = + Box::ContextMut<'_>) -> ::Function>; + +pub struct HostImportDescriptor { /// This closure will be invoked for corresponding import. - pub host_exported_func: HostExportedFunc, + pub host_exported_func: HostExportedFunc, /// Type of the closure arguments. pub argument_types: Vec, @@ -47,41 +55,29 @@ pub struct HostImportDescriptor { pub error_handler: ErrorHandler, } -pub struct MModuleConfig { +pub struct MModuleConfig { /// Maximum number of Wasm memory pages that loaded module can use. /// Each Wasm page is 65536 bytes long. pub max_heap_pages_count: u32, /// Import object that will be used in module instantiation process. - pub raw_imports: ImportObject, + pub raw_imports: HashMap>, /// Imports from the host side that will be used in module instantiation process. - pub host_imports: HashMap, - - /// Desired WASI version. - pub wasi_version: WasiVersion, - - /// Environment variables for loaded modules. - pub wasi_envs: HashMap, Vec>, - - /// List of available directories for loaded modules. - pub wasi_preopened_files: HashSet, + pub host_imports: HashMap>, - /// Mapping between paths. - pub wasi_mapped_dirs: HashMap, + /// WASI parameters: env variables, mapped dirs, preopened files and args + pub wasi_parameters: WasiParameters, } -impl Default for MModuleConfig { +impl Default for MModuleConfig { fn default() -> Self { // some reasonable defaults Self { max_heap_pages_count: DEFAULT_HEAP_PAGES_COUNT, - raw_imports: ImportObject::new(), + raw_imports: HashMap::new(), host_imports: HashMap::new(), - wasi_version: WasiVersion::Latest, - wasi_envs: HashMap::new(), - wasi_preopened_files: HashSet::new(), - wasi_mapped_dirs: HashMap::new(), + wasi_parameters: WasiParameters::default(), } } } @@ -89,29 +85,24 @@ impl Default for MModuleConfig { // TODO: implement debug for MModuleConfig #[allow(dead_code)] -impl MModuleConfig { +impl MModuleConfig { pub fn with_mem_pages_count(mut self, mem_pages_count: u32) -> Self { self.max_heap_pages_count = mem_pages_count; self } - pub fn with_wasi_version(mut self, wasi_version: WasiVersion) -> Self { - self.wasi_version = wasi_version; - self - } - pub fn with_wasi_envs(mut self, envs: HashMap, Vec>) -> Self { - self.wasi_envs = envs; + self.wasi_parameters.envs = envs; self } pub fn with_wasi_preopened_files(mut self, preopened_files: HashSet) -> Self { - self.wasi_preopened_files = preopened_files; + self.wasi_parameters.preopened_files = preopened_files; self } pub fn with_wasi_mapped_dirs(mut self, mapped_dirs: HashMap) -> Self { - self.wasi_mapped_dirs = mapped_dirs; + self.wasi_parameters.mapped_dirs = mapped_dirs; self } } diff --git a/core/src/errors.rs b/core/src/errors.rs index 1ad6e0b2f..040733671 100644 --- a/core/src/errors.rs +++ b/core/src/errors.rs @@ -20,8 +20,7 @@ use crate::misc::PrepareError; use marine_it_interfaces::MITInterfacesError; use marine_it_parser::ITParserError; use marine_module_interface::it_interface::ITInterfaceError; - -use wasmer_runtime::error as wasmer_error; +use marine_wasm_backend_traits::errors::*; use thiserror::Error as ThisError; @@ -30,41 +29,13 @@ use thiserror::Error as ThisError; #[derive(Debug, ThisError)] pub enum MError { - /// This error type is produced by Wasmer during resolving a Wasm function. - #[error("Wasmer resolve error: {0}")] - ResolveError(#[from] wasmer_error::ResolveError), - - /// Error related to calling a main Wasm module. - #[error("Wasmer invoke error: {0}")] - WasmerInvokeError(String), - - /// Error that raises during compilation Wasm code by Wasmer. - #[error("Wasmer creation error: {0}")] - WasmerCreationError(#[from] wasmer_error::CreationError), - - /// Error that raises during creation of some Wasm objects (like table and memory) by Wasmer. - #[error("Wasmer compile error: {0}")] - WasmerCompileError(#[from] wasmer_error::CompileError), - - /// Errors arisen during execution of a Wasm module. - #[error("Wasmer runtime error: {0}")] - WasmerRuntimeError(String), - - /// Errors arisen during linking Wasm modules with already loaded into Marine modules. - #[error("Wasmer link error: {0}")] - WasmerLinkError(#[from] wasmer_error::LinkError), - - /// Errors from the temporary class of amalgamation errors from the Wasmer side. - #[error("Wasmer error: {0}")] - WasmerError(String), - /// Errors related to failed resolving of records. #[error("{0}")] - RecordResolveError(String), + RecordResolveError(String), // TODO: use a proper error type /// Errors arisen during creation of a WASI context. - #[error("{0}")] - WASIPrepareError(String), + #[error(transparent)] + WASIPrepareError(#[from] WasiError), /// Errors occurred inside marine-module-interface crate. #[error(transparent)] @@ -100,7 +71,10 @@ pub enum MError { /// Incorrect IT section. #[error("{0}")] - IncorrectWIT(String), + IncorrectWIT(String), // TODO: use a proper error type + + #[error("Wasm backend error: {0}")] + WasmBackendError(#[from] WasmBackendError), } impl From for MError { @@ -109,26 +83,32 @@ impl From for MError { } } -impl From for MError { - fn from(err: wasmer_error::RuntimeError) -> Self { - Self::WasmerRuntimeError(err.to_string()) +impl From for MError { + fn from(value: ModuleCreationError) -> Self { + Into::::into(value).into() + } +} + +impl From for MError { + fn from(value: ResolveError) -> Self { + Into::::into(value).into() } } -impl From for MError { - fn from(err: wasmer_error::Error) -> Self { - Self::WasmerError(err.to_string()) +impl From for MError { + fn from(value: ImportError) -> Self { + Into::::into(value).into() } } -impl From for MError { - fn from(err: wasmer_error::InvokeError) -> Self { - Self::WasmerInvokeError(err.to_string()) +impl From for MError { + fn from(value: InstantiationError) -> Self { + Into::::into(value).into() } } -impl From<()> for MError { - fn from(_err: ()) -> Self { - MError::IncorrectWIT("failed to parse instructions for adapter type".to_string()) +impl From for MError { + fn from(value: RuntimeError) -> Self { + Into::::into(value).into() } } diff --git a/core/src/host_imports/errors.rs b/core/src/host_imports/errors.rs index 97887f68d..9ae93129c 100644 --- a/core/src/host_imports/errors.rs +++ b/core/src/host_imports/errors.rs @@ -36,15 +36,15 @@ pub enum HostImportError { #[error("Not enough WValue arguments are provided from the Wasm side")] MismatchWValuesCount, - #[error("{0}")] + #[error(transparent)] LifterError(#[from] LiError), - #[error("{0}")] + #[error(transparent)] LowererError(#[from] LoError), - #[error("{0}")] + #[error(transparent)] RecordNotFound(#[from] RecordResolvableError), - #[error("{0}")] + #[error(transparent)] InvalidUTF8String(#[from] std::string::FromUtf8Error), } diff --git a/core/src/host_imports/imports.rs b/core/src/host_imports/imports.rs index 57b3de922..e3e5b5a69 100644 --- a/core/src/host_imports/imports.rs +++ b/core/src/host_imports/imports.rs @@ -22,124 +22,187 @@ use super::lowering::LoHelper; use super::utils::itypes_args_to_wtypes; use super::utils::itypes_output_to_wtypes; +use crate::IType; +use crate::IValue; use crate::MRecordTypes; -use crate::init_wasm_func_once; +use crate::init_wasm_func; use crate::call_wasm_func; -use crate::HostImportDescriptor; -use crate::module::wit_prelude::WITMemoryView; - -use wasmer_core::Func; -use wasmer_core::vm::Ctx; -use wasmer_core::typed_func::DynamicFunc; -use wasmer_core::types::Value as WValue; -use wasmer_core::types::FuncSig; +use crate::generic::HostImportDescriptor; + +use marine_wasm_backend_traits::prelude::*; + use it_lilo::lifter::ILifter; use it_lilo::lowerer::ILowerer; +use it_memory_traits::Memory as ITMemory; + +use std::sync::Arc; + +pub(crate) fn create_host_import_func( + store: &mut ::Store, + descriptor: HostImportDescriptor, + record_types: Arc, +) -> ::Function { + let raw_args = itypes_args_to_wtypes(&descriptor.argument_types); + let raw_output = + itypes_output_to_wtypes(&output_type_to_types(descriptor.output_type.as_ref())); -use std::cell::RefCell; -use std::rc::Rc; + let func = move |caller: ::Caller<'_>, inputs: &[WValue]| -> Vec { + call_host_import(caller, inputs, &descriptor, record_types.clone()) + }; -pub(crate) fn create_host_import_func( - descriptor: HostImportDescriptor, - record_types: Rc, -) -> DynamicFunc<'static> { - let allocate_func: AllocateFunc = Box::new(RefCell::new(None)); - let set_result_ptr_func: SetResultPtrFunc = Box::new(RefCell::new(None)); - let set_result_size_func: SetResultSizeFunc = Box::new(RefCell::new(None)); + ::Function::new_with_caller( + &mut store.as_context_mut(), + FuncSig::new(raw_args, raw_output), + func, + ) +} +fn call_host_import( + mut caller: ::Caller<'_>, + inputs: &[WValue], + descriptor: &HostImportDescriptor, + record_types: Arc, +) -> Vec { let HostImportDescriptor { host_exported_func, argument_types, - output_type, error_handler, + .. } = descriptor; - let output_type_to_types = |output_type| match output_type { - Some(ty) => vec![ty], - None => vec![], + let memory = caller + .memory(STANDARD_MEMORY_INDEX) + .unwrap_or_else(|| panic!("Host import called directly, not from wasm")); + + let inputs = lift_inputs::( + &mut caller, + memory.clone(), + record_types, + inputs, + argument_types, + ); + let output = match inputs { + Ok(ivalues) => host_exported_func(&mut caller, ivalues), + Err(e) => { + log::error!("error occurred while lifting values in host import: {}", e); + error_handler + .as_ref() + .map_or_else(|| default_error_handler(&e), |h| h(&e)) + } }; - let raw_args = itypes_args_to_wtypes(&argument_types); - let raw_output = itypes_output_to_wtypes(&output_type_to_types(output_type)); - - let func = move |ctx: &mut Ctx, inputs: &[WValue]| -> Vec { - let result = { - let memory_index = 0; - let memory = ctx.memory(memory_index); - let memory_view = WITMemoryView(memory.view::()); - let li_helper = LiHelper::new(record_types.clone()); - let lifter = ILifter::new(memory_view, &li_helper); - - match wvalues_to_ivalues(&lifter, inputs, &argument_types) { - Ok(ivalues) => host_exported_func(ctx, ivalues), - Err(e) => { - log::error!("error occurred while lifting values in host import: {}", e); - error_handler - .as_ref() - .map_or_else(|| default_error_handler(&e), |h| h(&e)) - } - } - }; - - init_wasm_func_once!(allocate_func, ctx, (i32, i32), i32, ALLOCATE_FUNC_NAME, 2); - - let memory_index = 0; - let memory = ctx.memory(memory_index); - let memory_view = WITMemoryView(memory.view::()); - let lo_helper = LoHelper::new(&allocate_func, ctx); - let t = ILowerer::new(memory_view, &lo_helper) + lower_outputs::(&mut caller, memory, output) +} + +fn lift_inputs( + caller: &mut ::Caller<'_>, + memory: ::Memory, + record_types: Arc, + inputs: &[WValue], + argument_types: &[IType], +) -> HostImportResult> { + let memory_view = memory.view(); + let li_helper = LiHelper::new(record_types); + let lifter = ILifter::new(memory_view, &li_helper); + wvalues_to_ivalues( + &mut caller.as_context_mut(), + &lifter, + inputs, + argument_types, + ) +} + +fn lower_outputs( + caller: &mut ::Caller<'_>, + memory: ::Memory, + output: Option, +) -> Vec { + init_wasm_func!( + allocate_func, + caller, + (i32, i32), + i32, + ALLOCATE_FUNC_NAME, + 2 + ); + + let is_record = matches!(&output, Some(IValue::Record(_))); + + let memory_view = memory.view(); + let mut lo_helper = LoHelper::new(&mut allocate_func, memory); + let lowering_result = + ILowerer::<'_, _, _, DelayedContextLifetime>::new(memory_view, &mut lo_helper) .map_err(HostImportError::LowererError) - .and_then(|lowerer| ivalue_to_wvalues(&lowerer, result)); - - let wvalues = match t { - Ok(wvalues) => wvalues, - Err(e) => { - log::error!("host closure failed: {}", e); - - // returns 0 to a Wasm module in case of errors - init_wasm_func_once!(set_result_ptr_func, ctx, i32, (), SET_PTR_FUNC_NAME, 4); - init_wasm_func_once!(set_result_size_func, ctx, i32, (), SET_SIZE_FUNC_NAME, 4); - - call_wasm_func!(set_result_ptr_func, 0); - call_wasm_func!(set_result_size_func, 0); - return vec![WValue::I32(0)]; - } - }; - - // TODO: refactor this when multi-value is supported - match wvalues.len() { - // strings and arrays are passed back to the Wasm module by pointer and size - 2 => { - init_wasm_func_once!(set_result_ptr_func, ctx, i32, (), SET_PTR_FUNC_NAME, 4); - init_wasm_func_once!(set_result_size_func, ctx, i32, (), SET_SIZE_FUNC_NAME, 4); - - call_wasm_func!(set_result_ptr_func, wvalues[0].to_u128() as _); - call_wasm_func!(set_result_size_func, wvalues[1].to_u128() as _); - vec![] - } - - // records and primitive types are passed to the Wasm module by pointer - // and value on the stack - 1 => { - init_wasm_func_once!(set_result_ptr_func, ctx, i32, (), SET_PTR_FUNC_NAME, 3); - - call_wasm_func!(set_result_ptr_func, wvalues[0].to_u128() as _); - vec![wvalues[0].clone()] - } - - // when None is passed - 0 => vec![], - - // at now while multi-values aren't supported ivalue_to_wvalues returns only Vec with - // 0, 1, 2 values - _ => unimplemented!(), + .and_then(|mut lowerer| { + ivalue_to_wvalues(&mut caller.as_context_mut(), &mut lowerer, output) + }); + + let wvalues = match lowering_result { + Ok(wvalues) => wvalues, + Err(e) => { + log::error!("host closure failed: {}", e); + + // returns 0 to a Wasm module in case of errors + init_wasm_func!(set_result_ptr_func, caller, i32, (), SET_PTR_FUNC_NAME, 4); + init_wasm_func!(set_result_size_func, caller, i32, (), SET_SIZE_FUNC_NAME, 4); + + call_wasm_func!(set_result_ptr_func, &mut caller.as_context_mut(), 0); + call_wasm_func!(set_result_size_func, &mut caller.as_context_mut(), 0); + return vec![WValue::I32(0)]; } }; - DynamicFunc::new( - std::sync::Arc::new(FuncSig::new(raw_args, raw_output)), - func, - ) + // TODO: refactor this when multi-value is supported + match wvalues.len() { + // strings and arrays are passed back to the Wasm module by pointer and size + // values used and consumed by set_result_ptr and set_result_size + 2 => { + init_wasm_func!(set_result_ptr_func, caller, i32, (), SET_PTR_FUNC_NAME, 4); + init_wasm_func!(set_result_size_func, caller, i32, (), SET_SIZE_FUNC_NAME, 4); + + call_wasm_func!( + set_result_ptr_func, + &mut caller.as_context_mut(), + wvalues[0].to_u128() as _ + ); + call_wasm_func!( + set_result_size_func, + &mut caller.as_context_mut(), + wvalues[1].to_u128() as _ + ); + vec![] + } + + // records lowerer returns only pointer which has to be used and consumed via set_result_ptr + 1 if is_record => { + init_wasm_func!(set_result_ptr_func, caller, i32, (), SET_PTR_FUNC_NAME, 3); + + call_wasm_func!( + set_result_ptr_func, + &mut caller.as_context_mut(), + wvalues[0].to_u128() as _ + ); + + vec![] + } + + // primitive values are passed as is + 1 => vec![wvalues[0].clone()], + + // when None is passed + 0 => vec![], + + // at now while multi-values aren't supported ivalue_to_wvalues returns only Vec with + // 0, 1, 2 values + _ => unimplemented!(), + } +} + +fn output_type_to_types(output_type: Option<&IType>) -> Vec { + match output_type { + Some(ty) => vec![ty.clone()], + None => vec![], + } } fn default_error_handler(err: &HostImportError) -> Option { diff --git a/core/src/host_imports/lifting/li_helper.rs b/core/src/host_imports/lifting/li_helper.rs index f5f94f711..cabb8248b 100644 --- a/core/src/host_imports/lifting/li_helper.rs +++ b/core/src/host_imports/lifting/li_helper.rs @@ -19,14 +19,14 @@ use crate::IRecordType; use it_lilo::traits::RecordResolvable; use it_lilo::traits::RecordResolvableError; -use std::rc::Rc; +use std::sync::Arc; pub(crate) struct LiHelper { - record_types: Rc, + record_types: Arc, } impl LiHelper { - pub(crate) fn new(record_types: Rc) -> Self { + pub(crate) fn new(record_types: Arc) -> Self { Self { record_types } } } diff --git a/core/src/host_imports/lifting/lift_ivalues.rs b/core/src/host_imports/lifting/lift_ivalues.rs index 86303cad7..d7cf4e24f 100644 --- a/core/src/host_imports/lifting/lift_ivalues.rs +++ b/core/src/host_imports/lifting/lift_ivalues.rs @@ -43,8 +43,13 @@ macro_rules! simple_wvalue_to_ivalue { }}; } -pub(crate) fn wvalues_to_ivalues( - lifter: &ILifter<'_, R, MV>, +pub(crate) fn wvalues_to_ivalues< + R: RecordResolvable, + MV: MemoryView, + S: it_memory_traits::Store, +>( + store: &mut ::ActualStore<'_>, + lifter: &ILifter<'_, R, MV, S>, wvalues: &[WValue], itypes: &[IType], ) -> HostImportResult> { @@ -73,7 +78,9 @@ pub(crate) fn wvalues_to_ivalues( let offset = next_wvalue!(wvalue, I32); let size = next_wvalue!(wvalue, I32); - let raw_str = lifter.reader.read_raw_u8_array(offset as _, size as _)?; + let raw_str = lifter + .reader + .read_raw_u8_array(store, offset as _, size as _)?; let str = String::from_utf8(raw_str)?; result.push(IValue::String(str)); } @@ -81,21 +88,23 @@ pub(crate) fn wvalues_to_ivalues( let offset = next_wvalue!(wvalue, I32); let size = next_wvalue!(wvalue, I32); - let array = lifter.reader.read_raw_u8_array(offset as _, size as _)?; + let array = lifter + .reader + .read_raw_u8_array(store, offset as _, size as _)?; result.push(IValue::ByteArray(array)); } IType::Array(ty) => { let offset = next_wvalue!(wvalue, I32); let size = next_wvalue!(wvalue, I32); - let array = array_lift_memory(lifter, ty, offset as _, size as _)?; + let array = array_lift_memory(store, lifter, ty, offset as _, size as _)?; result.push(array); } IType::Record(record_type_id) => { let record_type = lifter.resolver.resolve_record(*record_type_id)?; let offset = next_wvalue!(wvalue, I32); - let record = record_lift_memory(lifter, record_type, offset as _)?; + let record = record_lift_memory(store, lifter, record_type, offset as _)?; result.push(record); } } diff --git a/core/src/host_imports/lowering/lo_helper.rs b/core/src/host_imports/lowering/lo_helper.rs index 024043533..22b420085 100644 --- a/core/src/host_imports/lowering/lo_helper.rs +++ b/core/src/host_imports/lowering/lo_helper.rs @@ -15,34 +15,59 @@ */ use super::AllocateFunc; -use crate::module::wit_prelude::WITMemoryView; - use crate::call_wasm_func; + +use marine_wasm_backend_traits::DelayedContextLifetime; +use marine_wasm_backend_traits::WasmBackend; + use it_lilo::traits::Allocatable; use it_lilo::traits::AllocatableError; +use it_memory_traits::MemoryView; +use it_memory_traits::Memory; -use it_lilo::traits::DEFAULT_MEMORY_INDEX; -use wasmer_core::vm::Ctx; +use std::marker::PhantomData; -pub(crate) struct LoHelper<'c> { - allocate_func: &'c AllocateFunc, - ctx: &'c Ctx, +pub(crate) struct LoHelper< + 'c, + WB: WasmBackend, + MV: MemoryView>, + M: Memory>, +> { + allocate_func: &'c mut AllocateFunc, + memory: M, + _memory_view_phantom: PhantomData, } -impl<'c> LoHelper<'c> { - pub(crate) fn new(allocate_func: &'c AllocateFunc, ctx: &'c Ctx) -> Self { - Self { allocate_func, ctx } +impl< + 'c, + WB: WasmBackend, + MV: MemoryView>, + M: Memory>, + > LoHelper<'c, WB, MV, M> +{ + pub(crate) fn new(allocate_func: &'c mut AllocateFunc, memory: M) -> Self { + Self { + allocate_func, + memory, + _memory_view_phantom: <_>::default(), + } } } -impl<'s> Allocatable> for LoHelper<'s> { +impl< + 's, + WB: WasmBackend, + MV: MemoryView>, + M: Memory>, + > Allocatable> for LoHelper<'s, WB, MV, M> +{ fn allocate( - &self, + &mut self, + store: &mut ::ContextMut<'_>, size: u32, type_tag: u32, - ) -> Result<(u32, WITMemoryView<'s>), AllocatableError> { - let offset = call_wasm_func!(self.allocate_func, size as _, type_tag as _); - let view = WITMemoryView(self.ctx.memory(DEFAULT_MEMORY_INDEX as u32).view()); - Ok((offset as u32, view)) + ) -> Result<(u32, MV), AllocatableError> { + let offset = call_wasm_func!(self.allocate_func, store, size as _, type_tag as _); + Ok((offset as u32, self.memory.view())) } } diff --git a/core/src/host_imports/lowering/lower_ivalues.rs b/core/src/host_imports/lowering/lower_ivalues.rs index ab0195013..9cd045e4a 100644 --- a/core/src/host_imports/lowering/lower_ivalues.rs +++ b/core/src/host_imports/lowering/lower_ivalues.rs @@ -22,8 +22,13 @@ use it_lilo::lowerer::*; use it_lilo::traits::Allocatable; use it_memory_traits::MemoryView; -pub(crate) fn ivalue_to_wvalues, MV: MemoryView>( - lowerer: &ILowerer<'_, A, MV>, +pub(crate) fn ivalue_to_wvalues< + A: Allocatable, + MV: MemoryView, + Store: it_memory_traits::Store, +>( + store: &mut ::ActualStore<'_>, + lowerer: &mut ILowerer<'_, A, MV, Store>, ivalue: Option, ) -> HostImportResult> { let result = match ivalue { @@ -41,21 +46,21 @@ pub(crate) fn ivalue_to_wvalues, MV: MemoryView>( Some(IValue::F32(v)) => vec![WValue::F32(v)], Some(IValue::F64(v)) => vec![WValue::F64(v)], Some(IValue::String(str)) => { - let offset = lowerer.writer.write_bytes(str.as_bytes())?; + let offset = lowerer.writer.write_bytes(store, str.as_bytes())?; vec![WValue::I32(offset as _), WValue::I32(str.len() as _)] } Some(IValue::ByteArray(array)) => { - let offset = lowerer.writer.write_bytes(&array)?; + let offset = lowerer.writer.write_bytes(store, &array)?; vec![WValue::I32(offset as _), WValue::I32(array.len() as _)] } Some(IValue::Array(values)) => { - let LoweredArray { offset, size } = array_lower_memory(lowerer, values)?; + let LoweredArray { offset, size } = array_lower_memory(store, lowerer, values)?; vec![WValue::I32(offset as _), WValue::I32(size as _)] } Some(IValue::Record(values)) => { - let offset = record_lower_memory(lowerer, values)?; + let offset = record_lower_memory(store, lowerer, values)?; vec![WValue::I32(offset as i32)] } None => vec![], diff --git a/core/src/host_imports/mod.rs b/core/src/host_imports/mod.rs index 58590b55f..45f591334 100644 --- a/core/src/host_imports/mod.rs +++ b/core/src/host_imports/mod.rs @@ -20,20 +20,20 @@ mod lowering; mod imports; mod utils; -use std::cell::RefCell; -use wasmer_core::Func; +use marine_wasm_backend_traits::RuntimeResult; +use marine_wasm_backend_traits::WasmBackend; pub use errors::HostImportError; pub(crate) use imports::create_host_import_func; -pub(self) use wasmer_core::types::Value as WValue; -pub(self) use wasmer_core::types::Type as WType; +pub(self) use marine_wasm_backend_traits::WValue; +pub(self) use marine_wasm_backend_traits::WType; pub(self) type HostImportResult = std::result::Result; -pub(self) type WasmModuleFunc = Box>>>; -pub(self) type AllocateFunc = WasmModuleFunc<(i32, i32), i32>; -pub(self) type SetResultPtrFunc = WasmModuleFunc; -pub(self) type SetResultSizeFunc = WasmModuleFunc; +pub(self) type WasmModuleFunc = Box< + dyn FnMut(&mut ::ContextMut<'_>, Args) -> RuntimeResult + Sync + Send, +>; +pub(self) type AllocateFunc = WasmModuleFunc; pub(self) const ALLOCATE_FUNC_NAME: &str = "allocate"; pub(self) const SET_PTR_FUNC_NAME: &str = "set_result_ptr"; diff --git a/core/src/host_imports/utils.rs b/core/src/host_imports/utils.rs index 5104638f6..1f3ec2dfb 100644 --- a/core/src/host_imports/utils.rs +++ b/core/src/host_imports/utils.rs @@ -17,85 +17,6 @@ use super::WType; use crate::IType; -use wasmer_core::backend::SigRegistry; -use wasmer_core::module::ExportIndex; -use wasmer_core::vm::Ctx; -use wasmer_core::typed_func::WasmTypeList; -use wasmer_runtime::Func; -use wasmer_runtime::error::ResolveError; -use wasmer_runtime::types::LocalOrImport; - -// based on Wasmer: https://github.com/wasmerio/wasmer/blob/081f6250e69b98b9f95a8f62ad6d8386534f3279/lib/runtime-core/src/instance.rs#L863 -/// Extract export function from Wasmer instance by name. -pub(super) unsafe fn get_export_func_by_name<'a, Args, Rets>( - ctx: &'a mut Ctx, - name: &str, -) -> Result, ResolveError> -where - Args: WasmTypeList, - Rets: WasmTypeList, -{ - let module_inner = &(*ctx.module); - - let export_index = - module_inner - .info - .exports - .get(name) - .ok_or_else(|| ResolveError::ExportNotFound { - name: name.to_string(), - })?; - - let export_func_index = match export_index { - ExportIndex::Func(func_index) => func_index, - _ => { - return Err(ResolveError::ExportWrongType { - name: name.to_string(), - }) - } - }; - - let export_func_signature_idx = *module_inner - .info - .func_assoc - .get(*export_func_index) - .expect("broken invariant, incorrect func index"); - - let export_func_signature = &module_inner.info.signatures[export_func_signature_idx]; - let export_func_signature_ref = SigRegistry.lookup_signature_ref(export_func_signature); - - if export_func_signature_ref.params() != Args::types() - || export_func_signature_ref.returns() != Rets::types() - { - return Err(ResolveError::Signature { - expected: (*export_func_signature).clone(), - found: Args::types().to_vec(), - }); - } - - let func_wasm_inner = module_inner - .runnable_module - .get_trampoline(&module_inner.info, export_func_signature_idx) - .unwrap(); - - let export_func_ptr = match export_func_index.local_or_import(&module_inner.info) { - LocalOrImport::Local(local_func_index) => module_inner - .runnable_module - .get_func(&module_inner.info, local_func_index) - .unwrap(), - _ => { - return Err(ResolveError::ExportNotFound { - name: name.to_string(), - }) - } - }; - - let typed_func: Func<'_, Args, Rets, wasmer_core::typed_func::Wasm> = - Func::from_raw_parts(func_wasm_inner, export_func_ptr, None, ctx as _); - - Ok(typed_func) -} - pub(super) fn itypes_args_to_wtypes(itypes: &[IType]) -> Vec { itypes .iter() @@ -122,35 +43,26 @@ pub(super) fn itypes_output_to_wtypes(itypes: &[IType]) -> Vec { .collect() } -#[macro_export] // https://github.com/rust-lang/rust/issues/57966#issuecomment-461077932 -/// Initialize Wasm function in form of Box>>> only once. -macro_rules! init_wasm_func_once { +#[macro_export] +/// Initialize Wasm function in form of Box>>>. +/// This macro does not cache result. +macro_rules! init_wasm_func { ($func:ident, $ctx:ident, $args:ty, $rets:ty, $func_name:ident, $ret_error_code: expr) => { - if $func.borrow().is_none() { - let raw_func = match unsafe { - super::utils::get_export_func_by_name::<$args, $rets>($ctx, $func_name) - } { - Ok(func) => func, - Err(_) => return vec![WValue::I32($ret_error_code)], - }; - - unsafe { - // assumed that this function will be used only in the context of closure - // linked to a corresponding Wasm import, so it is safe to make is static - // because all Wasm imports live in the Wasmer instances, which - // is itself static (i.e., lives until the end of the program) - let raw_func = std::mem::transmute::, Func<'static, _, _>>(raw_func); - - *$func.borrow_mut() = Some(raw_func); - } - } + let mut $func: Box< + dyn FnMut(&mut ::ContextMut<'_>, $args) -> RuntimeResult<$rets> + + Send + + Sync, + > = match { $ctx.get_func($func_name) } { + Ok(func) => func, + Err(_) => return vec![WValue::I32($ret_error_code)], + }; }; } #[macro_export] /// Call Wasm function that have Box>>> type. macro_rules! call_wasm_func { - ($func:expr, $($arg:expr),*) => { - $func.borrow().as_ref().unwrap().call($($arg),*).unwrap() + ($func:expr, $store:expr, $($arg:expr),*) => { + $func.as_mut()($store, ($($arg),*)).unwrap() }; } diff --git a/core/src/lib.rs b/core/src/lib.rs index c7921e61e..564ff0e1f 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -35,10 +35,6 @@ mod misc; mod module; mod memory_statistic; -pub use config::MModuleConfig; -pub use config::HostExportedFunc; -pub use config::HostImportDescriptor; -pub use crate::marine_core::MarineCore; pub use crate::marine_core::MModuleInterface; pub use errors::MError; pub use host_imports::HostImportError; @@ -59,3 +55,21 @@ pub mod ne_vec { } pub(crate) type MResult = std::result::Result; + +pub mod generic { + pub use crate::config::MModuleConfig; + pub use crate::config::HostExportedFunc; + pub use crate::config::HostImportDescriptor; + pub use crate::marine_core::MarineCore; +} + +pub mod wasmtime { + pub type WasmBackend = marine_wasmtime_backend::WasmtimeWasmBackend; + + pub type MModuleConfig = crate::config::MModuleConfig; + pub type HostExportedFunc = crate::config::HostExportedFunc; + pub type HostImportDescriptor = crate::config::HostImportDescriptor; + pub type MarineCore = crate::marine_core::MarineCore; +} + +pub use crate::wasmtime::*; diff --git a/core/src/marine_core.rs b/core/src/marine_core.rs index 03b8d516c..5742a5431 100644 --- a/core/src/marine_core.rs +++ b/core/src/marine_core.rs @@ -14,15 +14,22 @@ * limitations under the License. */ -use super::*; +use super::generic::*; use crate::module::MModule; use crate::module::MRecordTypes; +use crate::{IRecordType, IValue, MemoryStats, MError, MFunctionSignature, ModuleMemoryStat, MResult}; + +use marine_wasm_backend_traits::AsContextMut; +use marine_wasm_backend_traits::Store; +use marine_wasm_backend_traits::WasiState; +use marine_wasm_backend_traits::WasmBackend; use serde::Serialize; use std::collections::hash_map::Entry; use std::collections::HashMap; -use std::rc::Rc; +use std::sync::Arc; +use std::cell::RefCell; /// Represent Marine module interface. #[derive(PartialEq, Eq, Debug, Clone, Serialize)] @@ -31,17 +38,36 @@ pub struct MModuleInterface<'a> { pub function_signatures: Vec, } +/// # Description +/// /// The base struct of Marine, the Fluence compute runtime. -pub struct MarineCore { +/// Allows dynamic loading and unloading modules, but never frees resources used for instantiation. +/// A new module can import functions from previously loaded modules. +/// +/// # Recommendations +/// +/// Its not recommended to use this struct to load/unload unlimited number of modules. +/// Better alternative is to use multiple instances of this struct for independent groups of modules +/// and drop them when the group is no longer needed. +pub struct MarineCore { // set of modules registered inside Marine - modules: HashMap, + modules: HashMap>, + // Wasm backend may have state in the future + #[allow(unused)] + wasm_backend: WB, + /// Container for all objects created by a Wasm backend. + store: RefCell<::Store>, } -impl MarineCore { - pub fn new() -> Self { - Self { +impl MarineCore { + pub fn new() -> MResult { + let wasm_backend = WB::new()?; + let store = ::Store::new(&wasm_backend); + Ok(Self { modules: HashMap::new(), - } + wasm_backend, + store: RefCell::new(store), + }) } /// Invoke a function of a module inside Marine by given function name with given arguments. @@ -52,10 +78,17 @@ impl MarineCore { arguments: &[IValue], ) -> MResult> { let module_name = module_name.as_ref(); - + let store = &mut self.store; self.modules.get_mut(module_name).map_or_else( || Err(MError::NoSuchModule(module_name.to_string())), - |module| module.call(module_name, func_name.as_ref(), arguments), + |module| { + module.call( + &mut store.get_mut().as_context_mut(), + module_name, + func_name.as_ref(), + arguments, + ) + }, ) } @@ -64,7 +97,7 @@ impl MarineCore { &mut self, name: impl Into, wasm_bytes: &[u8], - config: MModuleConfig, + config: MModuleConfig, ) -> MResult<()> { self.load_module_(name.into(), wasm_bytes, config) } @@ -73,11 +106,17 @@ impl MarineCore { &mut self, name: String, wasm_bytes: &[u8], - config: MModuleConfig, + config: MModuleConfig, ) -> MResult<()> { let _prepared_wasm_bytes = crate::misc::prepare_module(wasm_bytes, config.max_heap_pages_count)?; - let module = MModule::new(&name, wasm_bytes, config, &self.modules)?; + let module = MModule::new( + &name, + self.store.get_mut(), + wasm_bytes, + config, + &self.modules, + )?; match self.modules.entry(name) { Entry::Vacant(entry) => { @@ -97,10 +136,10 @@ impl MarineCore { .ok_or_else(|| MError::NoSuchModule(name.as_ref().to_string())) } - pub fn module_wasi_state( - &mut self, + pub fn module_wasi_state<'s>( + &'s mut self, module_name: impl AsRef, - ) -> Option<&wasmer_wasi::state::WasiState> { + ) -> Option> { self.modules .get_mut(module_name.as_ref()) .map(|module| module.get_wasi_state()) @@ -132,7 +171,7 @@ impl MarineCore { &self, module_name: impl AsRef, record_id: u64, - ) -> Option<&Rc> { + ) -> Option<&Arc> { self.modules .get(module_name.as_ref()) .and_then(|module| module.export_record_type_by_id(record_id)) @@ -144,14 +183,18 @@ impl MarineCore { .modules .iter() .map(|(module_name, module)| { - ModuleMemoryStat::new(module_name, module.memory_size(), module.max_memory_size()) + ModuleMemoryStat::new( + module_name, + module.memory_size(&mut self.store.borrow_mut().as_context_mut()), + module.max_memory_size(), + ) }) .collect::>(); records.into() } - fn get_module_interface(module: &MModule) -> MModuleInterface<'_> { + fn get_module_interface(module: &MModule) -> MModuleInterface<'_> { let record_types = module.export_record_types(); let function_signatures = module.get_exports_signatures().collect::>(); @@ -162,9 +205,3 @@ impl MarineCore { } } } - -impl Default for MarineCore { - fn default() -> Self { - Self::new() - } -} diff --git a/core/src/misc/prepare.rs b/core/src/misc/prepare.rs index adccfa4b6..61e61a07b 100644 --- a/core/src/misc/prepare.rs +++ b/core/src/misc/prepare.rs @@ -44,7 +44,8 @@ impl ModuleBootstrapper { } fn set_max_heap_pages_count(self, max_heap_pages_count: u32) -> PrepareResult { - use elements::{MemoryType, MemorySection}; + use elements::MemoryType; + use elements::MemorySection; let Self { mut module } = self; let globals_pages_count = get_heap_base(&module) diff --git a/core/src/misc/prepare/heap_base.rs b/core/src/misc/prepare/heap_base.rs index 28068c104..8ba6c2ccc 100644 --- a/core/src/misc/prepare/heap_base.rs +++ b/core/src/misc/prepare/heap_base.rs @@ -57,7 +57,8 @@ fn find_global_by_index( } fn u32_from_global_entry(global_entry: &elements::GlobalEntry) -> HResult { - use elements::{Instruction, ValueType}; + use elements::Instruction; + use elements::ValueType; let entry_type = global_entry.global_type().content_type(); if !matches!(entry_type, ValueType::I32) { diff --git a/core/src/misc/version_checker.rs b/core/src/misc/version_checker.rs index 2c3018f63..047c3d604 100644 --- a/core/src/misc/version_checker.rs +++ b/core/src/misc/version_checker.rs @@ -20,23 +20,18 @@ use super::PrepareError; use marine_module_info_parser::sdk_version; use marine_min_it_version::min_sdk_version; use marine_min_it_version::min_it_version; +use marine_wasm_backend_traits::WasmBackend; -use wasmer_core::Module; - -pub(crate) fn check_sdk_version( - name: impl Into, - wasmer_module: &Module, +pub(crate) fn check_sdk_version( + name: String, + wasmer_module: &::Module, ) -> PrepareResult<()> { - let module_version = sdk_version::extract_from_wasmer_module(wasmer_module)?; - let module_version = match module_version { - Some(module_version) => module_version, - None => return Err(PrepareError::ModuleWithoutVersion(name.into())), - }; + let module_version = sdk_version::extract_from_compiled_module::(wasmer_module)?; let required_version = min_sdk_version(); if module_version < *required_version { return Err(PrepareError::IncompatibleSDKVersions { - module_name: name.into(), + module_name: name, required: required_version.clone(), provided: module_version, }); diff --git a/core/src/module/marine_module.rs b/core/src/module/marine_module.rs index 8ef11b092..dd88c8d6d 100644 --- a/core/src/module/marine_module.rs +++ b/core/src/module/marine_module.rs @@ -17,140 +17,140 @@ use super::wit_prelude::*; use super::MFunctionSignature; use super::MRecordTypes; -use super::{IType, IRecordType, IFunctionArg, IValue, WValue}; +use super::IType; +use super::IRecordType; +use super::IFunctionArg; +use super::IValue; +use super::WValue; +use crate::generic::HostImportDescriptor; use crate::MResult; -use crate::MModuleConfig; +use crate::generic::MModuleConfig; +use crate::config::RawImportCreator; + +use marine_wasm_backend_traits::prelude::*; use marine_it_interfaces::MITInterfaces; use marine_it_parser::extract_it_from_module; use marine_utils::SharedString; -use wasmer_core::Instance as WasmerInstance; -use wasmer_core::import::Namespace; -use wasmer_runtime::compile; -use wasmer_runtime::ImportObject; use wasmer_it::interpreter::Interpreter; use std::collections::HashMap; use std::convert::TryInto; use std::mem::MaybeUninit; use std::sync::Arc; -use std::rc::Rc; +use std::borrow::BorrowMut; -const MEMORY_INDEX: u32 = 0; const START_FUNC: &str = "_start"; const INITIALIZE_FUNC: &str = "_initialize"; -type ITInterpreter = - Interpreter>; +type ITInterpreter = Interpreter< + ITInstance, + ITExport, + WITFunction, + ::Memory, + ::MemoryView, + DelayedContextLifetime, +>; #[derive(Clone)] -pub(super) struct ITModuleFunc { - interpreter: Arc, - pub(super) arguments: Rc>, - pub(super) output_types: Rc>, +pub(super) struct ITModuleFunc { + interpreter: Arc>, + pub(super) arguments: Arc>, + pub(super) output_types: Arc>, } #[derive(Clone)] -pub(super) struct Callable { - pub(super) it_instance: Arc, - pub(super) it_module_func: ITModuleFunc, +pub(super) struct Callable { + pub(super) it_instance: Arc>, + pub(super) it_module_func: ITModuleFunc, } -impl Callable { - pub fn call(&mut self, args: &[IValue]) -> MResult> { +impl Callable { + pub fn call( + &mut self, + store: &mut ::ContextMut<'_>, + args: &[IValue], + ) -> MResult> { use wasmer_it::interpreter::stack::Stackable; let result = self .it_module_func .interpreter - .run(args, Arc::make_mut(&mut self.it_instance))? + .run(args, Arc::make_mut(&mut self.it_instance), store)? .as_slice() .to_owned(); - Ok(result) } } -type ExportFunctions = HashMap>; +type ExportFunctions = HashMap>>; -pub(crate) struct MModule { - // wasmer_instance is needed because WITInstance contains dynamic functions - // that internally keep pointer to it. - #[allow(unused)] - wasmer_instance: Box, +pub(crate) struct MModule { + wasm_instance: Box<::Instance>, - // import_object is needed because ImportObject::extend doesn't really deep copy - // imports, so we need to store imports of this module to prevent their removing. - #[allow(unused)] - it_import_object: ImportObject, - - // host_import_object is needed because ImportObject::extend doesn't really deep copy - // imports, so we need to store imports of this module to prevent their removing. - #[allow(unused)] - host_import_object: ImportObject, - - // host_closures_import_object is needed because ImportObject::extend doesn't really deep copy - // imports, so we need to store imports of this module to prevent their removing. - #[allow(unused)] - host_closures_import_object: ImportObject, - - // TODO: replace with dyn Trait - export_funcs: ExportFunctions, + export_funcs: ExportFunctions, // TODO: save refs instead copying of a record types HashMap. /// Record types used in exported functions as arguments or return values. export_record_types: MRecordTypes, } -impl MModule { +impl MModule { pub(crate) fn new( name: &str, + store: &mut ::Store, wasm_bytes: &[u8], - config: MModuleConfig, - modules: &HashMap, + config: MModuleConfig, + modules: &HashMap>, ) -> MResult { - let wasmer_module = compile(wasm_bytes)?; - crate::misc::check_sdk_version(name, &wasmer_module)?; + let wasm_module = ::Module::new(store, wasm_bytes)?; + crate::misc::check_sdk_version::(name.to_string(), &wasm_module)?; - let it = extract_it_from_module(&wasmer_module)?; + let it = extract_it_from_module::(&wasm_module)?; crate::misc::check_it_version(name, &it.version)?; let mit = MITInterfaces::new(it); let mut wit_instance = Arc::new_uninit(); - let wit_import_object = Self::adjust_wit_imports(&mit, wit_instance.clone())?; - let raw_imports = config.raw_imports.clone(); - let (wasi_import_object, host_closures_import_object) = - Self::create_import_objects(config, &mit, wit_import_object.clone())?; + let mut linker = ::Imports::new(store); + + let MModuleConfig { + raw_imports, + host_imports, + wasi_parameters, + .. + } = config; + + Self::add_wit_imports(store, &mut linker, &mit, wit_instance.clone())?; + Self::add_wasi_imports(store, &mut linker, wasi_parameters)?; + Self::add_host_imports(store, &mut linker, raw_imports, host_imports, &mit)?; - let wasmer_instance = wasmer_module.instantiate(&wasi_import_object)?; + let wasm_instance = wasm_module.instantiate(store, &linker)?; let it_instance = unsafe { + // TODO: check if this MaybeUninit/Arc tricks are still needed // get_mut_unchecked here is safe because currently only this modules have reference to // it and the environment is single-threaded *Arc::get_mut_unchecked(&mut wit_instance) = - MaybeUninit::new(ITInstance::new(&wasmer_instance, name, &mit, modules)?); - std::mem::transmute::<_, Arc>(wit_instance) + MaybeUninit::new(ITInstance::new(&wasm_instance, store, name, &mit, modules)?); + std::mem::transmute::<_, Arc>>(wit_instance) }; let (export_funcs, export_record_types) = Self::instantiate_exports(&it_instance, &mit)?; + // backend is not expected to call _start or _initialize // call _initialize to populate the WASI state of the module #[rustfmt::skip] - if let Ok(initialize_func) = wasmer_instance.exports.get::>(INITIALIZE_FUNC) { - initialize_func.call()?; + if let Ok(initialize_func) = wasm_instance.get_function(store, INITIALIZE_FUNC) { + initialize_func.call(store, &[])?; } - // call _start to call module's main function #[rustfmt::skip] - if let Ok(start_func) = wasmer_instance.exports.get::>(START_FUNC) { - start_func.call()?; + if let Ok(start_func) = wasm_instance.get_function(store, START_FUNC) { + start_func.call(store, &[])?; } Ok(Self { - wasmer_instance: Box::new(wasmer_instance), - it_import_object: wit_import_object, - host_import_object: raw_imports, - host_closures_import_object, + wasm_instance: Box::new(wasm_instance), export_funcs, export_record_types, }) @@ -158,19 +158,33 @@ impl MModule { pub(crate) fn call( &mut self, + store: &mut ::ContextMut<'_>, module_name: &str, function_name: &str, args: &[IValue], ) -> MResult> { - self.export_funcs.get_mut(function_name).map_or_else( + log::debug!( + "calling {}::{} with args: {:?}", + module_name, + function_name, + args + ); + let res = self.export_funcs.get_mut(function_name).map_or_else( || { Err(MError::NoSuchFunction( module_name.to_string(), function_name.to_string(), )) }, - |func| Rc::make_mut(func).call(args), - ) + |func| Arc::make_mut(func).call(store, args), + ); + log::debug!( + "calling {}::{} with result: {:?}", + module_name, + function_name, + res + ); + res } pub(crate) fn get_exports_signatures(&self) -> impl Iterator + '_ { @@ -187,30 +201,28 @@ impl MModule { &self.export_record_types } - pub(crate) fn export_record_type_by_id(&self, record_type: u64) -> Option<&Rc> { + pub(crate) fn export_record_type_by_id(&self, record_type: u64) -> Option<&Arc> { self.export_record_types.get(&record_type) } - pub(crate) fn get_wasi_state(&mut self) -> &wasmer_wasi::state::WasiState { - unsafe { wasmer_wasi::state::get_wasi_state(self.wasmer_instance.context_mut()) } + pub(crate) fn get_wasi_state<'s>(&'s mut self) -> Box { + ::Wasi::get_wasi_state(self.wasm_instance.borrow_mut()) } /// Returns Wasm linear memory size that this module consumes in bytes. - pub(crate) fn memory_size(&self) -> usize { - let pages = self.wasmer_instance.context().memory(MEMORY_INDEX).size(); - pages.bytes().0 + pub(crate) fn memory_size(&self, store: &mut ::ContextMut<'_>) -> usize { + let memory = self + .wasm_instance + .get_nth_memory(store, STANDARD_MEMORY_INDEX) + .expect("It is expected that the existence of at least one memory is checked in the MModule::new function"); + + memory.size(store) } /// Returns max Wasm linear memory size that this module could consume in bytes. pub(crate) fn max_memory_size(&self) -> Option { - let maybe_pages = self - .wasmer_instance - .context() - .memory(MEMORY_INDEX) - .descriptor() - .maximum; - - maybe_pages.map(|pages| pages.bytes().0) + // TODO: provide limits API to marine wasm backend traits + None } // TODO: change the cloning Callable behaviour after changes of Wasmer API @@ -218,7 +230,7 @@ impl MModule { &self, module_name: &str, function_name: &str, - ) -> MResult> { + ) -> MResult>> { match self.export_funcs.get(function_name) { Some(func) => Ok(func.clone()), None => Err(MError::NoSuchFunction( @@ -228,121 +240,101 @@ impl MModule { } } - fn create_import_objects( - config: MModuleConfig, + fn add_wasi_imports( + store: &mut ::Store, + linker: &mut ::Imports, + parameters: WasiParameters, + ) -> MResult<()> { + ::Wasi::register_in_linker( + &mut store.as_context_mut(), + linker, + parameters, + )?; + + Ok(()) + } + + fn add_host_imports( + store: &mut ::Store, + linker: &mut ::Imports, + raw_imports: HashMap>, + host_imports: HashMap>, mit: &MITInterfaces<'_>, - wit_import_object: ImportObject, - ) -> MResult<(ImportObject, ImportObject)> { + ) -> MResult<()> { use crate::host_imports::create_host_import_func; - let wasi_envs = config - .wasi_envs - .into_iter() - .map(|(mut left, right)| { - left.push(61); // 61 is ASCII code of '=' - left.extend(right); - left - }) - .collect::>(); - let wasi_preopened_files = config.wasi_preopened_files.into_iter().collect::>(); - let wasi_mapped_dirs = config.wasi_mapped_dirs.into_iter().collect::>(); - - let mut wasi_import_object = wasmer_wasi::generate_import_object_for_version( - config.wasi_version, - vec![], - wasi_envs, - wasi_preopened_files, - wasi_mapped_dirs, - ) - .map_err(MError::WASIPrepareError)?; - - let mut host_closures_namespace = Namespace::new(); let record_types = mit .record_types() .map(|(id, r)| (id, r.clone())) .collect::>(); - let record_types = Rc::new(record_types); - - for (import_name, descriptor) in config.host_imports { - let host_import = create_host_import_func(descriptor, record_types.clone()); - host_closures_namespace.insert(import_name, host_import); - } - let mut host_closures_import_object = ImportObject::new(); - host_closures_import_object.register("host", host_closures_namespace); - - wasi_import_object.extend(wit_import_object); - wasi_import_object.extend(config.raw_imports); - wasi_import_object.extend(host_closures_import_object.clone()); + let record_types = Arc::new(record_types); - Ok((wasi_import_object, host_closures_import_object)) - } - - fn instantiate_exports( - it_instance: &Arc, - mit: &MITInterfaces<'_>, - ) -> MResult<(ExportFunctions, MRecordTypes)> { - let module_interface = marine_module_interface::it_interface::get_interface(mit)?; - - let export_funcs = module_interface - .function_signatures + let host_imports = host_imports .into_iter() - .map(|sign| { - let adapter_instructions = mit.adapter_by_type_r(sign.adapter_function_type)?; - - let interpreter: ITInterpreter = adapter_instructions.clone().try_into()?; - let it_module_func = ITModuleFunc { - interpreter: Arc::new(interpreter), - arguments: sign.arguments.clone(), - output_types: sign.outputs.clone(), - }; + .map(|(import_name, descriptor)| { + let func = create_host_import_func::(store, descriptor, record_types.clone()); + (import_name, func) + }) + .collect::>(); - let shared_string = SharedString(sign.name); - let callable = Rc::new(Callable { - it_instance: it_instance.clone(), - it_module_func, - }); + let all_imports = raw_imports + .into_iter() + .map(|(name, creator)| (name, creator(store.as_context_mut()))) + .chain(host_imports.into_iter()) + .collect::>(); - Ok((shared_string, callable)) - }) - .collect::>()?; + linker.register(store, "host", all_imports.into_iter())?; - Ok((export_funcs, module_interface.export_record_types)) + Ok(()) } // this function deals only with import functions that have an adaptor implementation - fn adjust_wit_imports( + fn add_wit_imports( + store: &mut ::Store, + linker: &mut ::Imports, wit: &MITInterfaces<'_>, - wit_instance: Arc>, - ) -> MResult { + wit_instance: Arc>>, + ) -> MResult<()> { use marine_it_interfaces::ITAstType; - use wasmer_core::typed_func::DynamicFunc; - use wasmer_core::vm::Ctx; // returns function that will be called from imports of Wasmer module - fn dyn_func_from_raw_import<'a, 'b, F>( - inputs: impl Iterator, - outputs: impl Iterator, + fn func_from_raw_import<'a, 'b, F, WB, I1, I2>( + store: &mut ::Store, + inputs: I1, + outputs: I2, raw_import: F, - ) -> DynamicFunc<'static> + ) -> ::Function where - F: Fn(&mut Ctx, &[WValue]) -> Vec + 'static, + F: for<'c> Fn(::Caller<'c>, &[WValue]) -> Vec + + Sync + + Send + + 'static, + WB: WasmBackend, + I1: Iterator, + I2: Iterator, { - use wasmer_core::types::FuncSig; use super::type_converters::itype_to_wtype; let inputs = inputs.map(itype_to_wtype).collect::>(); let outputs = outputs.map(itype_to_wtype).collect::>(); - DynamicFunc::new(Arc::new(FuncSig::new(inputs, outputs)), raw_import) + ::Function::new_with_caller( + &mut store.as_context_mut(), + FuncSig::new(inputs, outputs), + raw_import, + ) } // creates a closure that is represent a IT module import - fn create_raw_import( - wit_instance: Arc>, - interpreter: ITInterpreter, + fn create_raw_import( + wit_instance: Arc>>, + interpreter: ITInterpreter, import_namespace: String, import_name: String, - ) -> impl Fn(&mut Ctx, &[WValue]) -> Vec + 'static { - move |_: &mut Ctx, inputs: &[WValue]| -> Vec { + ) -> impl for<'c> Fn(::Caller<'c>, &[WValue]) -> Vec + + Sync + + Send + + 'static { + move |mut ctx: ::Caller<'_>, inputs: &[WValue]| -> Vec { use wasmer_it::interpreter::stack::Stackable; use super::type_converters::wval_to_ival; @@ -363,6 +355,7 @@ impl MModule { interpreter.run( &wit_inputs, Arc::make_mut(&mut wit_instance_callable.assume_init()), + &mut ctx.as_context_mut(), ) }; @@ -374,6 +367,7 @@ impl MModule { // TODO: optimize by prevent copying stack values outputs + .map_err(|e| log::error!("interpreter got error {e}")) .unwrap_or_default() .as_slice() .iter() @@ -402,7 +396,12 @@ impl MModule { arguments, output_types, } => { - let interpreter: ITInterpreter = adapter_instructions.clone().try_into()?; + let interpreter: ITInterpreter = + adapter_instructions.clone().try_into().map_err(|_| { + MError::IncorrectWIT( + "failed to parse instructions for adapter type".to_string(), + ) + })?; let raw_import = create_raw_import( wit_instance.clone(), @@ -411,7 +410,8 @@ impl MModule { import_name.to_string(), ); - let wit_import = dyn_func_from_raw_import( + let wit_import = func_from_raw_import::<_, WB, _, _>( + store, arguments.iter().map(|IFunctionArg { ty, .. }| ty), output_types.iter(), raw_import, @@ -427,17 +427,49 @@ impl MModule { }) .collect::>>()?; - let mut import_object = ImportObject::new(); - - // TODO: refactor this for (namespace_name, funcs) in wit_import_funcs.into_iter() { - let mut namespace = Namespace::new(); - for (import_name, import_func) in funcs.into_iter() { - namespace.insert(import_name.to_string(), import_func); - } - import_object.register(namespace_name, namespace); + let funcs = funcs.into_iter().map(|(name, f)| (name.to_string(), f)); + linker.register(store, namespace_name, funcs)?; } - Ok(import_object) + Ok(()) + } + + fn instantiate_exports( + it_instance: &Arc>, + mit: &MITInterfaces<'_>, + ) -> MResult<(ExportFunctions, MRecordTypes)> { + let module_interface = marine_module_interface::it_interface::get_interface(mit)?; + + let export_funcs = module_interface + .function_signatures + .into_iter() + .map(|sign| { + let adapter_instructions = mit.adapter_by_type_r(sign.adapter_function_type)?; + + let interpreter: ITInterpreter = + adapter_instructions.clone().try_into().map_err(|_| { + MError::IncorrectWIT( + "failed to parse instructions for adapter type".to_string(), + ) + })?; + + let it_module_func = ITModuleFunc { + interpreter: Arc::new(interpreter), + arguments: sign.arguments.clone(), + output_types: sign.outputs.clone(), + }; + + let shared_string = SharedString(sign.name); + let callable = Arc::new(Callable { + it_instance: it_instance.clone(), + it_module_func, + }); + + Ok((shared_string, callable)) + }) + .collect::>>()?; + + Ok((export_funcs, module_interface.export_record_types)) } } diff --git a/core/src/module/memory.rs b/core/src/module/memory.rs deleted file mode 100644 index 2bb1187ff..000000000 --- a/core/src/module/memory.rs +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2020 Fluence Labs Limited - * - * 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 it_memory_traits::{MemoryAccessError, MemoryView, MemoryReadable, MemoryWritable}; -use wasmer_it::interpreter::wasm; - -use wasmer_core::memory::Memory; -use wasmer_core::memory::MemoryView as WasmerMemoryView; -use wasmer_core::vm::LocalMemory; - -use std::iter::zip; - -pub(crate) struct WITMemoryView<'a>(pub(crate) WasmerMemoryView<'a, u8>); - -#[derive(Clone)] -pub(crate) struct WITMemory(pub(super) Memory); -impl std::ops::Deref for WITMemory { - type Target = Memory; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl<'s> MemoryReadable for WITMemoryView<'s> { - fn read_byte(&self, offset: u32) -> u8 { - self.0[offset as usize].get() - } - - // needed because clippy suggests using an iterator which looks worse - #[allow(clippy::needless_range_loop)] - fn read_array(&self, offset: u32) -> [u8; COUNT] { - let mut result = [0u8; COUNT]; - for index in 0..COUNT { - result[index] = self.0[offset as usize + index].get(); - } - - result - } - - // needed because clippy suggests using an iterator which looks worse - #[allow(clippy::needless_range_loop)] - fn read_vec(&self, offset: u32, size: u32) -> Vec { - let end = (offset + size) as usize; - let start = offset as usize; - self.0[start..end].iter().map(|v| v.get()).collect() - } -} - -impl<'s> MemoryWritable for WITMemoryView<'s> { - fn write_byte(&self, offset: u32, value: u8) { - self.0[offset as usize].set(value); - } - - fn write_bytes(&self, offset: u32, bytes: &[u8]) { - let offset = offset as usize; - let pairs = zip(bytes.iter(), self.0[offset..offset + bytes.len()].iter()); - - for (src, dst) in pairs { - dst.set(*src) - } - } -} - -impl<'s> MemoryView for WITMemoryView<'s> { - fn check_bounds(&self, offset: u32, size: u32) -> Result<(), MemoryAccessError> { - let memory_size = self.0.len() as u32; - if offset + size >= memory_size { - Err(MemoryAccessError::OutOfBounds { - offset, - size, - memory_size, - }) - } else { - Ok(()) - } - } -} - -impl<'a> wasm::structures::Memory> for WITMemory { - fn view(&self) -> WITMemoryView<'a> { - let LocalMemory { base, .. } = unsafe { *self.0.vm_local_memory() }; - let length = self.0.size().bytes().0 / std::mem::size_of::(); - - unsafe { WITMemoryView(WasmerMemoryView::new(base as _, length as u32)) } - } -} diff --git a/core/src/module/mod.rs b/core/src/module/mod.rs index 09e9ef0f4..f0201d19f 100644 --- a/core/src/module/mod.rs +++ b/core/src/module/mod.rs @@ -16,12 +16,12 @@ mod exports; mod marine_module; -mod memory; mod wit_function; mod wit_instance; mod type_converters; pub use wit_instance::MRecordTypes; + pub use wasmer_it::IType; pub use wasmer_it::IRecordType; pub use wasmer_it::ast::FunctionArg as IFunctionArg; @@ -31,19 +31,18 @@ pub use wasmer_it::to_interface_value; use serde::Serialize; use serde::Deserialize; -use std::rc::Rc; +use std::sync::Arc; /// Represent a function type inside Marine module. #[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)] pub struct MFunctionSignature { - pub name: Rc, - pub arguments: Rc>, - pub outputs: Rc>, + pub name: Arc, + pub arguments: Arc>, + pub outputs: Arc>, } pub(crate) use marine_module::MModule; -pub(self) use wasmer_core::types::Type as WType; -pub(self) use wasmer_core::types::Value as WValue; +pub(self) use marine_wasm_backend_traits::WValue; // types that often used together pub(crate) mod wit_prelude { @@ -51,7 +50,4 @@ pub(crate) mod wit_prelude { pub(super) use super::exports::ITExport; pub(super) use crate::MError; pub(super) use super::wit_function::WITFunction; - - pub(crate) use super::memory::WITMemoryView; - pub(crate) use super::memory::WITMemory; } diff --git a/core/src/module/type_converters.rs b/core/src/module/type_converters.rs index 6c1a1730e..a45da1bde 100644 --- a/core/src/module/type_converters.rs +++ b/core/src/module/type_converters.rs @@ -14,8 +14,11 @@ * limitations under the License. */ -/// Contains converters of types and values between Wasmer and wasmer_interface_types. -use super::{WType, WValue, IType, IValue}; +use super::IType; +use super::IValue; + +use marine_wasm_backend_traits::WType; +use marine_wasm_backend_traits::WValue; pub(super) fn wtype_to_itype(ty: &WType) -> IType { match ty { @@ -23,7 +26,10 @@ pub(super) fn wtype_to_itype(ty: &WType) -> IType { WType::I64 => IType::I64, WType::F32 => IType::F32, WType::F64 => IType::F64, - WType::V128 => unimplemented!(), + ty => { + eprintln!("trying to convert {:?}", ty); + unimplemented!() + } } } @@ -64,6 +70,5 @@ pub(super) fn wval_to_ival(value: &WValue) -> IValue { WValue::I64(v) => IValue::I64(*v), WValue::F32(v) => IValue::F32(*v), WValue::F64(v) => IValue::F64(*v), - _ => unimplemented!(), } } diff --git a/core/src/module/wit_function.rs b/core/src/module/wit_function.rs index ffb59f1b8..ac108ed17 100644 --- a/core/src/module/wit_function.rs +++ b/core/src/module/wit_function.rs @@ -15,42 +15,50 @@ */ use super::marine_module::MModule; -use super::{IType, IFunctionArg, IValue, WValue}; +use super::IType; +use super::IFunctionArg; +use super::IValue; use super::marine_module::Callable; use crate::MResult; +use marine_wasm_backend_traits::DelayedContextLifetime; +use marine_wasm_backend_traits::WasmBackend; +use marine_wasm_backend_traits::WValue; +use marine_wasm_backend_traits::Function; + use wasmer_it::interpreter::wasm; -use wasmer_core::instance::DynFunc; -// use std::sync::Arc; -use std::rc::Rc; +use std::sync::Arc; #[derive(Clone)] -enum WITFunctionInner { +enum WITFunctionInner { Export { - func: Rc>, + func: Arc<::Function>, }, Import { // TODO: use dyn Callable here - callable: Rc, + callable: Arc>, }, } /// Represents all import and export functions that could be called from IT context by call-core. #[derive(Clone)] -pub(super) struct WITFunction { +pub(super) struct WITFunction { name: String, - arguments: Rc>, - outputs: Rc>, - inner: WITFunctionInner, + arguments: Arc>, + outputs: Arc>, + inner: WITFunctionInner, } -impl WITFunction { +impl WITFunction { /// Creates functions from a "usual" (not IT) module export. - pub(super) fn from_export(dyn_func: DynFunc<'static>, name: String) -> MResult { + pub(super) fn from_export( + store: &mut ::Store, + dyn_func: ::Function, + name: String, + ) -> MResult { use super::type_converters::wtype_to_itype; - - let signature = dyn_func.signature(); + let signature = dyn_func.signature(store); let arguments = signature .params() .iter() @@ -67,11 +75,11 @@ impl WITFunction { .collect::>(); let inner = WITFunctionInner::Export { - func: Rc::new(dyn_func), + func: Arc::new(dyn_func), }; - let arguments = Rc::new(arguments); - let outputs = Rc::new(outputs); + let arguments = Arc::new(arguments); + let outputs = Arc::new(outputs); Ok(Self { name, @@ -83,11 +91,11 @@ impl WITFunction { /// Creates function from a module import. pub(super) fn from_import( - wit_module: &MModule, + wit_module: &MModule, module_name: &str, function_name: &str, - arguments: Rc>, - outputs: Rc>, + arguments: Arc>, + outputs: Arc>, ) -> MResult { let callable = wit_module.get_callable(module_name, function_name)?; @@ -104,7 +112,9 @@ impl WITFunction { } } -impl wasm::structures::LocalImport for WITFunction { +impl wasm::structures::LocalImport> + for WITFunction +{ fn name(&self) -> &str { self.name.as_str() } @@ -125,17 +135,28 @@ impl wasm::structures::LocalImport for WITFunction { &self.outputs } - fn call(&self, arguments: &[IValue]) -> std::result::Result, ()> { - use super::type_converters::{ival_to_wval, wval_to_ival}; - + fn call( + &self, + store: &mut ::ContextMut<'_>, + arguments: &[IValue], + ) -> std::result::Result, ()> { + use super::type_converters::wval_to_ival; + use super::type_converters::ival_to_wval; match &self.inner { WITFunctionInner::Export { func, .. } => func .as_ref() - .call(&arguments.iter().map(ival_to_wval).collect::>()) - .map(|result| result.iter().map(wval_to_ival).collect()) - .map_err(|_| ()), - WITFunctionInner::Import { callable, .. } => Rc::make_mut(&mut callable.clone()) - .call(arguments) + .call( + store, + arguments + .iter() + .map(ival_to_wval) + .collect::>() + .as_slice(), + ) + .map_err(|_| ()) + .map(|results| results.iter().map(wval_to_ival).collect()), + WITFunctionInner::Import { callable, .. } => Arc::make_mut(&mut callable.clone()) + .call(store, arguments) .map_err(|_| ()), } } diff --git a/core/src/module/wit_instance.rs b/core/src/module/wit_instance.rs index 843ceafaf..5e90443ac 100644 --- a/core/src/module/wit_instance.rs +++ b/core/src/module/wit_instance.rs @@ -19,40 +19,49 @@ use super::marine_module::MModule; use super::IRecordType; use crate::MResult; +use marine_wasm_backend_traits::AsContextMut; +use marine_wasm_backend_traits::STANDARD_MEMORY_EXPORT_NAME; +use marine_wasm_backend_traits::DelayedContextLifetime; +use marine_wasm_backend_traits::WasmBackend; +use marine_wasm_backend_traits::Instance; + use marine_it_interfaces::MITInterfaces; use marine_it_interfaces::ITAstType; + use wasmer_it::interpreter::wasm; -use wasmer_it::interpreter::wasm::structures::{LocalImportIndex, Memory, TypedIndex}; -use wasmer_core::Instance as WasmerInstance; +use wasmer_it::interpreter::wasm::structures::LocalImportIndex; +use wasmer_it::interpreter::wasm::structures::Memory; +use wasmer_it::interpreter::wasm::structures::TypedIndex; use std::collections::HashMap; -use std::rc::Rc; +use std::sync::Arc; -pub type MRecordTypes = HashMap>; +pub type MRecordTypes = HashMap>; /// Contains all import and export functions that could be called from IT context by call-core. #[derive(Clone)] -pub(super) struct ITInstance { +pub(super) struct ITInstance { /// IT functions indexed by id. - funcs: HashMap, + funcs: HashMap>, /// IT memories. - memories: Vec, + memories: Vec<::Memory>, /// All record types that instance contains. record_types_by_id: MRecordTypes, } -impl ITInstance { +impl ITInstance { pub(super) fn new( - wasmer_instance: &WasmerInstance, + wasm_instance: &::Instance, + store: &mut ::Store, module_name: &str, wit: &MITInterfaces<'_>, - modules: &HashMap, + modules: &HashMap>, ) -> MResult { - let mut exports = Self::extract_raw_exports(wasmer_instance, wit)?; + let mut exports = Self::extract_raw_exports(wasm_instance, store, wit)?; let imports = Self::extract_imports(module_name, modules, wit, exports.len())?; - let memories = Self::extract_memories(wasmer_instance); + let memories = Self::extract_memories(wasm_instance, store); exports.extend(imports); let funcs = exports; @@ -67,27 +76,18 @@ impl ITInstance { } fn extract_raw_exports( - wasmer_instance: &WasmerInstance, + wasm_instance: &::Instance, + store: &mut ::Store, it: &MITInterfaces<'_>, - ) -> MResult> { - use wasmer_core::DynFunc; - - let module_exports = &wasmer_instance.exports; - + ) -> MResult>> { it.exports() .enumerate() .map(|(export_id, export)| { - let export_func = module_exports.get(export.name)?; - unsafe { - // TODO: refactor this with new Wasmer API when it is ready - // here it is safe because dyn func is never lives WITInstance - let export_func = - std::mem::transmute::, DynFunc<'static>>(export_func); - Ok(( - export_id, - WITFunction::from_export(export_func, export.name.to_string())?, - )) - } + let export_func = wasm_instance.get_function(store, export.name)?; + Ok(( + export_id, + WITFunction::from_export(store, export_func, export.name.to_string())?, + )) }) .collect() } @@ -95,10 +95,10 @@ impl ITInstance { /// Extracts only those imports that don't have implementations. fn extract_imports( module_name: &str, - modules: &HashMap, + modules: &HashMap>, wit: &MITInterfaces<'_>, start_index: usize, - ) -> MResult> { + ) -> MResult>> { wit.imports() .filter(|import| // filter out imports that have implementations @@ -129,29 +129,29 @@ impl ITInstance { output_types, )?; - Ok((start_index + idx as usize, func)) + Ok((start_index + idx, func)) } None => Err(MError::NoSuchModule(import.namespace.to_string())), }) .collect::>>() } - fn extract_memories(wasmer_instance: &WasmerInstance) -> Vec { - use wasmer_core::export::Export::Memory; + fn extract_memories( + wasm_instance: &::Instance, + store: &mut ::Store, + ) -> Vec<::Memory> { + use marine_wasm_backend_traits::Export::Memory; - let mut memories = wasmer_instance - .exports() + let mut memories = wasm_instance + .export_iter(store.as_context_mut()) .filter_map(|(_, export)| match export { - Memory(memory) => Some(WITMemory(memory)), + Memory(memory) => Some(memory), _ => None, }) .collect::>(); - if let Some(Memory(memory)) = wasmer_instance - .import_object - .maybe_with_namespace("env", |env| env.get_export("memory")) - { - memories.push(WITMemory(memory)); + if let Ok(memory) = wasm_instance.get_memory(store, STANDARD_MEMORY_EXPORT_NAME) { + memories.push(memory); } memories @@ -175,19 +175,28 @@ impl ITInstance { } } -impl<'v> wasm::structures::Instance> - for ITInstance +impl + wasm::structures::Instance< + ITExport, + WITFunction, + ::Memory, + ::MemoryView, + DelayedContextLifetime, + > for ITInstance { fn export(&self, _export_name: &str) -> Option<&ITExport> { // exports aren't used in this version of IT None } - fn local_or_import(&self, index: I) -> Option<&WITFunction> { + fn local_or_import( + &self, + index: I, + ) -> Option<&WITFunction> { self.funcs.get(&index.index()) } - fn memory(&self, index: usize) -> Option<&WITMemory> { + fn memory(&self, index: usize) -> Option<&::Memory> { if index >= self.memories.len() { None } else { @@ -195,17 +204,17 @@ impl<'v> wasm::structures::Instance Option> { + fn memory_view(&self, index: usize) -> Option<::MemoryView> { if index >= self.memories.len() { return None; } let memory = &self.memories[index]; - let view: WITMemoryView<'static> = memory.view(); + let view: ::MemoryView = memory.view(); Some(view) } - fn wit_record_by_id(&self, index: u64) -> Option<&Rc> { + fn wit_record_by_id(&self, index: u64) -> Option<&Arc> { self.record_types_by_id.get(&index) } } diff --git a/core/tests/greeting.rs b/core/tests/greeting.rs index e055d3de0..7aa102fa9 100644 --- a/core/tests/greeting.rs +++ b/core/tests/greeting.rs @@ -26,9 +26,9 @@ static GREETING_WASM_BYTES: Lazy> = Lazy::new(|| { #[test] pub fn greeting_basic() { - let mut marine_core = MarineCore::new(); + let mut marine_core = MarineCore::new().unwrap(); marine_core - .load_module("greeting", &*GREETING_WASM_BYTES, <_>::default()) + .load_module("greeting", &GREETING_WASM_BYTES, <_>::default()) .unwrap_or_else(|e| panic!("can't load a module into Marine: {:?}", e)); let result1 = marine_core @@ -50,13 +50,13 @@ pub fn greeting_basic() { #[test] // test loading module with the same name twice pub fn non_unique_module_name() { - let mut marine_core = MarineCore::new(); + let mut marine_core = MarineCore::new().unwrap(); let module_name = String::from("greeting"); marine_core - .load_module(&module_name, &*GREETING_WASM_BYTES, <_>::default()) + .load_module(&module_name, &GREETING_WASM_BYTES, <_>::default()) .unwrap_or_else(|e| panic!("can't load a module into Marine: {:?}", e)); - let load_result = marine_core.load_module(&module_name, &*GREETING_WASM_BYTES, <_>::default()); + let load_result = marine_core.load_module(&module_name, &GREETING_WASM_BYTES, <_>::default()); assert!(load_result.is_err()); assert!(std::matches!( load_result.err().unwrap(), @@ -68,9 +68,9 @@ pub fn non_unique_module_name() { #[allow(unused_variables)] // test calling Marine with non-exist module and function names pub fn non_exist_module_func() { - let mut marine_core = MarineCore::new(); + let mut marine_core = MarineCore::new().unwrap(); marine_core - .load_module("greeting", &*GREETING_WASM_BYTES, <_>::default()) + .load_module("greeting", &GREETING_WASM_BYTES, <_>::default()) .unwrap_or_else(|e| panic!("can't load a module into Marine: {:?}", e)); let module_name = "greeting"; diff --git a/core/tests/records.rs b/core/tests/records.rs index 33a9d3630..a52b5966f 100644 --- a/core/tests/records.rs +++ b/core/tests/records.rs @@ -25,7 +25,7 @@ pub fn records() { let pure_wasm_bytes = std::fs::read("../examples/records/artifacts/records_pure.wasm") .expect("../examples/records/artifacts/records_pure.wasm should presence"); - let mut marine_core = MarineCore::new(); + let mut marine_core = MarineCore::new().unwrap(); let load_result = marine_core.load_module("pure", &pure_wasm_bytes, <_>::default()); assert!(load_result.is_err()); diff --git a/core/tests/redis_sqlite.rs b/core/tests/redis_sqlite.rs index 944912ce6..fd2790e19 100644 --- a/core/tests/redis_sqlite.rs +++ b/core/tests/redis_sqlite.rs @@ -35,7 +35,7 @@ pub async fn download(url: &str) -> bytes::Bytes { async fn redis() { let wasm_bytes = download(REDIS_DOWNLOAD_URL).await; - let mut marine_core = MarineCore::new(); + let mut marine_core = MarineCore::new().unwrap(); let module_name = "redis"; let config = <_>::default(); @@ -95,7 +95,7 @@ async fn redis() { async fn sqlite() { let wasm_bytes = download(SQLITE_DOWNLOAD_URL).await; - let mut marine_core = MarineCore::new(); + let mut marine_core = MarineCore::new().unwrap(); let module_name = "sqlite"; let config = <_>::default(); diff --git a/core/tests/wasm_tests/lilo_after_2gb/Cargo.toml b/core/tests/wasm_tests/lilo_after_2gb/Cargo.toml index b2ce6f078..a53c4999f 100644 --- a/core/tests/wasm_tests/lilo_after_2gb/Cargo.toml +++ b/core/tests/wasm_tests/lilo_after_2gb/Cargo.toml @@ -2,7 +2,7 @@ name = "lilo-after-2gb-test" version = "0.1.0" authors = ["Fluence Labs"] -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/crates/fluence-app-service/Cargo.toml b/crates/fluence-app-service/Cargo.toml index 37f3b770e..825f6a978 100644 --- a/crates/fluence-app-service/Cargo.toml +++ b/crates/fluence-app-service/Cargo.toml @@ -4,11 +4,13 @@ description = "Fluence Application Service" version = "0.24.0" authors = ["Fluence Labs"] license = "Apache-2.0" -edition = "2018" +edition = "2021" [dependencies] marine-runtime = { path = "../../marine", version = "0.25.0" } marine-min-it-version = { path = "../../crates/min-it-version", version = "0.2.1" } +marine-wasm-backend-traits = {path = "../wasm-backend-traits", version = "0.1.0"} +marine-wasmtime-backend = { path = "../wasmtime-backend", version = "0.1.0"} maplit = "1.0.2" log = "0.4.17" @@ -16,7 +18,6 @@ serde = "1.0.147" serde_derive = "1.0.147" serde_json = "1.0.89" toml = "0.5.9" -wasmer-wasi = { package = "wasmer-wasi-fl", version = "0.17.1" } [features] raw-module-api = ["marine-runtime/raw-module-api"] diff --git a/crates/fluence-app-service/src/config.rs b/crates/fluence-app-service/src/config.rs index d40093c18..f2c691cdd 100644 --- a/crates/fluence-app-service/src/config.rs +++ b/crates/fluence-app-service/src/config.rs @@ -15,6 +15,7 @@ */ use marine::MarineConfig; + use std::path::PathBuf; /// Describes behaviour of the Fluence AppService. diff --git a/crates/fluence-app-service/src/raw_toml_config.rs b/crates/fluence-app-service/src/raw_toml_config.rs index 1423fb21b..8e521ac7b 100644 --- a/crates/fluence-app-service/src/raw_toml_config.rs +++ b/crates/fluence-app-service/src/raw_toml_config.rs @@ -19,6 +19,7 @@ use crate::AppServiceError; use crate::config::AppServiceConfig; use marine::TomlMarineConfig; + use serde_derive::Serialize; use serde_derive::Deserialize; diff --git a/crates/fluence-app-service/src/service.rs b/crates/fluence-app-service/src/service.rs index dfda7c380..b273db611 100644 --- a/crates/fluence-app-service/src/service.rs +++ b/crates/fluence-app-service/src/service.rs @@ -20,9 +20,12 @@ use crate::MemoryStats; use crate::service_interface::ServiceInterface; use super::AppServiceError; +#[cfg(feature = "raw-module-api")] +use marine_wasm_backend_traits::WasiState; use marine::Marine; use marine::MarineModuleConfig; use marine::IValue; + use serde_json::Value as JValue; use maplit::hashmap; @@ -44,8 +47,8 @@ impl AppService { /// Create Service with given modules and service id. pub fn new(config: C, service_id: S, envs: HashMap, Vec>) -> Result where - S: Into, C: TryInto, + S: Into, AppServiceError: From, { let mut config: AppServiceConfig = config.try_into()?; @@ -222,7 +225,7 @@ impl AppService { pub fn load_module(&mut self, name: S, wasm_bytes: &[u8], config: Option) -> Result<()> where S: Into, - C: TryInto, + C: TryInto, marine::MarineError: From, { self.marine @@ -243,7 +246,7 @@ impl AppService { pub fn get_wasi_state( &mut self, module_name: impl AsRef, - ) -> Result<&wasmer_wasi::state::WasiState> { + ) -> Result> { self.marine .module_wasi_state(module_name) .map_err(Into::into) diff --git a/crates/fluence-app-service/src/service_interface.rs b/crates/fluence-app-service/src/service_interface.rs index 1994f585e..18296025c 100644 --- a/crates/fluence-app-service/src/service_interface.rs +++ b/crates/fluence-app-service/src/service_interface.rs @@ -22,7 +22,7 @@ use marine::itype_text_view; use serde::Serialize; -use std::rc::Rc; +use std::sync::Arc; #[derive(Serialize)] pub struct FunctionSignature { @@ -91,7 +91,7 @@ fn serialize_function_signature( fn serialize_record_type( id: u64, - record: Rc, + record: Arc, record_types: &MRecordTypes, ) -> RecordType { let fields = record diff --git a/crates/it-generator/Cargo.toml b/crates/it-generator/Cargo.toml index cdb101dda..90a6a3462 100644 --- a/crates/it-generator/Cargo.toml +++ b/crates/it-generator/Cargo.toml @@ -4,7 +4,7 @@ description = "Fluence Marine interface types generator" version = "0.9.5" authors = ["Fluence Labs"] license = "Apache-2.0" -edition = "2018" +edition = "2021" [lib] name = "marine_it_generator" @@ -14,8 +14,8 @@ path = "src/lib.rs" marine-it-parser = { path = "../it-parser", version = "0.11.1" } marine-macro-impl = "0.7.1" -wasmer-it = { package = "wasmer-interface-types-fl", version = "0.24.1"} -it-lilo = "0.4.1" +wasmer-it = { workspace = true } +it-lilo = { workspace = true} thiserror = "1.0.37" walrus = "0.19.0" diff --git a/crates/it-generator/src/default_export_api_config.rs b/crates/it-generator/src/default_export_api_config.rs index adb31f42f..a6e06b946 100644 --- a/crates/it-generator/src/default_export_api_config.rs +++ b/crates/it-generator/src/default_export_api_config.rs @@ -19,7 +19,7 @@ use wasmer_it::IType; use wasmer_it::ast::FunctionArg as IFunctionArg; use once_cell::sync::Lazy; -use std::rc::Rc; +use std::sync::Arc; pub(crate) struct ApiExportFuncDescriptor { pub(crate) name: &'static str, @@ -31,8 +31,8 @@ pub(crate) struct ApiExportFuncDescriptor { impl ApiExportFuncDescriptor { pub fn update_interfaces(&self, interfaces: &mut Interfaces<'_>) { let func_type = wasmer_it::ast::Type::Function { - arguments: Rc::new(self.arguments.clone()), - output_types: Rc::new(self.output_types.clone()), + arguments: Arc::new(self.arguments.clone()), + output_types: Arc::new(self.output_types.clone()), }; interfaces.types.push(func_type); diff --git a/crates/it-generator/src/instructions_generator.rs b/crates/it-generator/src/instructions_generator.rs index 77994fb89..4514f26d7 100644 --- a/crates/it-generator/src/instructions_generator.rs +++ b/crates/it-generator/src/instructions_generator.rs @@ -27,7 +27,7 @@ use wasmer_it::IType; use wasmer_it::ast::Interfaces; use wasmer_it::IRecordType; -use std::rc::Rc; +use std::sync::Arc; #[derive(PartialEq, Eq, Debug, Default)] pub(crate) struct ITResolver<'a> { @@ -58,7 +58,7 @@ impl<'a> ITResolver<'a> { self.types.insert(record_name.to_string(), new_type_id); self.interfaces .types - .push(Type::Record(Rc::new(IRecordType::default()))); + .push(Type::Record(Arc::new(IRecordType::default()))); self.unresolved_types_count += 1; new_type_id @@ -87,14 +87,14 @@ impl<'a> ITResolver<'a> { match self.types.get(&record.name) { Some(pos) => { - self.interfaces.types[*pos] = Type::Record(Rc::new(record)); + self.interfaces.types[*pos] = Type::Record(Arc::new(record)); self.unresolved_types_count -= 1; } None => { self.types .insert(record.name.clone(), self.interfaces.types.len()); - self.interfaces.types.push(Type::Record(Rc::new(record))); + self.interfaces.types.push(Type::Record(Arc::new(record))); } } } @@ -152,8 +152,8 @@ impl<'a> ITResolver<'a> { pub(crate) fn add_fn_type( &mut self, - arguments: Rc>, - output_types: Rc>, + arguments: Arc>, + output_types: Arc>, ) { let fn_type = wasmer_it::ast::Type::Function { arguments, diff --git a/crates/it-generator/src/instructions_generator/fn_instructions/args_it_generator.rs b/crates/it-generator/src/instructions_generator/fn_instructions/args_it_generator.rs index 8065fe181..82dd9a9fa 100644 --- a/crates/it-generator/src/instructions_generator/fn_instructions/args_it_generator.rs +++ b/crates/it-generator/src/instructions_generator/fn_instructions/args_it_generator.rs @@ -25,16 +25,16 @@ use wasmer_it::IType; /// Generates IT instructions for a argument of an export function. pub(super) trait ArgumentITGenerator { - fn generate_instructions_for_arg<'a>( + fn generate_instructions_for_arg( &self, arg_id: u32, - it_resolver: &mut ITResolver<'a>, + it_resolver: &mut ITResolver<'_>, ) -> Result>; } impl ArgumentITGenerator for ParsedType { #[rustfmt::skip] - fn generate_instructions_for_arg<'a>(&self, index: u32, it_resolver: &mut ITResolver<'a>) -> Result> { + fn generate_instructions_for_arg(&self, index: u32, it_resolver: &mut ITResolver<'_>) -> Result> { let instructions = match self { ParsedType::Boolean(_) => vec![Instruction::ArgumentGet { index }, Instruction::I32FromBool], ParsedType::I8(_) => vec![Instruction::ArgumentGet { index }, Instruction::I32FromS8], diff --git a/crates/it-generator/src/instructions_generator/fn_instructions/output_type_it_generator.rs b/crates/it-generator/src/instructions_generator/fn_instructions/output_type_it_generator.rs index eca5b4b78..db5b9612c 100644 --- a/crates/it-generator/src/instructions_generator/fn_instructions/output_type_it_generator.rs +++ b/crates/it-generator/src/instructions_generator/fn_instructions/output_type_it_generator.rs @@ -25,15 +25,15 @@ use wasmer_it::IType; /// Generates IT instructions for a output type of an export function. pub(super) trait OutputITGenerator { - fn generate_instructions_for_output_type<'a>( + fn generate_instructions_for_output_type( &self, - it_resolver: &mut ITResolver<'a>, + it_resolver: &mut ITResolver<'_>, ) -> Result>; } impl OutputITGenerator for ParsedType { #[rustfmt::skip] - fn generate_instructions_for_output_type<'a>(&self, it_resolver: &mut ITResolver<'a>) -> Result> { + fn generate_instructions_for_output_type(&self, it_resolver: &mut ITResolver<'_>) -> Result> { let instructions = match self { ParsedType::Boolean(_) => vec![Instruction::BoolFromI32], ParsedType::I8(_) => vec![Instruction::S8FromI32], diff --git a/crates/it-generator/src/instructions_generator/foreign_mod_instructions.rs b/crates/it-generator/src/instructions_generator/foreign_mod_instructions.rs index 10b2c1bed..eeebdf2f7 100644 --- a/crates/it-generator/src/instructions_generator/foreign_mod_instructions.rs +++ b/crates/it-generator/src/instructions_generator/foreign_mod_instructions.rs @@ -33,7 +33,7 @@ use wasmer_it::ast::FunctionArg as IFunctionArg; use wasmer_it::interpreter::Instruction; use wasmer_it::IType; -use std::rc::Rc; +use std::sync::Arc; const HOST_NAMESPACE_NAME: &str = "host"; @@ -148,17 +148,17 @@ fn generate_it_instructions<'f>( Ok(()) } -pub(crate) fn generate_raw_args(signature: &FnSignature) -> Rc> { +pub(crate) fn generate_raw_args(signature: &FnSignature) -> Arc> { let raw_inputs = signature .arguments .iter() .flat_map(to_raw_input_types) .collect::>(); - Rc::new(raw_inputs) + Arc::new(raw_inputs) } -pub(crate) fn generate_raw_output_type(signature: &FnSignature) -> Rc> { +pub(crate) fn generate_raw_output_type(signature: &FnSignature) -> Arc> { let raw_outputs = signature .output_types .iter() @@ -170,7 +170,7 @@ pub(crate) fn generate_raw_output_type(signature: &FnSignature) -> Rc }) .collect::>(); - Rc::new(raw_outputs) + Arc::new(raw_outputs) } use marine_macro_impl::RustType; diff --git a/crates/it-generator/src/instructions_generator/foreign_mod_instructions/args_it_generator.rs b/crates/it-generator/src/instructions_generator/foreign_mod_instructions/args_it_generator.rs index 55853cb03..947068d91 100644 --- a/crates/it-generator/src/instructions_generator/foreign_mod_instructions/args_it_generator.rs +++ b/crates/it-generator/src/instructions_generator/foreign_mod_instructions/args_it_generator.rs @@ -24,19 +24,19 @@ use wasmer_it::IType; /// Generate IT instructions for a foreign mod. pub(super) trait ArgumentITGenerator { - fn generate_instructions_for_arg<'a>( + fn generate_instructions_for_arg( &self, arg_id: u32, - it_resolver: &mut ITResolver<'a>, + it_resolver: &mut ITResolver<'_>, ) -> Result<(Vec, u32)>; } #[rustfmt::skip] impl ArgumentITGenerator for ParsedType { - fn generate_instructions_for_arg<'a>( + fn generate_instructions_for_arg( &self, index: u32, - it_resolver: &mut ITResolver<'a>, + it_resolver: &mut ITResolver<'_>, ) -> Result<(Vec, u32)> { let instructions = match self { ParsedType::Boolean(_) => (vec![Instruction::ArgumentGet { index }, Instruction::BoolFromI32], 1), diff --git a/crates/it-generator/src/instructions_generator/foreign_mod_instructions/output_type_it_generator.rs b/crates/it-generator/src/instructions_generator/foreign_mod_instructions/output_type_it_generator.rs index db4bafdc4..0df232bec 100644 --- a/crates/it-generator/src/instructions_generator/foreign_mod_instructions/output_type_it_generator.rs +++ b/crates/it-generator/src/instructions_generator/foreign_mod_instructions/output_type_it_generator.rs @@ -25,16 +25,16 @@ use wasmer_it::IType; /// Generate IT instructions for a foreign mod. pub(super) trait OutputITGenerator { - fn generate_instructions_for_output_type<'a>( + fn generate_instructions_for_output_type( &self, - it_resolver: &mut ITResolver<'a>, + it_resolver: &mut ITResolver<'_>, ) -> Result>; } #[rustfmt::skip] impl OutputITGenerator for ParsedType { #[rustfmt::skip] - fn generate_instructions_for_output_type<'a>(&self, it_resolver: &mut ITResolver<'a>) -> Result> { + fn generate_instructions_for_output_type(&self, it_resolver: &mut ITResolver<'_>) -> Result> { let instructions = match self { ParsedType::Boolean(_) => vec![Instruction::I32FromBool], ParsedType::I8(_) => vec![Instruction::I32FromS8], diff --git a/crates/it-generator/src/instructions_generator/utils.rs b/crates/it-generator/src/instructions_generator/utils.rs index adf5d492a..5743039d3 100644 --- a/crates/it-generator/src/instructions_generator/utils.rs +++ b/crates/it-generator/src/instructions_generator/utils.rs @@ -23,7 +23,7 @@ use marine_macro_impl::ParsedType; use marine_macro_impl::RustType; use wasmer_it::ast::FunctionArg as IFunctionArg; -use std::rc::Rc; +use std::sync::Arc; // return error if there is no record with such name pub(crate) fn ptype_to_itype_checked( @@ -107,10 +107,10 @@ pub(crate) fn wtype_to_itype(pty: &RustType) -> IType { } } -pub(crate) fn generate_it_args<'f>( +pub(crate) fn generate_it_args( signature: &FnSignature, - it_resolver: &mut ITResolver<'f>, -) -> Result>> { + it_resolver: &mut ITResolver<'_>, +) -> Result>> { let arguments = signature .arguments .iter() @@ -122,21 +122,21 @@ pub(crate) fn generate_it_args<'f>( }) .collect::>>()?; - let arguments = Rc::new(arguments); + let arguments = Arc::new(arguments); Ok(arguments) } -pub(crate) fn generate_it_output_type<'f>( +pub(crate) fn generate_it_output_type( signature: &FnSignature, - it_resolver: &mut ITResolver<'f>, -) -> Result>> { + it_resolver: &mut ITResolver<'_>, +) -> Result>> { let output_types = signature .output_types .iter() .map(|ty| ptype_to_itype_checked(ty, it_resolver)) .collect::>>()?; - let output_types = Rc::new(output_types); + let output_types = Arc::new(output_types); Ok(output_types) } diff --git a/crates/it-interfaces/Cargo.toml b/crates/it-interfaces/Cargo.toml index 584192991..4b2e719c8 100644 --- a/crates/it-interfaces/Cargo.toml +++ b/crates/it-interfaces/Cargo.toml @@ -4,12 +4,12 @@ description = "Fluence Marine interface types helper crate" version = "0.7.3" authors = ["Fluence Labs"] license = "Apache-2.0" -edition = "2018" +edition = "2021" [lib] name = "marine_it_interfaces" path = "src/lib.rs" [dependencies] -wasmer-it = { package = "wasmer-interface-types-fl", version = "0.24.1"} +wasmer-it = { workspace = true} multimap = "0.8.3" diff --git a/crates/it-interfaces/src/mit_interfaces.rs b/crates/it-interfaces/src/mit_interfaces.rs index 9e58ebbcf..3ba6918a7 100644 --- a/crates/it-interfaces/src/mit_interfaces.rs +++ b/crates/it-interfaces/src/mit_interfaces.rs @@ -23,7 +23,7 @@ use multimap::MultiMap; use std::iter::Iterator; use std::collections::HashMap; -use std::rc::Rc; +use std::sync::Arc; pub type CoreFunctionType = u32; pub type AdapterFunctionType = u32; @@ -111,7 +111,7 @@ impl<'a> MITInterfaces<'a> { self.types.iter() } - pub fn record_types(&self) -> impl Iterator)> { + pub fn record_types(&self) -> impl Iterator)> { self.types.iter().enumerate().filter_map(|(id, t)| match t { ITAstType::Record(r) => Some((id as u64, r)), _ => None, diff --git a/crates/it-json-serde/Cargo.toml b/crates/it-json-serde/Cargo.toml index 768fc8c3e..e7c66f649 100644 --- a/crates/it-json-serde/Cargo.toml +++ b/crates/it-json-serde/Cargo.toml @@ -4,14 +4,14 @@ description = "Fluence Marine interface-types serde tools" version = "0.3.5" authors = ["Fluence Labs"] license = "Apache-2.0" -edition = "2018" +edition = "2021" [lib] name = "it_json_serde" path = "src/lib.rs" [dependencies] -wasmer-it = { package = "wasmer-interface-types-fl", version = "0.24.1"} +wasmer-it = { workspace = true} serde = { version = "1.0.147", features = ["derive"] } serde_json = "1.0.89" diff --git a/crates/it-json-serde/src/lib.rs b/crates/it-json-serde/src/lib.rs index 0a54840a9..f71b63ad4 100644 --- a/crates/it-json-serde/src/lib.rs +++ b/crates/it-json-serde/src/lib.rs @@ -33,9 +33,9 @@ pub use ivalues_to_json::ivalues_to_json; pub use json_to_ivalues::json_to_ivalues; use std::collections::HashMap; -use std::rc::Rc; +use std::sync::Arc; pub(crate) use wasmer_it::IValue; pub(crate) use wasmer_it::IType; pub(crate) use wasmer_it::IRecordType; -pub(crate) type MRecordTypes = HashMap>; +pub(crate) type MRecordTypes = HashMap>; diff --git a/crates/it-parser/Cargo.toml b/crates/it-parser/Cargo.toml index bb6ef5f17..92fd62149 100644 --- a/crates/it-parser/Cargo.toml +++ b/crates/it-parser/Cargo.toml @@ -4,7 +4,7 @@ description = "Fluence Marine interface types parser" version = "0.11.1" authors = ["Fluence Labs"] license = "Apache-2.0" -edition = "2018" +edition = "2021" [lib] name = "marine_it_parser" @@ -13,12 +13,12 @@ path = "src/lib.rs" [dependencies] marine-it-interfaces = { path = "../it-interfaces", version = "0.7.3" } marine-module-interface = { path = "../module-interface", version = "0.6.1" } +marine-wasm-backend-traits = { path = "../wasm-backend-traits", version = "0.1.0"} anyhow = "1.0.66" walrus = "0.19.0" -wasmer-core = { package = "wasmer-runtime-core-fl", version = "=0.17.1"} -wasmer-it = { package = "wasmer-interface-types-fl", version = "0.24.1" } -nom = "5.1" +wasmer-it = { workspace = true } +nom = "7.1" itertools = "0.10.5" semver = "1.0.14" diff --git a/crates/it-parser/src/deleter.rs b/crates/it-parser/src/deleter.rs index a6396b9eb..2a87f6c53 100644 --- a/crates/it-parser/src/deleter.rs +++ b/crates/it-parser/src/deleter.rs @@ -27,7 +27,7 @@ pub fn delete_it_section_from_file( out_wasm_path: PathBuf, ) -> Result<(), ITParserError> { let module = ModuleConfig::new() - .parse_file(&in_wasm_path) + .parse_file(in_wasm_path) .map_err(ITParserError::CorruptedWasmFile)?; let mut module = delete_it_section(module); diff --git a/crates/it-parser/src/embedder.rs b/crates/it-parser/src/embedder.rs index 3e6897f2f..8a871b660 100644 --- a/crates/it-parser/src/embedder.rs +++ b/crates/it-parser/src/embedder.rs @@ -19,10 +19,9 @@ use super::errors::ITParserError; use crate::ParserResult; use walrus::ModuleConfig; -use wasmer_it::{ - ast::Interfaces, - decoders::wat::{parse, Buffer}, -}; +use wasmer_it::ast::Interfaces; +use wasmer_it::decoders::wat::parse; +use wasmer_it::decoders::wat::Buffer; use wasmer_it::ToBytes; use std::path::Path; diff --git a/crates/it-parser/src/errors.rs b/crates/it-parser/src/errors.rs index d19a0e509..b98f9f4e6 100644 --- a/crates/it-parser/src/errors.rs +++ b/crates/it-parser/src/errors.rs @@ -45,15 +45,15 @@ pub enum ITParserError { CorruptedITSection(nom::Err<(Vec, nom::error::ErrorKind)>), /// An error related to incorrect data in IT section. - #[error("{0}")] - IncorrectITFormat(String), + #[error("0")] + IncorrectITFormat(String), // TODO: use a proper error type /// An error occurred while processing module interface. - #[error("{0}")] + #[error(transparent)] ModuleInterfaceError(#[from] InterfaceError), /// An error occurred while processing module IT interface. - #[error("{0}")] + #[error(transparent)] ModuleITInterfaceError(#[from] ITInterfaceError), /// An error occurred while parsing file in Wat format. diff --git a/crates/it-parser/src/extractor/it.rs b/crates/it-parser/src/extractor/it.rs index 5b63118ba..c59e114a6 100644 --- a/crates/it-parser/src/extractor/it.rs +++ b/crates/it-parser/src/extractor/it.rs @@ -20,7 +20,8 @@ use crate::ParserResult; use walrus::IdsToIndices; use wasmer_it::ast::Interfaces; -use wasmer_core::Module as WasmerModule; +use marine_wasm_backend_traits::WasmBackend; +use marine_wasm_backend_traits::Module as WasmModule; use std::borrow::Cow; use std::path::Path; @@ -42,16 +43,18 @@ where } /// Extracts IT section of provided Wasm binary and converts it to a MITInterfaces. -pub fn extract_it_from_module(wasmer_module: &WasmerModule) -> ParserResult> { - let wit_sections = wasmer_module - .custom_sections(IT_SECTION_NAME) - .ok_or(ITParserError::NoITSection)?; +pub fn extract_it_from_module( + wasm_module: &::Module, +) -> ParserResult> { + let wit_sections = wasm_module.custom_sections(IT_SECTION_NAME); - if wit_sections.len() > 1 { - return Err(ITParserError::MultipleITSections); - } + let it_section = match wit_sections.len() { + 0 => Err(ITParserError::NoITSection), + 1 => Ok(&wit_sections[0]), + _ => Err(ITParserError::MultipleITSections), + }?; - extract_it_from_bytes(&wit_sections[0]) + extract_it_from_bytes(it_section) } pub fn extract_version_from_module(module: &walrus::Module) -> ParserResult { diff --git a/crates/min-it-version/Cargo.toml b/crates/min-it-version/Cargo.toml index 108e7a87f..03474484e 100644 --- a/crates/min-it-version/Cargo.toml +++ b/crates/min-it-version/Cargo.toml @@ -4,7 +4,7 @@ version = "0.2.1" description = "Fluence Marine interface types minimum supported version checker" authors = ["Fluence Labs"] license = "Apache-2.0" -edition = "2018" +edition = "2021" [lib] name = "marine_min_it_version" diff --git a/crates/module-info-parser/Cargo.toml b/crates/module-info-parser/Cargo.toml index e7969da8c..dc76bd2cf 100644 --- a/crates/module-info-parser/Cargo.toml +++ b/crates/module-info-parser/Cargo.toml @@ -4,7 +4,7 @@ description = "Fluence Marine Wasm module info (manifest and version) parser" version = "0.5.1" authors = ["Fluence Labs"] license = "Apache-2.0" -edition = "2018" +edition = "2021" [lib] name = "marine_module_info_parser" @@ -13,7 +13,7 @@ path = "src/lib.rs" [dependencies] marine-rs-sdk-main = "0.7.1" -wasmer-core = { package = "wasmer-runtime-core-fl", version = "=0.17.1" } +marine-wasm-backend-traits = { path = "../wasm-backend-traits", version = "0.1.0"} anyhow = "1.0.66" chrono = "0.4.23" diff --git a/crates/module-info-parser/src/errors.rs b/crates/module-info-parser/src/errors.rs index 01fd580d6..904c5615b 100644 --- a/crates/module-info-parser/src/errors.rs +++ b/crates/module-info-parser/src/errors.rs @@ -30,11 +30,11 @@ pub enum ModuleInfoError { MultipleCustomSections(&'static str, usize), /// Errors related to corrupted version. - #[error("{0}")] + #[error(transparent)] VersionError(#[from] SDKVersionError), /// Errors related to corrupted manifest. - #[error("{0}")] + #[error(transparent)] ManifestError(#[from] ManifestError), /// An error occurred while parsing Wasm file. diff --git a/crates/module-info-parser/src/manifest/manifest_extractor.rs b/crates/module-info-parser/src/manifest/manifest_extractor.rs index 513b9bc07..f8d08bd00 100644 --- a/crates/module-info-parser/src/manifest/manifest_extractor.rs +++ b/crates/module-info-parser/src/manifest/manifest_extractor.rs @@ -20,7 +20,9 @@ use crate::ModuleInfoError; use crate::extract_custom_sections_by_name; use crate::try_as_one_section; -use wasmer_core::Module as WasmerModule; +use marine_wasm_backend_traits::Module as ModuleTrait; +use marine_wasm_backend_traits::WasmBackend; + use marine_rs_sdk_main::MANIFEST_SECTION_NAME; use walrus::ModuleConfig; use walrus::Module; @@ -29,7 +31,7 @@ use std::borrow::Cow; use std::path::Path; use std::convert::TryInto; -pub fn extract_from_path

(wasm_module_path: P) -> ModuleInfoResult> +pub fn extract_from_path

(wasm_module_path: P) -> ModuleInfoResult where P: AsRef, { @@ -40,12 +42,8 @@ where extract_from_module(&module) } -pub fn extract_from_module(wasm_module: &Module) -> ModuleInfoResult> { +pub fn extract_from_module(wasm_module: &Module) -> ModuleInfoResult { let sections = extract_custom_sections_by_name(wasm_module, MANIFEST_SECTION_NAME)?; - if sections.is_empty() { - return Ok(None); - } - let section = try_as_one_section(§ions, MANIFEST_SECTION_NAME)?; let manifest = match section { @@ -53,20 +51,15 @@ pub fn extract_from_module(wasm_module: &Module) -> ModuleInfoResult vec.as_slice().try_into(), }?; - Ok(Some(manifest)) + Ok(manifest) } -pub fn extract_from_wasmer_module( - wasmer_module: &WasmerModule, -) -> ModuleInfoResult> { - let sections = wasmer_module.custom_sections(MANIFEST_SECTION_NAME); - let sections = match sections { - Some(sections) => sections, - None => return Ok(None), - }; - +pub fn extract_from_compiled_module( + module: &::Module, +) -> ModuleInfoResult { + let sections = module.custom_sections(MANIFEST_SECTION_NAME); let section = try_as_one_section(sections, MANIFEST_SECTION_NAME)?; let manifest = section.as_slice().try_into()?; - Ok(Some(manifest)) + Ok(manifest) } diff --git a/crates/module-info-parser/src/manifest/mod.rs b/crates/module-info-parser/src/manifest/mod.rs index 011b344e7..14fb52e0a 100644 --- a/crates/module-info-parser/src/manifest/mod.rs +++ b/crates/module-info-parser/src/manifest/mod.rs @@ -23,5 +23,5 @@ mod tests; pub use errors::ManifestError; pub use manifest_extractor::extract_from_path; pub use manifest_extractor::extract_from_module; -pub use manifest_extractor::extract_from_wasmer_module; +pub use manifest_extractor::extract_from_compiled_module; pub use module_manifest::ModuleManifest; diff --git a/crates/module-info-parser/src/manifest/tests.rs b/crates/module-info-parser/src/manifest/tests.rs index 09aa299cc..a793099e2 100644 --- a/crates/module-info-parser/src/manifest/tests.rs +++ b/crates/module-info-parser/src/manifest/tests.rs @@ -109,7 +109,7 @@ fn test_too_big_field_len() { array.add_utf8_field("repository"); let actual: Result = array.as_bytes().try_into(); - let expected = Err(ManifestError::TooBigFieldSize("version", incorrect_size)); + let expected: Result<_, _> = Err(ManifestError::TooBigFieldSize("version", incorrect_size)); assert_eq!(actual, expected); } @@ -123,7 +123,7 @@ fn test_without_one_field() { array.add_utf8_field("description"); let actual: Result = array.as_bytes().try_into(); - let expected = Err(ManifestError::NotEnoughBytesForPrefix("repository")); + let expected: Result<_, _> = Err(ManifestError::NotEnoughBytesForPrefix("repository")); assert_eq!(actual, expected); } @@ -131,7 +131,7 @@ fn test_without_one_field() { #[test] fn test_with_empty_slice() { let actual: Result = vec![].as_slice().try_into(); - let expected = Err(ManifestError::NotEnoughBytesForPrefix("authors")); + let expected: Result<_, _> = Err(ManifestError::NotEnoughBytesForPrefix("authors")); assert_eq!(actual, expected); } @@ -148,7 +148,7 @@ fn test_not_enough_data_for_field() { array.add_utf8_string("repository"); let actual: Result = array.as_bytes().try_into(); - let expected = Err(ManifestError::NotEnoughBytesForField( + let expected: Result<_, _> = Err(ManifestError::NotEnoughBytesForField( "repository", too_big_size as usize, )); diff --git a/crates/module-info-parser/src/sdk_version/mod.rs b/crates/module-info-parser/src/sdk_version/mod.rs index 0d3cffb83..c0e668123 100644 --- a/crates/module-info-parser/src/sdk_version/mod.rs +++ b/crates/module-info-parser/src/sdk_version/mod.rs @@ -21,6 +21,6 @@ mod version_extractor; pub use errors::SDKVersionError; pub use version_extractor::extract_from_path; pub use version_extractor::extract_from_module; -pub use version_extractor::extract_from_wasmer_module; +pub use version_extractor::extract_from_compiled_module; pub use version_embedder::embed_from_path; pub use version_embedder::embed_from_module; diff --git a/crates/module-info-parser/src/sdk_version/version_extractor.rs b/crates/module-info-parser/src/sdk_version/version_extractor.rs index 89a668873..9677c47e1 100644 --- a/crates/module-info-parser/src/sdk_version/version_extractor.rs +++ b/crates/module-info-parser/src/sdk_version/version_extractor.rs @@ -20,7 +20,9 @@ use super::SDKVersionError; use crate::extract_custom_sections_by_name; use crate::try_as_one_section; -use wasmer_core::Module as WasmerModule; +use marine_wasm_backend_traits::WasmBackend; +use marine_wasm_backend_traits::Module as WasmModule; + use marine_rs_sdk_main::VERSION_SECTION_NAME; use walrus::ModuleConfig; use walrus::Module; @@ -29,7 +31,7 @@ use std::borrow::Cow; use std::str::FromStr; use std::path::Path; -pub fn extract_from_path

(wasm_module_path: P) -> ModuleInfoResult> +pub fn extract_from_path

(wasm_module_path: P) -> ModuleInfoResult where P: AsRef, { @@ -40,12 +42,8 @@ where extract_from_module(&module) } -pub fn extract_from_module(wasm_module: &Module) -> ModuleInfoResult> { +pub fn extract_from_module(wasm_module: &Module) -> ModuleInfoResult { let sections = extract_custom_sections_by_name(wasm_module, VERSION_SECTION_NAME)?; - - if sections.is_empty() { - return Ok(None); - } let section = try_as_one_section(§ions, VERSION_SECTION_NAME)?; let version = match section { @@ -53,23 +51,17 @@ pub fn extract_from_module(wasm_module: &Module) -> ModuleInfoResult as_semver(vec), }?; - Ok(Some(version)) + Ok(version) } -pub fn extract_from_wasmer_module( - wasmer_module: &WasmerModule, -) -> ModuleInfoResult> { - let sections = wasmer_module.custom_sections(VERSION_SECTION_NAME); - - let sections = match sections { - Some(sections) => sections, - None => return Ok(None), - }; - +pub fn extract_from_compiled_module( + wasm_module: &::Module, +) -> ModuleInfoResult { + let sections = wasm_module.custom_sections(VERSION_SECTION_NAME); let section = try_as_one_section(sections, VERSION_SECTION_NAME)?; let version = as_semver(section)?; - Ok(Some(version)) + Ok(version) } fn as_semver(version_as_bytes: &[u8]) -> Result { diff --git a/crates/module-interface/Cargo.toml b/crates/module-interface/Cargo.toml index 228012e4a..8ceda509a 100644 --- a/crates/module-interface/Cargo.toml +++ b/crates/module-interface/Cargo.toml @@ -4,7 +4,7 @@ description = "Fluence Marine module interface" version = "0.6.1" authors = ["Fluence Labs"] license = "Apache-2.0" -edition = "2018" +edition = "2021" [lib] name = "marine_module_interface" @@ -15,8 +15,8 @@ marine-it-interfaces = { path = "../it-interfaces", version = "0.7.3" } anyhow = "1.0.66" walrus = "0.19.0" -wasmer-it = { package = "wasmer-interface-types-fl", version = "0.24.1" } -nom = "5.1" +wasmer-it = { workspace = true } +nom = "7.1.3" itertools = "0.10.5" semver = "1.0.14" diff --git a/crates/module-interface/src/interface/errors.rs b/crates/module-interface/src/interface/errors.rs index 4b72cf0cc..5d698997c 100644 --- a/crates/module-interface/src/interface/errors.rs +++ b/crates/module-interface/src/interface/errors.rs @@ -22,6 +22,6 @@ pub enum InterfaceError { #[error("record type with type id {0} not found")] NotFoundRecordTypeId(u64), - #[error("{0}")] + #[error(transparent)] ITInterfaceError(#[from] ITInterfaceError), } diff --git a/crates/module-interface/src/interface/records_transformer.rs b/crates/module-interface/src/interface/records_transformer.rs index f692c015c..9241dcce9 100644 --- a/crates/module-interface/src/interface/records_transformer.rs +++ b/crates/module-interface/src/interface/records_transformer.rs @@ -24,7 +24,7 @@ use wasmer_it::IRecordType; use wasmer_it::IType; use std::collections::HashSet; -use std::rc::Rc; +use std::sync::Arc; use itertools::Itertools; pub(crate) struct RecordsTransformer { @@ -60,7 +60,7 @@ impl RecordsTransformer { fn dfs( &mut self, record_id: u64, - record: &Rc, + record: &Arc, exported_records: &IRecordTypes, ) -> InterfaceResult<()> { if !self.used.insert(record_id) { @@ -107,7 +107,7 @@ impl RecordsTransformer { fn convert_record( id: u64, - record: &Rc, + record: &Arc, record_types: &IRecordTypes, ) -> RecordType { use super::itype_text_view; diff --git a/crates/module-interface/src/it_interface/errors.rs b/crates/module-interface/src/it_interface/errors.rs index 8eec40695..d19f9d300 100644 --- a/crates/module-interface/src/it_interface/errors.rs +++ b/crates/module-interface/src/it_interface/errors.rs @@ -28,6 +28,6 @@ pub enum ITInterfaceError { #[error("mailformed module: a record contains more recursion level then allowed")] TooManyRecursionLevels, - #[error("{0}")] + #[error(transparent)] MITInterfacesError(#[from] MITInterfacesError), } diff --git a/crates/module-interface/src/it_interface/export_it_functions.rs b/crates/module-interface/src/it_interface/export_it_functions.rs index 58a2895b4..b4462bc06 100644 --- a/crates/module-interface/src/it_interface/export_it_functions.rs +++ b/crates/module-interface/src/it_interface/export_it_functions.rs @@ -20,7 +20,7 @@ use super::RIResult; use marine_it_interfaces::MITInterfaces; -use std::rc::Rc; +use std::sync::Arc; pub struct ITExportFuncDescriptor<'n> { pub adapter_function_type: u32, @@ -69,7 +69,7 @@ pub fn get_export_funcs(mit: &MITInterfaces<'_>) -> RIResult { let signature = IFunctionSignature { - name: Rc::new(descriptor.name.to_string()), + name: Arc::new(descriptor.name.to_string()), arguments: arguments.clone(), outputs: output_types.clone(), adapter_function_type: descriptor.adapter_function_type, diff --git a/crates/module-interface/src/it_interface/it_module_interface.rs b/crates/module-interface/src/it_interface/it_module_interface.rs index bff7b977a..08e08ee20 100644 --- a/crates/module-interface/src/it_interface/it_module_interface.rs +++ b/crates/module-interface/src/it_interface/it_module_interface.rs @@ -22,16 +22,16 @@ use serde::Serialize; use serde::Deserialize; use std::collections::HashMap; -use std::rc::Rc; +use std::sync::Arc; -pub type IRecordTypes = HashMap>; +pub type IRecordTypes = HashMap>; /// Represent a function type inside Marine module. #[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)] pub struct IFunctionSignature { - pub name: Rc, - pub arguments: Rc>, - pub outputs: Rc>, + pub name: Arc, + pub arguments: Arc>, + pub outputs: Arc>, pub adapter_function_type: u32, } diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml index d47447b76..3ac192635 100644 --- a/crates/utils/Cargo.toml +++ b/crates/utils/Cargo.toml @@ -4,7 +4,7 @@ description = "Fluence Marine utils crate" version = "0.4.0" authors = ["Fluence Labs"] license = "Apache-2.0" -edition = "2018" +edition = "2021" [lib] name = "marine_utils" diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs index 7c078129a..d0451cd0b 100644 --- a/crates/utils/src/lib.rs +++ b/crates/utils/src/lib.rs @@ -29,10 +29,10 @@ mod wasm_mem_pages_conversion; pub use wasm_mem_pages_conversion::*; -use std::rc::Rc; +use std::sync::Arc; #[derive(Debug, Clone, PartialEq, Eq, Default, Hash)] -pub struct SharedString(pub Rc); +pub struct SharedString(pub Arc); impl std::borrow::Borrow for SharedString { fn borrow(&self) -> &str { diff --git a/crates/wasm-backend-traits/Cargo.toml b/crates/wasm-backend-traits/Cargo.toml new file mode 100644 index 000000000..e950b4c26 --- /dev/null +++ b/crates/wasm-backend-traits/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "marine-wasm-backend-traits" +version = "0.1.0" +authors = ["Fluence Labs"] +license = "Apache-2.0" +edition = "2021" + +[dependencies] +wasmer-it = { workspace = true } +it-memory-traits = { workspace = true } + +thiserror = "1.0.24" +anyhow = "1.0.68" +wasmparser = "0.101.1" +paste = "1.0.9" +multimap = "0.8.3" diff --git a/crates/wasm-backend-traits/src/caller.rs b/crates/wasm-backend-traits/src/caller.rs new file mode 100644 index 000000000..100bf4f25 --- /dev/null +++ b/crates/wasm-backend-traits/src/caller.rs @@ -0,0 +1,36 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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 crate::AsContextMut; +use crate::FuncGetter; +use crate::WasmBackend; + +/// `Caller` is a structure used to pass context to imports. +/// It serves as a handle to `Store`, and also provides access to `Memory` and export functions +/// from the caller instance, if there is one. +pub trait Caller: + FuncGetter + + FuncGetter + + FuncGetter + + FuncGetter + + FuncGetter + + FuncGetter + + AsContextMut +{ + /// Gets the `Memory` from the caller instance. + /// Returns `None` if function was called directly from host. + fn memory(&mut self, memory_index: u32) -> Option<::Memory>; +} diff --git a/crates/wasm-backend-traits/src/errors.rs b/crates/wasm-backend-traits/src/errors.rs new file mode 100644 index 000000000..0bde2a31c --- /dev/null +++ b/crates/wasm-backend-traits/src/errors.rs @@ -0,0 +1,145 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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 crate::WType; + +use thiserror::Error; + +pub type WasmBackendResult = Result; +pub type ResolveResult = Result; +pub type RuntimeResult = Result; +pub type ModuleCreationResult = Result; +pub type InstantiationResult = Result; +pub type WasiResult = Result; + +/* + General error design goals: + * expose as much detail as possible + * make as much domain-specific errors as possible implementation-independent + + So, Error enums should follow this principle: + * errors fully expressible without implementation info should have implementation-independent view + * errors not fully expressible without implementation info should have some common view and a way to get implmententation-specific details + * "Other" type for all errors not suited for listed options +*/ + +#[derive(Debug, Error)] +pub enum WasmBackendError { + #[error(transparent)] + ResolveError(#[from] ResolveError), + + #[error(transparent)] + RuntimeError(#[from] RuntimeError), + + #[error(transparent)] + ModuleCreationError(#[from] ModuleCreationError), + + #[error(transparent)] + ImportError(#[from] ImportError), + + #[error(transparent)] + InstantiationError(#[from] InstantiationError), + + #[error(transparent)] + InitializationError(anyhow::Error), +} + +#[derive(Debug, Error)] +pub enum ResolveError { + #[error("export not found: {0}")] + ExportNotFound(String), + + #[error("export type mismatch: expected {expected}, found {actual}")] + ExportTypeMismatch { + expected: &'static str, + actual: &'static str, + }, + + #[error(transparent)] + Other(#[from] anyhow::Error), +} + +#[derive(Debug, Error)] +pub enum RuntimeError { + #[error("Unsupported type encountered: {0}")] + UnsupportedType(WType), + + #[error(transparent)] + Trap(anyhow::Error), + + #[error(transparent)] + UserError(#[from] UserError), + + #[error("A function returned invalid number of results: expected {expected}, got {actual}")] + IncorrectResultsNumber { expected: usize, actual: usize }, + + #[error(transparent)] + Other(anyhow::Error), +} + +#[derive(Debug, Error)] +pub enum ModuleCreationError { + #[error(transparent)] + FailedToCompileWasm(anyhow::Error), + + #[error("{0}")] + FailedToExtractCustomSections(String), // TODO: use a proper error type + + #[error(transparent)] + Other(anyhow::Error), +} + +#[derive(Debug, Error)] +pub enum ImportError { + #[error("Duplicate import")] + DuplicateImport(String, String), + + #[error(transparent)] + Other(#[from] anyhow::Error), +} + +#[derive(Debug, Error)] +pub enum InstantiationError { + #[error(transparent)] + RuntimeError(RuntimeError), + + #[error(transparent)] + Other(#[from] anyhow::Error), +} + +#[derive(Debug, Error)] +pub enum WasiError { + #[error(transparent)] + IOError(#[from] std::io::Error), + + #[error(transparent)] + EngineWasiError(#[from] anyhow::Error), + + #[error("Cumulative size of args array exceeds 2^32")] + TooLargeArgsArray, + + #[error("Cumulative size of envs array exceeds 2^32")] + TooLargeEnvsArray, +} + +#[derive(Debug, Error)] +pub enum UserError { + #[error(transparent)] + Recoverable(anyhow::Error), + + #[error(transparent)] + Unrecoverable(anyhow::Error), +} diff --git a/crates/wasm-backend-traits/src/exports.rs b/crates/wasm-backend-traits/src/exports.rs new file mode 100644 index 000000000..7903d814b --- /dev/null +++ b/crates/wasm-backend-traits/src/exports.rs @@ -0,0 +1,43 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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 static STANDARD_MEMORY_EXPORT_NAME: &str = "memory"; +pub static STANDARD_MEMORY_INDEX: u32 = 0; + +use crate::DelayedContextLifetime; +use crate::WasmBackend; + +/// Contains Wasm exports necessary for internal usage. +pub enum Export { + Memory(::Memory), + Function(::Function), + Other, +} + +// TODO: add read/write/etc methods to the `Memory` trait, +// and then make a generic implementation of interface-types traits +/// A wasm memory handle. +/// As it is only a handle to an object in `Store`, cloning is cheap. +pub trait Memory: + it_memory_traits::Memory<::MemoryView, DelayedContextLifetime> + + Clone + + Send + + Sync + + 'static +{ + /// Get the size of the allocated memory in bytes. + fn size(&self, store: &mut ::ContextMut<'_>) -> usize; +} diff --git a/crates/wasm-backend-traits/src/function.rs b/crates/wasm-backend-traits/src/function.rs new file mode 100644 index 000000000..961cc1149 --- /dev/null +++ b/crates/wasm-backend-traits/src/function.rs @@ -0,0 +1,169 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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 crate::AsContextMut; +use crate::FuncSig; +use crate::impl_for_each_function_signature; +use crate::RuntimeResult; +use crate::WasmBackend; +use crate::WValue; + +/// A Wasm function handle, it can be either a function from a host or an export from an `Instance`. +/// As it is only a handle to an object in `Store`, cloning is cheap +pub trait Function: Send + Sync { + /// Creates a new function with dynamic signature. + /// The signature check is performed at runtime. + fn new(store: &mut impl AsContextMut, sig: FuncSig, func: F) -> Self + where + F: for<'c> Fn(&[WValue]) -> Vec + Sync + Send + 'static; + + /// Creates a new function with dynamic signature that needs a context. + fn new_with_caller(store: &mut impl AsContextMut, sig: FuncSig, func: F) -> Self + where + F: for<'c> Fn(::Caller<'c>, &[WValue]) -> Vec + + Sync + + Send + + 'static; + + /// Creates a new function with static signature. + /// Requires less runtime checks when called. + fn new_typed( + store: &mut impl AsContextMut, + func: impl IntoFunc, + ) -> Self; + + /// Returns the signature of the function. + /// The signature is constructed each time this function is called, so + /// it is not recommended to use this function extensively. + fn signature(&self, store: &mut impl AsContextMut) -> FuncSig; + + /// Calls the wasm function. + /// # Panics: + /// If given a store different from the one that stores the function. + /// # Errors: + /// See `RuntimeError` documentation. + fn call( + &self, + store: &mut impl AsContextMut, + args: &[WValue], + ) -> RuntimeResult>; +} + +/// A helper trait for creating a function with a static signature. +/// Should not be implemented by users. +/// Implemented for all functions that meet the following criteria: +/// * implement Send + Sync + 'static +/// * take or not take Caller as first parameter +/// * take from 0 to 16 i32 parameters +/// * return () or i32 +pub trait IntoFunc { + fn into_func(self, ctx: &mut impl AsContextMut) -> ::Function; +} + +/// An indicator of using Caller argument. +pub struct WithEnv {} + +/// An indicator of using Caller argument. +pub struct WithoutEnv {} + +#[macro_export] +macro_rules! replace_with { + ($from:ident -> $to:ident) => { + $to + }; +} + +macro_rules! impl_into_func { + ($num:tt $($args:ident)*) => (paste::paste!{ + #[allow(non_snake_case)] + impl IntoFunc i32),)*), (), WithoutEnv> for F + where + WB: WasmBackend, + F: Fn($(replace_with!($args -> i32),)*) + Send + Sync + 'static, + { + fn into_func(self, ctx: &mut impl AsContextMut) -> ::Function { + ::Function:: [< new_typed_ $num >] (ctx.as_context_mut(), self) + } + } + + #[allow(non_snake_case)] + impl IntoFunc i32),)*), (), WithEnv> for F + where + WB: WasmBackend, + F: Fn(::Caller<'_>, $(replace_with!($args -> i32),)*) + Send + Sync + 'static, + { + fn into_func(self, ctx: &mut impl AsContextMut) -> ::Function { + ::Function:: [< new_typed_with_env_ $num >] (ctx.as_context_mut(), self) + } + } + + #[allow(non_snake_case)] + impl IntoFunc i32),)*), i32, WithoutEnv> for F + where + WB: WasmBackend, + F: Fn($(replace_with!($args -> i32),)*) -> i32 + Send + Sync + 'static, + { + fn into_func(self, ctx: &mut impl AsContextMut) -> ::Function { + ::Function:: [< new_typed_ $num _r >] (ctx.as_context_mut(), self) + } + } + + #[allow(non_snake_case)] + impl IntoFunc i32),)*), i32, WithEnv> for F + where + WB: WasmBackend, + F: Fn(::Caller<'_>, $(replace_with!($args -> i32),)*) -> i32 + Send + Sync + 'static, + { + fn into_func(self, ctx: &mut impl AsContextMut) -> ::Function { + ::Function:: [< new_typed_with_env_ $num _r >] (ctx.as_context_mut(), self) + } + } + }); +} + +impl_for_each_function_signature!(impl_into_func); + +macro_rules! declare_func_construction { + ($num:tt $($args:ident)*) => (paste::paste!{ + #[allow(non_snake_case)] + fn [< new_typed_ $num >](ctx: ::ContextMut<'_>, func: F) -> ::Function + where F: Fn($(replace_with!($args -> i32),)*) + Send + Sync + 'static + { + let func = move |_: ::Caller<'_>, $($args,)*| { func($($args,)*)}; + Self:: [< new_typed_with_env_ $num >] (ctx, func) + } + + #[allow(non_snake_case)] + fn [< new_typed_with_env_ $num >](ctx: ::ContextMut<'_>, func: F) -> ::Function + where F: Fn(::Caller<'_>, $(replace_with!($args -> i32),)*) + Send + Sync + 'static; + + #[allow(non_snake_case)] + fn [< new_typed_ $num _r>](ctx: ::ContextMut<'_>, func: F) -> ::Function + where F: Fn($(replace_with!($args -> i32),)*) -> i32 + Send + Sync + 'static + { + let func = move |_: ::Caller<'_>, $($args,)*| -> i32 { func($($args,)*)}; + Self:: [< new_typed_with_env_ $num _r >] (ctx, func) + } + + #[allow(non_snake_case)] + fn [< new_typed_with_env_ $num _r>](ctx: ::ContextMut<'_>, func: F) -> ::Function + where F: Fn(::Caller<'_>, $(replace_with!($args -> i32),)*) -> i32 + Send + Sync + 'static; + }); +} + +pub trait FuncConstructor { + impl_for_each_function_signature!(declare_func_construction); +} diff --git a/crates/wasm-backend-traits/src/impl_utils.rs b/crates/wasm-backend-traits/src/impl_utils.rs new file mode 100644 index 000000000..04040c9ab --- /dev/null +++ b/crates/wasm-backend-traits/src/impl_utils.rs @@ -0,0 +1,24 @@ +pub use multimap::MultiMap; + +pub fn custom_sections(bytes: &[u8]) -> Result>, String> { + use wasmparser::Parser; + use wasmparser::Payload; + + Parser::new(0) + .parse_all(bytes) + .filter_map(|payload| { + let payload = match payload { + Ok(payload) => payload, + Err(e) => return Some(Err(e.to_string())), + }; + match payload { + Payload::CustomSection(reader) => { + let name = reader.name().to_string(); + let data = reader.data().to_vec(); + Some(Ok((name, data))) + } + _ => None, + } + }) + .collect() +} diff --git a/crates/wasm-backend-traits/src/imports.rs b/crates/wasm-backend-traits/src/imports.rs new file mode 100644 index 000000000..91aefb33e --- /dev/null +++ b/crates/wasm-backend-traits/src/imports.rs @@ -0,0 +1,95 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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 crate::errors::*; + +use crate::AsContext; +use crate::WasmBackend; +use crate::WType; + +use std::borrow::Cow; + +/// A "Linker" object, that is used to match functions with module imports during instantiation. +/// Cloning is a cheap operation for this object. All clones refer to the same data in store. +pub trait Imports: Clone { + /// Creates a new empty object. + fn new(store: &mut ::Store) -> Self; + + /// Inserts a function with name `name` to the namespace `module`. + /// # Errors: + /// An error returned if such combination of `module` and `name` already has an associated function. + fn insert( + &mut self, + store: &impl AsContext, + module: impl Into, + name: impl Into, + func: ::Function, + ) -> Result<(), ImportError>; + + /// Inserts several named functions to the same namespace `module` at once, an equivalent to multiple calls of `insert`. + /// # Errors: + /// An error returned if such combination of `module` and `name` already has an associated function. + /// + fn register( + &mut self, + store: &impl AsContext, + name: S, + namespace: I, + ) -> Result<(), ImportError> + where + S: Into, + I: IntoIterator::Function)>; +} + +/// A type representing function signature. +#[derive(Clone)] +pub struct FuncSig { + params: Cow<'static, [WType]>, + returns: Cow<'static, [WType]>, +} + +impl FuncSig { + pub fn new(params: Params, returns: Returns) -> Self + where + Params: Into>, + Returns: Into>, + { + Self { + params: params.into(), + returns: returns.into(), + } + } + + pub fn params(&self) -> &[WType] { + &self.params + } + + pub fn returns(&self) -> &[WType] { + &self.returns + } +} + +pub type FuncFromCaller = Box< + dyn FnMut(&mut ::ContextMut<'_>, Args) -> RuntimeResult + + Sync + + Send + + 'static, +>; + +pub trait FuncGetter { + /// Gets an export function from the calling instance. + fn get_func(&mut self, name: &str) -> ResolveResult>; +} diff --git a/crates/wasm-backend-traits/src/instance.rs b/crates/wasm-backend-traits/src/instance.rs new file mode 100644 index 000000000..45014c35a --- /dev/null +++ b/crates/wasm-backend-traits/src/instance.rs @@ -0,0 +1,56 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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 crate::AsContextMut; +use crate::Export; +use crate::ResolveResult; +use crate::WasmBackend; + +/// A handle to an instantiated Wasm module. Cloning is cheap. +pub trait Instance: Clone { + /// Returns an `Iterator` to all exports of this instance. + fn export_iter<'a>( + &'a self, + store: ::ContextMut<'a>, + ) -> Box)> + 'a>; + + /// Returns nth exported memory, None if there is no nth memory. + /// No guaranties is known for memory order, but almost always a module has only one memory, + /// hence the only valid value for `memory_index` is 0. + fn get_nth_memory( + &self, + store: &mut impl AsContextMut, + memory_index: u32, // TODO: refactor memory indexing with enums + ) -> Option<::Memory>; + + /// Returns a memory export with given name. + /// # Errors: + /// Returns an error if there is no export with such name, or it is not a memory. + fn get_memory( + &self, + store: &mut impl AsContextMut, + memory_name: &str, + ) -> ResolveResult<::Memory>; + + /// Returns an exported function with the given name. + /// # Errors: + /// Returns an error if there is no export with such name, or it is not a function. + fn get_function( + &self, + store: &mut impl AsContextMut, + name: &str, + ) -> ResolveResult<::Function>; +} diff --git a/crates/wasm-backend-traits/src/lib.rs b/crates/wasm-backend-traits/src/lib.rs new file mode 100644 index 000000000..18e2e5965 --- /dev/null +++ b/crates/wasm-backend-traits/src/lib.rs @@ -0,0 +1,96 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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 errors; +pub mod exports; +pub mod imports; +pub mod store; +pub mod wasi; +pub mod wtype; +pub mod module; +pub mod instance; +pub mod caller; +pub mod function; +pub mod macros; + +/// Helper functions for backend implementations. +pub mod impl_utils; + +pub mod prelude { + pub use crate::errors::*; + pub use crate::exports::*; + pub use crate::imports::*; + pub use crate::store::*; + pub use crate::wasi::*; + pub use crate::wtype::*; + pub use crate::module::*; + pub use crate::instance::*; + pub use crate::caller::*; + pub use crate::function::*; + pub use crate::WasmBackend; + pub use crate::DelayedContextLifetime; +} + +pub use prelude::*; + +pub use macros::*; + +use it_memory_traits::MemoryView; + +use std::marker::PhantomData; + +/// A core trait for any backend. It serves two purposes: +/// * handles initialization of the library if needed +/// * provides access to all public types -- like `mod` but for trait impls. +pub trait WasmBackend: Clone + Default + 'static { + /// A type that stores all the data, while most of the types are handles to data from `Store`. + type Store: Store; + /// A compiled, but not instantiated module. + type Module: Module; + /// An object that holds all the functions that are given to `Module` as imports. + type Imports: Imports; // maybe rename to Linker? + /// An instantiated module ready to be executed. + type Instance: Instance; + /// A temporary immutable handle to `Store`. + type Context<'c>: Context; + /// A temporary mutable handle to `Store` + type ContextMut<'c>: ContextMut; + /// A type that is used to pass context to imports. + type Caller<'c>: Caller; + /// A function contained in `Store`, either host one or from wasm. + type Function: Function + FuncConstructor; + /// A wasm memory. + type Memory: Memory; + /// A view to the wasm memory. + type MemoryView: MemoryView>; + + /// Type that provides all WASI-related APIs. + type Wasi: WasiImplementation; + + /// Creates a new wasm backend with default configuration. In future, a configuration + /// may be passed as argument. + fn new() -> WasmBackendResult; +} + +/// This struct is a helper, that allows passing `::ContextMut` as template parameter, +/// but not specify a lifetime. Any local lifetime can be used instead. +pub struct DelayedContextLifetime { + _data: PhantomData, +} + +impl it_memory_traits::Store for DelayedContextLifetime { + type ActualStore<'c> = ::ContextMut<'c>; +} diff --git a/crates/wasm-backend-traits/src/macros.rs b/crates/wasm-backend-traits/src/macros.rs new file mode 100644 index 000000000..bc68f3768 --- /dev/null +++ b/crates/wasm-backend-traits/src/macros.rs @@ -0,0 +1,47 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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. + */ + +/// Copypasted from Wasmtime. +/// A helper macros for implementing anything for 0-16 generic parameters. +/// The expected argument signature is this: +/// ``` +/// macro_rules! example_arg { +/// ($num:tt $($args:ident)*) => (); +/// } +/// ``` +/// https://github.com/bytecodealliance/wasmtime/blob/812b4b5229eac29b18b5c70a48536a514d73a8a6/crates/wasmtime/src/func.rs#LL242C14-L242C41 +#[macro_export] +macro_rules! impl_for_each_function_signature { + ($mac:ident) => { + $mac!(0); + $mac!(1 A1); + $mac!(2 A1 A2); + $mac!(3 A1 A2 A3); + $mac!(4 A1 A2 A3 A4); + $mac!(5 A1 A2 A3 A4 A5); + $mac!(6 A1 A2 A3 A4 A5 A6); + $mac!(7 A1 A2 A3 A4 A5 A6 A7); + $mac!(8 A1 A2 A3 A4 A5 A6 A7 A8); + $mac!(9 A1 A2 A3 A4 A5 A6 A7 A8 A9); + $mac!(10 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10); + $mac!(11 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11); + $mac!(12 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12); + $mac!(13 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13); + $mac!(14 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14); + $mac!(15 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15); + $mac!(16 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15 A16); + }; +} diff --git a/crates/wasm-backend-traits/src/module.rs b/crates/wasm-backend-traits/src/module.rs new file mode 100644 index 000000000..3b40d8a0f --- /dev/null +++ b/crates/wasm-backend-traits/src/module.rs @@ -0,0 +1,40 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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 crate::ModuleCreationResult; +use crate::InstantiationResult; +use crate::WasmBackend; + +/// A handle to compiled wasm module. +pub trait Module: Sized { + /// Compiles a wasm bytes into a module and extracts custom sections. + fn new(store: &mut ::Store, wasm: &[u8]) -> ModuleCreationResult; + + /// Returns custom sections corresponding to `name`, empty slice if there is no sections. + fn custom_sections(&self, name: &str) -> &[Vec]; + + /// Instantiates module by allocating memory, VM state and linking imports with ones from `import` argument. + /// Does not call `_start` or `_initialize` functions. + /// + /// # Panics: + /// + /// If the `Store` given is not the same with `Store` used to create `Imports` and this object. + fn instantiate( + &self, + store: &mut ::Store, + imports: &::Imports, + ) -> InstantiationResult<::Instance>; +} diff --git a/crates/wasm-backend-traits/src/store.rs b/crates/wasm-backend-traits/src/store.rs new file mode 100644 index 000000000..a43d58574 --- /dev/null +++ b/crates/wasm-backend-traits/src/store.rs @@ -0,0 +1,41 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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 crate::WasmBackend; + +/// `Store` is an object that stores modules, instances, functions memories and so on. +/// `Store` is grow-only: once something added, it will not be removed until Store is destroyed. +/// Some of the implementations can limit allocated resources. +/// For example, Wasmtime cannot have more than 10000 instances in one `Store`. +/// +/// Most of the functions in this crate require a handle to `Store` to work. +pub trait Store: AsContextMut { + fn new(backend: &WB) -> Self; +} + +/// A temporary immutable handle to store +pub trait Context: AsContext {} + +/// A temporary mutable handle to store +pub trait ContextMut: AsContextMut {} + +pub trait AsContext { + fn as_context(&self) -> ::Context<'_>; +} + +pub trait AsContextMut: AsContext { + fn as_context_mut(&mut self) -> ::ContextMut<'_>; +} diff --git a/crates/wasm-backend-traits/src/wasi.rs b/crates/wasm-backend-traits/src/wasi.rs new file mode 100644 index 000000000..d26d9c114 --- /dev/null +++ b/crates/wasm-backend-traits/src/wasi.rs @@ -0,0 +1,52 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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 crate::WasiError; +use crate::WasmBackend; + +use std::path::PathBuf; +use std::collections::HashMap; +use std::collections::HashSet; + +/// A type that provides WASI functionality to the given Wasm backend. +pub trait WasiImplementation { + /// Configures WASI state and adds WASI functions to the `imports` object. + /// # Errors: + /// Returns an error if failed to open a preopen directory/file. + fn register_in_linker( + store: &mut ::ContextMut<'_>, + linker: &mut ::Imports, + config: WasiParameters, + ) -> Result<(), WasiError>; + + /// Optional API for getting current WASI state. + /// Returns None if not supported by current backend. + fn get_wasi_state<'s>( + instance: &'s mut ::Instance, + ) -> Box; +} + +#[derive(Default)] +pub struct WasiParameters { + pub args: Vec>, + pub envs: HashMap, Vec>, + pub preopened_files: HashSet, + pub mapped_dirs: HashMap, +} + +pub trait WasiState { + fn envs(&self) -> &[Vec]; +} diff --git a/crates/wasm-backend-traits/src/wtype.rs b/crates/wasm-backend-traits/src/wtype.rs new file mode 100644 index 000000000..415573bec --- /dev/null +++ b/crates/wasm-backend-traits/src/wtype.rs @@ -0,0 +1,92 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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. + */ + +#[derive(Debug, Clone, PartialEq)] +pub enum WValue { + /// The `i32` type. + I32(i32), + /// The `i64` type. + I64(i64), + /// The `f32` type. + F32(f32), + /// The `f64` type. + F64(f64), +} + +impl From for WValue { + fn from(value: i32) -> Self { + WValue::I32(value) + } +} + +impl From for WValue { + fn from(value: i64) -> Self { + WValue::I64(value) + } +} + +impl From for WValue { + fn from(value: f32) -> Self { + WValue::F32(value) + } +} + +impl From for WValue { + fn from(value: f64) -> Self { + WValue::F64(value) + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum WType { + /// The `i32` type. + I32, + /// The `i64` type. + I64, + /// The `f32` type. + F32, + /// The `f64` type. + F64, + /// The `v128` type, unsupported. + V128, + /// ExternRef type, unsupported. + ExternRef, + /// FuncRef type, unsupported. + FuncRef, +} + +impl WType { + pub fn is_supported(&self) -> bool { + !matches!(self, Self::ExternRef | Self::FuncRef | Self::V128) + } +} + +impl WValue { + pub fn to_u128(&self) -> u128 { + match *self { + Self::I32(x) => x as u128, + Self::I64(x) => x as u128, + Self::F32(x) => f32::to_bits(x) as u128, + Self::F64(x) => f64::to_bits(x) as u128, + } + } +} + +impl std::fmt::Display for WType { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} diff --git a/crates/wasmtime-backend/Cargo.toml b/crates/wasmtime-backend/Cargo.toml new file mode 100644 index 000000000..e2af8c88d --- /dev/null +++ b/crates/wasmtime-backend/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "marine-wasmtime-backend" +version = "0.1.0" +edition = "2021" +authors = ["Fluence Labs"] +license = "Apache-2.0" + +[dependencies] +marine-wasm-backend-traits = {path = "../wasm-backend-traits", version = "0.1.0"} +wasmer-it = { workspace = true } +it-memory-traits = { workspace = true } + +# all default features except async +wasmtime = {version = "6.0.1", default-features = false, features = ["cache", "wat", "jitdump", "parallel-compilation", "cranelift", "pooling-allocator", "vtune"]} +wasmtime-wasi = "6.0.1" +multimap = "0.8.3" +paste = "1.0.9" +anyhow = "1.0.68" +log = "0.4.1" diff --git a/crates/wasmtime-backend/src/caller.rs b/crates/wasmtime-backend/src/caller.rs new file mode 100644 index 000000000..e66df85d1 --- /dev/null +++ b/crates/wasmtime-backend/src/caller.rs @@ -0,0 +1,119 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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 crate::StoreState; +use crate::WasmtimeContext; +use crate::WasmtimeContextMut; +use crate::WasmtimeWasmBackend; +use crate::WasmtimeMemory; + +use marine_wasm_backend_traits::prelude::*; + +use wasmtime::AsContext as WasmtimeAsContext; +use wasmtime::AsContextMut as WasmtimeAsContextMut; + +pub struct WasmtimeCaller<'c> { + pub(crate) inner: wasmtime::Caller<'c, StoreState>, +} + +impl<'c> Caller for WasmtimeCaller<'c> { + fn memory(&mut self, _memory_index: u32) -> Option { + let memory = self + .inner + .get_export(STANDARD_MEMORY_EXPORT_NAME)? + .into_memory()?; + + Some(WasmtimeMemory::new(memory)) + } +} + +impl<'c> AsContext for WasmtimeCaller<'c> { + fn as_context(&self) -> WasmtimeContext<'_> { + WasmtimeContext { + inner: self.inner.as_context(), + } + } +} + +impl<'c> AsContextMut for WasmtimeCaller<'c> { + fn as_context_mut(&mut self) -> ::ContextMut<'_> { + WasmtimeContextMut { + inner: self.inner.as_context_mut(), + } + } +} + +/// Implements func_getter for given function signature. +/// Later `get_func` variant will be statically chosen based on types. +macro_rules! impl_func_getter { + ($args:ty, $rets:ty) => { + impl<'c> FuncGetter for WasmtimeCaller<'c> { + fn get_func( + &mut self, + name: &str, + ) -> Result< + Box< + dyn FnMut(&mut WasmtimeContextMut<'_>, $args) -> Result<$rets, RuntimeError> + + Sync + + Send + + 'static, + >, + ResolveError, + > { + let export = self + .inner + .get_export(name) + .ok_or(ResolveError::ExportNotFound(name.to_string()))?; + + match export { + wasmtime::Extern::Func(f) => { + let f = f + .typed(&mut self.inner) + .map_err(|e| ResolveError::Other(e))?; + + let closure = move |store: &mut WasmtimeContextMut<'_>, args| { + f.call(&mut store.inner, args).map_err(|e| { + if let Some(_) = e.downcast_ref::() { + RuntimeError::Trap(e) + } else { + RuntimeError::Other(e) + } + }) + }; + + Ok(Box::new(closure)) + } + wasmtime::Extern::Memory(_) => Err(ResolveError::ExportTypeMismatch { + expected: "function", + actual: "memory", + }), + _ => Err(ResolveError::ExportTypeMismatch { + expected: "function", + actual: "neither memory nor function", + }), + } + } + } + }; +} + +// These signatures are sufficient for marine to work. +impl_func_getter!((i32, i32), i32); +impl_func_getter!((i32, i32), ()); +impl_func_getter!(i32, i32); +impl_func_getter!(i32, ()); +impl_func_getter!((), i32); +impl_func_getter!((), ()); diff --git a/crates/wasmtime-backend/src/function.rs b/crates/wasmtime-backend/src/function.rs new file mode 100644 index 000000000..092225cf0 --- /dev/null +++ b/crates/wasmtime-backend/src/function.rs @@ -0,0 +1,178 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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 crate::WasmtimeContextMut; +use crate::WasmtimeWasmBackend; +use crate::WasmtimeCaller; +use crate::val_to_wvalue; +use crate::StoreState; +use crate::sig_to_fn_ty; +use crate::wvalue_to_val; +use crate::utils::fn_ty_to_sig; +use crate::utils::inspect_call_error; + +use marine_wasm_backend_traits::prelude::*; +use marine_wasm_backend_traits::impl_for_each_function_signature; +use marine_wasm_backend_traits::replace_with; + +use anyhow::anyhow; + +pub struct WasmtimeFunction { + pub(crate) inner: wasmtime::Func, +} + +impl Function for WasmtimeFunction { + fn new(store: &mut impl AsContextMut, sig: FuncSig, func: F) -> Self + where + F: for<'c> Fn(&[WValue]) -> Vec + Sync + Send + 'static, + { + let ty = sig_to_fn_ty(&sig); + let func = move |_: wasmtime::Caller<'_, StoreState>, + args: &[wasmtime::Val], + results_out: &mut [wasmtime::Val]| + -> Result<(), anyhow::Error> { + let args = process_func_args(args).map_err(|e| anyhow!(e))?; // TODO move earlier + let results = func(&args); + process_func_results(&results, results_out).map_err(|e| anyhow!(e)) + }; + + let func = wasmtime::Func::new(store.as_context_mut().inner, ty, func); + WasmtimeFunction { inner: func } + } + + fn new_with_caller( + store: &mut impl AsContextMut, + sig: FuncSig, + func: F, + ) -> Self + where + F: for<'c> Fn(::Caller<'c>, &[WValue]) -> Vec + + Sync + + Send + + 'static, + { + let ty = sig_to_fn_ty(&sig); + + let func = move |caller: wasmtime::Caller<'_, StoreState>, + args: &[wasmtime::Val], + results_out: &mut [wasmtime::Val]| + -> Result<(), anyhow::Error> { + let caller = WasmtimeCaller { inner: caller }; + let args = process_func_args(args).map_err(|e| anyhow!(e))?; + let results = func(caller, &args); + process_func_results(&results, results_out).map_err(|e| anyhow!(e)) + }; + + let func = wasmtime::Func::new(store.as_context_mut().inner, ty, func); + WasmtimeFunction { inner: func } + } + + fn new_typed( + store: &mut impl marine_wasm_backend_traits::AsContextMut, + func: impl IntoFunc, + ) -> Self { + func.into_func(store) + } + + fn signature<'c>(&self, store: &mut impl AsContextMut) -> FuncSig { + let ty = self.inner.ty(store.as_context_mut()); + fn_ty_to_sig(&ty) + } + + fn call<'c>( + &self, + store: &mut impl AsContextMut, + args: &[WValue], + ) -> RuntimeResult> { + let args = args.iter().map(wvalue_to_val).collect::>(); + + let results_count = self.inner.ty(store.as_context_mut()).results().len(); + let mut results = vec![wasmtime::Val::null(); results_count]; + + self.inner + .call(store.as_context_mut().inner, &args, &mut results) + .map_err(inspect_call_error)?; + + results + .iter() + .map(val_to_wvalue) + .collect::, _>>() + } +} + +/// Generates a function that accepts a Fn with $num template parameters and turns it into WasmtimeFunction. +/// Needed to allow users to pass almost any function to `Function::new_typed` without worrying about signature. +macro_rules! impl_func_construction { + ($num:tt $($args:ident)*) => (paste::paste!{ + fn [< new_typed_with_env_ $num >] (mut ctx: WasmtimeContextMut<'_>, func: F) -> WasmtimeFunction + where F: Fn(WasmtimeCaller<'_>, $(replace_with!($args -> i32),)*) + Send + Sync + 'static { + + let func = move |caller: wasmtime::Caller<'_, StoreState>, $($args,)*| { + let caller = WasmtimeCaller {inner: caller}; + func(caller, $($args,)*) + }; + + let func = wasmtime::Func::wrap(&mut ctx.inner, func); + + WasmtimeFunction { + inner: func + } + } + + fn [< new_typed_with_env_ $num _r>] (mut ctx: WasmtimeContextMut<'_>, func: F) -> WasmtimeFunction + where F: Fn(WasmtimeCaller<'_>, $(replace_with!($args -> i32),)*) -> i32 + Send + Sync + 'static { + + let func = move |caller: wasmtime::Caller<'_, StoreState>, $($args,)*| -> i32{ + let caller = WasmtimeCaller {inner: caller}; + func(caller, $($args,)*) + }; + + let func = wasmtime::Func::wrap(&mut ctx.inner, func); + + WasmtimeFunction { + inner: func + } + } + }); +} + +impl FuncConstructor for WasmtimeFunction { + impl_for_each_function_signature!(impl_func_construction); +} + +fn process_func_args(args: &[wasmtime::Val]) -> RuntimeResult> { + args.iter() + .map(val_to_wvalue) + .collect::>>() +} + +fn process_func_results( + results_in: &[WValue], + results_out: &mut [wasmtime::Val], +) -> RuntimeResult<()> { + if results_in.len() != results_out.len() { + return Err(RuntimeError::IncorrectResultsNumber { + expected: results_out.len(), + actual: results_in.len(), + }); + } + + for id in 0..results_in.len() { + results_out[id] = wvalue_to_val(&results_in[id]); + } + + Ok(()) +} diff --git a/crates/wasmtime-backend/src/imports.rs b/crates/wasmtime-backend/src/imports.rs new file mode 100644 index 000000000..e3d55e346 --- /dev/null +++ b/crates/wasmtime-backend/src/imports.rs @@ -0,0 +1,68 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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 crate::StoreState; +use crate::WasmtimeFunction; +use crate::WasmtimeStore; +use crate::WasmtimeWasmBackend; + +use marine_wasm_backend_traits::prelude::*; + +#[derive(Clone)] +pub struct WasmtimeImports { + pub(crate) linker: wasmtime::Linker, +} + +impl Imports for WasmtimeImports { + fn new(store: &mut WasmtimeStore) -> Self { + Self { + linker: wasmtime::Linker::new(store.inner.engine()), + } + } + + fn insert( + &mut self, + store: &impl AsContext, + module: impl Into, + name: impl Into, + func: ::Function, + ) -> Result<(), ImportError> { + let module = module.into(); + let name = name.into(); + self.linker + .define(store.as_context(), &module, &name, func.inner) + .map_err(|_| ImportError::DuplicateImport(module, name)) + .map(|_| ()) + } + + fn register( + &mut self, + store: &impl AsContext, + name: S, + namespace: I, + ) -> Result<(), ImportError> + where + S: Into, + I: IntoIterator, + { + let module: String = name.into(); + for (name, func) in namespace { + self.insert(store, &module, name, func)?; + } + + Ok(()) + } +} diff --git a/crates/wasmtime-backend/src/instance.rs b/crates/wasmtime-backend/src/instance.rs new file mode 100644 index 000000000..6b0dabded --- /dev/null +++ b/crates/wasmtime-backend/src/instance.rs @@ -0,0 +1,93 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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 crate::WasmtimeContextMut; +use crate::WasmtimeFunction; +use crate::WasmtimeMemory; +use crate::WasmtimeWasmBackend; + +use marine_wasm_backend_traits::prelude::*; + +#[derive(Clone)] +pub struct WasmtimeInstance { + pub(crate) inner: wasmtime::Instance, +} + +impl Instance for WasmtimeInstance { + fn export_iter<'a>( + &'a self, + store: WasmtimeContextMut<'a>, + ) -> Box)> + 'a> { + let exports = self.inner.exports(store.inner).map(|export| { + let name = export.name(); + let export = match export.into_extern() { + wasmtime::Extern::Memory(memory) => Export::Memory(WasmtimeMemory::new(memory)), + wasmtime::Extern::Func(func) => Export::Function(WasmtimeFunction { inner: func }), + _ => Export::Other, + }; + (name, export) + }); + Box::new(exports) + } + + fn get_nth_memory( + &self, + store: &mut impl AsContextMut, + memory_index: u32, + ) -> Option<::Memory> { + self.inner + .exports(&mut store.as_context_mut().inner) + .filter_map(wasmtime::Export::into_memory) + .nth(memory_index as usize) + .map(WasmtimeMemory::new) + } + + fn get_memory( + &self, + store: &mut impl AsContextMut, + memory_name: &str, + ) -> ResolveResult<::Memory> { + self.inner + .get_export(&mut store.as_context_mut().inner, memory_name) + .ok_or_else(|| ResolveError::ExportNotFound(memory_name.to_string())) + .and_then(|e| { + e.into_memory().ok_or(ResolveError::ExportTypeMismatch { + expected: "memory", + actual: "other", + }) + }) + .map(WasmtimeMemory::new) + } + + fn get_function( + &self, + store: &mut impl AsContextMut, + name: &str, + ) -> ResolveResult<::Function> { + let func = self + .inner + .get_export(&mut store.as_context_mut().inner, name) + .ok_or_else(|| ResolveError::ExportNotFound(name.to_owned())) + .and_then(|e| { + e.into_func().ok_or(ResolveError::ExportTypeMismatch { + expected: "function", + actual: "other", + }) + })?; + + Ok(WasmtimeFunction { inner: func }) + } +} diff --git a/crates/wasmtime-backend/src/lib.rs b/crates/wasmtime-backend/src/lib.rs new file mode 100644 index 000000000..fe8dd9228 --- /dev/null +++ b/crates/wasmtime-backend/src/lib.rs @@ -0,0 +1,74 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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. + */ + +mod caller; +mod store; +mod utils; +mod module; +mod instance; +mod wasi; +mod function; +mod imports; +mod memory; + +use store::*; +use caller::*; +use module::*; +use instance::*; +use wasi::*; +use function::*; +use memory::*; +use imports::*; +use utils::*; + +use marine_wasm_backend_traits::prelude::*; + +use wasmtime_wasi::WasiCtx; + +#[derive(Clone, Default)] +pub struct WasmtimeWasmBackend { + engine: wasmtime::Engine, +} + +impl WasmBackend for WasmtimeWasmBackend { + type Store = WasmtimeStore; + type Module = WasmtimeModule; + type Imports = WasmtimeImports; + type Instance = WasmtimeInstance; + type Context<'c> = WasmtimeContext<'c>; + type ContextMut<'c> = WasmtimeContextMut<'c>; + type Caller<'c> = WasmtimeCaller<'c>; + type Function = WasmtimeFunction; + type Memory = WasmtimeMemory; + type MemoryView = WasmtimeMemory; + type Wasi = WasmtimeWasi; + + fn new() -> WasmBackendResult { + let mut config = wasmtime::Config::new(); + config + .debug_info(false) + .wasm_backtrace_details(wasmtime::WasmBacktraceDetails::Enable); + let engine = + wasmtime::Engine::new(&config).map_err(WasmBackendError::InitializationError)?; + + Ok(Self { engine }) + } +} + +#[derive(Default)] +pub struct StoreState { + wasi: Vec, // wasmtime store does not release memory until drop, so do we +} diff --git a/crates/wasmtime-backend/src/memory.rs b/crates/wasmtime-backend/src/memory.rs new file mode 100644 index 000000000..afe663385 --- /dev/null +++ b/crates/wasmtime-backend/src/memory.rs @@ -0,0 +1,131 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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 crate::WasmtimeContextMut; +use crate::WasmtimeWasmBackend; + +use marine_wasm_backend_traits::DelayedContextLifetime; +use marine_wasm_backend_traits::Memory; + +use it_memory_traits::MemoryAccessError; + +static MEMORY_ACCESS_CONTRACT: &str = "api requires checking memory bounds before accessing memory"; + +#[derive(Clone)] +pub struct WasmtimeMemory { + memory: wasmtime::Memory, +} + +impl WasmtimeMemory { + pub(crate) fn new(memory: wasmtime::Memory) -> Self { + Self { memory } + } +} + +impl it_memory_traits::Memory> + for WasmtimeMemory +{ + // Wasmtime does not have the idea of MemoryView, while Wasmer has. + // And our interface-types implementation has MemoryView concept + // So, MemoryView in Wasmtime is just the memory. + fn view(&self) -> WasmtimeMemory { + self.clone() + } +} + +impl Memory for WasmtimeMemory { + fn size(&self, store: &mut WasmtimeContextMut<'_>) -> usize { + self.memory.data_size(store) + } +} + +impl it_memory_traits::MemoryReadable> + for WasmtimeMemory +{ + fn read_byte(&self, store: &mut WasmtimeContextMut<'_>, offset: u32) -> u8 { + let mut value = [0u8]; + self.memory + .read(&mut store.inner, offset as usize, &mut value) + .expect(MEMORY_ACCESS_CONTRACT); + + value[0] + } + + fn read_array( + &self, + store: &mut WasmtimeContextMut<'_>, + offset: u32, + ) -> [u8; COUNT] { + let mut value = [0u8; COUNT]; + self.memory + .read(&mut store.inner, offset as usize, &mut value) + .expect(MEMORY_ACCESS_CONTRACT); + value + } + + fn read_vec(&self, store: &mut WasmtimeContextMut<'_>, offset: u32, size: u32) -> Vec { + let mut value = vec![0u8; size as usize]; + self.memory + .read(&mut store.inner, offset as usize, &mut value) + .expect(MEMORY_ACCESS_CONTRACT); + value + } +} + +impl it_memory_traits::MemoryWritable> + for WasmtimeMemory +{ + fn write_byte(&self, store: &mut WasmtimeContextMut<'_>, offset: u32, value: u8) { + let buffer = [value]; + self.memory + .write(&mut store.inner, offset as usize, &buffer) + .expect(MEMORY_ACCESS_CONTRACT); + } + + fn write_bytes(&self, store: &mut WasmtimeContextMut<'_>, offset: u32, bytes: &[u8]) { + self.memory + .write(&mut store.inner, offset as usize, bytes) + .expect(MEMORY_ACCESS_CONTRACT); + } +} + +impl it_memory_traits::MemoryView> for WasmtimeMemory { + fn check_bounds( + &self, + store: &mut WasmtimeContextMut<'_>, + offset: u32, + size: u32, + ) -> Result<(), MemoryAccessError> { + let memory_size = self.memory.data_size(&mut store.inner); + let final_size = offset + .checked_add(size) + .ok_or(MemoryAccessError::OutOfBounds { + offset, + size, + memory_size: memory_size as u32, + })? as usize; + + if memory_size <= final_size { + Err(MemoryAccessError::OutOfBounds { + offset, + size, + memory_size: memory_size as u32, // TODO rewrite api when memory64 arrives + }) + } else { + Ok(()) + } + } +} diff --git a/crates/wasmtime-backend/src/module.rs b/crates/wasmtime-backend/src/module.rs new file mode 100644 index 000000000..dd2818d97 --- /dev/null +++ b/crates/wasmtime-backend/src/module.rs @@ -0,0 +1,66 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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 crate::WasmtimeImports; +use crate::WasmtimeInstance; +use crate::WasmtimeStore; +use crate::WasmtimeWasmBackend; +use crate::utils::inspect_instantiation_error; + +use marine_wasm_backend_traits::prelude::*; +use marine_wasm_backend_traits::impl_utils::custom_sections; + +use multimap::MultiMap; + +pub struct WasmtimeModule { + pub(crate) custom_sections: MultiMap>, + pub(crate) inner: wasmtime::Module, +} + +impl Module for WasmtimeModule { + fn new(store: &mut WasmtimeStore, wasm: &[u8]) -> ModuleCreationResult { + let module = wasmtime::Module::new(store.inner.engine(), wasm) + .map_err(ModuleCreationError::FailedToCompileWasm)?; + let custom_sections = + custom_sections(wasm) // TODO: avoid double module parsing + .map_err(ModuleCreationError::FailedToExtractCustomSections)?; + + Ok(WasmtimeModule { + custom_sections, + inner: module, + }) + } + + fn custom_sections(&self, name: &str) -> &[Vec] { + self.custom_sections + .get_vec(name) + .map(|value| value.as_slice()) + .unwrap_or_default() + } + + fn instantiate( + &self, + store: &mut WasmtimeStore, + imports: &WasmtimeImports, + ) -> InstantiationResult<::Instance> { + // linker will not call _start, or _initialize unless Linker::module or Linker::module_async is used + let instance = imports + .linker + .instantiate(&mut store.inner, &self.inner) + .map_err(inspect_instantiation_error)?; // TODO add detail + Ok(WasmtimeInstance { inner: instance }) + } +} diff --git a/crates/wasmtime-backend/src/store.rs b/crates/wasmtime-backend/src/store.rs new file mode 100644 index 000000000..5dab3bdf4 --- /dev/null +++ b/crates/wasmtime-backend/src/store.rs @@ -0,0 +1,132 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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 crate::StoreState; +use crate::WasmtimeWasmBackend; + +use marine_wasm_backend_traits::prelude::*; + +use wasmtime::StoreContext; +use wasmtime::StoreContextMut; +use wasmtime::AsContext as WasmtimeAsContext; +use wasmtime::AsContextMut as WasmtimeAsContextMut; + +use std::default::Default; + +/// A type that is used to store resources allocated by runtime. It includes memories, functions, +/// tables, globals and so on. More information here: https://webassembly.github.io/spec/core/exec/runtime.html#store. +/// Because of that, most of the methods in API require a handle to store to function. +pub struct WasmtimeStore { + pub(crate) inner: wasmtime::Store, +} + +/// Temporary immutable handle to `Store`, used to interact with stored data. +pub struct WasmtimeContext<'s> { + pub(crate) inner: wasmtime::StoreContext<'s, StoreState>, +} + +/// Temporary mutable handle to `Store`, used to interact with stored data. +pub struct WasmtimeContextMut<'s> { + pub(crate) inner: wasmtime::StoreContextMut<'s, StoreState>, +} + +impl Store for WasmtimeStore { + fn new(backend: &WasmtimeWasmBackend) -> Self { + Self { + inner: wasmtime::Store::new(&backend.engine, <_>::default()), + } + } +} + +impl<'c> Context for WasmtimeContext<'c> {} + +impl<'c> ContextMut for WasmtimeContextMut<'c> {} + +impl AsContext for WasmtimeStore { + fn as_context(&self) -> WasmtimeContext<'_> { + WasmtimeContext { + inner: self.inner.as_context(), + } + } +} + +impl AsContextMut for WasmtimeStore { + fn as_context_mut(&mut self) -> WasmtimeContextMut<'_> { + WasmtimeContextMut { + inner: self.inner.as_context_mut(), + } + } +} + +impl<'ctx> AsContext for WasmtimeContext<'ctx> { + fn as_context(&self) -> WasmtimeContext<'_> { + WasmtimeContext { + inner: self.inner.as_context(), + } + } +} + +impl<'ctx> AsContext for WasmtimeContextMut<'ctx> { + fn as_context(&self) -> WasmtimeContext<'_> { + WasmtimeContext { + inner: self.inner.as_context(), + } + } +} + +impl<'ctx> AsContextMut for WasmtimeContextMut<'ctx> { + fn as_context_mut(&mut self) -> WasmtimeContextMut<'_> { + WasmtimeContextMut { + inner: self.inner.as_context_mut(), + } + } +} + +impl wasmtime::AsContext for WasmtimeStore { + type Data = StoreState; + + fn as_context(&self) -> StoreContext<'_, Self::Data> { + self.inner.as_context() + } +} + +impl wasmtime::AsContextMut for WasmtimeStore { + fn as_context_mut(&mut self) -> StoreContextMut<'_, Self::Data> { + self.inner.as_context_mut() + } +} + +impl wasmtime::AsContext for WasmtimeContext<'_> { + type Data = StoreState; + + fn as_context(&self) -> StoreContext<'_, Self::Data> { + self.inner.as_context() + } +} + +impl wasmtime::AsContext for WasmtimeContextMut<'_> { + type Data = StoreState; + + fn as_context(&self) -> StoreContext<'_, Self::Data> { + self.inner.as_context() + } +} + +impl wasmtime::AsContextMut for WasmtimeContextMut<'_> { + fn as_context_mut(&mut self) -> StoreContextMut<'_, Self::Data> { + self.inner.as_context_mut() + } +} diff --git a/crates/wasmtime-backend/src/utils.rs b/crates/wasmtime-backend/src/utils.rs new file mode 100644 index 000000000..9030c0f3f --- /dev/null +++ b/crates/wasmtime-backend/src/utils.rs @@ -0,0 +1,108 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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 marine_wasm_backend_traits::prelude::*; + +use wasmtime::Val; +use wasmtime::ValType; + +pub(crate) fn val_type_to_wtype(ty: &ValType) -> WType { + match ty { + ValType::I32 => WType::I32, + ValType::I64 => WType::I64, + ValType::F32 => WType::F32, + ValType::F64 => WType::F64, + ValType::V128 => WType::V128, + ValType::FuncRef => WType::FuncRef, + ValType::ExternRef => WType::ExternRef, + } +} + +pub(crate) fn wtype_to_val_type(ty: &WType) -> ValType { + match ty { + WType::I32 => ValType::I32, + WType::I64 => ValType::I64, + WType::F32 => ValType::F32, + WType::F64 => ValType::F64, + WType::V128 => ValType::V128, + WType::FuncRef => ValType::FuncRef, + WType::ExternRef => ValType::ExternRef, + } +} + +pub(crate) fn wvalue_to_val(value: &WValue) -> Val { + match value { + WValue::I32(value) => Val::I32(*value), + WValue::I64(value) => Val::I64(*value), + WValue::F32(value) => Val::F32(value.to_bits()), + WValue::F64(value) => Val::F64(value.to_bits()), + } +} + +pub(crate) fn val_to_wvalue(value: &Val) -> RuntimeResult { + match value { + Val::I32(value) => Ok(WValue::I32(*value)), + Val::I64(value) => Ok(WValue::I64(*value)), + Val::F32(value) => Ok(WValue::F32(f32::from_bits(*value))), + Val::F64(value) => Ok(WValue::F64(f64::from_bits(*value))), + Val::V128(_) => Err(RuntimeError::UnsupportedType(WType::V128)), + Val::FuncRef(_) => Err(RuntimeError::UnsupportedType(WType::V128)), + Val::ExternRef(_) => Err(RuntimeError::UnsupportedType(WType::V128)), + } +} + +pub(crate) fn sig_to_fn_ty(sig: &FuncSig) -> wasmtime::FuncType { + let params = sig.params().iter().map(wtype_to_val_type); + let rets = sig.returns().iter().map(wtype_to_val_type); + + wasmtime::FuncType::new(params, rets) +} + +pub(crate) fn fn_ty_to_sig(ty: &wasmtime::FuncType) -> FuncSig { + let params = ty + .params() + .map(|ty| val_type_to_wtype(&ty)) + .collect::>(); + + let rets = ty + .results() + .map(|ty| val_type_to_wtype(&ty)) + .collect::>(); + + FuncSig::new(params, rets) +} + +pub(crate) fn inspect_call_error(e: anyhow::Error) -> RuntimeError { + if e.downcast_ref::().is_some() { + RuntimeError::Trap(e) + } else { + match e.downcast::() { + Ok(e) => RuntimeError::UserError(e), + Err(e) => RuntimeError::Other(e), + } + } +} + +pub(crate) fn inspect_instantiation_error(e: anyhow::Error) -> InstantiationError { + if e.downcast_ref::().is_some() { + InstantiationError::RuntimeError(RuntimeError::Trap(e)) + } else { + match e.downcast::() { + Ok(e) => InstantiationError::RuntimeError(RuntimeError::UserError(e)), + Err(e) => InstantiationError::Other(e), + } + } +} diff --git a/crates/wasmtime-backend/src/wasi.rs b/crates/wasmtime-backend/src/wasi.rs new file mode 100644 index 000000000..21c6c3aa3 --- /dev/null +++ b/crates/wasmtime-backend/src/wasi.rs @@ -0,0 +1,159 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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 crate::StoreState; +use crate::WasmtimeContextMut; +use crate::WasmtimeImports; +use crate::WasmtimeWasmBackend; + +use marine_wasm_backend_traits::prelude::*; + +use wasmtime_wasi::ambient_authority; +use wasmtime_wasi::WasiCtxBuilder; +use anyhow::anyhow; + +use std::path::Path; +use std::path::PathBuf; +use std::collections::HashMap; +use std::collections::HashSet; + +pub struct WasmtimeWasi {} + +impl WasiImplementation for WasmtimeWasi { + fn register_in_linker( + store: &mut WasmtimeContextMut<'_>, + linker: &mut WasmtimeImports, + parameters: WasiParameters, + ) -> Result<(), WasiError> { + let WasiParameters { + args, + envs, + preopened_files, + mapped_dirs, + } = parameters; + + let wasi_ctx_builder = WasiCtxBuilder::new(); + // process and add CLI arguments to wasi context + let wasi_ctx_builder = populate_args(wasi_ctx_builder, args)?; + // process and add environment variables to wasi context + let wasi_ctx_builder = populate_envs(wasi_ctx_builder, envs)?; + // add preopened files to wasi context, do not create dirs + let wasi_ctx_builder = populate_preopens(wasi_ctx_builder, preopened_files)?; + // add mapped directories to wasi context , do not create dirs + let wasi_ctx_builder = populate_mapped_dirs(wasi_ctx_builder, mapped_dirs)?; + + let wasi_ctx = wasi_ctx_builder.build(); + add_wasi_to_linker(store, linker, wasi_ctx) + } + + fn get_wasi_state<'s>( + _instance: &'s mut ::Instance, + ) -> Box { + // TODO give actual state + Box::new(WasmtimeWasiState {}) + } +} + +pub struct WasmtimeWasiState {} + +impl WasiState for WasmtimeWasiState { + fn envs(&self) -> &[Vec] { + &[] + } +} + +fn add_wasi_to_linker( + store: &mut WasmtimeContextMut<'_>, + linker: &mut WasmtimeImports, + wasi_ctx: wasmtime_wasi::WasiCtx, +) -> Result<(), WasiError> { + // wasmtime-wasi gets its context from Caller, which can hold any user info + // the only convenient method is to be provided with a closure that extracts context + // from used-defined type. + // So, here each module has its own wasi context which is stored in a vector in store. + let id = store.inner.data().wasi.len(); + wasmtime_wasi::add_to_linker(&mut linker.linker, move |s: &mut StoreState| { + &mut s.wasi[id] + }) + .map_err(|e| WasiError::EngineWasiError(anyhow!(e)))?; + + store.inner.data_mut().wasi.push(wasi_ctx); + + Ok(()) +} + +fn populate_args(builder: WasiCtxBuilder, args: Vec>) -> Result { + let args = args + .into_iter() + .map(|arg| unsafe { String::from_utf8_unchecked(arg) }) + .collect::>(); + + builder + .args(&args) + .map_err(|_| WasiError::TooLargeArgsArray) +} + +fn populate_preopens( + builder: WasiCtxBuilder, + preopened_files: HashSet, +) -> Result { + preopened_files + .iter() + .try_fold(builder, |builder, host_path| -> Result<_, WasiError> { + let guest_dir = wasmtime_wasi::Dir::open_ambient_dir(host_path, ambient_authority())?; + builder + .preopened_dir(guest_dir, host_path) + .map_err(|e| WasiError::EngineWasiError(anyhow!(e))) + }) +} + +fn populate_mapped_dirs( + builder: WasiCtxBuilder, + mapped_dirs: HashMap, +) -> Result { + mapped_dirs.iter().try_fold( + builder, + |builder, (guest_name, host_path)| -> Result<_, WasiError> { + let host_dir = wasmtime_wasi::Dir::open_ambient_dir(host_path, ambient_authority())?; + let guest_path = Path::new(&guest_name); + builder + .preopened_dir(host_dir, guest_path) + .map_err(|e| WasiError::EngineWasiError(anyhow!(e))) + }, + ) +} + +fn populate_envs( + builder: WasiCtxBuilder, + envs: HashMap, Vec>, +) -> Result { + let envs = envs + .into_iter() + .map(|(key, value)| { + unsafe { + // TODO maybe use strings in signature? + ( + String::from_utf8_unchecked(key), + String::from_utf8_unchecked(value), + ) + } + }) + .collect::>(); + + builder + .envs(&envs) + .map_err(|_| WasiError::TooLargeEnvsArray) +} diff --git a/examples/build_rs/Cargo.toml b/examples/build_rs/Cargo.toml index 0992c9a26..db80bef5a 100644 --- a/examples/build_rs/Cargo.toml +++ b/examples/build_rs/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Fluence Labs"] description = "The greeting module for the Fluence network" repository = "https://github.com/fluencelabs/marine/tree/master/examples/build_rs" -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/examples/call_parameters/Cargo.toml b/examples/call_parameters/Cargo.toml index 1b2432f76..ae91003df 100644 --- a/examples/call_parameters/Cargo.toml +++ b/examples/call_parameters/Cargo.toml @@ -2,7 +2,7 @@ name = "call_parameters" version = "0.1.0" authors = ["Fluence Labs"] -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/examples/call_parameters/src/main.rs b/examples/call_parameters/src/main.rs index e3d4dd586..4ed3ddde8 100644 --- a/examples/call_parameters/src/main.rs +++ b/examples/call_parameters/src/main.rs @@ -43,7 +43,6 @@ pub fn call_parameters() -> String { mod tests { use marine_rs_sdk_test::marine_test; use marine_rs_sdk_test::CallParameters; - use marine_rs_sdk_test::SecurityTetraplet; #[marine_test(config_path = "../Config.toml", modules_dir = "../artifacts")] fn empty_string(call_parameters: marine_test_env::call_parameters::ModuleInterface) { @@ -53,9 +52,12 @@ mod tests { let host_id = "host_id"; let particle_id = "particle_id"; - let mut tetraplet = SecurityTetraplet::default(); - tetraplet.function_name = "some_func_name".to_string(); - tetraplet.json_path = "some_json_path".to_string(); + let tetraplet = marine_rs_sdk::SecurityTetraplet { + function_name: "some_func_name".to_string(), + json_path: "some_json_path".to_string(), + ..Default::default() + }; + let tetraplets = vec![vec![tetraplet]]; let cp = CallParameters { diff --git a/examples/failing/Cargo.toml b/examples/failing/Cargo.toml index 157cd2744..a4cc657ec 100644 --- a/examples/failing/Cargo.toml +++ b/examples/failing/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Fluence Labs"] description = "The failing module for the Fluence network" repository = "https://github.com/fluencelabs/marine/tree/master/examples/failing" -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/examples/greeting/Cargo.toml b/examples/greeting/Cargo.toml index ae65ba6a2..b366037d3 100644 --- a/examples/greeting/Cargo.toml +++ b/examples/greeting/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Fluence Labs"] description = "The greeting module for the Fluence network" repository = "https://github.com/fluencelabs/marine/tree/master/examples/greeting" -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/examples/greeting/artifacts/greeting.wasm b/examples/greeting/artifacts/greeting.wasm index cc5cb57e9..1db643a6f 100755 Binary files a/examples/greeting/artifacts/greeting.wasm and b/examples/greeting/artifacts/greeting.wasm differ diff --git a/examples/greeting_record/Cargo.toml b/examples/greeting_record/Cargo.toml index b4f38965c..2e4537990 100644 --- a/examples/greeting_record/Cargo.toml +++ b/examples/greeting_record/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Fluence Labs"] description = "The greeting module with records for the Fluence network" repository = "https://github.com/fluencelabs/marine/tree/master/examples/greeting_record" -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/examples/ipfs-node/effector/Cargo.toml b/examples/ipfs-node/effector/Cargo.toml index 45c652dcc..3263aa361 100644 --- a/examples/ipfs-node/effector/Cargo.toml +++ b/examples/ipfs-node/effector/Cargo.toml @@ -2,7 +2,7 @@ name = "ipfs-effector" version = "0.1.0" authors = ["Fluence Labs"] -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/examples/ipfs-node/pure/Cargo.toml b/examples/ipfs-node/pure/Cargo.toml index eb061d090..93a58b398 100644 --- a/examples/ipfs-node/pure/Cargo.toml +++ b/examples/ipfs-node/pure/Cargo.toml @@ -2,7 +2,7 @@ name = "ipfs-pure" version = "0.1.0" authors = ["Fluence Labs"] -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/examples/motivational-example/donkey/Cargo.toml b/examples/motivational-example/donkey/Cargo.toml index 34c0f4edb..3fd4a9ea1 100644 --- a/examples/motivational-example/donkey/Cargo.toml +++ b/examples/motivational-example/donkey/Cargo.toml @@ -2,7 +2,7 @@ name = "donkey" version = "0.1.0" authors = ["Fluence Labs"] -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/examples/motivational-example/shrek/Cargo.toml b/examples/motivational-example/shrek/Cargo.toml index 55c964e64..7daafb617 100644 --- a/examples/motivational-example/shrek/Cargo.toml +++ b/examples/motivational-example/shrek/Cargo.toml @@ -2,7 +2,7 @@ name = "shrek" version = "0.1.0" authors = ["Fluence Labs"] -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/examples/multiservice_marine_test/Cargo.toml b/examples/multiservice_marine_test/Cargo.toml index 7b9e38789..52d28275c 100644 --- a/examples/multiservice_marine_test/Cargo.toml +++ b/examples/multiservice_marine_test/Cargo.toml @@ -2,7 +2,7 @@ name = "multiservice-marine-test" version = "0.1.0" authors = ["Fluence Labs"] -edition = "2018" +edition = "2021" publish = false [dependencies] diff --git a/examples/multiservice_marine_test/consumer/Cargo.toml b/examples/multiservice_marine_test/consumer/Cargo.toml index 40a08ddf5..0829cbc31 100644 --- a/examples/multiservice_marine_test/consumer/Cargo.toml +++ b/examples/multiservice_marine_test/consumer/Cargo.toml @@ -2,7 +2,7 @@ name = "consumer" version = "0.1.0" authors = ["Fluence Labs"] -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/examples/multiservice_marine_test/producer/Cargo.toml b/examples/multiservice_marine_test/producer/Cargo.toml index 6e980d505..bdc29305f 100644 --- a/examples/multiservice_marine_test/producer/Cargo.toml +++ b/examples/multiservice_marine_test/producer/Cargo.toml @@ -2,7 +2,7 @@ name = "producer" version = "0.1.0" authors = ["Fluence Labs"] -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/examples/records/effector/Cargo.toml b/examples/records/effector/Cargo.toml index 426a4e173..0349680e0 100644 --- a/examples/records/effector/Cargo.toml +++ b/examples/records/effector/Cargo.toml @@ -2,7 +2,7 @@ name = "record-effector" version = "0.1.0" authors = ["Fluence Labs"] -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/examples/records/pure/Cargo.toml b/examples/records/pure/Cargo.toml index 2aa953019..455673178 100644 --- a/examples/records/pure/Cargo.toml +++ b/examples/records/pure/Cargo.toml @@ -2,7 +2,7 @@ name = "record-pure" version = "0.1.0" authors = ["Fluence Labs"] -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/examples/records/test-record/Cargo.toml b/examples/records/test-record/Cargo.toml index 5153048e6..31107a78b 100644 --- a/examples/records/test-record/Cargo.toml +++ b/examples/records/test-record/Cargo.toml @@ -2,7 +2,7 @@ name = "test-record" version = "0.1.0" authors = ["Fluence Labs"] -edition = "2018" +edition = "2021" publish = false [lib] diff --git a/examples/sqlite/Cargo.toml b/examples/sqlite/Cargo.toml index a10aa847e..911a93801 100644 --- a/examples/sqlite/Cargo.toml +++ b/examples/sqlite/Cargo.toml @@ -2,7 +2,7 @@ name = "wasm-sqlite-test" version = "0.1.0" authors = ["Fluence Labs"] -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/examples/url-downloader/curl_adapter/Cargo.toml b/examples/url-downloader/curl_adapter/Cargo.toml index 8df273359..ad03413e0 100644 --- a/examples/url-downloader/curl_adapter/Cargo.toml +++ b/examples/url-downloader/curl_adapter/Cargo.toml @@ -2,7 +2,7 @@ name = "curl_adapter" version = "0.1.0" authors = ["Fluence Labs"] -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/examples/url-downloader/facade/Cargo.toml b/examples/url-downloader/facade/Cargo.toml index 0da8b6901..e8aa1b1c6 100644 --- a/examples/url-downloader/facade/Cargo.toml +++ b/examples/url-downloader/facade/Cargo.toml @@ -2,7 +2,7 @@ name = "facade" version = "0.1.0" authors = ["Fluence Labs"] -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/examples/url-downloader/local_storage/Cargo.toml b/examples/url-downloader/local_storage/Cargo.toml index 38c7986c8..632adb741 100644 --- a/examples/url-downloader/local_storage/Cargo.toml +++ b/examples/url-downloader/local_storage/Cargo.toml @@ -2,7 +2,7 @@ name = "local_storage" version = "0.1.0" authors = ["Fluence Labs"] -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/marine-js/Cargo.toml b/marine-js/Cargo.toml index fb65466a5..53f09c366 100644 --- a/marine-js/Cargo.toml +++ b/marine-js/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "marine-js" version = "0.3.3" -edition = "2018" +edition = "2021" description = "Web version of the marine runtime" publish = false @@ -17,13 +17,13 @@ marine-min-it-version = { path = "../crates/min-it-version", version = "0.2.1" } it-json-serde = { path = "../crates/it-json-serde", version = "0.3.5" } marine-rs-sdk = "0.7.1" -wasmer-it = { package = "wasmer-interface-types-fl", version = "0.24.1"} -fluence-it-types = {version = "0.3.2", features = ["impls"] } -it-lilo = "0.4.1" -it-memory-traits = "0.3.1" +wasmer-it = { workspace = true} +it-memory-traits = { workspace = true} +fluence-it-types = { workspace = true } +it-lilo = { workspace = true } wasm-bindgen = "0.2" -nom = "5.1" +nom = "7.1" itertools = "0.10.5" multimap = "0.8.3" boolinator = "2.4.0" diff --git a/marine-js/src/api.rs b/marine-js/src/api.rs index 3169d1a77..e5eacb0a7 100644 --- a/marine-js/src/api.rs +++ b/marine-js/src/api.rs @@ -22,7 +22,8 @@ use marine_rs_sdk::CallParameters; use wasm_bindgen::prelude::*; use serde_json::Value as JValue; -use serde::{Serialize, Deserialize}; +use serde::Serialize; +use serde::Deserialize; use maplit::hashmap; #[derive(Serialize, Deserialize)] diff --git a/marine-js/src/engine.rs b/marine-js/src/engine.rs index f2478afe3..4973a2908 100644 --- a/marine-js/src/engine.rs +++ b/marine-js/src/engine.rs @@ -25,7 +25,7 @@ use crate::IRecordType; use serde::Serialize; use std::collections::HashMap; use std::collections::hash_map::Entry; -use std::rc::Rc; +use std::sync::Arc; /// Represent Marine module interface. #[derive(PartialEq, Eq, Debug, Clone, Serialize)] @@ -65,16 +65,12 @@ impl Marine { } /// Load a new module inside Marine. - pub fn load_module>( - &mut self, - name: S, - wit_section_bytes: &[u8], - ) -> MResult<()> { - self.load_module_(name.into(), wit_section_bytes) + pub fn load_module>(&mut self, name: S, wasm_bytes: &[u8]) -> MResult<()> { + self.load_module_(name.into(), wasm_bytes) } - fn load_module_(&mut self, name: String, wit_section_bytes: &[u8]) -> MResult<()> { - let module = MModule::new(&name, wit_section_bytes)?; + fn load_module_(&mut self, name: String, wasm_bytes: &[u8]) -> MResult<()> { + let module = MModule::new(&name, wasm_bytes)?; match self.modules.entry(name) { Entry::Vacant(entry) => { @@ -120,7 +116,7 @@ impl Marine { &self, module_name: S, record_id: u64, - ) -> Option<&Rc> { + ) -> Option<&Arc> { self.modules .get(module_name.as_ref()) .and_then(|module| module.export_record_type_by_id(record_id)) diff --git a/marine-js/src/faas/faas.rs b/marine-js/src/faas/faas.rs index d28756685..95695266d 100644 --- a/marine-js/src/faas/faas.rs +++ b/marine-js/src/faas/faas.rs @@ -30,14 +30,14 @@ use marine_rs_sdk::CallParameters; use serde_json::Value as JValue; use std::cell::RefCell; use std::collections::HashMap; -use std::rc::Rc; +use std::sync::Arc; -type MFunctionSignature = (Rc>, Rc>); -type MModuleInterface = (Rc>, Rc>, Rc); +type MFunctionSignature = (Arc>, Arc>); +type MModuleInterface = (Arc>, Arc>, Arc); struct ModuleInterface { function_signatures: HashMap, - record_types: Rc, + record_types: Arc, } // TODO: remove and use mutex instead @@ -49,7 +49,7 @@ pub struct FluenceFaaS { marine: Marine, /// Parameters of call accessible by Wasm modules. - call_parameters: Rc>, + call_parameters: Arc>, /// Cached module interfaces by names. module_interfaces_cache: HashMap, @@ -60,7 +60,7 @@ impl FluenceFaaS { /// Creates FaaS with given modules. pub fn with_modules(modules: HashMap>) -> Result { let mut marine = Marine::new(); - let call_parameters = Rc::new(RefCell::new(CallParameters::default())); + let call_parameters = Arc::new(RefCell::new(CallParameters::default())); for (name, wit_section_bytes) in modules { marine.load_module(name, &wit_section_bytes)?; @@ -133,8 +133,8 @@ impl FluenceFaaS { /// At first, tries to find function signature and record types in module_interface_cache, /// if there is no them, tries to look - fn lookup_module_interface<'faas>( - &'faas mut self, + fn lookup_module_interface( + &mut self, module_name: &str, func_name: &str, ) -> Result { @@ -171,7 +171,7 @@ impl FluenceFaaS { let arg_types = arg_types.clone(); let output_types = output_types.clone(); - let record_types = Rc::new(module_interface.record_types.clone()); + let record_types = Arc::new(module_interface.record_types.clone()); let module_interface = ModuleInterface { function_signatures, diff --git a/marine-js/src/marine_js.rs b/marine-js/src/marine_js.rs index 30e0c1d91..b9634723f 100644 --- a/marine-js/src/marine_js.rs +++ b/marine-js/src/marine_js.rs @@ -14,16 +14,18 @@ * limitations under the License. */ -use crate::module::type_converters::{itypes_args_to_wtypes, itypes_output_to_wtypes}; +use crate::module::type_converters::itypes_args_to_wtypes; +use crate::module::type_converters::itypes_output_to_wtypes; use crate::global_state::INSTANCE; use marine_it_interfaces::MITInterfaces; use wasmer_it::ast::FunctionArg; use wasm_bindgen::prelude::*; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use serde_json::Value as JValue; -use std::borrow::{Cow}; +use std::borrow::Cow; use std::rc::Rc; const ALLOCATE_FUNC_NAME: &str = "allocate"; diff --git a/marine-js/src/module/marine_module.rs b/marine-js/src/module/marine_module.rs index eb25b03bd..09e568e2b 100644 --- a/marine-js/src/module/marine_module.rs +++ b/marine-js/src/module/marine_module.rs @@ -17,10 +17,14 @@ use super::wit_prelude::*; use super::MFunctionSignature; use super::MRecordTypes; -use super::{IType, IRecordType, IFunctionArg, IValue}; +use super::IType; +use super::IRecordType; +use super::IFunctionArg; +use super::IValue; use crate::MResult; -use crate::marine_js::{Instance as WasmerInstance}; +use crate::marine_js::Instance as WasmerInstance; use crate::module::wit_function::WITFunction; +use crate::module::wit_store::WITStore; use marine_it_interfaces::MITInterfaces; use marine_utils::SharedString; @@ -34,13 +38,14 @@ use std::rc::Rc; const INITIALIZE_FUNC: &str = "_initialize"; -type ITInterpreter = Interpreter; +type ITInterpreter = + Interpreter; #[derive(Clone)] pub(super) struct ITModuleFunc { interpreter: Arc, - pub(super) arguments: Rc>, - pub(super) output_types: Rc>, + pub(super) arguments: Arc>, + pub(super) output_types: Arc>, } #[derive(Clone)] @@ -55,7 +60,7 @@ impl Callable { let result = self .it_module_func .interpreter - .run(args, Arc::make_mut(&mut self.it_instance))? + .run(args, Arc::make_mut(&mut self.it_instance), &mut ())? .as_slice() .to_owned(); Ok(result) @@ -65,10 +70,10 @@ impl Callable { type ExportFunctions = HashMap>; pub(crate) struct MModule { - // wasmer_instance is needed because WITInstance contains dynamic functions + // wasm_instance is needed because WITInstance contains dynamic functions // that internally keep pointer to it. #[allow(unused)] - wasmer_instance: Box, + wasm_instance: Box, // TODO: replace with dyn Trait export_funcs: ExportFunctions, @@ -88,20 +93,21 @@ pub(crate) fn extract_it_from_bytes(wit_section_bytes: &[u8]) -> Result MResult { - let it = extract_it_from_bytes(wit_section_bytes)?; + pub(crate) fn new(name: &str, wasm_bytes: &[u8]) -> MResult { + // TODO: extract sdk version + let it = extract_it_from_bytes(wasm_bytes)?; crate::misc::check_it_version(name, &it.version)?; let mit = MITInterfaces::new(it); - let wasmer_instance = WasmerInstance::new(&mit, Rc::new(name.to_string())); - let it_instance = Arc::new(ITInstance::new(&wasmer_instance, &mit)?); + let wasm_instance = WasmerInstance::new(&mit, Rc::new(name.to_string())); + let it_instance = Arc::new(ITInstance::new(&wasm_instance, &mit)?); let (export_funcs, export_record_types) = Self::instantiate_exports(&it_instance, &mit)?; - if let Ok(initialize_func) = wasmer_instance.exports.get(INITIALIZE_FUNC) { + if let Ok(initialize_func) = wasm_instance.exports.get(INITIALIZE_FUNC) { initialize_func.call(&[])?; } Ok(Self { - wasmer_instance: Box::new(wasmer_instance), + wasm_instance: Box::new(wasm_instance), export_funcs, export_record_types, }) @@ -138,7 +144,7 @@ impl MModule { &self.export_record_types } - pub(crate) fn export_record_type_by_id(&self, record_type: u64) -> Option<&Rc> { + pub(crate) fn export_record_type_by_id(&self, record_type: u64) -> Option<&Arc> { self.export_record_types.get(&record_type) } diff --git a/marine-js/src/module/memory.rs b/marine-js/src/module/memory.rs index 4ba631d60..3be799f0a 100644 --- a/marine-js/src/module/memory.rs +++ b/marine-js/src/module/memory.rs @@ -16,10 +16,14 @@ use crate::marine_js::JsWasmMemoryProxy; -use it_memory_traits::{MemoryAccessError, MemoryView, MemoryWritable, MemoryReadable}; +use it_memory_traits::MemoryAccessError; +use it_memory_traits::MemoryView; +use it_memory_traits::MemoryWritable; +use it_memory_traits::MemoryReadable; use wasmer_it::interpreter::wasm; use std::rc::Rc; +use crate::module::wit_store::WITStore; pub(super) struct WITMemoryView { memory: JsWasmMemoryProxy, @@ -33,35 +37,40 @@ impl WITMemoryView { } } -impl MemoryWritable for WITMemoryView { - fn write_byte(&self, offset: u32, value: u8) { +impl MemoryWritable for WITMemoryView { + fn write_byte(&self, _store: &mut (), offset: u32, value: u8) { self.memory.set(offset, value); } - fn write_bytes(&self, offset: u32, bytes: &[u8]) { + fn write_bytes(&self, _store: &mut (), offset: u32, bytes: &[u8]) { self.memory.set_range(offset, bytes); } } -impl MemoryReadable for WITMemoryView { - fn read_byte(&self, offset: u32) -> u8 { +impl MemoryReadable for WITMemoryView { + fn read_byte(&self, _store: &mut (), offset: u32) -> u8 { self.memory.get(offset) } - fn read_array(&self, offset: u32) -> [u8; COUNT] { + fn read_array(&self, _store: &mut (), offset: u32) -> [u8; COUNT] { let mut result = [0u8; COUNT]; let data = self.memory.get_range(offset, COUNT as u32); result.copy_from_slice(&data[..COUNT]); result } - fn read_vec(&self, offset: u32, size: u32) -> Vec { + fn read_vec(&self, _store: &mut (), offset: u32, size: u32) -> Vec { self.memory.get_range(offset, size) } } -impl MemoryView for WITMemoryView { - fn check_bounds(&self, offset: u32, size: u32) -> Result<(), MemoryAccessError> { +impl MemoryView for WITMemoryView { + fn check_bounds( + &self, + _store: &mut (), + offset: u32, + size: u32, + ) -> Result<(), MemoryAccessError> { let memory_size = self.memory.len(); if offset + size >= memory_size { Err(MemoryAccessError::OutOfBounds { @@ -86,7 +95,7 @@ impl WITMemory { } } -impl wasm::structures::Memory for WITMemory { +impl wasm::structures::Memory for WITMemory { fn view(&self) -> WITMemoryView { WITMemoryView::new(self.module_name.clone()) } diff --git a/marine-js/src/module/mod.rs b/marine-js/src/module/mod.rs index a0fc39d8b..95e293224 100644 --- a/marine-js/src/module/mod.rs +++ b/marine-js/src/module/mod.rs @@ -19,6 +19,7 @@ mod marine_module; mod memory; mod wit_function; mod wit_instance; +mod wit_store; pub mod type_converters; pub use wit_instance::MRecordTypes; @@ -31,14 +32,14 @@ pub use wasmer_it::to_interface_value; use serde::Serialize; use serde::Deserialize; -use std::rc::Rc; +use std::sync::Arc; /// Represent a function type inside Marine module. #[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)] pub struct MFunctionSignature { - pub name: Rc, - pub arguments: Rc>, - pub outputs: Rc>, + pub name: Arc, + pub arguments: Arc>, + pub outputs: Arc>, } pub(crate) use marine_module::MModule; diff --git a/marine-js/src/module/type_converters.rs b/marine-js/src/module/type_converters.rs index 99325151c..63c015e0b 100644 --- a/marine-js/src/module/type_converters.rs +++ b/marine-js/src/module/type_converters.rs @@ -14,8 +14,10 @@ * limitations under the License. */ -/// Contains converters of types and values between Wasmer and wasmer_interface_types. -use super::{WType, WValue, IType, IValue}; +use super::WType; +use super::WValue; +use super::IType; +use super::IValue; pub(crate) fn wtype_to_itype(ty: &WType) -> IType { match ty { diff --git a/marine-js/src/module/wit_function.rs b/marine-js/src/module/wit_function.rs index f3fc2c8be..d84d57892 100644 --- a/marine-js/src/module/wit_function.rs +++ b/marine-js/src/module/wit_function.rs @@ -14,9 +14,13 @@ * limitations under the License. */ -use super::{IType, IFunctionArg, IValue, WValue}; +use super::IType; +use super::IFunctionArg; +use super::IValue; +use super::WValue; use crate::MResult; use crate::marine_js::DynFunc; +use crate::module::wit_store::WITStore; use wasmer_it::interpreter::wasm; @@ -73,7 +77,7 @@ impl WITFunction { } } -impl wasm::structures::LocalImport for WITFunction { +impl wasm::structures::LocalImport for WITFunction { fn name(&self) -> &str { self.name.as_str() } @@ -94,8 +98,9 @@ impl wasm::structures::LocalImport for WITFunction { &self.outputs } - fn call(&self, arguments: &[IValue]) -> std::result::Result, ()> { - use super::type_converters::{ival_to_wval, wval_to_ival}; + fn call(&self, _store: &mut (), arguments: &[IValue]) -> std::result::Result, ()> { + use super::type_converters::ival_to_wval; + use super::type_converters::wval_to_ival; match &self.inner { WITFunctionInner::Export { func, .. } => func diff --git a/marine-js/src/module/wit_instance.rs b/marine-js/src/module/wit_instance.rs index 548ca2bda..69432fee0 100644 --- a/marine-js/src/module/wit_instance.rs +++ b/marine-js/src/module/wit_instance.rs @@ -16,18 +16,22 @@ use super::wit_prelude::*; use super::IRecordType; -use crate::{MResult}; -use crate::marine_js::{Instance as WasmerInstance}; +use crate::MResult; +use crate::marine_js::Instance as WasmerInstance; +use crate::module::wit_store::WITStore; use marine_it_interfaces::MITInterfaces; use marine_it_interfaces::ITAstType; use wasmer_it::interpreter::wasm; -use wasmer_it::interpreter::wasm::structures::{LocalImportIndex, Memory, TypedIndex}; +use wasmer_it::interpreter::wasm::structures::LocalImportIndex; +use wasmer_it::interpreter::wasm::structures::Memory; +use wasmer_it::interpreter::wasm::structures::TypedIndex; use std::collections::HashMap; -use std::rc::Rc; -pub type MRecordTypes = HashMap>; +use std::sync::Arc; + +pub type MRecordTypes = HashMap>; /// Contains all import and export functions that could be called from IT context by call-core. #[derive(Clone)] @@ -43,9 +47,9 @@ pub(super) struct ITInstance { } impl ITInstance { - pub(super) fn new(wasmer_instance: &WasmerInstance, wit: &MITInterfaces<'_>) -> MResult { - let exports = Self::extract_raw_exports(wasmer_instance, wit)?; - let memories = Self::extract_memories(wasmer_instance); + pub(super) fn new(wasm_instance: &WasmerInstance, wit: &MITInterfaces<'_>) -> MResult { + let exports = Self::extract_raw_exports(wasm_instance, wit)?; + let memories = Self::extract_memories(wasm_instance); let funcs = exports; @@ -59,10 +63,10 @@ impl ITInstance { } fn extract_raw_exports( - wasmer_instance: &WasmerInstance, + wasm_instance: &WasmerInstance, it: &MITInterfaces<'_>, ) -> MResult> { - let module_exports = &wasmer_instance.exports; + let module_exports = &wasm_instance.exports; it.exports() .enumerate() @@ -77,13 +81,13 @@ impl ITInstance { .collect() } - fn extract_memories(wasmer_instance: &WasmerInstance) -> Vec { + fn extract_memories(wasm_instance: &WasmerInstance) -> Vec { use crate::marine_js::Export::Memory; - let memories = wasmer_instance + let memories = wasm_instance .exports() .filter_map(|(_, export)| match export { - Memory => Some(WITMemory::new(wasmer_instance.module_name.clone())), + Memory => Some(WITMemory::new(wasm_instance.module_name.clone())), _ => None, }) .collect::>(); @@ -109,7 +113,9 @@ impl ITInstance { } } -impl wasm::structures::Instance for ITInstance { +impl wasm::structures::Instance + for ITInstance +{ fn export(&self, _export_name: &str) -> Option<&ITExport> { // exports aren't used in this version of IT None @@ -137,7 +143,7 @@ impl wasm::structures::Instance Some(memory.view()) } - fn wit_record_by_id(&self, index: u64) -> Option<&Rc> { + fn wit_record_by_id(&self, index: u64) -> Option<&Arc> { self.record_types_by_id.get(&index) } } diff --git a/marine-js/src/module/wit_store.rs b/marine-js/src/module/wit_store.rs new file mode 100644 index 000000000..07c15ee0b --- /dev/null +++ b/marine-js/src/module/wit_store.rs @@ -0,0 +1,21 @@ +/* + * Copyright 2023 Fluence Labs Limited + * + * 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(crate) struct WITStore {} + +impl it_memory_traits::Store for WITStore { + type ActualStore<'c> = (); +} diff --git a/marine/Cargo.toml b/marine/Cargo.toml index bd981532c..8b42bef78 100644 --- a/marine/Cargo.toml +++ b/marine/Cargo.toml @@ -4,7 +4,7 @@ description = "The Fluence Wasm Runtime" version = "0.25.0" authors = ["Fluence Labs"] license = "Apache-2.0" -edition = "2018" +edition = "2021" [lib] name = "marine" @@ -17,12 +17,11 @@ marine-utils = { path = "../crates/utils", version = "0.4.0" } marine-rs-sdk-main = { version = "0.7.1", features = ["logger"] } marine-rs-sdk = { version = "0.7.1", features = ["logger"] } it-json-serde = { path = "../crates/it-json-serde", version = "0.3.5" } +marine-wasm-backend-traits = { path = "../crates/wasm-backend-traits", version = "0.1.0"} +marine-wasmtime-backend = { path = "../crates/wasmtime-backend", version = "0.1.0"} -wasmer-runtime = { package = "wasmer-runtime-fl", version = "=0.17.1" } -# dynamicfunc-fat-closures allows using state inside DynamicFunc -wasmer-core = { package = "wasmer-runtime-core-fl", version = "=0.17.1", features = ["dynamicfunc-fat-closures"] } -wasmer-wasi = { package = "wasmer-wasi-fl", version = "0.17.1" } -wasmer-it = { package = "wasmer-interface-types-fl", version = "0.24.1"} +wasmer-it = { workspace = true } +it-memory-traits = { workspace = true } toml = "0.5.9" serde = { version = "1.0.147", features = ["derive"] } @@ -34,6 +33,7 @@ itertools = "0.10.5" log = "0.4.17" safe-transmute = "0.11.2" thiserror = "1.0.37" +parking_lot = "0.12.1" [dev-dependencies] once_cell = "1.16.0" diff --git a/marine/src/config/marine_config.rs b/marine/src/config/marine_config.rs index 500761c55..add8cd6e9 100644 --- a/marine/src/config/marine_config.rs +++ b/marine/src/config/marine_config.rs @@ -14,7 +14,8 @@ * limitations under the License. */ -use marine_core::HostImportDescriptor; +use marine_wasm_backend_traits::WasmBackend; +use marine_core::generic::HostImportDescriptor; use std::collections::HashMap; use std::collections::HashSet; @@ -43,14 +44,14 @@ impl ConfigContext { /// Info to load a module from filesystem into runtime. #[derive(Default)] -pub struct ModuleDescriptor { +pub struct ModuleDescriptor { pub load_from: Option, pub file_name: String, pub import_name: String, - pub config: MarineModuleConfig, + pub config: MarineModuleConfig, } -impl ModuleDescriptor { +impl ModuleDescriptor { pub fn get_path(&self, modules_dir: &Option) -> Result { match &self.load_from { None => match modules_dir { @@ -73,20 +74,20 @@ impl ModuleDescriptor { /// Describes the behaviour of the Marine component. #[derive(Default)] -pub struct MarineConfig { +pub struct MarineConfig { /// Path to a dir where compiled Wasm modules are located. pub modules_dir: Option, /// Settings for a module with particular name (not HashMap because the order is matter). - pub modules_config: Vec, + pub modules_config: Vec>, /// Settings for a module that name's not been found in modules_config. - pub default_modules_config: Option, + pub default_modules_config: Option>, } /// Various settings that could be used to guide Marine how to load a module in a proper way. #[derive(Default)] -pub struct MarineModuleConfig { +pub struct MarineModuleConfig { /// Maximum memory size accessible by a module in Wasm pages (64 Kb). pub mem_pages_count: Option, @@ -97,7 +98,7 @@ pub struct MarineModuleConfig { pub logger_enabled: bool, /// Export from host functions that will be accessible on the Wasm side by provided name. - pub host_imports: HashMap, + pub host_imports: HashMap>, /// A WASI config. pub wasi: Option, @@ -106,7 +107,7 @@ pub struct MarineModuleConfig { pub logging_mask: i32, } -impl MarineModuleConfig { +impl MarineModuleConfig { pub fn extend_wasi_envs(&mut self, new_envs: HashMap, Vec>) { match &mut self.wasi { Some(MarineWASIConfig { envs, .. }) => envs.extend(new_envs), @@ -152,14 +153,14 @@ impl MarineModuleConfig { mapped_dirs, .. }) => { - mapped_dirs - .values_mut() - .map(|path| *path = root.join(&path)) - .for_each(drop); + mapped_dirs.values_mut().for_each(|path| { + *path = root.join(&path); + }); - let mapped_preopens = preopened_files - .iter() - .map(|path| (path.to_string_lossy().into(), root.join(path))); + let mapped_preopens = preopened_files.iter().map(|path| { + let new_path = root.join(path); + (path.to_string_lossy().into(), new_path) + }); mapped_dirs.extend(mapped_preopens); @@ -193,9 +194,10 @@ use crate::config::as_relative_to_base; use itertools::Itertools; -use std::convert::{TryFrom, TryInto}; +use std::convert::TryFrom; +use std::convert::TryInto; -impl TryFrom for MarineConfig { +impl TryFrom for MarineConfig { type Error = MarineError; fn try_from(toml_config: TomlMarineConfig) -> Result { @@ -228,7 +230,9 @@ impl TryFrom for MarineConfig { } } -impl<'c> TryFrom> for ModuleDescriptor { +impl<'c, WB: WasmBackend> TryFrom> + for ModuleDescriptor +{ type Error = MarineError; fn try_from(config: WithContext<'c, TomlMarineNamedModuleConfig>) -> Result { @@ -252,7 +256,9 @@ impl<'c> TryFrom> for ModuleDescrip } } -impl<'c> TryFrom> for MarineModuleConfig { +impl<'c, WB: WasmBackend> TryFrom> + for MarineModuleConfig +{ type Error = MarineError; fn try_from(toml_config: WithContext<'c, TomlMarineModuleConfig>) -> Result { diff --git a/marine/src/config/raw_marine_config.rs b/marine/src/config/raw_marine_config.rs index 7c42b9478..5a4d20a4f 100644 --- a/marine/src/config/raw_marine_config.rs +++ b/marine/src/config/raw_marine_config.rs @@ -140,7 +140,9 @@ pub struct TomlWASIConfig { mod tests { use std::path::PathBuf; use bytesize::ByteSize; - use super::{TomlMarineNamedModuleConfig, TomlMarineModuleConfig, TomlWASIConfig}; + use super::TomlMarineNamedModuleConfig; + use super::TomlMarineModuleConfig; + use super::TomlWASIConfig; #[test] fn serialize_marine_named_module_config() { diff --git a/marine/src/config/to_marine_config.rs b/marine/src/config/to_marine_config.rs index 7717599a1..6e2ee2a47 100644 --- a/marine/src/config/to_marine_config.rs +++ b/marine/src/config/to_marine_config.rs @@ -23,26 +23,27 @@ use crate::host_imports::logger::LoggerFilter; use crate::host_imports::logger::WASM_LOG_ENV_NAME; use crate::host_imports::create_call_parameters_import; -use marine_core::HostImportDescriptor; -use marine_core::MModuleConfig; -use marine_rs_sdk::CallParameters; +use marine_core::generic::HostImportDescriptor; +use marine_core::generic::MModuleConfig; +use marine_wasm_backend_traits::Function; +use marine_wasm_backend_traits::WasmBackend; use marine_utils::bytes_to_wasm_pages_ceil; -use wasmer_core::import::ImportObject; -use wasmer_core::import::Namespace; -use wasmer_runtime::func; + +use marine_rs_sdk::CallParameters; + +use parking_lot::Mutex; use std::collections::HashMap; use std::collections::hash_map::Entry; -use std::cell::RefCell; -use std::rc::Rc; +use std::sync::Arc; const WASM_MAX_HEAP_SIZE: u64 = 4 * 1024 * 1024 * 1024 - 1; // 4 GiB - 1 -struct MModuleConfigBuilder { - config: MModuleConfig, +struct MModuleConfigBuilder { + config: MModuleConfig, } -impl MModuleConfigBuilder { +impl MModuleConfigBuilder { pub(self) fn new() -> Self { Self { config: <_>::default(), @@ -52,10 +53,10 @@ impl MModuleConfigBuilder { pub(self) fn build( self, module_name: String, - marine_module_config: Option, - call_parameters: Rc>, + marine_module_config: Option>, + call_parameters: Arc>, logger_filter: &LoggerFilter<'_>, - ) -> MarineResult { + ) -> MarineResult> { let marine_module_config = match marine_module_config { Some(config) => config, None => return Ok(self.into_config()), @@ -75,7 +76,6 @@ impl MModuleConfigBuilder { .populate_logger(logger_enabled, logging_mask, logger_filter, module_name) .populate_host_imports(host_imports, call_parameters) .populate_wasi(wasi)? - .add_version() .into_config(); Ok(config) @@ -87,18 +87,17 @@ impl MModuleConfigBuilder { None => return Ok(self), }; - self.config.wasi_envs = wasi.envs; + self.config.wasi_parameters.envs = wasi.envs; - self.config.wasi_mapped_dirs = wasi.mapped_dirs; + self.config.wasi_parameters.mapped_dirs = wasi.mapped_dirs; - // Preopened files and mapped dirs are treated in the same way by the wasmer-wasi. + // Preopened files and mapped dirs are treated in the same way by the wasm backends. // The only difference is that for preopened files the alias and the value are the same, - // while for mapped dirs user defines the alias. So it may happen that some preooened file - // and mapped directory will have the same alias, which will cause wasmer to panic. - // So here preopened files are moved directly to the mapped dirs to catch errors beforehand. + // while for mapped dirs user defines the alias. To avoid having same alias pointing to different files, + // preopened files are moved directly to the mapped dirs. for path in wasi.preopened_files { let alias = path.to_string_lossy(); - match self.config.wasi_mapped_dirs.entry(alias.to_string()) { + match self.config.wasi_parameters.mapped_dirs.entry(alias.to_string()) { Entry::Occupied(entry) => { return Err(MarineError::InvalidConfig(format!( "WASI preopened files conflict with WASI mapped dirs: preopen {} is also mapped to: {}. Remove one of the entries to fix this error.", entry.key(), entry.get().display()) @@ -114,7 +113,8 @@ impl MModuleConfigBuilder { // create environment variables for all mapped directories let mapped_dirs = self .config - .wasi_mapped_dirs + .wasi_parameters + .mapped_dirs .iter() .map(|(from, to)| { ( @@ -124,15 +124,15 @@ impl MModuleConfigBuilder { }) .collect::>(); - self.config.wasi_envs.extend(mapped_dirs); + self.config.wasi_parameters.envs.extend(mapped_dirs); Ok(self) } fn populate_host_imports( mut self, - host_imports: HashMap, - call_parameters: Rc>, + host_imports: HashMap>, + call_parameters: Arc>, // TODO show mike ) -> Self { self.config.host_imports = host_imports; self.config.host_imports.insert( @@ -187,43 +187,40 @@ impl MModuleConfigBuilder { }; // overwrite possibly installed log variable in config - self.config.wasi_envs.insert( + self.config.wasi_parameters.envs.insert( WASM_LOG_ENV_NAME.as_bytes().to_owned(), log_level_str.into_bytes(), ); } - let logging_mask = logging_mask; - let mut namespace = Namespace::new(); - namespace.insert( - "log_utf8_string", - func!(log_utf8_string_closure(logging_mask, module_name)), - ); + let creator = move |mut store: ::ContextMut<'_>| { + let logging_mask = logging_mask; - let mut raw_host_imports = ImportObject::new(); - raw_host_imports.register("host", namespace); - self.config.raw_imports = raw_host_imports; + ::Function::new_typed( + &mut store, + log_utf8_string_closure::(logging_mask, module_name), + ) + }; - self - } + self.config + .raw_imports + .insert("log_utf8_string".to_string(), Box::new(creator)); - fn add_version(mut self) -> Self { - self.config.wasi_version = wasmer_wasi::WasiVersion::Latest; self } - fn into_config(self) -> MModuleConfig { + fn into_config(self) -> MModuleConfig { self.config } } /// Make Marine config from provided Marine config. -pub(crate) fn make_marine_config( +pub(crate) fn make_marine_config( module_name: String, - marine_module_config: Option, - call_parameters: Rc>, + marine_module_config: Option>, + call_parameters: Arc>, logger_filter: &LoggerFilter<'_>, -) -> MarineResult { +) -> MarineResult> { MModuleConfigBuilder::new().build( module_name, marine_module_config, diff --git a/marine/src/host_imports/call_parameters.rs b/marine/src/host_imports/call_parameters.rs index 519891710..7a6f90597 100644 --- a/marine/src/host_imports/call_parameters.rs +++ b/marine/src/host_imports/call_parameters.rs @@ -14,21 +14,30 @@ * limitations under the License. */ -use marine_core::HostImportDescriptor; -use wasmer_core::vm::Ctx; +use marine_wasm_backend_traits::WasmBackend; +use marine_core::generic::HostImportDescriptor; + use wasmer_it::IValue; use wasmer_it::IType; -use std::rc::Rc; -use std::cell::RefCell; +use parking_lot::Mutex; + use std::ops::Deref; +use std::sync::Arc; /// Create the import intended for handling get_call_parameters SDK api. -pub(crate) fn create_call_parameters_import( - call_parameters: Rc>, -) -> HostImportDescriptor { - let call_parameters_closure = move |_ctx: &mut Ctx, _args: Vec| { - let result = crate::to_interface_value(call_parameters.borrow().deref()).unwrap(); + +pub(crate) fn create_call_parameters_import( + call_parameters: Arc>, // TODO try to avoid using mutex +) -> HostImportDescriptor { + let call_parameters_closure = move |_ctx: &mut ::Caller<'_>, + _args: Vec| { + let result = { + // a separate code block to unlock the mutex ASAP and to avoid double locking + crate::to_interface_value(call_parameters.lock().deref()) + .unwrap_or_else(|_| panic!("CallParameters should be convertible to IValue")) + }; + Some(result) }; diff --git a/marine/src/host_imports/logger/log_utf8_string_impl.rs b/marine/src/host_imports/logger/log_utf8_string_impl.rs index d0b81697e..bf9230f07 100644 --- a/marine/src/host_imports/logger/log_utf8_string_impl.rs +++ b/marine/src/host_imports/logger/log_utf8_string_impl.rs @@ -14,29 +14,33 @@ * limitations under the License. */ -use wasmer_core::vm::Ctx; -use wasmer_core::memory::ptr::{Array, WasmPtr}; +use marine_wasm_backend_traits::AsContextMut; +use marine_wasm_backend_traits::Caller; +use marine_wasm_backend_traits::WasmBackend; -pub(crate) fn log_utf8_string_closure( +use it_memory_traits::Memory; +use it_memory_traits::MemoryReadable; + +pub(crate) fn log_utf8_string_closure( logging_mask: i32, module: String, -) -> impl Fn(&mut Ctx, i32, i32, i32, i32) { +) -> impl Fn(::Caller<'_>, i32, i32, i32, i32) { move |ctx, level, target, msg_offset, msg_size| { if target == 0 || target & logging_mask != 0 { - log_utf8_string(&module, ctx, level, msg_offset, msg_size) + log_utf8_string::(&module, ctx, level, msg_offset, msg_size) } } } -pub(crate) fn log_utf8_string( +pub(crate) fn log_utf8_string( module: &str, - ctx: &mut Ctx, + mut ctx: ::Caller<'_>, level: i32, msg_offset: i32, msg_size: i32, ) { let level = level_from_i32(level); - let msg = read_string(ctx, msg_offset, msg_size); + let msg = read_string::(&mut ctx, msg_offset, msg_size); match msg { Some(msg) => log::logger().log( @@ -52,9 +56,14 @@ pub(crate) fn log_utf8_string( } #[inline] -fn read_string(ctx: &Ctx, offset: i32, size: i32) -> Option<&str> { - let wasm_ptr = WasmPtr::::new(offset as u32); - wasm_ptr.get_utf8_string(ctx.memory(0), size as u32) +fn read_string( + ctx: &mut ::Caller<'_>, + offset: i32, + size: i32, +) -> Option { + let view = ctx.memory(0).unwrap().view(); // TODO handle error + let bytes = view.read_vec(&mut ctx.as_context_mut(), offset as u32, size as u32); + String::from_utf8(bytes).ok() } #[inline] diff --git a/marine/src/host_imports/mounted_binaries.rs b/marine/src/host_imports/mounted_binaries.rs index 777125e79..ce88606c5 100644 --- a/marine/src/host_imports/mounted_binaries.rs +++ b/marine/src/host_imports/mounted_binaries.rs @@ -14,16 +14,22 @@ * limitations under the License. */ -use std::path::{Path, PathBuf}; -use marine_core::HostImportDescriptor; +use marine_wasm_backend_traits::WasmBackend; + +use marine_core::generic::HostImportDescriptor; use marine_rs_sdk::MountedBinaryResult; -use wasmer_core::vm::Ctx; use wasmer_it::IValue; use wasmer_it::IType; -pub(crate) fn create_mounted_binary_import(mounted_binary_path: PathBuf) -> HostImportDescriptor { - let host_cmd_closure = move |_ctx: &mut Ctx, raw_args: Vec| { +use std::path::Path; +use std::path::PathBuf; + +pub(crate) fn create_mounted_binary_import( + mounted_binary_path: PathBuf, +) -> HostImportDescriptor { + let host_cmd_closure = move |_ctx: &mut ::Caller<'_>, + raw_args: Vec| { let result = mounted_binary_import_impl(&mounted_binary_path, raw_args).unwrap_or_else(Into::into); @@ -117,7 +123,7 @@ mod tests { #[test] fn call_non_existent_binary() { let path = std::path::Path::new("____non_existent_path____"); - let actual = mounted_binary_import_impl(&path, vec![]).unwrap_err(); + let actual = mounted_binary_import_impl(path, vec![]).unwrap_err(); assert_eq!(actual.ret_code, 100002); } diff --git a/marine/src/lib.rs b/marine/src/lib.rs index ef17d559e..b71138c1c 100644 --- a/marine/src/lib.rs +++ b/marine/src/lib.rs @@ -33,15 +33,11 @@ mod module_loading; pub(crate) type MarineResult = std::result::Result; -pub use crate::marine::Marine; pub use marine_interface::MarineInterface; pub use config::ConfigContext; pub use config::WithContext; -pub use config::MarineConfig; -pub use config::MarineModuleConfig; pub use config::MarineWASIConfig; -pub use config::ModuleDescriptor; pub use config::TomlMarineConfig; pub use config::TomlMarineModuleConfig; @@ -60,8 +56,6 @@ pub use marine_core::MFunctionSignature as MarineFunctionSignature; pub use marine_core::MemoryStats; pub use marine_core::ModuleMemoryStat; pub use marine_core::MRecordTypes; -pub use marine_core::HostExportedFunc; -pub use marine_core::HostImportDescriptor; pub use marine_core::HostImportError; pub use marine_core::to_interface_value; pub use marine_core::from_interface_values; @@ -72,4 +66,25 @@ pub use marine_module_interface::interface::itype_text_view; pub use marine_rs_sdk::CallParameters; pub use marine_rs_sdk::SecurityTetraplet; -pub use wasmer_core::vm::Ctx; +pub mod generic { + pub use crate::marine::Marine; + pub use crate::config::MarineModuleConfig; + pub use crate::config::ModuleDescriptor; + pub use crate::config::MarineConfig; + + pub use marine_core::generic::*; +} + +pub mod wasmtime { + pub type WasmBackend = marine_core::wasmtime::WasmBackend; + + pub type Marine = crate::marine::Marine; + pub type MarineModuleConfig = crate::config::MarineModuleConfig; + pub type ModuleDescriptor = crate::config::ModuleDescriptor; + pub type MarineConfig = crate::config::MarineConfig; + + pub use marine_core::wasmtime::HostExportedFunc; + pub use marine_core::wasmtime::HostImportDescriptor; +} + +pub use wasmtime::*; diff --git a/marine/src/marine.rs b/marine/src/marine.rs index 95830fa19..25c74e14b 100644 --- a/marine/src/marine.rs +++ b/marine/src/marine.rs @@ -26,47 +26,48 @@ use crate::host_imports::logger::LoggerFilter; use crate::host_imports::logger::WASM_LOG_ENV_NAME; use crate::json_to_marine_err; -use marine_core::MarineCore; +use marine_wasm_backend_traits::WasmBackend; +#[cfg(feature = "raw-module-api")] +use marine_wasm_backend_traits::WasiState; + +use marine_core::generic::MarineCore; use marine_core::IFunctionArg; use marine_core::MRecordTypes; use marine_utils::SharedString; use marine_rs_sdk::CallParameters; +use parking_lot::Mutex; use serde_json::Value as JValue; -use std::cell::RefCell; + use std::convert::TryInto; use std::collections::HashMap; use std::path::PathBuf; -use std::rc::Rc; +use std::sync::Arc; -type MFunctionSignature = (Rc>, Rc>); -type MModuleInterface = (Rc>, Rc>, Rc); +type MFunctionSignature = (Arc>, Arc>); +type MModuleInterface = (Arc>, Arc>, Arc); struct ModuleInterface { function_signatures: HashMap, - record_types: Rc, + record_types: Arc, } -// TODO: remove and use mutex instead -#[allow(clippy::non_send_fields_in_send_ty)] -unsafe impl Send for Marine {} - -pub struct Marine { +pub struct Marine { /// Marine instance. - core: MarineCore, + core: MarineCore, /// Parameters of call accessible by Wasm modules. - call_parameters: Rc>, + call_parameters: Arc>, /// Cached module interfaces by names. module_interfaces_cache: HashMap, } -impl Marine { +impl Marine { /// Creates Marine from config deserialized from TOML. pub fn with_raw_config(config: C) -> MarineResult where - C: TryInto, + C: TryInto>, MarineError: From, { let config = config.try_into()?; @@ -78,18 +79,18 @@ impl Marine { }) .collect::>>()?; - Self::with_module_names::(&modules, config) + Self::with_module_names::>(&modules, config) } /// Creates Marine with given modules. pub fn with_modules(mut modules: HashMap>, config: C) -> MarineResult where - C: TryInto, + C: TryInto>, MarineError: From, { - let mut marine = MarineCore::new(); + let mut marine = MarineCore::new()?; let config = config.try_into()?; - let call_parameters = Rc::new(RefCell::new(<_>::default())); + let call_parameters = Arc::>::default(); let modules_dir = config.modules_dir; @@ -125,13 +126,13 @@ impl Marine { /// Searches for modules in `config.modules_dir`, loads only those in the `names` set pub fn with_module_names(names: &HashMap, config: C) -> MarineResult where - C: TryInto, + C: TryInto>, MarineError: From, { let config = config.try_into()?; let modules = load_modules_from_fs(names)?; - Self::with_modules::(modules, config) + Self::with_modules::>(modules, config) } /// Call a specified function of loaded on a startup module by its name. @@ -142,7 +143,11 @@ impl Marine { args: &[IValue], call_parameters: marine_rs_sdk::CallParameters, ) -> MarineResult> { - self.call_parameters.replace(call_parameters); + { + // a separate code block to unlock the mutex ASAP and to avoid double locking + let mut cp = self.call_parameters.lock(); + *cp = call_parameters; + } self.core .call(module_name, func_name, args) @@ -175,7 +180,12 @@ impl Marine { func_name.to_string() )?; - self.call_parameters.replace(call_parameters); + { + // a separate code block to unlock the mutex ASAP and to avoid double locking + let mut cp = self.call_parameters.lock(); + *cp = call_parameters; + } + let result = self.core.call(module_name, func_name, &iargs)?; json_to_marine_err!( @@ -199,8 +209,8 @@ impl Marine { /// At first, tries to find function signature and record types in module_interface_cache, /// if there is no them, tries to look - fn lookup_module_interface<'marine>( - &'marine mut self, + fn lookup_module_interface( + &mut self, module_name: &str, func_name: &str, ) -> MarineResult { @@ -237,7 +247,7 @@ impl Marine { let arg_types = arg_types.clone(); let output_types = output_types.clone(); - let record_types = Rc::new(module_interface.record_types.clone()); + let record_types = Arc::new(module_interface.record_types.clone()); let module_interface = ModuleInterface { function_signatures, @@ -253,7 +263,7 @@ impl Marine { // This API is intended for testing purposes (mostly in Marine REPL) #[cfg(feature = "raw-module-api")] -impl Marine { +impl Marine { pub fn load_module( &mut self, name: S, @@ -262,7 +272,7 @@ impl Marine { ) -> MarineResult<()> where S: Into, - C: TryInto, + C: TryInto>, MarineError: From, { let config = config.map(|c| c.try_into()).transpose()?; @@ -290,7 +300,7 @@ impl Marine { pub fn module_wasi_state( &mut self, module_name: impl AsRef, - ) -> MarineResult<&wasmer_wasi::state::WasiState> { + ) -> MarineResult> { let module_name = module_name.as_ref(); self.core diff --git a/marine/tests/arguments_passing.rs b/marine/tests/arguments_passing.rs index 715db15b4..e56041ece 100644 --- a/marine/tests/arguments_passing.rs +++ b/marine/tests/arguments_passing.rs @@ -23,7 +23,7 @@ use pretty_assertions::assert_eq; use once_cell::sync::Lazy; use serde_json::json; -use std::rc::Rc; +use std::sync::Arc; static ARG_CONFIG: Lazy = Lazy::new(|| { marine::TomlMarineConfig::load("./tests/wasm_tests/arguments_passing/Config.toml") @@ -48,15 +48,15 @@ pub fn get_interfaces() { let string_type_outputs = vec![IType::String]; let string_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("string_type")), - arguments: Rc::new(string_type_arguments.clone()), - outputs: Rc::new(string_type_outputs.clone()), + name: Arc::new(String::from("string_type")), + arguments: Arc::new(string_type_arguments.clone()), + outputs: Arc::new(string_type_outputs.clone()), }; let string_ref_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("string_ref_type")), - arguments: Rc::new(string_type_arguments), - outputs: Rc::new(string_type_outputs), + name: Arc::new(String::from("string_ref_type")), + arguments: Arc::new(string_type_arguments), + outputs: Arc::new(string_type_outputs), }; let str_type_arguments = vec![marine::IFunctionArg { @@ -66,9 +66,9 @@ pub fn get_interfaces() { let str_type_outputs = vec![IType::String]; let str_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("str_type")), - arguments: Rc::new(str_type_arguments), - outputs: Rc::new(str_type_outputs), + name: Arc::new(String::from("str_type")), + arguments: Arc::new(str_type_arguments), + outputs: Arc::new(str_type_outputs), }; let bytearray_type_arguments = vec![marine::IFunctionArg { @@ -78,15 +78,15 @@ pub fn get_interfaces() { let bytearray_type_outputs = vec![IType::ByteArray]; let bytearray_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("bytearray_type")), - arguments: Rc::new(bytearray_type_arguments.clone()), - outputs: Rc::new(bytearray_type_outputs.clone()), + name: Arc::new(String::from("bytearray_type")), + arguments: Arc::new(bytearray_type_arguments.clone()), + outputs: Arc::new(bytearray_type_outputs.clone()), }; let bytearray_ref_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("bytearray_ref_type")), - arguments: Rc::new(bytearray_type_arguments), - outputs: Rc::new(bytearray_type_outputs), + name: Arc::new(String::from("bytearray_ref_type")), + arguments: Arc::new(bytearray_type_arguments), + outputs: Arc::new(bytearray_type_outputs), }; let i32_type_arguments = vec![marine::IFunctionArg { @@ -96,15 +96,15 @@ pub fn get_interfaces() { let i32_type_outputs = vec![IType::S32]; let i32_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("i32_type")), - arguments: Rc::new(i32_type_arguments.clone()), - outputs: Rc::new(i32_type_outputs.clone()), + name: Arc::new(String::from("i32_type")), + arguments: Arc::new(i32_type_arguments.clone()), + outputs: Arc::new(i32_type_outputs.clone()), }; let i32_ref_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("i32_ref_type")), - arguments: Rc::new(i32_type_arguments), - outputs: Rc::new(i32_type_outputs), + name: Arc::new(String::from("i32_ref_type")), + arguments: Arc::new(i32_type_arguments), + outputs: Arc::new(i32_type_outputs), }; let i64_type_arguments = vec![marine::IFunctionArg { @@ -115,15 +115,15 @@ pub fn get_interfaces() { let i64_type_outputs = vec![IType::S64]; let i64_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("i64_type")), - arguments: Rc::new(i64_type_arguments.clone()), - outputs: Rc::new(i64_type_outputs.clone()), + name: Arc::new(String::from("i64_type")), + arguments: Arc::new(i64_type_arguments.clone()), + outputs: Arc::new(i64_type_outputs.clone()), }; let i64_ref_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("i64_ref_type")), - arguments: Rc::new(i64_type_arguments), - outputs: Rc::new(i64_type_outputs), + name: Arc::new(String::from("i64_ref_type")), + arguments: Arc::new(i64_type_arguments), + outputs: Arc::new(i64_type_outputs), }; let u32_type_arguments = vec![marine::IFunctionArg { @@ -133,15 +133,15 @@ pub fn get_interfaces() { let u32_type_outputs = vec![IType::U32]; let u32_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("u32_type")), - arguments: Rc::new(u32_type_arguments.clone()), - outputs: Rc::new(u32_type_outputs.clone()), + name: Arc::new(String::from("u32_type")), + arguments: Arc::new(u32_type_arguments.clone()), + outputs: Arc::new(u32_type_outputs.clone()), }; let u32_ref_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("u32_ref_type")), - arguments: Rc::new(u32_type_arguments), - outputs: Rc::new(u32_type_outputs), + name: Arc::new(String::from("u32_ref_type")), + arguments: Arc::new(u32_type_arguments), + outputs: Arc::new(u32_type_outputs), }; let u64_type_arguments = vec![marine::IFunctionArg { @@ -151,15 +151,15 @@ pub fn get_interfaces() { let u64_type_outputs = vec![IType::U64]; let u64_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("u64_type")), - arguments: Rc::new(u64_type_arguments.clone()), - outputs: Rc::new(u64_type_outputs.clone()), + name: Arc::new(String::from("u64_type")), + arguments: Arc::new(u64_type_arguments.clone()), + outputs: Arc::new(u64_type_outputs.clone()), }; let u64_ref_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("u64_ref_type")), - arguments: Rc::new(u64_type_arguments), - outputs: Rc::new(u64_type_outputs), + name: Arc::new(String::from("u64_ref_type")), + arguments: Arc::new(u64_type_arguments), + outputs: Arc::new(u64_type_outputs), }; let f32_type_arguments = vec![marine::IFunctionArg { @@ -169,15 +169,15 @@ pub fn get_interfaces() { let f32_type_outputs = vec![IType::F32]; let f32_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("f32_type")), - arguments: Rc::new(f32_type_arguments.clone()), - outputs: Rc::new(f32_type_outputs.clone()), + name: Arc::new(String::from("f32_type")), + arguments: Arc::new(f32_type_arguments.clone()), + outputs: Arc::new(f32_type_outputs.clone()), }; let f32_ref_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("f32_ref_type")), - arguments: Rc::new(f32_type_arguments), - outputs: Rc::new(f32_type_outputs), + name: Arc::new(String::from("f32_ref_type")), + arguments: Arc::new(f32_type_arguments), + outputs: Arc::new(f32_type_outputs), }; let f64_type_arguments = vec![marine::IFunctionArg { @@ -187,24 +187,24 @@ pub fn get_interfaces() { let f64_type_outputs = vec![IType::F64]; let f64_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("f64_type")), - arguments: Rc::new(f64_type_arguments.clone()), - outputs: Rc::new(f64_type_outputs.clone()), + name: Arc::new(String::from("f64_type")), + arguments: Arc::new(f64_type_arguments.clone()), + outputs: Arc::new(f64_type_outputs.clone()), }; let f64_ref_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("f64_ref_type")), - arguments: Rc::new(f64_type_arguments), - outputs: Rc::new(f64_type_outputs), + name: Arc::new(String::from("f64_ref_type")), + arguments: Arc::new(f64_type_arguments), + outputs: Arc::new(f64_type_outputs), }; let empty_type_arguments = vec![]; let empty_type_outputs = vec![IType::String]; let empty_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("empty_type")), - arguments: Rc::new(empty_type_arguments), - outputs: Rc::new(empty_type_outputs), + name: Arc::new(String::from("empty_type")), + arguments: Arc::new(empty_type_arguments), + outputs: Arc::new(empty_type_outputs), }; let bool_type_arguments = vec![marine::IFunctionArg { @@ -214,15 +214,15 @@ pub fn get_interfaces() { let bool_type_outputs = vec![IType::Boolean]; let bool_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("bool_type")), - arguments: Rc::new(bool_type_arguments.clone()), - outputs: Rc::new(bool_type_outputs.clone()), + name: Arc::new(String::from("bool_type")), + arguments: Arc::new(bool_type_arguments.clone()), + outputs: Arc::new(bool_type_outputs.clone()), }; let bool_ref_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("bool_ref_type")), - arguments: Rc::new(bool_type_arguments), - outputs: Rc::new(bool_type_outputs), + name: Arc::new(String::from("bool_ref_type")), + arguments: Arc::new(bool_type_arguments), + outputs: Arc::new(bool_type_outputs), }; let all_types_arguments = vec![ @@ -278,15 +278,15 @@ pub fn get_interfaces() { let all_types_outputs = vec![IType::ByteArray]; let all_types_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("all_types")), - arguments: Rc::new(all_types_arguments.clone()), - outputs: Rc::new(all_types_outputs.clone()), + name: Arc::new(String::from("all_types")), + arguments: Arc::new(all_types_arguments.clone()), + outputs: Arc::new(all_types_outputs.clone()), }; let all_ref_types_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("all_ref_types")), - arguments: Rc::new(all_types_arguments), - outputs: Rc::new(all_types_outputs), + name: Arc::new(String::from("all_ref_types")), + arguments: Arc::new(all_types_arguments), + outputs: Arc::new(all_types_outputs), }; let functions = vec![ @@ -320,11 +320,11 @@ pub fn get_interfaces() { let pure_module_interface = interface .modules .get(pure_module_name) - .expect(&format!("{} should present in interface", pure_module_name)); + .unwrap_or_else(|| panic!("{} should present in interface", pure_module_name)); let effector_module_interface = interface .modules .get(effector_module_name) - .expect(&format!("{} should present in interface", pure_module_name)); + .unwrap_or_else(|| panic!("{} should present in interface", pure_module_name)); assert!(pure_module_interface.record_types.is_empty()); assert!(effector_module_interface.record_types.is_empty()); @@ -609,7 +609,7 @@ pub fn string_type() { #[test] pub fn str_type() { - const FUNC_NAME: &'static str = "str_type"; + const FUNC_NAME: &str = "str_type"; let mut faas = Marine::with_raw_config(ARG_CONFIG.clone()) .unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {}", e)); @@ -681,7 +681,7 @@ pub fn bool_type() { #[test] pub fn empty_type() { - const FUNC_NAME: &'static str = "empty_type"; + const FUNC_NAME: &str = "empty_type"; let mut faas = Marine::with_raw_config(ARG_CONFIG.clone()) .unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {}", e)); diff --git a/marine/tests/arrays_passing.rs b/marine/tests/arrays_passing.rs index 13d01039e..a0ea2fda8 100644 --- a/marine/tests/arrays_passing.rs +++ b/marine/tests/arrays_passing.rs @@ -22,7 +22,7 @@ use marine::IType; use once_cell::sync::Lazy; use serde_json::json; -use std::rc::Rc; +use std::sync::Arc; static ARG_CONFIG: Lazy = Lazy::new(|| { marine::TomlMarineConfig::load("./tests/wasm_tests/arrays_passing/Config.toml") @@ -33,10 +33,10 @@ static ARG_CONFIG: Lazy = Lazy::new(|| { pub fn get_interfaces() { use std::collections::HashSet; - let faas = Marine::with_raw_config(ARG_CONFIG.clone()) + let marine = Marine::with_raw_config(ARG_CONFIG.clone()) .unwrap_or_else(|e| panic!("can't create Fluence Marine instance: {}", e)); - let interface = faas.get_interface(); + let interface = marine.get_interface(); let byte_type_arguments = vec![marine::IFunctionArg { name: String::from("arg"), @@ -45,9 +45,9 @@ pub fn get_interfaces() { let byte_type_outputs = vec![IType::ByteArray]; let byte_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("byte_type")), - arguments: Rc::new(byte_type_arguments), - outputs: Rc::new(byte_type_outputs), + name: Arc::new(String::from("byte_type")), + arguments: Arc::new(byte_type_arguments), + outputs: Arc::new(byte_type_outputs), }; let inner_arrays_1_arguments = vec![marine::IFunctionArg { @@ -61,9 +61,9 @@ pub fn get_interfaces() { ))))]; let inner_arrays_1_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("inner_arrays_1")), - arguments: Rc::new(inner_arrays_1_arguments), - outputs: Rc::new(inner_arrays_1_outputs), + name: Arc::new(String::from("inner_arrays_1")), + arguments: Arc::new(inner_arrays_1_arguments), + outputs: Arc::new(inner_arrays_1_outputs), }; // save it until record will be refactored in the future @@ -92,9 +92,9 @@ pub fn get_interfaces() { let string_type_outputs = vec![IType::Array(Box::new(IType::String))]; let string_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("string_type")), - arguments: Rc::new(string_type_arguments), - outputs: Rc::new(string_type_outputs), + name: Arc::new(String::from("string_type")), + arguments: Arc::new(string_type_arguments), + outputs: Arc::new(string_type_outputs), }; let i32_type_arguments = vec![marine::IFunctionArg { @@ -104,9 +104,9 @@ pub fn get_interfaces() { let i32_type_outputs = vec![IType::Array(Box::new(IType::S32))]; let i32_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("i32_type")), - arguments: Rc::new(i32_type_arguments), - outputs: Rc::new(i32_type_outputs), + name: Arc::new(String::from("i32_type")), + arguments: Arc::new(i32_type_arguments), + outputs: Arc::new(i32_type_outputs), }; let i64_type_arguments = vec![marine::IFunctionArg { @@ -117,9 +117,9 @@ pub fn get_interfaces() { let i64_type_outputs = vec![IType::Array(Box::new(IType::S64))]; let i64_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("i64_type")), - arguments: Rc::new(i64_type_arguments), - outputs: Rc::new(i64_type_outputs), + name: Arc::new(String::from("i64_type")), + arguments: Arc::new(i64_type_arguments), + outputs: Arc::new(i64_type_outputs), }; let u32_type_arguments = vec![marine::IFunctionArg { @@ -129,9 +129,9 @@ pub fn get_interfaces() { let u32_type_outputs = vec![IType::Array(Box::new(IType::U32))]; let u32_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("u32_type")), - arguments: Rc::new(u32_type_arguments), - outputs: Rc::new(u32_type_outputs), + name: Arc::new(String::from("u32_type")), + arguments: Arc::new(u32_type_arguments), + outputs: Arc::new(u32_type_outputs), }; let u64_type_arguments = vec![marine::IFunctionArg { @@ -141,9 +141,9 @@ pub fn get_interfaces() { let u64_type_outputs = vec![IType::Array(Box::new(IType::U64))]; let u64_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("u64_type")), - arguments: Rc::new(u64_type_arguments), - outputs: Rc::new(u64_type_outputs), + name: Arc::new(String::from("u64_type")), + arguments: Arc::new(u64_type_arguments), + outputs: Arc::new(u64_type_outputs), }; let f32_type_arguments = vec![marine::IFunctionArg { @@ -153,9 +153,9 @@ pub fn get_interfaces() { let f32_type_outputs = vec![IType::Array(Box::new(IType::F32))]; let f32_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("f32_type")), - arguments: Rc::new(f32_type_arguments), - outputs: Rc::new(f32_type_outputs), + name: Arc::new(String::from("f32_type")), + arguments: Arc::new(f32_type_arguments), + outputs: Arc::new(f32_type_outputs), }; let f64_type_arguments = vec![marine::IFunctionArg { @@ -165,18 +165,18 @@ pub fn get_interfaces() { let f64_type_outputs = vec![IType::Array(Box::new(IType::F64))]; let f64_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("f64_type")), - arguments: Rc::new(f64_type_arguments), - outputs: Rc::new(f64_type_outputs), + name: Arc::new(String::from("f64_type")), + arguments: Arc::new(f64_type_arguments), + outputs: Arc::new(f64_type_outputs), }; let empty_type_arguments = vec![]; let empty_type_outputs = vec![IType::Array(Box::new(IType::String))]; let empty_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("empty_type")), - arguments: Rc::new(empty_type_arguments), - outputs: Rc::new(empty_type_outputs), + name: Arc::new(String::from("empty_type")), + arguments: Arc::new(empty_type_arguments), + outputs: Arc::new(empty_type_outputs), }; let bool_type_arguments = vec![marine::IFunctionArg { @@ -186,9 +186,9 @@ pub fn get_interfaces() { let bool_type_outputs = vec![IType::Array(Box::new(IType::Boolean))]; let bool_type_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("bool_type")), - arguments: Rc::new(bool_type_arguments), - outputs: Rc::new(bool_type_outputs), + name: Arc::new(String::from("bool_type")), + arguments: Arc::new(bool_type_arguments), + outputs: Arc::new(bool_type_outputs), }; let functions = vec![ @@ -211,11 +211,11 @@ pub fn get_interfaces() { let pure_module_interface = interface .modules .get(pure_module_name) - .expect(&format!("{} should present in interface", pure_module_name)); + .unwrap_or_else(|| panic!("{} should present in interface", pure_module_name)); let effector_module_interface = interface .modules .get(effector_module_name) - .expect(&format!("{} should present in interface", pure_module_name)); + .unwrap_or_else(|| panic!("{} should present in interface", pure_module_name)); assert!(!pure_module_interface.record_types.is_empty()); assert!(!effector_module_interface.record_types.is_empty()); @@ -239,12 +239,12 @@ pub fn get_interfaces() { #[test] pub fn i32_type() { - let mut faas = Marine::with_raw_config(ARG_CONFIG.clone()) + let mut marine = Marine::with_raw_config(ARG_CONFIG.clone()) .unwrap_or_else(|e| panic!("can't create Fluence Marine instance: {}", e)); let expected_result = json!([0, 1, 2, 3, 4, 0, 2]); - let result1 = faas + let result1 = marine .call_with_json( "arrays_passing_pure", "i32_type", @@ -254,7 +254,7 @@ pub fn i32_type() { .unwrap_or_else(|e| panic!("can't invoke i32_type: {:?}", e)); assert_eq!(result1, expected_result); - let result2 = faas + let result2 = marine .call_with_json( "arrays_passing_pure", "i32_type", @@ -265,7 +265,7 @@ pub fn i32_type() { assert_eq!(result2, expected_result); let expected_result = json!([1, 0, 1, 2, 3, 4, 0, 2]); - let result3 = faas + let result3 = marine .call_with_json( "arrays_passing_pure", "i32_type", @@ -278,18 +278,20 @@ pub fn i32_type() { #[test] pub fn i64_type() { - let mut faas = Marine::with_raw_config(ARG_CONFIG.clone()) + let mut marine = Marine::with_raw_config(ARG_CONFIG.clone()) .unwrap_or_else(|e| panic!("can't create Fluence Marine instance: {}", e)); - let result1 = faas.call_with_json("arrays_passing_pure", "i64_type", json!({}), <_>::default()); + let result1 = + marine.call_with_json("arrays_passing_pure", "i64_type", json!({}), <_>::default()); assert!(result1.is_err()); - let result2 = faas.call_with_json("arrays_passing_pure", "i64_type", json!([]), <_>::default()); + let result2 = + marine.call_with_json("arrays_passing_pure", "i64_type", json!([]), <_>::default()); assert!(result2.is_err()); let expected_result = json!([1, 0, 1, 2, 3, 4, 1, 1]); - let result3 = faas + let result3 = marine .call_with_json( "arrays_passing_pure", "i64_type", @@ -299,7 +301,7 @@ pub fn i64_type() { .unwrap_or_else(|e| panic!("can't invoke i64_type: {:?}", e)); assert_eq!(result3, expected_result); - let result4 = faas + let result4 = marine .call_with_json( "arrays_passing_pure", "i64_type", @@ -312,85 +314,91 @@ pub fn i64_type() { #[test] pub fn u32_type() { - let mut faas = Marine::with_raw_config(ARG_CONFIG.clone()) + let mut marine = Marine::with_raw_config(ARG_CONFIG.clone()) .unwrap_or_else(|e| panic!("can't create Fluence Marine instance: {}", e)); - let result1 = faas.call_with_json("arrays_passing_pure", "u32_type", json!({}), <_>::default()); + let result1 = + marine.call_with_json("arrays_passing_pure", "u32_type", json!({}), <_>::default()); assert!(result1.is_err()); - let result2 = faas.call_with_json("arrays_passing_pure", "u32_type", json!([]), <_>::default()); + let result2 = + marine.call_with_json("arrays_passing_pure", "u32_type", json!([]), <_>::default()); assert!(result2.is_err()); let expected_result = json!([1, 0, 13, 37, 2]); let result3 = call_faas!( - faas, + marine, "arrays_passing_pure", "u32_type", json!({ "arg": [1] }) ); assert_eq!(result3, expected_result); - let result4 = call_faas!(faas, "arrays_passing_pure", "u32_type", json!([[1]])); + let result4 = call_faas!(marine, "arrays_passing_pure", "u32_type", json!([[1]])); assert_eq!(result4, expected_result); } #[test] pub fn u64_type() { - let mut faas = Marine::with_raw_config(ARG_CONFIG.clone()) + let mut marine = Marine::with_raw_config(ARG_CONFIG.clone()) .unwrap_or_else(|e| panic!("can't create Fluence Marine instance: {}", e)); - let result1 = faas.call_with_json("arrays_passing_pure", "u64_type", json!({}), <_>::default()); + let result1 = + marine.call_with_json("arrays_passing_pure", "u64_type", json!({}), <_>::default()); assert!(result1.is_err()); - let result2 = faas.call_with_json("arrays_passing_pure", "u64_type", json!([]), <_>::default()); + let result2 = + marine.call_with_json("arrays_passing_pure", "u64_type", json!([]), <_>::default()); assert!(result2.is_err()); let expected_result = json!([1, 0, 1, 2, 3, 4, 2]); let result3 = call_faas!( - faas, + marine, "arrays_passing_pure", "u64_type", json!({ "arg": [1] }) ); assert_eq!(result3, expected_result); - let result4 = call_faas!(faas, "arrays_passing_pure", "u64_type", json!([[1]])); + let result4 = call_faas!(marine, "arrays_passing_pure", "u64_type", json!([[1]])); assert_eq!(result4, expected_result); } #[test] pub fn f64_type() { - let mut faas = Marine::with_raw_config(ARG_CONFIG.clone()) + let mut marine = Marine::with_raw_config(ARG_CONFIG.clone()) .unwrap_or_else(|e| panic!("can't create Fluence Marine instance: {}", e)); - let result1 = faas.call_with_json("arrays_passing_pure", "f32_type", json!({}), <_>::default()); + let result1 = + marine.call_with_json("arrays_passing_pure", "f32_type", json!({}), <_>::default()); assert!(result1.is_err()); - let result2 = faas.call_with_json("arrays_passing_pure", "f32_type", json!([]), <_>::default()); + let result2 = + marine.call_with_json("arrays_passing_pure", "f32_type", json!([]), <_>::default()); assert!(result2.is_err()); let expected_result = json!([1.0, 0.0, 13.37, 1.0]); let result3 = call_faas!( - faas, + marine, "arrays_passing_pure", "f64_type", json!({ "arg": [1.0] }) ); assert_eq!(result3, expected_result); - let result4 = call_faas!(faas, "arrays_passing_pure", "f64_type", json!([[1.0]])); + let result4 = call_faas!(marine, "arrays_passing_pure", "f64_type", json!([[1.0]])); assert_eq!(result4, expected_result); } #[test] pub fn string_type() { - let mut faas = Marine::with_raw_config(ARG_CONFIG.clone()) + let mut marine = Marine::with_raw_config(ARG_CONFIG.clone()) .unwrap_or_else(|e| panic!("can't create Fluence Marine instance: {}", e)); - let result1 = faas.call_with_json( + let result1 = marine.call_with_json( "arrays_passing_pure", "string_type", json!({}), @@ -398,7 +406,7 @@ pub fn string_type() { ); assert!(result1.is_err()); - let result2 = faas.call_with_json( + let result2 = marine.call_with_json( "arrays_passing_pure", "string_type", json!([]), @@ -409,7 +417,7 @@ pub fn string_type() { let expected_result = json!(["Fluence", "marine", "from effector", "test"]); let result3 = call_faas!( - faas, + marine, "arrays_passing_pure", "string_type", json!({ "arg": ["Fluence"] }) @@ -417,7 +425,7 @@ pub fn string_type() { assert_eq!(result3, expected_result); let result4 = call_faas!( - faas, + marine, "arrays_passing_pure", "string_type", json!([["Fluence"]]) @@ -427,10 +435,10 @@ pub fn string_type() { #[test] pub fn byte_type() { - let mut faas = Marine::with_raw_config(ARG_CONFIG.clone()) + let mut marine = Marine::with_raw_config(ARG_CONFIG.clone()) .unwrap_or_else(|e| panic!("can't create Fluence Marine instance: {}", e)); - let result1 = faas.call_with_json( + let result1 = marine.call_with_json( "arrays_passing_pure", "byte_type", json!({}), @@ -438,7 +446,7 @@ pub fn byte_type() { ); assert!(result1.is_err()); - let result2 = faas.call_with_json( + let result2 = marine.call_with_json( "arrays_passing_pure", "byte_type", json!([]), @@ -448,7 +456,7 @@ pub fn byte_type() { let expected_result = json!([0x13, 0x37, 0, 1, 2]); let result3 = call_faas!( - faas, + marine, "arrays_passing_pure", "byte_type", json!({ "arg": [0x13, 0x37] }) @@ -456,7 +464,7 @@ pub fn byte_type() { assert_eq!(result3, expected_result); let result4 = call_faas!( - faas, + marine, "arrays_passing_pure", "byte_type", json!([[0x13, 0x37]]) @@ -466,10 +474,10 @@ pub fn byte_type() { #[test] pub fn inner_arrays_1_type() { - let mut faas = Marine::with_raw_config(ARG_CONFIG.clone()) + let mut marine = Marine::with_raw_config(ARG_CONFIG.clone()) .unwrap_or_else(|e| panic!("can't create Fluence Marine instance: {}", e)); - let result1 = faas.call_with_json( + let result1 = marine.call_with_json( "arrays_passing_pure", "inner_arrays_1", json!({}), @@ -477,7 +485,7 @@ pub fn inner_arrays_1_type() { ); assert!(result1.is_err()); - let result2 = faas.call_with_json( + let result2 = marine.call_with_json( "arrays_passing_pure", "inner_arrays_1", json!([]), @@ -495,7 +503,7 @@ pub fn inner_arrays_1_type() { [[[2]]] ]); let result3 = call_faas!( - faas, + marine, "arrays_passing_pure", "inner_arrays_1", json!({ "arg": [[[[0x13, 0x37]]]] }) @@ -503,7 +511,7 @@ pub fn inner_arrays_1_type() { assert_eq!(result3, expected_result); let result4 = call_faas!( - faas, + marine, "arrays_passing_pure", "inner_arrays_1", json!([[[[[0x13, 0x37]]]]]) @@ -513,10 +521,10 @@ pub fn inner_arrays_1_type() { #[test] pub fn inner_arrays_2_type() { - let mut faas = Marine::with_raw_config(ARG_CONFIG.clone()) + let mut marine = Marine::with_raw_config(ARG_CONFIG.clone()) .unwrap_or_else(|e| panic!("can't create Fluence Marine instance: {}", e)); - let result1 = faas.call_with_json( + let result1 = marine.call_with_json( "arrays_passing_pure", "inner_arrays_2", json!({}), @@ -524,7 +532,7 @@ pub fn inner_arrays_2_type() { ); assert!(result1.is_err()); - let result2 = faas.call_with_json( + let result2 = marine.call_with_json( "arrays_passing_pure", "inner_arrays_2", json!([]), @@ -567,7 +575,7 @@ pub fn inner_arrays_2_type() { ]); let result3 = call_faas!( - faas, + marine, "arrays_passing_pure", "inner_arrays_2", json!({ "arg": [[[[[0, [[1]]]]]]] }) @@ -575,7 +583,7 @@ pub fn inner_arrays_2_type() { assert_eq!(result3, expected_result); let result4 = call_faas!( - faas, + marine, "arrays_passing_pure", "inner_arrays_2", json!([[[[[{"field_0": 0, "field_1": [[1]]}]]]]]) @@ -585,10 +593,10 @@ pub fn inner_arrays_2_type() { #[test] pub fn bool_type() { - let mut faas = Marine::with_raw_config(ARG_CONFIG.clone()) + let mut marine = Marine::with_raw_config(ARG_CONFIG.clone()) .unwrap_or_else(|e| panic!("can't create Fluence Marine instance: {}", e)); - let result1 = faas.call_with_json( + let result1 = marine.call_with_json( "arrays_passing_pure", "bool_type", json!({}), @@ -596,7 +604,7 @@ pub fn bool_type() { ); assert!(result1.is_err()); - let result2 = faas.call_with_json( + let result2 = marine.call_with_json( "arrays_passing_pure", "bool_type", json!([]), @@ -607,33 +615,33 @@ pub fn bool_type() { let expected_result = json!([true, true, false, true, false, true]); let result3 = call_faas!( - faas, + marine, "arrays_passing_pure", "bool_type", json!({ "arg": [false] }) ); assert_eq!(result3, expected_result); - let result4 = call_faas!(faas, "arrays_passing_pure", "bool_type", json!([[false]])); + let result4 = call_faas!(marine, "arrays_passing_pure", "bool_type", json!([[false]])); assert_eq!(result4, expected_result); } #[test] pub fn empty_type() { - let mut faas = Marine::with_raw_config(ARG_CONFIG.clone()) + let mut marine = Marine::with_raw_config(ARG_CONFIG.clone()) .unwrap_or_else(|e| panic!("can't create Fluence Marine instance: {}", e)); let expected_result = json!(["from effector"]); - let result1 = call_faas!(faas, "arrays_passing_pure", "empty_type", json!({})); + let result1 = call_faas!(marine, "arrays_passing_pure", "empty_type", json!({})); assert_eq!(result1, expected_result); - let result2 = call_faas!(faas, "arrays_passing_pure", "empty_type", json!([])); + let result2 = call_faas!(marine, "arrays_passing_pure", "empty_type", json!([])); assert_eq!(result2, expected_result); - let result3 = call_faas!(faas, "arrays_passing_pure", "empty_type", json!([])); + let result3 = call_faas!(marine, "arrays_passing_pure", "empty_type", json!([])); assert_eq!(result3, expected_result); - let result4 = faas.call_with_json( + let result4 = marine.call_with_json( "arrays_passing_pure", "empty_type", json!([1]), diff --git a/marine/tests/call_parameters.rs b/marine/tests/call_parameters.rs index f244869bd..e272cf177 100644 --- a/marine/tests/call_parameters.rs +++ b/marine/tests/call_parameters.rs @@ -43,9 +43,12 @@ pub fn call_parameters() { let host_id = "host_id"; let particle_id = "particle_id"; - let mut tetraplet = marine_rs_sdk::SecurityTetraplet::default(); - tetraplet.function_name = "some_func_name".to_string(); - tetraplet.json_path = "some_json_path".to_string(); + let tetraplet = marine_rs_sdk::SecurityTetraplet { + function_name: "some_func_name".to_string(), + json_path: "some_json_path".to_string(), + ..Default::default() + }; + let tetraplets = vec![vec![tetraplet]]; let call_parameters = marine_rs_sdk::CallParameters { diff --git a/marine/tests/config.rs b/marine/tests/config.rs index 4e85d3a6a..1a6b23251 100644 --- a/marine/tests/config.rs +++ b/marine/tests/config.rs @@ -16,8 +16,12 @@ extern crate core; -use serde_json::{json, Value}; -use marine::{Marine, MarineError, TomlMarineConfig}; +use marine::Marine; +use marine::MarineError; +use marine::TomlMarineConfig; + +use serde_json::json; +use serde_json::Value; #[test] fn load_from_modules_dir() { @@ -102,7 +106,8 @@ fn mapping_to_absolute_path_in_wasi_prohibited() { fn mapping_from_absolute_path_in_wasi_allowed() { let config_path = "tests/wasm_tests/wasi/MapFromAbsolutePath.toml"; let raw_config = TomlMarineConfig::load(config_path).expect("Config must be loaded"); - let result = Marine::with_raw_config(raw_config).expect("Module should be loaded successfully"); + let _result = + Marine::with_raw_config(raw_config).expect("Module should be loaded successfully"); } #[test] diff --git a/marine/tests/greeting.rs b/marine/tests/greeting.rs index f7c85bfe9..b257633f5 100644 --- a/marine/tests/greeting.rs +++ b/marine/tests/greeting.rs @@ -14,14 +14,14 @@ * limitations under the License. */ -use std::path::PathBuf; use marine::Marine; use marine::MarineModuleInterface; use marine::IValue; use pretty_assertions::assert_eq; -use std::rc::Rc; +use std::path::PathBuf; +use std::sync::Arc; #[test] pub fn greeting() { @@ -82,9 +82,9 @@ pub fn get_interfaces() { let output_types = vec![marine::IType::String]; let greeting_sign = marine::MarineFunctionSignature { - name: Rc::new(String::from("greeting")), - arguments: Rc::new(arguments), - outputs: Rc::new(output_types), + name: Arc::new(String::from("greeting")), + arguments: Arc::new(arguments), + outputs: Arc::new(output_types), }; let record_types = std::collections::HashMap::new(); diff --git a/marine/tests/records.rs b/marine/tests/records.rs index bc3341976..48db3db20 100644 --- a/marine/tests/records.rs +++ b/marine/tests/records.rs @@ -34,10 +34,10 @@ pub fn records() { toml::from_slice(&records_config_raw).expect("records config should be well-formed"); records_config.modules_dir = Some(PathBuf::from("../examples/records/artifacts/")); - let mut faas = Marine::with_raw_config(records_config) + let mut marine = Marine::with_raw_config(records_config) .unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {}", e)); - let result1 = faas + let result1 = marine .call_with_ivalues("records_pure", "invoke", &[], <_>::default()) .unwrap_or_else(|e| panic!("can't invoke pure: {:?}", e)); @@ -79,7 +79,7 @@ pub fn records() { )] ); - let result2 = faas + let result2 = marine .call_with_json( "records_effector", "mutate_struct", @@ -107,7 +107,7 @@ pub fn records() { assert_eq!(result2, expected_result); - let result3 = faas + let result3 = marine .call_with_json( "records_effector", "mutate_struct", @@ -121,7 +121,7 @@ pub fn records() { assert_eq!(result3, expected_result); - let result4 = faas + let result4 = marine .call_with_json( "records_effector", "mutate_struct", @@ -147,7 +147,7 @@ pub fn records() { assert_eq!(result4, expected_result); - let result5 = faas + let result5 = marine .call_with_json( "records_effector", "mutate_struct", @@ -172,11 +172,11 @@ fn records_passing() { "./tests/wasm_tests/records_passing/artifacts", )); - let mut faas = Marine::with_raw_config(records_passing_config) + let mut marine = Marine::with_raw_config(records_passing_config) .unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {}", e)); let mut test = |func_name: &str| { - let result = faas + let result = marine .call_with_json( "records_passing_pure", func_name, @@ -233,7 +233,7 @@ fn records_destruction() { "./tests/wasm_tests/records_passing/artifacts", )); - let mut faas = Marine::with_raw_config(records_passing_config) + let mut marine = Marine::with_raw_config(records_passing_config) .unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {}", e)); let record_array = json!([ @@ -249,16 +249,16 @@ fn records_destruction() { ] ]); - let result = faas + let _result = marine .call_with_json( "records_passing_pure", "pass_droppable_record", - record_array.clone(), + record_array, <_>::default(), ) .unwrap_or_else(|e| panic!("can't invoke pure: {:?}", e)); - let result = faas + let result = marine .call_with_json( "records_passing_pure", "get_drop_count", @@ -288,10 +288,10 @@ fn records_return_frees() { "./tests/wasm_tests/records_passing/artifacts", )); - let mut faas = Marine::with_raw_config(records_passing_config) + let mut marine = Marine::with_raw_config(records_passing_config) .unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {}", e)); - let _result = faas + let _result = marine .call_with_json( "records_passing_pure", "return_256kb_struct", @@ -300,15 +300,15 @@ fn records_return_frees() { ) .unwrap_or_else(|e| panic!("can't invoke pure: {:?}", e)); - let stats_after_first_call = faas + let stats_after_first_call = marine .module_memory_stats() .0 .iter() .map(|stat| (stat.name.to_string(), stat.memory_size)) .collect::>(); - for i in 0..128 { - let result = faas + for _ in 0..128 { + let _result = marine .call_with_json( "records_passing_pure", "return_256kb_struct", @@ -317,7 +317,7 @@ fn records_return_frees() { ) .unwrap_or_else(|e| panic!("can't invoke pure: {:?}", e)); - for stat in faas.module_memory_stats().0 { + for stat in marine.module_memory_stats().0 { let memory_size = stats_after_first_call.get(stat.name).unwrap(); assert_eq!(*memory_size, stat.memory_size) } @@ -326,10 +326,7 @@ fn records_return_frees() { #[test] fn records_pass_frees() { - let inner_records_config_raw = std::fs::read("./tests/wasm_tests/records_passing/Config.toml") - .expect("./tests/wasm_tests/records_passing/Config.toml should presence"); - - let mut records_passing_config = + let records_passing_config = marine::TomlMarineConfig::load("./tests/wasm_tests/records_passing/Config.toml") .expect("argument passing test config should be well-formed"); @@ -353,83 +350,83 @@ fn records_pass_frees() { }); let struct_1kb = json!({ - "field1": struct_64b.clone(), - "field2": struct_64b.clone(), - "field3": struct_64b.clone(), - "field4": struct_64b.clone(), - "field5": struct_64b.clone(), - "field6": struct_64b.clone(), - "field7": struct_64b.clone(), - "field8": struct_64b.clone(), - "field11": struct_64b.clone(), - "field12": struct_64b.clone(), - "field13": struct_64b.clone(), - "field14": struct_64b.clone(), - "field15": struct_64b.clone(), - "field16": struct_64b.clone(), - "field17": struct_64b.clone(), - "field18": struct_64b.clone(), + "field1": struct_64b, + "field2": struct_64b, + "field3": struct_64b, + "field4": struct_64b, + "field5": struct_64b, + "field6": struct_64b, + "field7": struct_64b, + "field8": struct_64b, + "field11": struct_64b, + "field12": struct_64b, + "field13": struct_64b, + "field14": struct_64b, + "field15": struct_64b, + "field16": struct_64b, + "field17": struct_64b, + "field18": struct_64b, }); let struct_16kb = json!({ - "field1": struct_1kb.clone(), - "field2": struct_1kb.clone(), - "field3": struct_1kb.clone(), - "field4": struct_1kb.clone(), - "field5": struct_1kb.clone(), - "field6": struct_1kb.clone(), - "field7": struct_1kb.clone(), - "field8": struct_1kb.clone(), - "field11": struct_1kb.clone(), - "field12": struct_1kb.clone(), - "field13": struct_1kb.clone(), - "field14": struct_1kb.clone(), - "field15": struct_1kb.clone(), - "field16": struct_1kb.clone(), - "field17": struct_1kb.clone(), - "field18": struct_1kb.clone(), + "field1": struct_1kb, + "field2": struct_1kb, + "field3": struct_1kb, + "field4": struct_1kb, + "field5": struct_1kb, + "field6": struct_1kb, + "field7": struct_1kb, + "field8": struct_1kb, + "field11": struct_1kb, + "field12": struct_1kb, + "field13": struct_1kb, + "field14": struct_1kb, + "field15": struct_1kb, + "field16": struct_1kb, + "field17": struct_1kb, + "field18": struct_1kb, }); let struct_256kb = json!({ - "field1": struct_16kb.clone(), - "field2": struct_16kb.clone(), - "field3": struct_16kb.clone(), - "field4": struct_16kb.clone(), - "field5": struct_16kb.clone(), - "field6": struct_16kb.clone(), - "field7": struct_16kb.clone(), - "field8": struct_16kb.clone(), - "field11": struct_16kb.clone(), - "field12": struct_16kb.clone(), - "field13": struct_16kb.clone(), - "field14": struct_16kb.clone(), - "field15": struct_16kb.clone(), - "field16": struct_16kb.clone(), - "field17": struct_16kb.clone(), - "field18": struct_16kb.clone(), + "field1": struct_16kb, + "field2": struct_16kb, + "field3": struct_16kb, + "field4": struct_16kb, + "field5": struct_16kb, + "field6": struct_16kb, + "field7": struct_16kb, + "field8": struct_16kb, + "field11": struct_16kb, + "field12": struct_16kb, + "field13": struct_16kb, + "field14": struct_16kb, + "field15": struct_16kb, + "field16": struct_16kb, + "field17": struct_16kb, + "field18": struct_16kb, }); - let mut faas = Marine::with_raw_config(records_passing_config) + let mut marine = Marine::with_raw_config(records_passing_config) .unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {}", e)); - let result = faas + let _result = marine .call_with_json( "records_passing_pure", "pass_256kb_struct", - json!([struct_256kb.clone()]), + json!([struct_256kb]), <_>::default(), ) .unwrap_or_else(|e| panic!("can't invoke pure: {:?}", e)); - let stats_after_first_call = faas + let stats_after_first_call = marine .module_memory_stats() .0 .iter() .map(|stat| (stat.name.to_string(), stat.memory_size)) .collect::>(); - for i in 0..128 { - let result = faas + for _ in 0..128 { + let _result = marine .call_with_json( "records_passing_pure", "pass_256kb_struct", @@ -438,7 +435,7 @@ fn records_pass_frees() { ) .unwrap_or_else(|e| panic!("can't invoke pure: {:?}", e)); - for stat in faas.module_memory_stats().0 { + for stat in marine.module_memory_stats().0 { let memory_size = stats_after_first_call.get(stat.name).unwrap(); assert_eq!(*memory_size, stat.memory_size) } diff --git a/marine/tests/wasm_tests/arguments_passing/Cargo.toml b/marine/tests/wasm_tests/arguments_passing/Cargo.toml index f19b12762..0d80ea9c6 100644 --- a/marine/tests/wasm_tests/arguments_passing/Cargo.toml +++ b/marine/tests/wasm_tests/arguments_passing/Cargo.toml @@ -2,7 +2,7 @@ name = "arguments-passing-test" version = "0.1.0" authors = ["Fluence Labs"] -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/marine/tests/wasm_tests/arrays_passing/Cargo.toml b/marine/tests/wasm_tests/arrays_passing/Cargo.toml index cb95a9459..9c3793b25 100644 --- a/marine/tests/wasm_tests/arrays_passing/Cargo.toml +++ b/marine/tests/wasm_tests/arrays_passing/Cargo.toml @@ -2,7 +2,7 @@ name = "arrays-passing-test" version = "0.1.0" authors = ["Fluence Labs"] -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/marine/tests/wasm_tests/records_passing/.cargo/config.toml b/marine/tests/wasm_tests/records_passing/.cargo/config.toml new file mode 100644 index 000000000..8a39568a6 --- /dev/null +++ b/marine/tests/wasm_tests/records_passing/.cargo/config.toml @@ -0,0 +1,4 @@ +[target.wasm32-wasi] +rustflags = [ + "-C", "link-args=-zstack-size=52428800", +] diff --git a/marine/tests/wasm_tests/records_passing/Cargo.toml b/marine/tests/wasm_tests/records_passing/Cargo.toml index d37262bf1..31ea321a6 100644 --- a/marine/tests/wasm_tests/records_passing/Cargo.toml +++ b/marine/tests/wasm_tests/records_passing/Cargo.toml @@ -2,7 +2,7 @@ name = "records-passing-test" version = "0.1.0" authors = ["Fluence Labs"] -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/marine/tests/wasm_tests/records_passing/src/pure.rs b/marine/tests/wasm_tests/records_passing/src/pure.rs index 8b9c12778..d5635a4b6 100644 --- a/marine/tests/wasm_tests/records_passing/src/pure.rs +++ b/marine/tests/wasm_tests/records_passing/src/pure.rs @@ -218,7 +218,8 @@ fn pass_256kb_struct(arg: Data256KB) { mod effector { use marine_rs_sdk::marine; - use crate::{Data256KB, DroppableRecordTreeConainer}; + use crate::Data256KB; + use crate::DroppableRecordTreeConainer; use super::TestRecord2; #[marine] diff --git a/marine/tests/wasm_tests/wasi/Cargo.toml b/marine/tests/wasm_tests/wasi/Cargo.toml index c9df719f4..d606c10d7 100644 --- a/marine/tests/wasm_tests/wasi/Cargo.toml +++ b/marine/tests/wasm_tests/wasi/Cargo.toml @@ -2,7 +2,7 @@ name = "wasi-test" version = "0.1.0" authors = ["Fluence Labs"] -edition = "2018" +edition = "2021" publish = false [[bin]] diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 4a380bf98..a259e64b7 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "nightly-2022-09-15" +channel = "nightly-2022-12-01" targets = [ "x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl", diff --git a/tools/cli/Cargo.toml b/tools/cli/Cargo.toml index eea2beabd..a3ad0ab9e 100644 --- a/tools/cli/Cargo.toml +++ b/tools/cli/Cargo.toml @@ -5,7 +5,7 @@ version = "0.13.0" authors = ["Fluence Labs"] repository = "https://github.com/fluencelabs/marine/tools/cli" license = "Apache-2.0" -edition = "2018" +edition = "2021" [[bin]] name = "marine" diff --git a/tools/cli/src/args.rs b/tools/cli/src/args.rs index 6113c0e0d..a1bc74efa 100644 --- a/tools/cli/src/args.rs +++ b/tools/cli/src/args.rs @@ -14,7 +14,9 @@ * limitations under the License. */ -use clap::{App, Arg, SubCommand}; +use clap::App; +use clap::Arg; +use clap::SubCommand; pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub const AUTHORS: &str = env!("CARGO_PKG_AUTHORS"); diff --git a/tools/cli/src/cargo_manifest.rs b/tools/cli/src/cargo_manifest.rs index e9ffba42f..0db6a5500 100644 --- a/tools/cli/src/cargo_manifest.rs +++ b/tools/cli/src/cargo_manifest.rs @@ -1,4 +1,5 @@ -use cargo_toml::{Error as CargoTomlError, Manifest}; +use cargo_toml::Error as CargoTomlError; +use cargo_toml::Manifest; use toml::de::Error as TomlError; use semver::Version; use thiserror::Error as ThisError; diff --git a/tools/cli/src/main.rs b/tools/cli/src/main.rs index 3ca0d23f1..0710fa12d 100644 --- a/tools/cli/src/main.rs +++ b/tools/cli/src/main.rs @@ -26,6 +26,7 @@ )] use marine_module_info_parser::manifest; +use marine_module_info_parser::ModuleInfoError; use marine_module_info_parser::sdk_version; mod args; @@ -201,19 +202,23 @@ fn info(args: &clap::ArgMatches<'_>) -> Result<(), anyhow::Error> { let wasm_path = args.value_of(args::IN_WASM_PATH).unwrap(); let wasm_module = walrus::ModuleConfig::new().parse_file(wasm_path)?; - let sdk_version = sdk_version::extract_from_module(&wasm_module)?; - let module_manifest = manifest::extract_from_module(&wasm_module)?; + let sdk_version = sdk_version::extract_from_module(&wasm_module); + let module_manifest = manifest::extract_from_module(&wasm_module); let it_version = marine_it_parser::extract_version_from_module(&wasm_module)?; println!("it version: {}", it_version); match sdk_version { - Some(sdk_version) => println!("sdk version: {}", sdk_version), - None => println!("module doesn't contain sdk version"), + Ok(sdk_version) => println!("sdk version: {}", sdk_version), + Err(ModuleInfoError::NoCustomSection(_)) => println!("module doesn't contain sdk version"), + Err(e) => return Err(e.into()), } match module_manifest { - Some(manifest) => println!("{}", manifest), - None => println!("module doesn't contain module manifest"), + Ok(manifest) => println!("{}", manifest), + Err(ModuleInfoError::NoCustomSection(_)) => { + println!("module doesn't contain module manifest") + } + Err(e) => return Err(e.into()), } Ok(()) diff --git a/tools/repl/Cargo.toml b/tools/repl/Cargo.toml index 0dfa52f77..5d69d7484 100644 --- a/tools/repl/Cargo.toml +++ b/tools/repl/Cargo.toml @@ -5,7 +5,7 @@ version = "0.20.0" authors = ["Fluence Labs"] repository = "https://github.com/fluencelabs/marine/tools/repl" license = "Apache-2.0" -edition = "2018" +edition = "2021" [[bin]] name = "mrepl" @@ -14,12 +14,12 @@ path = "src/main.rs" [dependencies] fluence-app-service = { path = "../../crates/fluence-app-service", version = "0.24.0", features = ["raw-module-api"] } marine-rs-sdk-main = { version = "0.7.1", features = ["logger"] } +marine-wasm-backend-traits = {path = "../../crates/wasm-backend-traits", version = "0.1.0"} anyhow = "1.0.66" clap = "2.34.0" serde = "1.0.147" serde_json = "1.0.89" -wasmer-wasi = { package = "wasmer-wasi-fl", version = "0.17.1"} env_logger = "0.9.3" check-latest = { version = "1.0.1", optional = true } diff --git a/tools/repl/src/editor.rs b/tools/repl/src/editor.rs index fbe4f926e..42478c6c9 100644 --- a/tools/repl/src/editor.rs +++ b/tools/repl/src/editor.rs @@ -16,15 +16,29 @@ use crate::ReplResult; -use rustyline::completion::{Completer, FilenameCompleter, Pair}; +use rustyline::completion::Completer; +use rustyline::completion::FilenameCompleter; +use rustyline::completion::Pair; use rustyline::error::ReadlineError; -use rustyline::highlight::{Highlighter, MatchingBracketHighlighter}; -use rustyline::hint::{Hinter, HistoryHinter}; -use rustyline::validate::{self, MatchingBracketValidator, Validator}; -use rustyline::{Cmd, CompletionType, Config, Context, EditMode, Editor, KeyEvent}; +use rustyline::highlight::Highlighter; +use rustyline::highlight::MatchingBracketHighlighter; +use rustyline::hint::Hinter; +use rustyline::hint::HistoryHinter; +use rustyline::validate; +use rustyline::validate::MatchingBracketValidator; +use rustyline::validate::Validator; +use rustyline::Cmd; +use rustyline::CompletionType; +use rustyline::Config; +use rustyline::Context; +use rustyline::EditMode; +use rustyline::Editor; +use rustyline::KeyEvent; use rustyline_derive::Helper; -use std::borrow::Cow::{self, Borrowed, Owned}; +use std::borrow::Cow; +use std::borrow::Cow::Borrowed; +use std::borrow::Cow::Owned; use std::collections::HashSet; pub(super) fn init_editor() -> ReplResult> { diff --git a/tools/repl/src/logger.rs b/tools/repl/src/logger.rs index a91fa3352..391dfc0fd 100644 --- a/tools/repl/src/logger.rs +++ b/tools/repl/src/logger.rs @@ -48,6 +48,7 @@ pub(super) fn init_logger() { // set a default level Info for Wasmer components .filter(Some("cranelift_codegen"), Info) .filter(Some("wasmer_wasi"), Info) + .filter(Some("wasmtime_wasi"), Info) //.filter(Some(WIT_MODULE_PATH), Info) // the same for rustyline and marine .filter(Some("rustyline"), Info) diff --git a/tools/repl/src/repl.rs b/tools/repl/src/repl.rs index 3b6d18a5d..ae8c5be0a 100644 --- a/tools/repl/src/repl.rs +++ b/tools/repl/src/repl.rs @@ -126,15 +126,17 @@ impl REPL { let start = Instant::now(); let config = MarineModuleConfig { logger_enabled: true, - ..<_>::default() + mem_pages_count: Default::default(), + max_heap_size: Default::default(), + host_imports: Default::default(), + wasi: Default::default(), + logging_mask: Default::default(), }; - let result_msg = match self - .app_service - .load_module::( - module_name.into(), - &wasm_bytes.unwrap(), - Some(config), - ) { + let result_msg = match self.app_service.load_module::( + module_name.into(), + &wasm_bytes.unwrap(), + Some(config), + ) { Ok(_) => { let elapsed_time = start.elapsed(); format!( @@ -211,7 +213,7 @@ impl REPL { fn show_envs<'args>(&mut self, mut args: impl Iterator) { next_argument!(module_name, args, "Module name should be specified"); match self.app_service.get_wasi_state(module_name) { - Ok(wasi_state) => print_envs(module_name, wasi_state), + Ok(wasi_state) => print_envs(module_name, wasi_state.as_ref()), Err(e) => println!("{}", e), }; } @@ -219,7 +221,7 @@ impl REPL { fn show_fs<'args>(&mut self, mut args: impl Iterator) { next_argument!(module_name, args, "Module name should be specified"); match self.app_service.get_wasi_state(module_name) { - Ok(wasi_state) => print_fs_state(wasi_state), + Ok(wasi_state) => print_fs_state(wasi_state.as_ref()), Err(e) => println!("{}", e), }; } @@ -230,7 +232,7 @@ impl REPL { print!("Loaded modules interface:\n{}", interface); } - fn show_memory_stats(&mut self) { + fn show_memory_stats(&self) { let statistic = self.app_service.module_memory_stats(); print!("Loaded modules heap sizes:\n{}", statistic); diff --git a/tools/repl/src/repl/print_state.rs b/tools/repl/src/repl/print_state.rs index 2c9b29320..67e11747f 100644 --- a/tools/repl/src/repl/print_state.rs +++ b/tools/repl/src/repl/print_state.rs @@ -14,10 +14,10 @@ * limitations under the License. */ -use wasmer_wasi::state::WasiState; +use marine_wasm_backend_traits::WasiState; -pub(super) fn print_envs(module_name: &str, wasi_state: &WasiState) { - let envs = &wasi_state.envs; +pub(super) fn print_envs(module_name: &str, wasi_state: &dyn WasiState) { + let envs = wasi_state.envs(); if envs.is_empty() { println!("{} don't have environment variables", module_name); return; @@ -32,28 +32,6 @@ pub(super) fn print_envs(module_name: &str, wasi_state: &WasiState) { } } -pub(super) fn print_fs_state(wasi_state: &WasiState) { - let wasi_fs = &wasi_state.fs; - - println!("preopened file descriptors:\n{:?}\n", wasi_fs.preopen_fds); - - println!("name map:"); - for (name, inode) in &wasi_fs.name_map { - println!("{} - {:?}", name, inode); - } - - println!("\nfile descriptors map:"); - for (id, fd) in &wasi_fs.fd_map { - println!("{} - {:?}", id, fd); - } - - println!("\norphan file descriptors:"); - for (fd, inode) in &wasi_fs.orphan_fds { - println!("{:?} - {:?}", fd, inode); - } - - println!("\ninodes:"); - for (id, inode) in wasi_fs.inodes.iter().enumerate() { - println!("{}: {:?}", id, inode); - } +pub(super) fn print_fs_state(_wasi_state: &dyn WasiState) { + println!("Printing WASI filesystem state is not supported now."); }