mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 14:25:32 +00:00
Merge #579
579: fix caching for other backends, improve default compiler code r=MarkMcCaskey a=MarkMcCaskey Co-authored-by: Mark McCaskey <mark@wasmer.io> Co-authored-by: Syrus Akbary <me@syrusakbary.com>
This commit is contained in:
commit
53c343bc6f
@ -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)
|
||||||
|
@ -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"]
|
||||||
|
|
||||||
|
@ -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" = []
|
||||||
|
@ -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",
|
||||||
|
@ -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 {
|
||||||
|
@ -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"
|
||||||
|
@ -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(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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");
|
||||||
|
Loading…
Reference in New Issue
Block a user