Merge branch 'master' into feature/spectests-runner

This commit is contained in:
Brandon Fish 2019-07-26 22:15:42 -05:00
commit 8098b7e44d
14 changed files with 164 additions and 18 deletions

View File

@ -129,6 +129,26 @@ jobs:
- target/release/deps - target/release/deps
key: v8-test-cargo-cache-linux-nightly-{{ arch }}-{{ checksum "Cargo.lock" }} key: v8-test-cargo-cache-linux-nightly-{{ arch }}-{{ checksum "Cargo.lock" }}
test-rust-example:
docker:
- image: circleci/rust:latest
<<: *run_with_build_env_vars
steps:
- checkout
- run:
name: "Check Wasmer Rust example"
command: |
git clone https://github.com/wasmerio/wasmer-rust-example
rustup default stable
rustup target add wasm32-unknown-unknown
cd wasmer-rust-example
cd wasm-sample-app
cargo build --release
cd ..
sed -i 's/wasmer-runtime.*/wasmer-runtime = \{ path = "..\/lib\/runtime" \}/g' Cargo.toml
cargo run
cargo test
test-macos: test-macos:
macos: macos:
xcode: "9.0" xcode: "9.0"
@ -383,6 +403,12 @@ workflows:
only: only:
- trying - trying
- staging - staging
- test-rust-example:
filters:
branches:
only:
- trying
- staging
- test-macos: - test-macos:
filters: filters:
branches: branches:

View File

