Merge branch 'master' into feature/emscripten-in-c-api

This commit is contained in:
Mark McCaskey
2019-12-16 13:50:12 -08:00
committed by GitHub
14 changed files with 106 additions and 23 deletions

View File

@ -31,18 +31,21 @@ steps:
- bash: | - bash: |
set -ex set -ex
curl -OL https://github.com/wasmerio/windows-llvm-build/releases/download/v8.0.0/llvm-8.0.0-install.zip mkdir Win64_Release
7z x llvm-8.0.0-install.zip cd Win64_Release
llvm=`pwd`/llvm-8.0.0-install curl -OL https://github.com/wasmerio/llvm-build/releases/download/8.x/Win64_Release.zip
7z x Win64_Release.zip
llvm=`pwd`
echo "##vso[task.prependpath]$llvm/bin" echo "##vso[task.prependpath]$llvm/bin"
echo "##vso[task.setvariable variable=LLVM_SYS_80_PREFIX;]$llvm" echo "##vso[task.setvariable variable=LLVM_SYS_80_PREFIX;]$llvm"
cd ..
displayName: "Install LLVM (Windows)" displayName: "Install LLVM (Windows)"
condition: eq(variables['Agent.OS'], 'Windows_NT') condition: eq(variables['Agent.OS'], 'Windows_NT')
# Just to make sure the paths and vars are set properly # Just to make sure the paths and vars are set properly
- powershell: | - powershell: |
Write-Host "##vso[task.prependpath]$pwd/llvm-8.0.0-install/bin" Write-Host "##vso[task.prependpath]$pwd/Win64_Release/bin"
Write-Host "##vso[task.setvariable variable=LLVM_SYS_80_PREFIX;]$pwd/llvm-8.0.0-install/" Write-Host "##vso[task.setvariable variable=LLVM_SYS_80_PREFIX;]$pwd/Win64_Release/"
displayName: Install LLVM (Windows) displayName: Install LLVM (Windows)
condition: eq(variables['Agent.OS'], 'Windows_NT') condition: eq(variables['Agent.OS'], 'Windows_NT')

View File

