From 835fdd26422dca3c1659b421b10304a2f0b9c037 Mon Sep 17 00:00:00 2001 From: Koute Date: Tue, 7 Feb 2023 00:40:50 +0900 Subject: [PATCH] Bump `wasmtime` to 5.0.0 (and a few other deps) (#13160) * Bump `wasmtime` to 4.0.0 (and a few other deps) * Use `Error::msg` instead of `anyhow!` * Bump `wasmtime` to 5.0.0 * Update `Cargo.lock` * Add `wasmtime` feature to `sp-wasm-interface` dependency --- Cargo.lock | 159 ++++++++---------- client/executor/wasmtime/Cargo.toml | 11 +- client/executor/wasmtime/src/imports.rs | 4 +- .../executor/wasmtime/src/instance_wrapper.rs | 34 ++-- client/executor/wasmtime/src/runtime.rs | 40 +++-- client/executor/wasmtime/src/tests.rs | 35 +++- .../host_function_interface.rs | 6 +- primitives/wasm-interface/Cargo.toml | 4 +- primitives/wasm-interface/src/lib.rs | 3 + utils/wasm-builder/Cargo.toml | 2 +- 10 files changed, 156 insertions(+), 142 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index afebaabd6c06c..a74ad26e7a9a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -813,15 +813,16 @@ dependencies = [ [[package]] name = "cargo_metadata" -version = "0.14.2" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" +checksum = "982a0cf6a99c350d7246035613882e376d58cebe571785abc5da4f648d53ac0a" dependencies = [ "camino", "cargo-platform", "semver 1.0.16", "serde", "serde_json", + "thiserror", ] [[package]] @@ -1178,18 +1179,18 @@ checksum = "dcb25d077389e53838a8158c8e99174c5a9d902dee4904320db714f3c653ffba" [[package]] name = "cranelift-bforest" -version = "0.88.2" +version = "0.92.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52056f6d0584484b57fa6c1a65c1fcb15f3780d8b6a758426d9e3084169b2ddd" +checksum = "2f3d54eab028f5805ae3b26fd60eca3f3a9cfb76b989d9bab173be3f61356cc3" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.88.2" +version = "0.92.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fed94c8770dc25d01154c3ffa64ed0b3ba9d583736f305fed7beebe5d9cf74" +checksum = "2be1d5f2c3cca1efb691844bc1988b89c77291f13f778499a3f3c0cf49c0ed61" dependencies = [ "arrayvec 0.7.2", "bumpalo", @@ -1199,6 +1200,7 @@ dependencies = [ "cranelift-entity", "cranelift-isle", "gimli 0.26.2", + "hashbrown 0.12.3", "log", "regalloc2", "smallvec", @@ -1207,33 +1209,33 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.88.2" +version = "0.92.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c451b81faf237d11c7e4f3165eeb6bac61112762c5cfe7b4c0fb7241474358f" +checksum = "3f9b1b1089750ce4005893af7ee00bb08a2cf1c9779999c0f7164cbc8ad2e0d2" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.88.2" +version = "0.92.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7c940133198426d26128f08be2b40b0bd117b84771fd36798969c4d712d81fc" +checksum = "cc5fbaec51de47297fd7304986fd53c8c0030abbe69728a60d72e1c63559318d" [[package]] name = "cranelift-entity" -version = "0.88.2" +version = "0.92.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87a0f1b2fdc18776956370cf8d9b009ded3f855350c480c1c52142510961f352" +checksum = "dab984c94593f876090fae92e984bdcc74d9b1acf740ab5f79036001c65cba13" dependencies = [ "serde", ] [[package]] name = "cranelift-frontend" -version = "0.88.2" +version = "0.92.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34897538b36b216cc8dd324e73263596d51b8cf610da6498322838b2546baf8a" +checksum = "6e0cb3102d21a2fe5f3210af608748ddd0cd09825ac12d42dc56ed5ed8725fe0" dependencies = [ "cranelift-codegen", "log", @@ -1243,15 +1245,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.88.2" +version = "0.92.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b2629a569fae540f16a76b70afcc87ad7decb38dc28fa6c648ac73b51e78470" +checksum = "72101dd1f441d629735143c41e00b3428f9267738176983ef588ff43382af0a0" [[package]] name = "cranelift-native" -version = "0.88.2" +version = "0.92.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20937dab4e14d3e225c5adfc9c7106bafd4ac669bdb43027b911ff794c6fb318" +checksum = "c22b0d9fcbe3fc5a1af9e7021b44ce42b930bcefac446ce22e02e8f9a0d67120" dependencies = [ "cranelift-codegen", "libc", @@ -1260,9 +1262,9 @@ dependencies = [ [[package]] name = "cranelift-wasm" -version = "0.88.2" +version = "0.92.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80fc2288957a94fd342a015811479de1837850924166d1f1856d8406e6f3609b" +checksum = "bddebe32fb14fbfd9efa5f130ffb8f4665795de019928dcd7247b136c46f9249" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -3251,12 +3253,6 @@ dependencies = [ "webrtc-util", ] -[[package]] -name = "io-lifetimes" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ce5ef949d49ee85593fc4d3f3f95ad61657076395cbbce23e2121fc5542074" - [[package]] name = "io-lifetimes" version = "1.0.3" @@ -3298,8 +3294,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" dependencies = [ "hermit-abi 0.2.6", - "io-lifetimes 1.0.3", - "rustix 0.36.6", + "io-lifetimes", + "rustix", "windows-sys 0.42.0", ] @@ -4193,12 +4189,6 @@ dependencies = [ "nalgebra", ] -[[package]] -name = "linux-raw-sys" -version = "0.0.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" - [[package]] name = "linux-raw-sys" version = "0.1.4" @@ -4349,7 +4339,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b20a59d985586e4a5aef64564ac77299f8586d8be6cf9106a5a40207e8908efb" dependencies = [ - "rustix 0.36.6", + "rustix", ] [[package]] @@ -7550,9 +7540,9 @@ dependencies = [ [[package]] name = "regalloc2" -version = "0.3.2" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d43a209257d978ef079f3d446331d0f1794f5e0fc19b306a199983857833a779" +checksum = "300d4fbfb40c1c66a78ba3ddd41c1110247cf52f97b87d0f2fc9209bd49b030c" dependencies = [ "fxhash", "log", @@ -7747,20 +7737,6 @@ dependencies = [ "nom", ] -[[package]] -name = "rustix" -version = "0.35.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "727a1a6d65f786ec22df8a81ca3121107f235970dc1705ed681d3e6e8b9cd5f9" -dependencies = [ - "bitflags", - "errno", - "io-lifetimes 0.7.5", - "libc", - "linux-raw-sys 0.0.46", - "windows-sys 0.42.0", -] - [[package]] name = "rustix" version = "0.36.6" @@ -7769,9 +7745,9 @@ checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549" dependencies = [ "bitflags", "errno", - "io-lifetimes 1.0.3", + "io-lifetimes", "libc", - "linux-raw-sys 0.1.4", + "linux-raw-sys", "windows-sys 0.42.0", ] @@ -8389,13 +8365,15 @@ dependencies = [ name = "sc-executor-wasmtime" version = "0.10.0-dev" dependencies = [ + "anyhow", + "cargo_metadata", "cfg-if", "libc", "log", "once_cell", "parity-scale-codec", "paste", - "rustix 0.35.13", + "rustix", "sc-allocator", "sc-executor-common", "sc-runtime-test", @@ -10418,6 +10396,7 @@ dependencies = [ name = "sp-wasm-interface" version = "7.0.0" dependencies = [ + "anyhow", "impl-trait-for-tuples", "log", "parity-scale-codec", @@ -11918,11 +11897,12 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.89.1" +version = "0.96.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5d3e08b13876f96dd55608d03cd4883a0545884932d5adf11925876c96daef" +checksum = "adde01ade41ab9a5d10ec8ed0bb954238cf8625b5cd5a13093d6de2ad9c2be1a" dependencies = [ "indexmap", + "url", ] [[package]] @@ -11936,9 +11916,9 @@ dependencies = [ [[package]] name = "wasmtime" -version = "1.0.2" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ad5af6ba38311282f2a21670d96e78266e8c8e2f38cbcd52c254df6ccbc7731" +checksum = "4e5b183a159484980138cc05231419c536d395a7b25c1802091310ea2f74276a" dependencies = [ "anyhow", "bincode", @@ -11959,23 +11939,23 @@ dependencies = [ "wasmtime-environ", "wasmtime-jit", "wasmtime-runtime", - "windows-sys 0.36.1", + "windows-sys 0.42.0", ] [[package]] name = "wasmtime-asm-macros" -version = "1.0.2" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45de63ddfc8b9223d1adc8f7b2ee5f35d1f6d112833934ad7ea66e4f4339e597" +checksum = "c0aeb1cb256d76cf07b20264c808351c8b525ece56de1ef4d93f87a0aaf342db" dependencies = [ "cfg-if", ] [[package]] name = "wasmtime-cache" -version = "1.0.2" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcd849399d17d2270141cfe47fa0d91ee52d5f8ea9b98cf7ddde0d53e5f79882" +checksum = "830570847f905b8f6d2ca635c33cf42ce701dd8e4abd7d1806c631f8f06e9e4b" dependencies = [ "anyhow", "base64", @@ -11983,19 +11963,19 @@ dependencies = [ "directories-next", "file-per-thread-logger", "log", - "rustix 0.35.13", + "rustix", "serde", - "sha2 0.9.9", + "sha2 0.10.6", "toml", - "windows-sys 0.36.1", + "windows-sys 0.42.0", "zstd", ] [[package]] name = "wasmtime-cranelift" -version = "1.0.2" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bd91339b742ff20bfed4532a27b73c86b5bcbfedd6bea2dcdf2d64471e1b5c6" +checksum = "2f7695d3814dcb508bf4d1c181a86ea6b97a209f6444478e95d86e2ffab8d1a3" dependencies = [ "anyhow", "cranelift-codegen", @@ -12014,9 +11994,9 @@ dependencies = [ [[package]] name = "wasmtime-environ" -version = "1.0.2" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebb881c61f4f627b5d45c54e629724974f8a8890d455bcbe634330cc27309644" +checksum = "e5a2a5f0fb93aa837a727a48dd1076e8a9f882cc2fee20b433c04a18740ff63b" dependencies = [ "anyhow", "cranelift-entity", @@ -12033,9 +12013,9 @@ dependencies = [ [[package]] name = "wasmtime-jit" -version = "1.0.2" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1985c628011fe26adf5e23a5301bdc79b245e0e338f14bb58b39e4e25e4d8681" +checksum = "01c78f9fb2922dbb5a95f009539d4badb44866caeeb53d156bf2cf4d683c3afd" dependencies = [ "addr2line 0.17.0", "anyhow", @@ -12046,32 +12026,42 @@ dependencies = [ "log", "object 0.29.0", "rustc-demangle", - "rustix 0.35.13", "serde", "target-lexicon", - "thiserror", "wasmtime-environ", "wasmtime-jit-debug", + "wasmtime-jit-icache-coherence", "wasmtime-runtime", - "windows-sys 0.36.1", + "windows-sys 0.42.0", ] [[package]] name = "wasmtime-jit-debug" -version = "1.0.2" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f671b588486f5ccec8c5a3dba6b4c07eac2e66ab8c60e6f4e53717c77f709731" +checksum = "67cacdb52a77b8c8e744e510beeabf0bd698b1c94c59eed33c52b3fbd19639b0" dependencies = [ "object 0.29.0", "once_cell", - "rustix 0.35.13", + "rustix", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08fcba5ebd96da2a9f0747ab6337fe9788adfb3f63fa2c180520d665562d257e" +dependencies = [ + "cfg-if", + "libc", + "windows-sys 0.42.0", ] [[package]] name = "wasmtime-runtime" -version = "1.0.2" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee8f92ad4b61736339c29361da85769ebc200f184361959d1792832e592a1afd" +checksum = "0793210acf50d4c69182c916abaee1d423dc5d172cdfde6acfea2f9446725940" dependencies = [ "anyhow", "cc", @@ -12084,19 +12074,18 @@ dependencies = [ "memoffset 0.6.5", "paste", "rand 0.8.5", - "rustix 0.35.13", - "thiserror", + "rustix", "wasmtime-asm-macros", "wasmtime-environ", "wasmtime-jit-debug", - "windows-sys 0.36.1", + "windows-sys 0.42.0", ] [[package]] name = "wasmtime-types" -version = "1.0.2" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d23d61cb4c46e837b431196dd06abb11731541021916d03476a178b54dc07aeb" +checksum = "50d015ba8b231248a811e323cf7a525cd3f982d4be0b9e62d27685102e5f12b1" dependencies = [ "cranelift-entity", "serde", diff --git a/client/executor/wasmtime/Cargo.toml b/client/executor/wasmtime/Cargo.toml index 983ca3c44fba0..acd1a5aef9391 100644 --- a/client/executor/wasmtime/Cargo.toml +++ b/client/executor/wasmtime/Cargo.toml @@ -19,18 +19,18 @@ log = "0.4.17" # When bumping wasmtime do not forget to also bump rustix # to exactly the same version as used by wasmtime! -wasmtime = { version = "1.0.0", default-features = false, features = [ +wasmtime = { version = "5.0.0", default-features = false, features = [ "cache", "cranelift", "jitdump", "parallel-compilation", - "memory-init-cow", - "pooling-allocator", + "pooling-allocator" ] } +anyhow = "1.0.68" sc-allocator = { version = "4.1.0-dev", path = "../../allocator" } sc-executor-common = { version = "0.10.0-dev", path = "../common" } sp-runtime-interface = { version = "7.0.0", path = "../../../primitives/runtime-interface" } -sp-wasm-interface = { version = "7.0.0", path = "../../../primitives/wasm-interface" } +sp-wasm-interface = { version = "7.0.0", path = "../../../primitives/wasm-interface", features = ["wasmtime"] } # Here we include the rustix crate in the exactly same semver-compatible version as used by # wasmtime and enable its 'use-libc' flag. @@ -38,7 +38,7 @@ sp-wasm-interface = { version = "7.0.0", path = "../../../primitives/wasm-interf # By default rustix directly calls the appropriate syscalls completely bypassing libc; # this doesn't have any actual benefits for us besides making it harder to debug memory # problems (since then `mmap` etc. cannot be easily hooked into). -rustix = { version = "0.35.9", default-features = false, features = ["std", "mm", "fs", "param", "use-libc"] } +rustix = { version = "0.36.0", default-features = false, features = ["std", "mm", "fs", "param", "use-libc"] } once_cell = "1.12.0" [dev-dependencies] @@ -48,3 +48,4 @@ sp-io = { version = "7.0.0", path = "../../../primitives/io" } tempfile = "3.3.0" paste = "1.0" codec = { package = "parity-scale-codec", version = "3.2.2" } +cargo_metadata = "0.15.2" diff --git a/client/executor/wasmtime/src/imports.rs b/client/executor/wasmtime/src/imports.rs index c80952a2541ce..fad3195de93dc 100644 --- a/client/executor/wasmtime/src/imports.rs +++ b/client/executor/wasmtime/src/imports.rs @@ -20,7 +20,7 @@ use crate::{host::HostContext, runtime::StoreData}; use sc_executor_common::error::WasmError; use sp_wasm_interface::{FunctionContext, HostFunctions}; use std::collections::HashMap; -use wasmtime::{ExternType, FuncType, ImportType, Linker, Module, Trap}; +use wasmtime::{ExternType, FuncType, ImportType, Linker, Module}; /// Goes over all imports of a module and prepares the given linker for instantiation of the module. /// Returns an error if there are imports that cannot be satisfied. @@ -67,7 +67,7 @@ where log::debug!("Missing import: '{}' {:?}", name, func_ty); linker .func_new("env", &name, func_ty.clone(), move |_, _, _| { - Err(Trap::new(error.clone())) + Err(anyhow::Error::msg(error.clone())) }) .expect("adding a missing import stub can only fail when the item already exists, and it is missing here; qed"); } diff --git a/client/executor/wasmtime/src/instance_wrapper.rs b/client/executor/wasmtime/src/instance_wrapper.rs index feded4008068d..2117f1ebf2e91 100644 --- a/client/executor/wasmtime/src/instance_wrapper.rs +++ b/client/executor/wasmtime/src/instance_wrapper.rs @@ -76,27 +76,17 @@ impl EntryPoint { .as_mut() .expect("host state cannot be empty while a function is being called; qed"); - // The logic to print out a backtrace is somewhat complicated, - // so let's get wasmtime to print it out for us. - let mut backtrace_string = trap.to_string(); - let suffix = "\nwasm backtrace:"; - if let Some(index) = backtrace_string.find(suffix) { - // Get rid of the error message and just grab the backtrace, - // since we're storing the error message ourselves separately. - backtrace_string.replace_range(0..index + suffix.len(), ""); - } - - let backtrace = Backtrace { backtrace_string }; - if let Some(error) = host_state.take_panic_message() { - Error::AbortedDueToPanic(MessageWithBacktrace { - message: error, - backtrace: Some(backtrace), - }) + let backtrace = trap.downcast_ref::().map(|backtrace| { + // The logic to print out a backtrace is somewhat complicated, + // so let's get wasmtime to print it out for us. + Backtrace { backtrace_string: backtrace.to_string() } + }); + + if let Some(message) = host_state.take_panic_message() { + Error::AbortedDueToPanic(MessageWithBacktrace { message, backtrace }) } else { - Error::AbortedDueToTrap(MessageWithBacktrace { - message: trap.display_reason().to_string(), - backtrace: Some(backtrace), - }) + let message = trap.root_cause().to_string(); + Error::AbortedDueToTrap(MessageWithBacktrace { message, backtrace }) } }) } @@ -106,7 +96,7 @@ impl EntryPoint { ctx: impl AsContext, ) -> std::result::Result { let entrypoint = func - .typed::<(u32, u32), u64, _>(ctx) + .typed::<(u32, u32), u64>(ctx) .map_err(|_| "Invalid signature for direct entry point")?; Ok(Self { call_type: EntryPointType::Direct { entrypoint } }) } @@ -117,7 +107,7 @@ impl EntryPoint { ctx: impl AsContext, ) -> std::result::Result { let dispatcher = dispatcher - .typed::<(u32, u32, u32), u64, _>(ctx) + .typed::<(u32, u32, u32), u64>(ctx) .map_err(|_| "Invalid signature for wrapped entry point")?; Ok(Self { call_type: EntryPointType::Wrapped { func, dispatcher } }) } diff --git a/client/executor/wasmtime/src/runtime.rs b/client/executor/wasmtime/src/runtime.rs index 0c3fe228f08d5..e54070065274b 100644 --- a/client/executor/wasmtime/src/runtime.rs +++ b/client/executor/wasmtime/src/runtime.rs @@ -366,29 +366,27 @@ fn common_config(semantics: &Semantics) -> std::result::Result String { // We need two limits here since depending on whether the code is compiled in debug // or in release mode the maximum call depth is slightly different. -const CALL_DEPTH_LOWER_LIMIT: usize = 65478; -const CALL_DEPTH_UPPER_LIMIT: usize = 65514; +const CALL_DEPTH_LOWER_LIMIT: usize = 65455; +const CALL_DEPTH_UPPER_LIMIT: usize = 65503; test_wasm_execution!(test_consume_under_1mb_of_stack_does_not_trap); fn test_consume_under_1mb_of_stack_does_not_trap(instantiation_strategy: InstantiationStrategy) { @@ -555,3 +555,34 @@ fn test_instances_without_reuse_are_not_leaked() { instance.call_export("test_empty_return", &[0]).unwrap(); } } + +#[test] +fn test_rustix_version_matches_with_wasmtime() { + let metadata = cargo_metadata::MetadataCommand::new() + .manifest_path("../../../Cargo.toml") + .exec() + .unwrap(); + + let wasmtime_rustix = metadata + .packages + .iter() + .find(|pkg| pkg.name == "wasmtime-runtime") + .unwrap() + .dependencies + .iter() + .find(|dep| dep.name == "rustix") + .unwrap(); + let our_rustix = metadata + .packages + .iter() + .find(|pkg| pkg.name == "sc-executor-wasmtime") + .unwrap() + .dependencies + .iter() + .find(|dep| dep.name == "rustix") + .unwrap(); + + if wasmtime_rustix.req != our_rustix.req { + panic!("our version of rustix ({0}) doesn't match wasmtime's ({1}); bump the version in `sc-executor-wasmtime`'s `Cargo.toml' to '{1}' and try again", our_rustix.req, wasmtime_rustix.req); + } +} diff --git a/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs b/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs index 03da0bed59815..280c13667fde3 100644 --- a/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs +++ b/primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs @@ -371,14 +371,14 @@ fn generate_host_function_implementation( registry.register_static( #crate_::sp_wasm_interface::Function::name(&#struct_name), |mut caller: #crate_::sp_wasm_interface::wasmtime::Caller, #(#ffi_args_prototype),*| - -> std::result::Result<#ffi_return_ty, #crate_::sp_wasm_interface::wasmtime::Trap> + -> std::result::Result<#ffi_return_ty, #crate_::sp_wasm_interface::anyhow::Error> { T::with_function_context(caller, move |__function_context__| { let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { #struct_name::call( __function_context__, #(#ffi_names,)* - ).map_err(#crate_::sp_wasm_interface::wasmtime::Trap::new) + ).map_err(#crate_::sp_wasm_interface::anyhow::Error::msg) })); match result { Ok(result) => result, @@ -391,7 +391,7 @@ fn generate_host_function_implementation( } else { "host code panicked while being called by the runtime".to_owned() }; - return Err(#crate_::sp_wasm_interface::wasmtime::Trap::new(message)); + return Err(#crate_::sp_wasm_interface::anyhow::Error::msg(message)); } } }) diff --git a/primitives/wasm-interface/Cargo.toml b/primitives/wasm-interface/Cargo.toml index 69937e6b05205..5f914ae3aa177 100644 --- a/primitives/wasm-interface/Cargo.toml +++ b/primitives/wasm-interface/Cargo.toml @@ -18,9 +18,11 @@ codec = { package = "parity-scale-codec", version = "3.2.2", default-features = impl-trait-for-tuples = "0.2.2" log = { version = "0.4.17", optional = true } wasmi = { version = "0.13", optional = true } -wasmtime = { version = "1.0.0", default-features = false, optional = true } +wasmtime = { version = "5.0.0", default-features = false, optional = true } +anyhow = { version = "1.0.68", optional = true } sp-std = { version = "5.0.0", default-features = false, path = "../std" } [features] default = [ "std" ] std = [ "codec/std", "log", "sp-std/std", "wasmi", "wasmtime" ] +wasmtime = [ "dep:wasmtime", "anyhow" ] diff --git a/primitives/wasm-interface/src/lib.rs b/primitives/wasm-interface/src/lib.rs index 1ecff5a0ce91e..c06eb43c7268b 100644 --- a/primitives/wasm-interface/src/lib.rs +++ b/primitives/wasm-interface/src/lib.rs @@ -41,6 +41,9 @@ macro_rules! if_wasmtime_is_enabled { if_wasmtime_is_enabled! { // Reexport wasmtime so that its types are accessible from the procedural macro. pub use wasmtime; + + // Wasmtime uses anyhow types but doesn't reexport them. + pub use anyhow; } /// Result type used by traits in this crate. diff --git a/utils/wasm-builder/Cargo.toml b/utils/wasm-builder/Cargo.toml index 84693f5eec049..c1ef006b5a92f 100644 --- a/utils/wasm-builder/Cargo.toml +++ b/utils/wasm-builder/Cargo.toml @@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] ansi_term = "0.12.1" build-helper = "0.1.1" -cargo_metadata = "0.14.2" +cargo_metadata = "0.15.2" strum = { version = "0.24.1", features = ["derive"] } tempfile = "3.1.0" toml = "0.5.4"