Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure the compile function passed to runners is Send+Sync #3795

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>();
}
}