Skip to content

Commit

Permalink
Merge pull request #3795 from wasmerio/compile-func-send-sync
Browse files Browse the repository at this point in the history
Make sure the compile function passed to runners is Send+Sync
  • Loading branch information
syrusakbary authored Apr 20, 2023
2 parents 14ae368 + b7632f7 commit f64fc3d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/wasi/src/runners/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub use self::runner::Runner;
use anyhow::Error;
use wasmer::{Engine, Module};

pub type CompileModule = dyn Fn(&Engine, &[u8]) -> Result<Module, Error>;
pub type CompileModule = dyn Fn(&Engine, &[u8]) -> Result<Module, Error> + Send + Sync;

#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct MappedDirectory {
Expand Down
16 changes: 15 additions & 1 deletion lib/wasi/src/runners/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl WasiRunner {
/// Sets the compile function
pub fn with_compile(
mut self,
compile: impl Fn(&Engine, &[u8]) -> Result<Module, Error> + 'static,
compile: impl Fn(&Engine, &[u8]) -> Result<Module, Error> + Send + Sync + 'static,
) -> Self {
self.compile = Some(Box::new(compile));
self
Expand Down Expand Up @@ -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<T: Send>() {}
fn assert_sync<T: Sync>() {}

assert_send::<WasiRunner>();
assert_sync::<WasiRunner>();
}
}
16 changes: 15 additions & 1 deletion lib/wasi/src/runners/wcgi/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl WcgiRunner {
/// Sets the compile function
pub fn with_compile(
mut self,
compile: impl Fn(&Engine, &[u8]) -> Result<Module, Error> + 'static,
compile: impl Fn(&Engine, &[u8]) -> Result<Module, Error> + Send + Sync + 'static,
) -> Self {
self.compile = Some(Arc::new(compile));
self
Expand Down Expand Up @@ -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<T: Send>() {}
fn assert_sync<T: Sync>() {}

assert_send::<WcgiRunner>();
assert_sync::<WcgiRunner>();
}
}

0 comments on commit f64fc3d

Please sign in to comment.