Skip to content

Commit

Permalink
Merge branch 'master' into ventuzelo/fix-653-panic-memorydescriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
pventuzelo authored Sep 24, 2019
2 parents 79ff370 + 6792db9 commit ac32184
Show file tree
Hide file tree
Showing 56 changed files with 850 additions and 517 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ links to related issues, and the context of the PR.

# Review

- [ ] Create a short description of the the change in the CHANGELOG.md file
- [ ] Add a short description of the the change to the CHANGELOG.md file
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ Blocks of changes will separated by version increments.

## **[Unreleased]**

- [#829](https://github.com/wasmerio/wasmer/pull/829) Fix deps on `make bench-*` commands; benchmarks don't compile other backends now
- [#807](https://github.com/wasmerio/wasmer/pull/807) Implement Send for `Instance`, breaking change on `ImportObject`, remove method `get_namespace` replaced with `with_namespace` and `maybe_with_namespace`
- [#817](https://github.com/wasmerio/wasmer/pull/817) Add document for tracking features across backends and language integrations, [docs/feature_matrix.md]
- [#823](https://github.com/wasmerio/wasmer/issues/823) Improved Emscripten / WASI integration
- [#821](https://github.com/wasmerio/wasmer/issues/821) Remove patch version on most deps Cargo manifests. This gives Wasmer library users more control over which versions of the deps they use.
- [#820](https://github.com/wasmerio/wasmer/issues/820) Remove null-pointer checks in `WasmPtr` from runtime-core, re-add them in Emscripten
- [#803](https://github.com/wasmerio/wasmer/issues/803) Add method to `Ctx` to invoke functions by their `TableIndex`
- [#790](https://github.com/wasmerio/wasmer/pull/790) Fix flaky test failure with LLVM, switch to large code model.
- [#788](https://github.com/wasmerio/wasmer/pull/788) Use union merge on the changelog file.
- [#785](https://github.com/wasmerio/wasmer/pull/785) Include Apache license file for spectests.
Expand Down
153 changes: 42 additions & 111 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ include = [
]

[dependencies]
byteorder = "1.3.2"
errno = "0.2.4"
structopt = "0.3.0"
byteorder = "1.3"
errno = "0.2"
structopt = "0.3"
wabt = "0.9.1"
wasmer-clif-backend = { path = "lib/clif-backend" }
wasmer-singlepass-backend = { path = "lib/singlepass-backend", optional = true }
Expand Down Expand Up @@ -58,13 +58,13 @@ members = [
"lib/wasi-tests",
"lib/emscripten-tests",
"lib/middleware-common-tests",
"examples/plugin-for-example"
"examples/plugin-for-example",
]

[build-dependencies]
wabt = "0.9.1"
glob = "0.3.0"
rustc_version = "0.2.3"
glob = "0.3"
rustc_version = "0.2"

[dev-dependencies]
serde = { version = "1", features = ["derive"] } # used by the plugin example
Expand Down Expand Up @@ -105,3 +105,7 @@ managed = ["backend-singlepass", "wasmer-runtime-core/managed"]
[[example]]
name = "plugin"
crate-type = ["bin"]

[[example]]
name = "callback"
crate-type = ["bin"]
36 changes: 26 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
.PHONY: spectests emtests clean build install lint precommit docs
.PHONY: spectests emtests clean build install lint precommit docs examples

# Generate files
generate-spectests:
WASMER_RUNTIME_GENERATE_SPECTESTS=1 cargo build -p wasmer-runtime-core --release
WASMER_RUNTIME_GENERATE_SPECTESTS=1 cargo build -p wasmer-runtime-core --release \
&& echo "formatting" \
&& cargo fmt

generate-emtests:
WASM_EMSCRIPTEN_GENERATE_EMTESTS=1 cargo build -p wasmer-emscripten-tests --release
WASM_EMSCRIPTEN_GENERATE_EMTESTS=1 cargo build -p wasmer-emscripten-tests --release \
&& echo "formatting" \
&& cargo fmt

generate-wasitests: wasitests-setup
WASM_WASI_GENERATE_WASITESTS=1 cargo build -p wasmer-wasi-tests --release -vv \
Expand Down Expand Up @@ -111,12 +115,16 @@ test: spectests emtests middleware wasitests circleci-clean test-rest


# Integration tests
integration-tests: release-clif
integration-tests: release-clif examples
echo "Running Integration Tests"
./integration_tests/lua/test.sh
./integration_tests/nginx/test.sh
./integration_tests/cowsay/test.sh

examples:
cargo run --example plugin
cargo run --example callback


# Utils
lint:
Expand All @@ -132,11 +140,15 @@ install:

# Checks
check-bench-singlepass:
cargo bench --all --no-run --no-default-features --features "backend-singlepass"
cargo bench --all --no-run --no-default-features --features "backend-singlepass" \
--exclude wasmer-clif-backend --exclude wasmer-llvm-backend --exclude wasmer-kernel-loader
check-bench-clif:
cargo bench --all --no-run --no-default-features --features "backend-cranelift"
cargo bench --all --no-run --no-default-features --features "backend-cranelift" \
--exclude wasmer-singlepass-backend --exclude wasmer-llvm-backend --exclude wasmer-kernel-loader \
--exclude wasmer-middleware-common-tests
check-bench-llvm:
cargo bench --all --no-run --no-default-features --features "backend-llvm"
cargo bench --all --no-run --no-default-features --features "backend-llvm" \
--exclude wasmer-singlepass-backend --exclude wasmer-clif-backend --exclude wasmer-kernel-loader

check-bench: check-bench-singlepass check-bench-llvm

Expand All @@ -160,11 +172,15 @@ release-llvm:
cargo build --release --features backend-llvm

bench-singlepass:
cargo bench --all --no-default-features --features "backend-singlepass"
cargo bench --all --no-default-features --features "backend-singlepass" \
--exclude wasmer-clif-backend --exclude wasmer-llvm-backend --exclude wasmer-kernel-loader
bench-clif:
cargo bench --all --no-default-features --features "backend-cranelift"
cargo bench --all --no-default-features --features "backend-cranelift" \
--exclude wasmer-singlepass-backend --exclude wasmer-llvm-backend --exclude wasmer-kernel-loader \
--exclude wasmer-middleware-common-tests
bench-llvm:
cargo bench --all --no-default-features --features "backend-llvm"
cargo bench --all --no-default-features --features "backend-llvm" \
--exclude wasmer-singlepass-backend --exclude wasmer-clif-backend --exclude wasmer-kernel-loader

# Build utils
build-install:
Expand Down
26 changes: 26 additions & 0 deletions docs/feature_matrix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Feature Table

## Compiler Backend

|   | Singlepass | Cranelift | LLVM |
| - | - | - | - |
| Caching ||||
| Emscripten ||||
| Metering ||||
| Multi-value return ||||
| OSR | 🚧 |||
| SIMD ||||
| WASI ||||


## Language integration

TODO: define a set of features that are relevant and mark them here

Current ideas:

- WASI FS API
- Callbacks
- Exiting early in hostcall
- Metering
- Caching
5 changes: 5 additions & 0 deletions examples/callback-guest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Call back guest

This is part of the `callback` example. This Wasm module passes host imports and its own functions to the Wasm host to execute.

See `examples/callback.rs` for the host
24 changes: 24 additions & 0 deletions examples/callback-guest/callback-guest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
extern "C" {
fn call_guest_fn(f: u32) -> u32;
fn call_guest_fn2(f: u32) -> u32;
fn host_callback() -> u32;
}

#[no_mangle]
fn test_callback() -> u32 {
42
}

#[no_mangle]
fn test_callback2() -> u32 {
45
}

fn main() {
unsafe { call_guest_fn(test_callback as usize as u32) };
unsafe { call_guest_fn(host_callback as usize as u32) };
unsafe { call_guest_fn(test_callback2 as usize as u32) };
unsafe { call_guest_fn2(test_callback2 as usize as u32) };
unsafe { call_guest_fn2(test_callback as usize as u32) };
unsafe { call_guest_fn2(host_callback as usize as u32) };
}
Binary file added examples/callback-guest/callback-guest.wasm
Binary file not shown.
46 changes: 46 additions & 0 deletions examples/callback.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/// This example demonstrates the use of callbacks: calling functions (Host and Wasm)
/// passed to us from the Wasm via hostcall
use wasmer_runtime::{compile_with, compiler_for_backend, func, imports, Backend, Ctx};
use wasmer_runtime_core::{structures::TypedIndex, types::TableIndex};

static WASM: &'static str = "examples/callback-guest/callback-guest.wasm";

/// This function matches our arbitrarily decided callback signature
/// in this example we'll only call functions that take no arguments and return one value
fn host_callback(_ctx: &mut Ctx) -> u32 {
55
}

fn call_guest_fn(ctx: &mut Ctx, guest_fn: u32) -> u32 {
// We get a TableIndex from our raw value passed in
let guest_fn_typed = TableIndex::new(guest_fn as usize);
// and use it to call the corresponding function
let result = ctx.call_with_table_index(guest_fn_typed, &[]).unwrap();

println!("Guest fn {} returned {:?}", guest_fn, result);

0
}

fn main() {
let wasm_bytes =
std::fs::read(WASM).expect(&format!("Could not read in WASM plugin at {}", WASM));

let imports = imports! {
"env" => {
"call_guest_fn" => func!(call_guest_fn),
"call_guest_fn2" => func!(call_guest_fn),
"host_callback" => func!(host_callback),
},
};

let compiler = compiler_for_backend(Backend::default()).unwrap();
let module = compile_with(&wasm_bytes[..], compiler.as_ref()).unwrap();
let instance = module
.instantiate(&imports)
.expect("failed to instantiate wasm module");

let entry_point = instance.func::<(u32, u32), u32>("main").unwrap();

entry_point.call(0, 0).expect("START");
}
16 changes: 8 additions & 8 deletions lib/clif-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ cranelift-codegen = { version = "0.31" }
cranelift-entity = { version = "0.31" }
cranelift-frontend = { package = "wasmer-clif-fork-frontend", version = "0.33" }
cranelift-wasm = { package = "wasmer-clif-fork-wasm", version = "0.33" }
target-lexicon = "0.4.0"
target-lexicon = "0.4"
wasmparser = "0.35.1"
byteorder = "1.3.2"
nix = "0.15.0"
byteorder = "1.3"
nix = "0.15"
libc = "0.2.60"
rayon = "1.1.0"
rayon = "1.1"

# Dependencies for caching.
[dependencies.serde]
version = "1.0.99"
version = "1.0"
features = ["rc"]
[dependencies.serde_derive]
version = "1.0.98"
version = "1.0"
[dependencies.serde_bytes]
version = "0.11.2"
version = "0.11"
[dependencies.serde-bench]
version = "0.0.7"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.8", features = ["errhandlingapi", "minwindef", "minwinbase", "winnt"] }
winapi = { version = "0.3", features = ["errhandlingapi", "minwindef", "minwinbase", "winnt"] }
wasmer-win-exception-handler = { path = "../win-exception-handler", version = "0.7.0" }

[features]
Expand Down
2 changes: 1 addition & 1 deletion lib/emscripten-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ wabt = "0.9.1"
wasmer-dev-utils = { path = "../dev-utils", version = "0.7.0"}

[build-dependencies]
glob = "0.3.0"
glob = "0.3"

[features]
clif = []
Expand Down
8 changes: 4 additions & 4 deletions lib/emscripten/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ repository = "https://github.com/wasmerio/wasmer"
edition = "2018"

[dependencies]
byteorder = "1.3.2"
lazy_static = "1.4.0"
byteorder = "1.3"
lazy_static = "1.4"
libc = "0.2.60"
time = "0.1.42"
time = "0.1"
wasmer-runtime-core = { path = "../runtime-core", version = "0.7.0" }

[target.'cfg(windows)'.dependencies]
rand = "0.7.0"
rand = "0.7"

[features]
debug = ["wasmer-runtime-core/debug"]
12 changes: 6 additions & 6 deletions lib/emscripten/src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ pub use self::windows::*;

use libc::c_char;

use crate::{allocate_on_stack, EmscriptenData};
use crate::{
allocate_on_stack,
ptr::{Array, WasmPtr},
EmscriptenData,
};

use std::os::raw::c_int;
use wasmer_runtime_core::{
memory::ptr::{Array, WasmPtr},
types::ValueType,
vm::Ctx,
};
use wasmer_runtime_core::{types::ValueType, vm::Ctx};

pub fn call_malloc(ctx: &mut Ctx, size: u32) -> u32 {
get_emscripten_data(ctx)
Expand Down
6 changes: 2 additions & 4 deletions lib/emscripten/src/env/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ use std::mem;
use std::os::raw::c_char;

use crate::env::{call_malloc, call_malloc_with_cast, EmAddrInfo, EmSockAddr};
use crate::ptr::{Array, WasmPtr};
use crate::utils::{copy_cstr_into_wasm, copy_terminated_array_of_cstrs};
use wasmer_runtime_core::{
memory::ptr::{Array, WasmPtr},
vm::Ctx,
};
use wasmer_runtime_core::vm::Ctx;

// #[no_mangle]
/// emscripten: _getenv // (name: *const char) -> *const c_char;
Expand Down
3 changes: 2 additions & 1 deletion lib/emscripten/src/env/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use std::mem;
use std::os::raw::c_char;

use crate::env::{call_malloc, EmAddrInfo};
use crate::ptr::WasmPtr;
use crate::utils::{copy_cstr_into_wasm, read_string_from_wasm};
use wasmer_runtime_core::{memory::ptr::WasmPtr, vm::Ctx};
use wasmer_runtime_core::vm::Ctx;

extern "C" {
#[link_name = "_putenv"]
Expand Down
7 changes: 6 additions & 1 deletion lib/emscripten/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ mod math;
mod memory;
mod process;
mod pthread;
mod ptr;
mod signal;
mod storage;
mod syscalls;
Expand Down Expand Up @@ -730,8 +731,9 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"___syscall345" => func!(crate::syscalls::___syscall345),

// Process
"abort" => func!(crate::process::em_abort),
"abort" => func!(crate::process::_abort),
"_abort" => func!(crate::process::_abort),
"_prctl" => func!(crate::process::_prctl),
"abortStackOverflow" => func!(crate::process::abort_stack_overflow),
"_llvm_trap" => func!(crate::process::_llvm_trap),
"_fork" => func!(crate::process::_fork),
Expand Down Expand Up @@ -824,6 +826,9 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"_gmtime" => func!(crate::time::_gmtime),

// Math
"sqrt" => func!(crate::math::sqrt),
"floor" => func!(crate::math::floor),
"fabs" => func!(crate::math::fabs),
"f64-rem" => func!(crate::math::f64_rem),
"_llvm_copysign_f32" => func!(crate::math::_llvm_copysign_f32),
"_llvm_copysign_f64" => func!(crate::math::_llvm_copysign_f64),
Expand Down
15 changes: 15 additions & 0 deletions lib/emscripten/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ pub fn log(_ctx: &mut Ctx, value: f64) -> f64 {
value.ln()
}

// emscripten: global.Math sqrt
pub fn sqrt(_ctx: &mut Ctx, value: f64) -> f64 {
value.sqrt()
}

// emscripten: global.Math floor
pub fn floor(_ctx: &mut Ctx, value: f64) -> f64 {
value.floor()
}

// emscripten: global.Math fabs
pub fn fabs(_ctx: &mut Ctx, value: f64) -> f64 {
value.abs()
}

// emscripten: asm2wasm.f64-to-int
pub fn f64_to_int(_ctx: &mut Ctx, value: f64) -> i32 {
debug!("emscripten::f64_to_int {}", value);
Expand Down
Loading

0 comments on commit ac32184

Please sign in to comment.