From b7632f7b60f67cb9e2155d5ddb8e63af498174e9 Mon Sep 17 00:00:00 2001 From: Michael-F-Bryan Date: Thu, 20 Apr 2023 15:37:53 +0800 Subject: [PATCH] Make sure the compile function passed to runners is Send+Sync --- lib/wasi/src/runners/mod.rs | 2 +- lib/wasi/src/runners/wasi.rs | 16 +++++++++++++++- lib/wasi/src/runners/wcgi/runner.rs | 16 +++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/wasi/src/runners/mod.rs b/lib/wasi/src/runners/mod.rs index ae12493aab6..3aca293256e 100644 --- a/lib/wasi/src/runners/mod.rs +++ b/lib/wasi/src/runners/mod.rs @@ -14,7 +14,7 @@ pub use self::runner::Runner; use anyhow::Error; use wasmer::{Engine, Module}; -pub type CompileModule = dyn Fn(&Engine, &[u8]) -> Result; +pub type CompileModule = dyn Fn(&Engine, &[u8]) -> Result + Send + Sync; #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] pub struct MappedDirectory { diff --git a/lib/wasi/src/runners/wasi.rs b/lib/wasi/src/runners/wasi.rs index 59f65231bf9..0c4d08f70d4 100644 --- a/lib/wasi/src/runners/wasi.rs +++ b/lib/wasi/src/runners/wasi.rs @@ -41,7 +41,7 @@ impl WasiRunner { /// Sets the compile function pub fn with_compile( mut self, - compile: impl Fn(&Engine, &[u8]) -> Result + 'static, + compile: impl Fn(&Engine, &[u8]) -> Result + Send + Sync + 'static, ) -> Self { self.compile = Some(Box::new(compile)); self @@ -190,3 +190,17 @@ impl crate::runners::Runner for WasiRunner { Ok(()) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn send_and_sync() { + fn assert_send() {} + fn assert_sync() {} + + assert_send::(); + assert_sync::(); + } +} diff --git a/lib/wasi/src/runners/wcgi/runner.rs b/lib/wasi/src/runners/wcgi/runner.rs index beb3a25b9b6..b75c733946b 100644 --- a/lib/wasi/src/runners/wcgi/runner.rs +++ b/lib/wasi/src/runners/wcgi/runner.rs @@ -120,7 +120,7 @@ impl WcgiRunner { /// Sets the compile function pub fn with_compile( mut self, - compile: impl Fn(&Engine, &[u8]) -> Result + 'static, + compile: impl Fn(&Engine, &[u8]) -> Result + Send + Sync + 'static, ) -> Self { self.compile = Some(Arc::new(compile)); self @@ -374,3 +374,17 @@ pub trait Callbacks: Send + Sync + 'static { struct NoopCallbacks; impl Callbacks for NoopCallbacks {} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn send_and_sync() { + fn assert_send() {} + fn assert_sync() {} + + assert_send::(); + assert_sync::(); + } +}