@ -5,6 +5,9 @@ All PRs to the Wasmer repository must add to this file.
Blocks of changes will separated by version increments. Blocks of changes will separated by version increments.
## **[Unreleased]** ## **[Unreleased]**
- [#579](https://github.com/wasmerio/wasmer/pull/579) Fix bug in caching with LLVM and Singlepass backends.
Add `default-backend-singlepass`, `default-backend-llvm`, and `default-backend-cranelift` features to `wasmer-runtime`
to control the `default_compiler()` function (this is a breaking change). Add `compiler_for_backend` function in `wasmer-runtime`
- [#561](https://github.com/wasmerio/wasmer/pull/561) Call the `data_finalizer` field on the `Ctx` - [#561](https://github.com/wasmerio/wasmer/pull/561) Call the `data_finalizer` field on the `Ctx`
- [#576](https://github.com/wasmerio/wasmer/pull/576) fix `Drop` of uninit `Ctx` - [#576](https://github.com/wasmerio/wasmer/pull/576) fix `Drop` of uninit `Ctx`
- [#542](https://github.com/wasmerio/wasmer/pull/542) Add SIMD support to Wasmer (LLVM backend only) - [#542](https://github.com/wasmerio/wasmer/pull/542) Add SIMD support to Wasmer (LLVM backend only)

View File

@ -66,15 +66,16 @@ glob = "0.2.11"
rustc_version = "0.2.3" rustc_version = "0.2.3"
[features] [features]
default = ["fast-tests", "wasi"] default = ["fast-tests", "wasi", "backend-cranelift"]
"loader-kernel" = ["wasmer-kernel-loader"] "loader-kernel" = ["wasmer-kernel-loader"]
debug = ["wasmer-runtime-core/debug"] debug = ["wasmer-runtime-core/debug"]
trace = ["wasmer-runtime-core/trace"] trace = ["wasmer-runtime-core/trace"]
extra-debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] extra-debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"]
# This feature will allow cargo test to run much faster # This feature will allow cargo test to run much faster
fast-tests = [] fast-tests = []
"backend-llvm" = ["wasmer-llvm-backend", "wasmer-runtime-core/backend-llvm"] backend-cranelift = ["wasmer-runtime-core/backend-cranelift", "wasmer-runtime/cranelift"]
"backend-singlepass" = ["wasmer-singlepass-backend", "wasmer-runtime-core/backend-singlepass"] backend-llvm = ["wasmer-llvm-backend", "wasmer-runtime-core/backend-llvm", "wasmer-runtime/llvm"]
backend-singlepass = ["wasmer-singlepass-backend", "wasmer-runtime-core/backend-singlepass", "wasmer-runtime/singlepass"]
wasi = ["wasmer-wasi"] wasi = ["wasmer-wasi"]
# vfs = ["wasmer-runtime-abi"] # vfs = ["wasmer-runtime-abi"]

View File

@ -3,6 +3,7 @@ status = [
"ci/circleci: test", "ci/circleci: test",
"ci/circleci: test-macos", "ci/circleci: test-macos",
"ci/circleci: test-stable", "ci/circleci: test-stable",
"ci/circleci: test-rust-example",
"continuous-integration/appveyor/branch" "continuous-integration/appveyor/branch"
] ]
required_approvals = 1 required_approvals = 1

View File

@ -304,8 +304,15 @@ impl ModuleCodeGenerator<CraneliftFunctionCodeGenerator, Caller, CodegenError>
let trampolines = Arc::new(Trampolines::new(&*self.isa, module_info)); let trampolines = Arc::new(Trampolines::new(&*self.isa, module_info));
let signatures_empty = Map::new();
let signatures = if self.signatures.is_some() {
&self.signatures.as_ref().unwrap()
} else {
&signatures_empty
};
let (func_resolver, backend_cache) = func_resolver_builder.finalize( let (func_resolver, backend_cache) = func_resolver_builder.finalize(
&self.signatures.as_ref().unwrap(), signatures,
Arc::clone(&trampolines), Arc::clone(&trampolines),
handler_data.clone(), handler_data.clone(),
)?; )?;

View File

@ -55,5 +55,6 @@ cc = "1.0"
debug = [] debug = []
trace = ["debug"] trace = ["debug"]
# backend flags used in conditional compilation of Backend::variants # backend flags used in conditional compilation of Backend::variants
"backend-cranelift" = []
"backend-singlepass" = [] "backend-singlepass" = []
"backend-llvm" = [] "backend-llvm" = []

View File

@ -32,6 +32,7 @@ pub enum Backend {
impl Backend { impl Backend {
pub fn variants() -> &'static [&'static str] { pub fn variants() -> &'static [&'static str] {
&[ &[
#[cfg(feature = "backend-cranelift")]
"cranelift", "cranelift",
#[cfg(feature = "backend-singlepass")] #[cfg(feature = "backend-singlepass")]
"singlepass", "singlepass",
@ -110,14 +111,20 @@ impl Default for MemoryBoundCheckMode {
} }
} }
#[derive(Debug, Default)]
pub struct Features {
pub simd: bool,
}
/// Configuration data for the compiler /// Configuration data for the compiler
#[derive(Default)] #[derive(Debug, Default)]
pub struct CompilerConfig { pub struct CompilerConfig {
/// Symbol information generated from emscripten; used for more detailed debug messages /// Symbol information generated from emscripten; used for more detailed debug messages
pub symbol_map: Option<HashMap<u32, String>>, pub symbol_map: Option<HashMap<u32, String>>,
pub memory_bound_check_mode: MemoryBoundCheckMode, pub memory_bound_check_mode: MemoryBoundCheckMode,
pub enforce_stack_check: bool, pub enforce_stack_check: bool,
pub track_state: bool, pub track_state: bool,
pub features: Features,
} }
pub trait Compiler { pub trait Compiler {

View File

@ -20,6 +20,7 @@ pub enum Error {
Unknown(String), Unknown(String),
InvalidFile(InvalidFileType), InvalidFile(InvalidFileType),
InvalidatedCache, InvalidatedCache,
UnsupportedBackend(Backend),
} }
impl From<io::Error> for Error { impl From<io::Error> for Error {

View File

@ -117,8 +117,26 @@ pub fn validate(wasm: &[u8]) -> bool {
/// The same as `validate` but with an Error message on failure /// The same as `validate` but with an Error message on failure
pub fn validate_and_report_errors(wasm: &[u8]) -> ::std::result::Result<(), String> { pub fn validate_and_report_errors(wasm: &[u8]) -> ::std::result::Result<(), String> {
validate_and_report_errors_with_features(wasm, Default::default())
}
/// The same as `validate_and_report_errors` but with a Features.
pub fn validate_and_report_errors_with_features(
wasm: &[u8],
features: backend::Features,
) -> ::std::result::Result<(), String> {
use wasmparser::WasmDecoder; use wasmparser::WasmDecoder;
let mut parser = wasmparser::ValidatingParser::new(wasm, None); let config = wasmparser::ValidatingParserConfig {
operator_config: wasmparser::OperatorValidatorConfig {
enable_simd: features.simd,
enable_bulk_memory: false,
enable_multi_value: false,
enable_reference_types: false,
enable_threads: false,
},
mutable_global_imports: false,
};
let mut parser = wasmparser::ValidatingParser::new(wasm, Some(config));
loop { loop {
let state = parser.read(); let state = parser.read();
match *state { match *state {

View File

@ -32,12 +32,15 @@ path = "../llvm-backend"
optional = true optional = true
[features] [features]
default = ["default-compiler"] default = ["cranelift", "default-backend-cranelift"]
default-compiler = ["wasmer-clif-backend"] cranelift = ["wasmer-clif-backend"]
cache = ["default-compiler"] cache = ["cranelift"]
debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"]
llvm = ["wasmer-llvm-backend"] llvm = ["wasmer-llvm-backend"]
singlepass = ["wasmer-singlepass-backend"] singlepass = ["wasmer-singlepass-backend"]
default-backend-singlepass = ["singlepass"]
default-backend-llvm = ["llvm"]
default-backend-cranelift = ["cranelift"]
[[bench]] [[bench]]
name = "nginx" name = "nginx"

View File

@ -103,7 +103,12 @@ impl Cache for FileSystemCache {
let serialized_cache = Artifact::deserialize(&mmap[..])?; let serialized_cache = Artifact::deserialize(&mmap[..])?;
unsafe { unsafe {
wasmer_runtime_core::load_cache_with(serialized_cache, &super::default_compiler()) wasmer_runtime_core::load_cache_with(
serialized_cache,
super::compiler_for_backend(backend)
.ok_or_else(|| CacheError::UnsupportedBackend(backend))?
.as_ref(),
)
} }
} }

View File

@ -76,6 +76,7 @@
//! [`wasmer-clif-backend`]: https://crates.io/crates/wasmer-clif-backend //! [`wasmer-clif-backend`]: https://crates.io/crates/wasmer-clif-backend
//! [`compile_with`]: fn.compile_with.html //! [`compile_with`]: fn.compile_with.html
pub use wasmer_runtime_core::backend::Backend;
pub use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler}; pub use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler};
pub use wasmer_runtime_core::export::Export; pub use wasmer_runtime_core::export::Export;
pub use wasmer_runtime_core::global::Global; pub use wasmer_runtime_core::global::Global;
@ -179,17 +180,56 @@ pub fn instantiate(wasm: &[u8], import_object: &ImportObject) -> error::Result<I
/// Get a single instance of the default compiler to use. /// Get a single instance of the default compiler to use.
pub fn default_compiler() -> impl Compiler { pub fn default_compiler() -> impl Compiler {
#[cfg(feature = "llvm")] #[cfg(any(
all(
feature = "default-backend-llvm",
any(
feature = "default-backend-cranelift",
feature = "default-backend-singlepass"
)
),
all(
feature = "default-backend-cranelift",
feature = "default-backend-singlepass"
)
))]
compile_error!(
"The `default-backend-X` features are mutually exclusive. Please choose just one"
);
#[cfg(feature = "default-backend-llvm")]
use wasmer_llvm_backend::LLVMCompiler as DefaultCompiler; use wasmer_llvm_backend::LLVMCompiler as DefaultCompiler;
#[cfg(feature = "singlepass")] #[cfg(feature = "default-backend-singlepass")]
use wasmer_singlepass_backend::SinglePassCompiler as DefaultCompiler; use wasmer_singlepass_backend::SinglePassCompiler as DefaultCompiler;
#[cfg(not(any(feature = "llvm", feature = "singlepass")))] #[cfg(feature = "default-backend-cranelift")]
use wasmer_clif_backend::CraneliftCompiler as DefaultCompiler; use wasmer_clif_backend::CraneliftCompiler as DefaultCompiler;
DefaultCompiler::new() DefaultCompiler::new()
} }
pub fn compiler_for_backend(backend: Backend) -> Option<Box<dyn Compiler>> {
match backend {
#[cfg(feature = "cranelift")]
Backend::Cranelift => Some(Box::new(wasmer_clif_backend::CraneliftCompiler::new())),
#[cfg(feature = "singlepass")]
Backend::Singlepass => Some(Box::new(
wasmer_singlepass_backend::SinglePassCompiler::new(),
)),
#[cfg(feature = "llvm")]
Backend::LLVM => Some(Box::new(wasmer_llvm_backend::LLVMCompiler::new())),
#[cfg(any(
not(feature = "llvm"),
not(feature = "singlepass"),
not(feature = "cranelift")
))]
_ => None,
}
}
/// The current version of this crate /// The current version of this crate
pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub const VERSION: &str = env!("CARGO_PKG_VERSION");

View File

@ -55,6 +55,7 @@ fn handle_client(mut stream: UnixStream) {
memory_bound_check_mode: MemoryBoundCheckMode::Disable, memory_bound_check_mode: MemoryBoundCheckMode::Disable,
enforce_stack_check: true, enforce_stack_check: true,
track_state: false, track_state: false,
features: Default::default(),
}, },
&SinglePassCompiler::new(), &SinglePassCompiler::new(),
) )

View File

@ -23,7 +23,7 @@ use wasmer_runtime::{
}; };
use wasmer_runtime_core::{ use wasmer_runtime_core::{
self, self,
backend::{Backend, Compiler, CompilerConfig, MemoryBoundCheckMode}, backend::{Backend, Compiler, CompilerConfig, Features, MemoryBoundCheckMode},
debug, debug,
loader::{Instance as LoadedInstance, LocalLoader}, loader::{Instance as LoadedInstance, LocalLoader},
}; };
@ -67,6 +67,17 @@ enum CLIOptions {
SelfUpdate, SelfUpdate,
} }
#[derive(Debug, StructOpt)]
struct PrestandardFeatures {
/// Enable support for the SIMD proposal.
#[structopt(long = "enable-simd")]
simd: bool,
/// Enable support for all pre-standard proposals.
#[structopt(long = "enable-all")]
all: bool,
}
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
struct Run { struct Run {
// Disable the cache // Disable the cache
@ -134,6 +145,9 @@ struct Run {
#[structopt(long = "cache-key", hidden = true)] #[structopt(long = "cache-key", hidden = true)]
cache_key: Option<String>, cache_key: Option<String>,
#[structopt(flatten)]
features: PrestandardFeatures,
/// Application arguments /// Application arguments
#[structopt(name = "--", raw(multiple = "true"))] #[structopt(name = "--", raw(multiple = "true"))]
args: Vec<String>, args: Vec<String>,
@ -185,6 +199,9 @@ struct Validate {
/// Input file /// Input file
#[structopt(parse(from_os_str))] #[structopt(parse(from_os_str))]
path: PathBuf, path: PathBuf,
#[structopt(flatten)]
features: PrestandardFeatures,
} }
/// Read the contents of a file /// Read the contents of a file
@ -315,10 +332,14 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
None None
}; };
// Don't error on --enable-all for other backends.
if options.features.simd && options.backend != Backend::LLVM {
return Err("SIMD is only supported in the LLVM backend for now".to_string());
}
if !utils::is_wasm_binary(&wasm_binary) { if !utils::is_wasm_binary(&wasm_binary) {
let mut features = wabt::Features::new(); let mut features = wabt::Features::new();
if options.backend == Backend::LLVM { if options.features.simd || options.features.all {
// SIMD is only supported in the LLVM backend for now
features.enable_simd(); features.enable_simd();
} }
wasm_binary = wabt::wat2wasm_with_features(wasm_binary, features) wasm_binary = wabt::wat2wasm_with_features(wasm_binary, features)
@ -357,6 +378,9 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
memory_bound_check_mode: MemoryBoundCheckMode::Disable, memory_bound_check_mode: MemoryBoundCheckMode::Disable,
enforce_stack_check: true, enforce_stack_check: true,
track_state, track_state,
features: Features {
simd: options.features.simd || options.features.all,
},
}, },
&*compiler, &*compiler,
) )
@ -367,6 +391,9 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
CompilerConfig { CompilerConfig {
symbol_map: em_symbol_map, symbol_map: em_symbol_map,
track_state, track_state,
features: Features {
simd: options.features.simd || options.features.all,
},
..Default::default() ..Default::default()
}, },
&*compiler, &*compiler,
@ -737,8 +764,13 @@ fn validate_wasm(validate: Validate) -> Result<(), String> {
)); ));
} }
wasmer_runtime_core::validate_and_report_errors(&wasm_binary) wasmer_runtime_core::validate_and_report_errors_with_features(
.map_err(|err| format!("Validation failed: {}", err))?; &wasm_binary,
Features {
simd: validate.features.simd || validate.features.all,
},
)
.map_err(|err| format!("Validation failed: {}", err))?;
Ok(()) Ok(())
} }