mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-20 12:16:30 +00:00
Update cache key generation to use backend compiler name too
This commit is contained in:
@ -6,6 +6,7 @@ Blocks of changes will separated by version increments.
|
|||||||
|
|
||||||
## **[Unreleased]**
|
## **[Unreleased]**
|
||||||
## 0.5.4
|
## 0.5.4
|
||||||
|
- [#536](https://github.com/wasmerio/wasmer/pull/536) Update cache to use compiler backend name in cache key
|
||||||
- [#529](https://github.com/wasmerio/wasmer/pull/529) Updates the Wasm Interface library, which is used by wapm, with bug fixes and error message improvements
|
- [#529](https://github.com/wasmerio/wasmer/pull/529) Updates the Wasm Interface library, which is used by wapm, with bug fixes and error message improvements
|
||||||
|
|
||||||
## 0.5.3
|
## 0.5.3
|
||||||
|
@ -29,6 +29,56 @@ pub enum Backend {
|
|||||||
LLVM,
|
LLVM,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Backend {
|
||||||
|
pub fn variants() -> &'static [&'static str] {
|
||||||
|
&[
|
||||||
|
"cranelift",
|
||||||
|
#[cfg(feature = "backend:singlepass")]
|
||||||
|
"singlepass",
|
||||||
|
#[cfg(feature = "backend:llvm")]
|
||||||
|
"llvm",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
/// stable string representation of the backend
|
||||||
|
/// can be used as part of a cache key, for example
|
||||||
|
pub fn to_string(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Backend::Cranelift => "cranelift",
|
||||||
|
Backend::Singlepass => "singlepass",
|
||||||
|
Backend::LLVM => "llvm",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::str::FromStr for Backend {
|
||||||
|
type Err = String;
|
||||||
|
fn from_str(s: &str) -> Result<Backend, String> {
|
||||||
|
match s.to_lowercase().as_str() {
|
||||||
|
"singlepass" => Ok(Backend::Singlepass),
|
||||||
|
"cranelift" => Ok(Backend::Cranelift),
|
||||||
|
"llvm" => Ok(Backend::LLVM),
|
||||||
|
_ => Err(format!("The backend {} doesn't exist", s)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod backend_test {
|
||||||
|
use super::*;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn str_repr_matches() {
|
||||||
|
// if this test breaks, think hard about why it's breaking
|
||||||
|
// can we avoid having these be different?
|
||||||
|
|
||||||
|
for &backend in &[Backend::Cranelift, Backend::LLVM, Backend::Singlepass] {
|
||||||
|
assert_eq!(backend, Backend::from_str(backend.to_string()).unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// This type cannot be constructed from
|
/// This type cannot be constructed from
|
||||||
/// outside the runtime crate.
|
/// outside the runtime crate.
|
||||||
pub struct Token {
|
pub struct Token {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
|
backend::Backend,
|
||||||
module::{Module, ModuleInfo},
|
module::{Module, ModuleInfo},
|
||||||
sys::Memory,
|
sys::Memory,
|
||||||
};
|
};
|
||||||
@ -41,12 +42,13 @@ impl WasmHash {
|
|||||||
/// # Note:
|
/// # Note:
|
||||||
/// This does no verification that the supplied data
|
/// This does no verification that the supplied data
|
||||||
/// is, in fact, a wasm module.
|
/// is, in fact, a wasm module.
|
||||||
pub fn generate(wasm: &[u8]) -> Self {
|
pub fn generate(wasm: &[u8], backend: Backend) -> Self {
|
||||||
let mut first_part = [0u8; 32];
|
let mut first_part = [0u8; 32];
|
||||||
let mut second_part = [0u8; 32];
|
let mut second_part = [0u8; 32];
|
||||||
|
|
||||||
let mut state = blake2bp::State::new();
|
let mut state = blake2bp::State::new();
|
||||||
state.update(wasm);
|
state.update(wasm);
|
||||||
|
state.update(backend.to_string().as_bytes());
|
||||||
|
|
||||||
let hasher = state.finalize();
|
let hasher = state.finalize();
|
||||||
let generic_array = hasher.as_bytes();
|
let generic_array = hasher.as_bytes();
|
||||||
|
@ -23,7 +23,7 @@ use wasmer_runtime::{
|
|||||||
};
|
};
|
||||||
use wasmer_runtime_core::{
|
use wasmer_runtime_core::{
|
||||||
self,
|
self,
|
||||||
backend::{Compiler, CompilerConfig, MemoryBoundCheckMode},
|
backend::{Backend, Compiler, CompilerConfig, MemoryBoundCheckMode},
|
||||||
loader::{Instance as LoadedInstance, LocalLoader},
|
loader::{Instance as LoadedInstance, LocalLoader},
|
||||||
};
|
};
|
||||||
#[cfg(feature = "backend:singlepass")]
|
#[cfg(feature = "backend:singlepass")]
|
||||||
@ -153,42 +153,6 @@ impl FromStr for LoaderName {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
|
||||||
enum Backend {
|
|
||||||
Cranelift,
|
|
||||||
Singlepass,
|
|
||||||
LLVM,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Backend {
|
|
||||||
pub fn variants() -> &'static [&'static str] {
|
|
||||||
&[
|
|
||||||
"cranelift",
|
|
||||||
#[cfg(feature = "backend:singlepass")]
|
|
||||||
"singlepass",
|
|
||||||
#[cfg(feature = "backend:llvm")]
|
|
||||||
"llvm",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromStr for Backend {
|
|
||||||
type Err = String;
|
|
||||||
fn from_str(s: &str) -> Result<Backend, String> {
|
|
||||||
match s.to_lowercase().as_str() {
|
|
||||||
"singlepass" => Ok(Backend::Singlepass),
|
|
||||||
"cranelift" => Ok(Backend::Cranelift),
|
|
||||||
"llvm" => Ok(Backend::LLVM),
|
|
||||||
// "llvm" => Err(
|
|
||||||
// "The LLVM backend option is not enabled by default due to binary size constraints"
|
|
||||||
// .to_string(),
|
|
||||||
// ),
|
|
||||||
_ => Err(format!("The backend {} doesn't exist", s)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
enum Cache {
|
enum Cache {
|
||||||
/// Clear the cache
|
/// Clear the cache
|
||||||
@ -388,7 +352,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
|
|||||||
|
|
||||||
// We generate a hash for the given binary, so we can use it as key
|
// We generate a hash for the given binary, so we can use it as key
|
||||||
// for the Filesystem cache
|
// for the Filesystem cache
|
||||||
let hash = WasmHash::generate(&wasm_binary);
|
let hash = WasmHash::generate(&wasm_binary, options.backend);
|
||||||
|
|
||||||
let wasmer_cache_dir = get_cache_dir();
|
let wasmer_cache_dir = get_cache_dir();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user