Skip to content

Commit

Permalink
Merge branch 'master' into get_namespace_exports
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary authored Oct 12, 2021
2 parents 42c77b9 + 22bedba commit cff5ad9
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 57 deletions.
32 changes: 16 additions & 16 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
benches @syrusakbary
examples @Hywan
examples
fuzz @syrusakbary
lib/api @syrusakbary @Hywan
lib/c-api @Hywan
lib/cache @syrusakbary @Hywan
lib/api @syrusakbary
lib/c-api
lib/cache @syrusakbary
lib/cli @syrusakbary
lib/compiler @syrusakbary @Hywan
lib/compiler @syrusakbary
lib/compiler-cranelift @syrusakbary
lib/compiler-llvm @Hywan
lib/compiler-llvm
lib/compiler-singlepass @syrusakbary
lib/deprecated @Hywan
lib/emscripten @Hywan
lib/engine @syrusakbary @Hywan
lib/engine-jit @syrusakbary @Hywan
lib/engine-native @syrusakbary @Hywan
lib/engine-object-file @syrusakbary @Hywan
lib/deprecated
lib/emscripten
lib/engine @syrusakbary
lib/engine-jit @syrusakbary
lib/engine-native @syrusakbary
lib/engine-object-file @syrusakbary
lib/object @syrusakbary
lib/vm @syrusakbary @Hywan
lib/wasi @Hywan
lib/wasmer-types @syrusakbary @Hywan
lib/vm @syrusakbary
lib/wasi
lib/wasmer-types @syrusakbary
scripts @syrusakbary
tests @Hywan
tests
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Looking for changes that affect our C API? See the [C API Changelog](lib/c-api/C
## **[Unreleased]**

### Added
- [#2535](https://github.com/wasmerio/wasmer/pull/2427) Added iOS support for Wasmer. This relies on the `dylib-engine`.
- [#2574](https://github.com/wasmerio/wasmer/pull/2574) Added Windows support to Singlepass.
- [#2535](https://github.com/wasmerio/wasmer/pull/2435) Added iOS support for Wasmer. This relies on the `dylib-engine`.
- [#2427](https://github.com/wasmerio/wasmer/pull/2427) Wasmer can now compile to Javascript via `wasm-bindgen`. Use the `js-default` (and no default features) feature to try it!.
- [#2436](https://github.com/wasmerio/wasmer/pull/2436) Added the x86-32 bit variant support to LLVM compiler.

Expand Down
12 changes: 12 additions & 0 deletions lib/api/src/js/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pub struct VMMemory {
pub(crate) ty: MemoryType,
}

unsafe impl Send for VMMemory {}
unsafe impl Sync for VMMemory {}

impl VMMemory {
pub(crate) fn new(memory: Memory, ty: MemoryType) -> Self {
Self { memory, ty }
Expand All @@ -34,12 +37,18 @@ impl VMGlobal {
}
}

unsafe impl Send for VMGlobal {}
unsafe impl Sync for VMGlobal {}

#[derive(Clone, Debug, PartialEq)]
pub struct VMTable {
pub(crate) table: Table,
pub(crate) ty: TableType,
}

unsafe impl Send for VMTable {}
unsafe impl Sync for VMTable {}

impl VMTable {
pub(crate) fn new(table: Table, ty: TableType) -> Self {
Self { table, ty }
Expand All @@ -53,6 +62,9 @@ pub struct VMFunction {
pub(crate) environment: Option<Arc<RefCell<Box<dyn WasmerEnv>>>>,
}

unsafe impl Send for VMFunction {}
unsafe impl Sync for VMFunction {}

impl VMFunction {
pub(crate) fn new(
function: Function,
Expand Down
4 changes: 2 additions & 2 deletions lib/api/src/js/import_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub trait LikeNamespace {
/// ```
#[derive(Clone, Default)]
pub struct ImportObject {
map: Arc<Mutex<HashMap<String, Box<dyn LikeNamespace>>>>,
map: Arc<Mutex<HashMap<String, Box<dyn LikeNamespace + Send + Sync>>>>,
}

impl ImportObject {
Expand Down Expand Up @@ -88,7 +88,7 @@ impl ImportObject {
pub fn register<S, N>(&mut self, name: S, namespace: N) -> Option<Box<dyn LikeNamespace>>
where
S: Into<String>,
N: LikeNamespace + 'static,
N: LikeNamespace + Send + Sync + 'static,
{
let mut guard = self.map.lock().unwrap();
let map = guard.borrow_mut();
Expand Down
5 changes: 4 additions & 1 deletion lib/api/src/js/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ impl Instance {
/// Those are, as defined by the spec:
/// * Link errors that happen when plugging the imports into the instance
/// * Runtime errors that happen when running the module `start` function.
pub fn new(module: &Module, resolver: &dyn Resolver) -> Result<Self, InstantiationError> {
pub fn new(
module: &Module,
resolver: &(dyn Resolver + Send + Sync),
) -> Result<Self, InstantiationError> {
let (instance, imports) = module
.instantiate(resolver)
.map_err(|e| InstantiationError::Start(e))?;
Expand Down
32 changes: 16 additions & 16 deletions lib/api/src/js/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl<T: NamedResolver> NamedResolver for &T {
}
}

impl NamedResolver for Box<dyn NamedResolver> {
impl NamedResolver for Box<dyn NamedResolver + Send + Sync> {
fn resolve_by_name(&self, module: &str, field: &str) -> Option<Export> {
(**self).resolve_by_name(module, field)
}
Expand All @@ -75,7 +75,7 @@ impl Resolver for NullResolver {
}

/// A [`Resolver`] that links two resolvers together in a chain.
pub struct NamedResolverChain<A: NamedResolver, B: NamedResolver> {
pub struct NamedResolverChain<A: NamedResolver + Send + Sync, B: NamedResolver + Send + Sync> {
a: A,
b: B,
}
Expand All @@ -85,31 +85,31 @@ pub struct NamedResolverChain<A: NamedResolver, B: NamedResolver> {
/// ```
/// # use wasmer_engine::{ChainableNamedResolver, NamedResolver};
/// # fn chainable_test<A, B>(imports1: A, imports2: B)
/// # where A: NamedResolver + Sized,
/// # B: NamedResolver + Sized,
/// # where A: NamedResolver + Sized + Send + Sync,
/// # B: NamedResolver + Sized + Send + Sync,
/// # {
/// // override duplicates with imports from `imports2`
/// imports1.chain_front(imports2);
/// # }
/// ```
pub trait ChainableNamedResolver: NamedResolver + Sized {
pub trait ChainableNamedResolver: NamedResolver + Sized + Send + Sync {
/// Chain a resolver in front of the current resolver.
///
/// This will cause the second resolver to override the first.
///
/// ```
/// # use wasmer_engine::{ChainableNamedResolver, NamedResolver};
/// # fn chainable_test<A, B>(imports1: A, imports2: B)
/// # where A: NamedResolver + Sized,
/// # B: NamedResolver + Sized,
/// # where A: NamedResolver + Sized + Send + Sync,
/// # B: NamedResolver + Sized + Send + Sync,
/// # {
/// // override duplicates with imports from `imports2`
/// imports1.chain_front(imports2);
/// # }
/// ```
fn chain_front<U>(self, other: U) -> NamedResolverChain<U, Self>
where
U: NamedResolver,
U: NamedResolver + Send + Sync,
{
NamedResolverChain { a: other, b: self }
}
Expand All @@ -121,28 +121,28 @@ pub trait ChainableNamedResolver: NamedResolver + Sized {
/// ```
/// # use wasmer_engine::{ChainableNamedResolver, NamedResolver};
/// # fn chainable_test<A, B>(imports1: A, imports2: B)
/// # where A: NamedResolver + Sized,
/// # B: NamedResolver + Sized,
/// # where A: NamedResolver + Sized + Send + Sync,
/// # B: NamedResolver + Sized + Send + Sync,
/// # {
/// // override duplicates with imports from `imports1`
/// imports1.chain_back(imports2);
/// # }
/// ```
fn chain_back<U>(self, other: U) -> NamedResolverChain<Self, U>
where
U: NamedResolver,
U: NamedResolver + Send + Sync,
{
NamedResolverChain { a: self, b: other }
}
}

// We give these chain methods to all types implementing NamedResolver
impl<T: NamedResolver> ChainableNamedResolver for T {}
impl<T: NamedResolver + Send + Sync> ChainableNamedResolver for T {}

impl<A, B> NamedResolver for NamedResolverChain<A, B>
where
A: NamedResolver,
B: NamedResolver,
A: NamedResolver + Send + Sync,
B: NamedResolver + Send + Sync,
{
fn resolve_by_name(&self, module: &str, field: &str) -> Option<Export> {
self.a
Expand All @@ -153,8 +153,8 @@ where

impl<A, B> Clone for NamedResolverChain<A, B>
where
A: NamedResolver + Clone,
B: NamedResolver + Clone,
A: NamedResolver + Clone + Send + Sync,
B: NamedResolver + Clone + Send + Sync,
{
fn clone(&self) -> Self {
Self {
Expand Down
4 changes: 2 additions & 2 deletions lib/api/src/sys/import_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub trait LikeNamespace {
/// ```
#[derive(Clone, Default)]
pub struct ImportObject {
map: Arc<Mutex<HashMap<String, Box<dyn LikeNamespace>>>>,
map: Arc<Mutex<HashMap<String, Box<dyn LikeNamespace + Send + Sync>>>>,
}

impl ImportObject {
Expand Down Expand Up @@ -94,7 +94,7 @@ impl ImportObject {
pub fn register<S, N>(&mut self, name: S, namespace: N) -> Option<Box<dyn LikeNamespace>>
where
S: Into<String>,
N: LikeNamespace + 'static,
N: LikeNamespace + Send + Sync + 'static,
{
let mut guard = self.map.lock().unwrap();
let map = guard.borrow_mut();
Expand Down
5 changes: 4 additions & 1 deletion lib/api/src/sys/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ impl Instance {
/// Those are, as defined by the spec:
/// * Link errors that happen when plugging the imports into the instance
/// * Runtime errors that happen when running the module `start` function.
pub fn new(module: &Module, resolver: &dyn Resolver) -> Result<Self, InstantiationError> {
pub fn new(
module: &Module,
resolver: &(dyn Resolver + Send + Sync),
) -> Result<Self, InstantiationError> {
let store = module.store();
let handle = module.instantiate(resolver)?;
let exports = module
Expand Down
32 changes: 16 additions & 16 deletions lib/engine/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<T: NamedResolver> NamedResolver for &T {
}
}

impl NamedResolver for Box<dyn NamedResolver> {
impl NamedResolver for Box<dyn NamedResolver + Send + Sync> {
fn resolve_by_name(&self, module: &str, field: &str) -> Option<Export> {
(**self).resolve_by_name(module, field)
}
Expand Down Expand Up @@ -293,7 +293,7 @@ pub fn resolve_imports(
}

/// A [`Resolver`] that links two resolvers together in a chain.
pub struct NamedResolverChain<A: NamedResolver, B: NamedResolver> {
pub struct NamedResolverChain<A: NamedResolver + Send + Sync, B: NamedResolver + Send + Sync> {
a: A,
b: B,
}
Expand All @@ -303,31 +303,31 @@ pub struct NamedResolverChain<A: NamedResolver, B: NamedResolver> {
/// ```
/// # use wasmer_engine::{ChainableNamedResolver, NamedResolver};
/// # fn chainable_test<A, B>(imports1: A, imports2: B)
/// # where A: NamedResolver + Sized,
/// # B: NamedResolver + Sized,
/// # where A: NamedResolver + Sized + Send + Sync,
/// # B: NamedResolver + Sized + Send + Sync,
/// # {
/// // override duplicates with imports from `imports2`
/// imports1.chain_front(imports2);
/// # }
/// ```
pub trait ChainableNamedResolver: NamedResolver + Sized {
pub trait ChainableNamedResolver: NamedResolver + Sized + Send + Sync {
/// Chain a resolver in front of the current resolver.
///
/// This will cause the second resolver to override the first.
///
/// ```
/// # use wasmer_engine::{ChainableNamedResolver, NamedResolver};
/// # fn chainable_test<A, B>(imports1: A, imports2: B)
/// # where A: NamedResolver + Sized,
/// # B: NamedResolver + Sized,
/// # where A: NamedResolver + Sized + Send + Sync,
/// # B: NamedResolver + Sized + Send + Sync,
/// # {
/// // override duplicates with imports from `imports2`
/// imports1.chain_front(imports2);
/// # }
/// ```
fn chain_front<U>(self, other: U) -> NamedResolverChain<U, Self>
where
U: NamedResolver,
U: NamedResolver + Send + Sync,
{
NamedResolverChain { a: other, b: self }
}
Expand All @@ -339,28 +339,28 @@ pub trait ChainableNamedResolver: NamedResolver + Sized {
/// ```
/// # use wasmer_engine::{ChainableNamedResolver, NamedResolver};
/// # fn chainable_test<A, B>(imports1: A, imports2: B)
/// # where A: NamedResolver + Sized,
/// # B: NamedResolver + Sized,
/// # where A: NamedResolver + Sized + Send + Sync,
/// # B: NamedResolver + Sized + Send + Sync,
/// # {
/// // override duplicates with imports from `imports1`
/// imports1.chain_back(imports2);
/// # }
/// ```
fn chain_back<U>(self, other: U) -> NamedResolverChain<Self, U>
where
U: NamedResolver,
U: NamedResolver + Send + Sync,
{
NamedResolverChain { a: self, b: other }
}
}

// We give these chain methods to all types implementing NamedResolver
impl<T: NamedResolver> ChainableNamedResolver for T {}
impl<T: NamedResolver + Send + Sync> ChainableNamedResolver for T {}

impl<A, B> NamedResolver for NamedResolverChain<A, B>
where
A: NamedResolver,
B: NamedResolver,
A: NamedResolver + Send + Sync,
B: NamedResolver + Send + Sync,
{
fn resolve_by_name(&self, module: &str, field: &str) -> Option<Export> {
self.a
Expand All @@ -371,8 +371,8 @@ where

impl<A, B> Clone for NamedResolverChain<A, B>
where
A: NamedResolver + Clone,
B: NamedResolver + Clone,
A: NamedResolver + Clone + Send + Sync,
B: NamedResolver + Clone + Send + Sync,
{
fn clone(&self) -> Self {
Self {
Expand Down
1 change: 1 addition & 0 deletions lib/wasi-experimental-io-devices/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ maintenance = { status = "experimental" }
wasmer-wasi = { version = "2.0.0", path = "../wasi", default-features=false }
tracing = "0.1"
minifb = "0.19"
nix = "0.20.2"
ref_thread_local = "0.1"
serde = "1"
typetag = "0.1"
Expand Down
5 changes: 3 additions & 2 deletions lib/wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ impl WasiEnv {
pub fn import_object_for_all_wasi_versions(
&mut self,
module: &Module,
) -> Result<Box<dyn NamedResolver>, WasiError> {
) -> Result<Box<dyn NamedResolver + Send + Sync>, WasiError> {
let wasi_versions =
get_wasi_versions(module, false).ok_or(WasiError::UnknownWasiVersion)?;

let mut resolver: Box<dyn NamedResolver> = { Box::new(()) };
let mut resolver: Box<dyn NamedResolver + Send + Sync> =
{ Box::new(()) as Box<dyn NamedResolver + Send + Sync> };
for version in wasi_versions.iter() {
let new_import_object =
generate_import_object_from_env(module.store(), self.clone(), *version);
Expand Down
Binary file modified tests/wasi-wast/wasi/snapshot1/fd_rename_path.wasm
Binary file not shown.

0 comments on commit cff5ad9

Please sign in to comment.