From 8ea42abb14ca4c4bdc9c191d9584786fae1b5416 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Fri, 29 Jan 2021 14:25:29 -0800 Subject: [PATCH] fix wasi-nn and wasi-crypto integrations for wasmtime-wiggle changes the Rc> wrapping inside the wasmtime-generated bindings was eliminated, and instead the caller of ::new(linker, ctx) is required to wrap the ctx in Rc>. The Rc wrapping inside WasiCryptoCtx can be eliminated due to this change. --- crates/wasi-crypto/src/wiggle_interfaces/mod.rs | 15 +-------------- src/commands/run.rs | 10 +++++++--- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/crates/wasi-crypto/src/wiggle_interfaces/mod.rs b/crates/wasi-crypto/src/wiggle_interfaces/mod.rs index 8784a10bd1..4315388855 100644 --- a/crates/wasi-crypto/src/wiggle_interfaces/mod.rs +++ b/crates/wasi-crypto/src/wiggle_interfaces/mod.rs @@ -1,6 +1,6 @@ use std::rc::Rc; -use wasi_crypto::CryptoCtx; +pub use wasi_crypto::CryptoCtx as WasiCryptoCtx; wiggle::from_witx!({ witx: ["$CARGO_MANIFEST_DIR/spec/witx/wasi_ephemeral_crypto.witx"], @@ -17,19 +17,6 @@ pub mod wasi_modules { pub use types as guest_types; -#[derive(Clone)] -pub struct WasiCryptoCtx { - ctx: Rc, -} - -impl WasiCryptoCtx { - pub fn new() -> Self { - WasiCryptoCtx { - ctx: Rc::new(CryptoCtx::new()), - } - } -} - mod asymmetric_common; mod common; mod error; diff --git a/src/commands/run.rs b/src/commands/run.rs index 8011d8cf91..80d3de587c 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -363,17 +363,21 @@ fn populate_with_wasi( #[cfg(feature = "wasi-nn")] { - let wasi_nn = WasiNn::new(linker.store(), WasiNnCtx::new()?); + use std::cell::RefCell; + use std::rc::Rc; + let wasi_nn = WasiNn::new(linker.store(), Rc::new(RefCell::new(WasiNnCtx::new()?))); wasi_nn.add_to_linker(linker)?; } #[cfg(feature = "wasi-crypto")] { - let cx_crypto = WasiCryptoCtx::new(); + use std::cell::RefCell; + use std::rc::Rc; + let cx_crypto = Rc::new(RefCell::new(WasiCryptoCtx::new())); WasiCryptoCommon::new(linker.store(), cx_crypto.clone()).add_to_linker(linker)?; WasiCryptoAsymmetricCommon::new(linker.store(), cx_crypto.clone()).add_to_linker(linker)?; WasiCryptoSignatures::new(linker.store(), cx_crypto.clone()).add_to_linker(linker)?; - WasiCryptoSymmetric::new(linker.store(), cx_crypto.clone()).add_to_linker(linker)?; + WasiCryptoSymmetric::new(linker.store(), cx_crypto).add_to_linker(linker)?; } Ok(())