mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-27 07:31:33 +00:00
Merge remote-tracking branch 'origin/master' into feature/dynasm-backend
This commit is contained in:
@ -46,3 +46,5 @@ field-offset = "0.1.1"
|
|||||||
[features]
|
[features]
|
||||||
debug = []
|
debug = []
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
blake2b_simd = "0.4.1"
|
26
lib/runtime-core/build.rs
Normal file
26
lib/runtime-core/build.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
use blake2b_simd::blake2bp;
|
||||||
|
use std::{env, fs, io::Write, path::PathBuf};
|
||||||
|
|
||||||
|
const WASMER_VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut state = blake2bp::State::new();
|
||||||
|
state.update(WASMER_VERSION.as_bytes());
|
||||||
|
|
||||||
|
let hasher = state.finalize();
|
||||||
|
let hash_string = hasher.to_hex().as_str().to_owned();
|
||||||
|
|
||||||
|
let crate_dir = env::var("OUT_DIR").unwrap();
|
||||||
|
let wasmer_version_hash_file = {
|
||||||
|
let mut path = PathBuf::from(&crate_dir);
|
||||||
|
path.push("wasmer_version_hash.txt");
|
||||||
|
path
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut f_out = fs::File::create(wasmer_version_hash_file)
|
||||||
|
.expect("Could not create file for wasmer hash value");
|
||||||
|
|
||||||
|
f_out
|
||||||
|
.write_all(hash_string.as_bytes())
|
||||||
|
.expect("Could not write to file for wasmer hash value");
|
||||||
|
}
|
@ -207,3 +207,7 @@ pub trait Cache {
|
|||||||
fn load(&self, key: WasmHash) -> Result<Module, Self::LoadError>;
|
fn load(&self, key: WasmHash) -> Result<Module, Self::LoadError>;
|
||||||
fn store(&mut self, key: WasmHash, module: Module) -> Result<(), Self::StoreError>;
|
fn store(&mut self, key: WasmHash, module: Module) -> Result<(), Self::StoreError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A unique ID generated from the version of Wasmer for use with cache versioning
|
||||||
|
pub const WASMER_VERSION_HASH: &'static str =
|
||||||
|
include_str!(concat!(env!("OUT_DIR"), "/wasmer_version_hash.txt"));
|
||||||
|
@ -7,7 +7,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use wasmer_runtime_core::cache::Error as CacheError;
|
use wasmer_runtime_core::cache::Error as CacheError;
|
||||||
pub use wasmer_runtime_core::cache::{Artifact, Cache, WasmHash};
|
pub use wasmer_runtime_core::cache::{Artifact, Cache, WasmHash, WASMER_VERSION_HASH};
|
||||||
|
|
||||||
/// Representation of a directory that contains compiled wasm artifacts.
|
/// Representation of a directory that contains compiled wasm artifacts.
|
||||||
///
|
///
|
||||||
@ -40,12 +40,17 @@ pub struct FileSystemCache {
|
|||||||
|
|
||||||
impl FileSystemCache {
|
impl FileSystemCache {
|
||||||
/// Construct a new `FileSystemCache` around the specified directory.
|
/// Construct a new `FileSystemCache` around the specified directory.
|
||||||
|
/// The contents of the cache are stored in sub-versioned directories.
|
||||||
///
|
///
|
||||||
/// # Note:
|
/// # Note:
|
||||||
/// This method is unsafe because there's no way to ensure the artifacts
|
/// This method is unsafe because there's no way to ensure the artifacts
|
||||||
/// stored in this cache haven't been corrupted or tampered with.
|
/// stored in this cache haven't been corrupted or tampered with.
|
||||||
pub unsafe fn new<P: Into<PathBuf>>(path: P) -> io::Result<Self> {
|
pub unsafe fn new<P: Into<PathBuf>>(path: P) -> io::Result<Self> {
|
||||||
let path: PathBuf = path.into();
|
let path: PathBuf = {
|
||||||
|
let mut path = path.into();
|
||||||
|
path.push(WASMER_VERSION_HASH);
|
||||||
|
path
|
||||||
|
};
|
||||||
|
|
||||||
if path.exists() {
|
if path.exists() {
|
||||||
let metadata = path.metadata()?;
|
let metadata = path.metadata()?;
|
||||||
|
@ -12,7 +12,7 @@ use structopt::StructOpt;
|
|||||||
use wasmer::webassembly::InstanceABI;
|
use wasmer::webassembly::InstanceABI;
|
||||||
use wasmer::*;
|
use wasmer::*;
|
||||||
use wasmer_emscripten;
|
use wasmer_emscripten;
|
||||||
use wasmer_runtime::cache::{Cache as BaseCache, FileSystemCache, WasmHash};
|
use wasmer_runtime::cache::{Cache as BaseCache, FileSystemCache, WasmHash, WASMER_VERSION_HASH};
|
||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
#[structopt(name = "wasmer", about = "Wasm execution runtime.")]
|
#[structopt(name = "wasmer", about = "Wasm execution runtime.")]
|
||||||
@ -48,9 +48,11 @@ struct Run {
|
|||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
enum Cache {
|
enum Cache {
|
||||||
|
/// Clear the cache
|
||||||
#[structopt(name = "clean")]
|
#[structopt(name = "clean")]
|
||||||
Clean,
|
Clean,
|
||||||
|
|
||||||
|
/// Display the location of the cache
|
||||||
#[structopt(name = "dir")]
|
#[structopt(name = "dir")]
|
||||||
Dir,
|
Dir,
|
||||||
}
|
}
|
||||||
@ -72,6 +74,7 @@ fn get_cache_dir() -> PathBuf {
|
|||||||
// We use a temporal directory for saving cache files
|
// We use a temporal directory for saving cache files
|
||||||
let mut temp_dir = env::temp_dir();
|
let mut temp_dir = env::temp_dir();
|
||||||
temp_dir.push("wasmer");
|
temp_dir.push("wasmer");
|
||||||
|
temp_dir.push(WASMER_VERSION_HASH);
|
||||||
temp_dir
|
temp_dir
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,8 +198,10 @@ fn main() {
|
|||||||
Cache::Clean => {
|
Cache::Clean => {
|
||||||
use std::fs;
|
use std::fs;
|
||||||
let cache_dir = get_cache_dir();
|
let cache_dir = get_cache_dir();
|
||||||
|
if cache_dir.exists() {
|
||||||
fs::remove_dir_all(cache_dir.clone()).expect("Can't remove cache dir");
|
fs::remove_dir_all(cache_dir.clone()).expect("Can't remove cache dir");
|
||||||
fs::create_dir(cache_dir.clone()).expect("Can't create cache dir");
|
}
|
||||||
|
fs::create_dir_all(cache_dir.clone()).expect("Can't create cache dir");
|
||||||
}
|
}
|
||||||
Cache::Dir => {
|
Cache::Dir => {
|
||||||
println!("{}", get_cache_dir().to_string_lossy());
|
println!("{}", get_cache_dir().to_string_lossy());
|
||||||
|
Reference in New Issue
Block a user