@ -2,6 +2,7 @@
## **[Unreleased]** ## **[Unreleased]**
- [#1060](https://github.com/wasmerio/wasmer/pull/1060) Test the capi with all the backends
- [#1058](https://github.com/wasmerio/wasmer/pull/1058) Fix minor panic issue when `wasmer::compile_with` called with llvm backend. - [#1058](https://github.com/wasmerio/wasmer/pull/1058) Fix minor panic issue when `wasmer::compile_with` called with llvm backend.
- [#858](https://github.com/wasmerio/wasmer/pull/858) Minor panic fix when wasmer binary with `loader` option run a module without exported `_start` function. - [#858](https://github.com/wasmerio/wasmer/pull/858) Minor panic fix when wasmer binary with `loader` option run a module without exported `_start` function.
- [#1056](https://github.com/wasmerio/wasmer/pull/1056) Improved `--invoke` args parsing (supporting `i32`, `i64`, `f32` and `f32`) in Wasmer CLI - [#1056](https://github.com/wasmerio/wasmer/pull/1056) Improved `--invoke` args parsing (supporting `i32`, `i64`, `f32` and `f32`) in Wasmer CLI
@ -10,6 +11,7 @@
- [#1052](https://github.com/wasmerio/wasmer/pull/1052) Fix minor panic and improve Error handling in singlepass backend. - [#1052](https://github.com/wasmerio/wasmer/pull/1052) Fix minor panic and improve Error handling in singlepass backend.
- [#1050](https://github.com/wasmerio/wasmer/pull/1050) Attach C & C++ headers to releases. - [#1050](https://github.com/wasmerio/wasmer/pull/1050) Attach C & C++ headers to releases.
- [#1033](https://github.com/wasmerio/wasmer/pull/1033) Set cranelift backend as default compiler backend again, require at least one backend to be enabled for Wasmer CLI - [#1033](https://github.com/wasmerio/wasmer/pull/1033) Set cranelift backend as default compiler backend again, require at least one backend to be enabled for Wasmer CLI
- [#1044](https://github.com/wasmerio/wasmer/pull/1044) Enable AArch64 support in the LLVM backend.
- [#1030](https://github.com/wasmerio/wasmer/pull/1030) Ability to generate `ImportObject` for a specific version WASI version with the C API. - [#1030](https://github.com/wasmerio/wasmer/pull/1030) Ability to generate `ImportObject` for a specific version WASI version with the C API.
- [#1028](https://github.com/wasmerio/wasmer/pull/1028) Introduce strict/non-strict modes for `get_wasi_version` - [#1028](https://github.com/wasmerio/wasmer/pull/1028) Introduce strict/non-strict modes for `get_wasi_version`
- [#1029](https://github.com/wasmerio/wasmer/pull/1029) Add the “floating” `WasiVersion::Latest` version. - [#1029](https://github.com/wasmerio/wasmer/pull/1029) Add the “floating” `WasiVersion::Latest` version.

View File

@ -89,7 +89,7 @@ wasitests: wasitests-unit wasitests-singlepass wasitests-cranelift wasitests-llv
# Backends # Backends
singlepass: spectests-singlepass emtests-singlepass middleware-singlepass wasitests-singlepass singlepass: spectests-singlepass emtests-singlepass middleware-singlepass wasitests-singlepass
cargo test -p wasmer-singlepass-backend --release cargo test -p wasmer-singlepass-backend --release
cargo test -p wasmer-runtime-core-tests --release --no-default-features --features backend-singlepass cargo test --manifest-path lib/runtime-core-tests/Cargo.toml --release --no-default-features --features backend-singlepass
cranelift: spectests-cranelift emtests-cranelift middleware-cranelift wasitests-cranelift cranelift: spectests-cranelift emtests-cranelift middleware-cranelift wasitests-cranelift
cargo test -p wasmer-clif-backend --release cargo test -p wasmer-clif-backend --release
@ -98,16 +98,38 @@ cranelift: spectests-cranelift emtests-cranelift middleware-cranelift wasitests-
llvm: spectests-llvm emtests-llvm wasitests-llvm llvm: spectests-llvm emtests-llvm wasitests-llvm
cargo test -p wasmer-llvm-backend --release cargo test -p wasmer-llvm-backend --release
cargo test -p wasmer-llvm-backend-tests --release cargo test -p wasmer-llvm-backend-tests --release
cargo test -p wasmer-runtime-core-tests --release --no-default-features --features backend-llvm cargo test --manifest-path lib/runtime-core-tests/Cargo.toml --release --no-default-features --features backend-llvm
# All tests # All tests
capi: capi-singlepass:
cargo build --release --features backend-cranelift cargo build --manifest-path lib/runtime-c-api/Cargo.toml --release \
cargo build -p wasmer-runtime-c-api --release --no-default-features --features singlepass-backend,wasi
test-capi: capi capi-cranelift:
cargo test -p wasmer-runtime-c-api --release cargo build --manifest-path lib/runtime-c-api/Cargo.toml --release \
--no-default-features --features cranelift-backend,wasi
capi-llvm:
cargo build --manifest-path lib/runtime-c-api/Cargo.toml --release \
--no-default-features --features llvm-backend,wasi
# We use cranelift as the default backend for the capi for now
capi: capi-cranelift
test-capi-singlepass: capi-singlepass
cargo test --manifest-path lib/runtime-c-api/Cargo.toml --release \
--no-default-features --features singlepass-backend,wasi
test-capi-cranelift: capi-cranelift
cargo test --manifest-path lib/runtime-c-api/Cargo.toml --release \
--no-default-features --features cranelift-backend,wasi
test-capi-llvm: capi-llvm
cargo test --manifest-path lib/runtime-c-api/Cargo.toml --release \
--no-default-features --features llvm-backend,wasi
test-capi: test-capi-singlepass test-capi-cranelift test-capi-llvm
capi-test: test-capi capi-test: test-capi

View File

@ -180,30 +180,30 @@ jobs:
- checkout: self - checkout: self
submodules: true submodules: true
- template: .azure/install-rust.yml - template: .azure/install-rust.yml
# - template: .azure/install-llvm.yml - template: .azure/install-llvm.yml
- template: .azure/install-sccache.yml - template: .azure/install-sccache.yml
- template: .azure/install-cmake.yml - template: .azure/install-cmake.yml
- bash: | - bash: |
mkdir -p artifacts mkdir -p artifacts
displayName: Create Artifacts Dir displayName: Create Artifacts Dir
- bash: | - bash: |
make capi
make test-capi make test-capi
displayName: Test c-api
condition: and(succeeded(), not(eq(variables['Agent.OS'], 'Windows_NT')))
- bash: |
make capi
cp target/release/libwasmer_runtime_c_api.so ./artifacts cp target/release/libwasmer_runtime_c_api.so ./artifacts
find target/release/build -name 'wasmer.h*' -exec cp {} ./artifacts ';' find target/release/build -name 'wasmer.h*' -exec cp {} ./artifacts ';'
displayName: Build c-api (Linux) displayName: Build c-api (Linux)
condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux')) condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux'))
- bash: | - bash: |
make capi make capi
make test-capi
install_name_tool -id "@rpath/libwasmer_runtime_c_api.dylib" target/release/libwasmer_runtime_c_api.dylib install_name_tool -id "@rpath/libwasmer_runtime_c_api.dylib" target/release/libwasmer_runtime_c_api.dylib
cp target/release/libwasmer_runtime_c_api.dylib ./artifacts cp target/release/libwasmer_runtime_c_api.dylib ./artifacts
displayName: Build c-api (Darwin) displayName: Build c-api (Darwin)
condition: and(succeeded(), eq(variables['Agent.OS'], 'Darwin')) condition: and(succeeded(), eq(variables['Agent.OS'], 'Darwin'))
- bash: | - bash: |
make capi make capi
# Tests are failing on Windows, comment for now
# make test-capi
cp target/release/wasmer_runtime_c_api.dll ./artifacts cp target/release/wasmer_runtime_c_api.dll ./artifacts
displayName: Build c-api (Windows) displayName: Build c-api (Windows)
condition: and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT')) condition: and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT'))

View File

@ -32,6 +32,7 @@ pub fn ___cxa_rethrow_primary_exception(_ctx: &mut Ctx, _a: u32) {
/// TODO: We don't have support for exceptions yet /// TODO: We don't have support for exceptions yet
pub fn ___cxa_throw(ctx: &mut Ctx, _ptr: u32, _ty: u32, _destructor: u32) { pub fn ___cxa_throw(ctx: &mut Ctx, _ptr: u32, _ty: u32, _destructor: u32) {
debug!("emscripten::___cxa_throw"); debug!("emscripten::___cxa_throw");
eprintln!("Throwing exceptions not yet implemented: aborting!");
_abort(ctx); _abort(ctx);
} }

View File

@ -752,7 +752,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"___syscall345" => func!(crate::syscalls::___syscall345), "___syscall345" => func!(crate::syscalls::___syscall345),
// Process // Process
"abort" => func!(crate::process::_abort), "abort" => func!(crate::process::em_abort),
"_abort" => func!(crate::process::_abort), "_abort" => func!(crate::process::_abort),
"_prctl" => func!(crate::process::_prctl), "_prctl" => func!(crate::process::_prctl),
"abortStackOverflow" => func!(crate::process::abort_stack_overflow), "abortStackOverflow" => func!(crate::process::abort_stack_overflow),

View File

@ -13,6 +13,13 @@ pub fn abort_with_message(ctx: &mut Ctx, message: &str) {
_abort(ctx); _abort(ctx);
} }
/// The name of this call is `abort` but we want to avoid conflicts with libc::abort
pub fn em_abort(ctx: &mut Ctx, arg: u32) {
debug!("emscripten::abort");
eprintln!("Program aborted with value {}", arg);
_abort(ctx);
}
pub fn _abort(_ctx: &mut Ctx) { pub fn _abort(_ctx: &mut Ctx) {
debug!("emscripten::_abort"); debug!("emscripten::_abort");
unsafe { unsafe {

View File

@ -17,12 +17,18 @@ goblin = "0.0.24"
libc = "0.2.60" libc = "0.2.60"
byteorder = "1" byteorder = "1"
[dependencies.inkwell] [target.'cfg(target_arch = "x86_64")'.dependencies.inkwell]
git = "https://github.com/TheDan64/inkwell" git = "https://github.com/TheDan64/inkwell"
rev = "781620e9fa30e51a6e03bd0d49b5f5bb7a782520" rev = "781620e9fa30e51a6e03bd0d49b5f5bb7a782520"
default-features = false default-features = false
features = ["llvm8-0", "target-x86"] features = ["llvm8-0", "target-x86"]
[target.'cfg(target_arch = "aarch64")'.dependencies.inkwell]
git = "https://github.com/TheDan64/inkwell"
rev = "781620e9fa30e51a6e03bd0d49b5f5bb7a782520"
default-features = false
features = ["llvm8-0", "target-aarch64"]
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]
nix = "0.15" nix = "0.15"

View File

@ -8465,6 +8465,7 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
let triple = triple.unwrap_or(TargetMachine::get_default_triple().to_string()); let triple = triple.unwrap_or(TargetMachine::get_default_triple().to_string());
match triple { match triple {
#[cfg(target_arch = "x86_64")]
_ if triple.starts_with("x86") => Target::initialize_x86(&InitializationConfig { _ if triple.starts_with("x86") => Target::initialize_x86(&InitializationConfig {
asm_parser: true, asm_parser: true,
asm_printer: true, asm_printer: true,
@ -8473,7 +8474,18 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
info: true, info: true,
machine_code: true, machine_code: true,
}), }),
_ => unimplemented!("compile to target other than x86-64 is not supported"), #[cfg(target_arch = "aarch64")]
_ if triple.starts_with("aarch64") => {
Target::initialize_aarch64(&InitializationConfig {
asm_parser: true,
asm_printer: true,
base: true,
disassembler: true,
info: true,
machine_code: true,
})
}
_ => unimplemented!("target {} not supported", triple),
} }
let target = Target::from_triple(&triple).unwrap(); let target = Target::from_triple(&triple).unwrap();

View File

@ -6,7 +6,10 @@
unused_unsafe, unused_unsafe,
unreachable_patterns unreachable_patterns
)] )]
#![cfg_attr(not(target_os = "windows"), deny(dead_code))] #![cfg_attr(
all(not(target_os = "windows"), not(target_arch = "aarch64")),
deny(dead_code)
)]
#![cfg_attr(nightly, feature(unwind_attributes))] #![cfg_attr(nightly, feature(unwind_attributes))]
#![doc(html_favicon_url = "https://wasmer.io/static/icons/favicon.ico")] #![doc(html_favicon_url = "https://wasmer.io/static/icons/favicon.ico")]
#![doc(html_logo_url = "https://avatars3.githubusercontent.com/u/44205449?s=200&v=4")] #![doc(html_logo_url = "https://avatars3.githubusercontent.com/u/44205449?s=200&v=4")]

View File

@ -40,9 +40,9 @@ optional = true
[features] [features]
default = ["cranelift-backend", "wasi"] default = ["cranelift-backend", "wasi"]
debug = ["wasmer-runtime/debug"] debug = ["wasmer-runtime/debug"]
singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass"]
cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift"] cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift"]
llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm"] llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm"]
singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass"]
wasi = ["wasmer-wasi"] wasi = ["wasmer-wasi"]
emscripten = ["wasmer-emscripten"] emscripten = ["wasmer-emscripten"]

View File

@ -273,6 +273,11 @@ llvm:fail:f64.wast:1621 # AssertReturn - result F64(0) ("0x0") does not match ex
llvm:fail:f64.wast:2020 # AssertReturn - result F64(9223372036854775808) ("0x8000000000000000") does not match expected F64(0) ("0x0") llvm:fail:f64.wast:2020 # AssertReturn - result F64(9223372036854775808) ("0x8000000000000000") does not match expected F64(0) ("0x0")
llvm:fail:linking.wast:388 # AssertReturn - Call failed RuntimeError: WebAssembly trap occurred during runtime: incorrect `call_indirect` signature llvm:fail:linking.wast:388 # AssertReturn - Call failed RuntimeError: WebAssembly trap occurred during runtime: incorrect `call_indirect` signature
# LLVM AArch64
llvm:skip:atomic.wast:*:*:aarch64 # Out of range relocations.
llvm:skip:skip-stack-guard-page.wast:2275:*:aarch64 # Uncaught SIGSEGV only in release builds
llvm:skip:skip-stack-guard-page.wast:2282:*:aarch64 # Uncaught SIGSEGV only in release builds
# LLVM Windows # LLVM Windows
llvm:skip:address.wast:*:windows llvm:skip:address.wast:*:windows
llvm:skip:align.wast:*:windows llvm:skip:align.wast:*:windows

View File

@ -1,4 +1,4 @@
//! Builder code for [`WasiState`] //! Builder system for configuring a [`WasiState`] and creating it.
use crate::state::{WasiFs, WasiState}; use crate::state::{WasiFs, WasiState};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};

View File

@ -376,6 +376,7 @@ impl WasiFs {
} }
} }
/// Returns the next available inode index for creating a new inode.
fn get_next_inode_index(&mut self) -> u64 { fn get_next_inode_index(&mut self) -> u64 {
let next = self.inode_counter.get(); let next = self.inode_counter.get();
self.inode_counter.set(next + 1); self.inode_counter.set(next + 1);
@ -491,6 +492,19 @@ impl WasiFs {
} }
} }
/// Internal part of the core path resolution function which implements path
/// traversal logic such as resolving relative path segments (such as
/// `.` and `..`) and resolving symlinks (while preventing infinite
/// loops/stack overflows).
///
/// TODO: expand upon exactly what the state of the returned value is,
/// explaining lazy-loading from the real file system and synchronizing
/// between them.
///
/// This is where a lot of the magic happens, be very careful when editing
/// this code.
///
/// TODO: write more tests for this code
fn get_inode_at_path_inner( fn get_inode_at_path_inner(
&mut self, &mut self,
base: __wasi_fd_t, base: __wasi_fd_t,
@ -672,6 +686,14 @@ impl WasiFs {
Ok(cur_inode) Ok(cur_inode)
} }
/// Splits a path into the first preopened directory that is a parent of it,
/// if such a preopened directory exists, and the rest of the path.
///
/// NOTE: this behavior seems to be not the same as what libpreopen is
/// doing in WASI.
///
/// TODO: evaluate users of this function and explain why this behavior is
/// not the same as libpreopen or update its behavior to be the same.
fn path_into_pre_open_and_relative_path( fn path_into_pre_open_and_relative_path(
&self, &self,
path: &Path, path: &Path,