mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 06:15:33 +00:00
Improvement cache in Windows
This commit is contained in:
parent
f483c89da7
commit
13901cc665
@ -241,3 +241,5 @@ pub trait Cache {
|
|||||||
/// A unique ID generated from the version of Wasmer for use with cache versioning
|
/// A unique ID generated from the version of Wasmer for use with cache versioning
|
||||||
pub const WASMER_VERSION_HASH: &'static str =
|
pub const WASMER_VERSION_HASH: &'static str =
|
||||||
include_str!(concat!(env!("OUT_DIR"), "/wasmer_version_hash.txt"));
|
include_str!(concat!(env!("OUT_DIR"), "/wasmer_version_hash.txt"));
|
||||||
|
|
||||||
|
pub const WASMER_VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||||
|
@ -9,7 +9,7 @@ use std::{
|
|||||||
use wasmer_runtime_core::cache::Error as CacheError;
|
use wasmer_runtime_core::cache::Error as CacheError;
|
||||||
pub use wasmer_runtime_core::{
|
pub use wasmer_runtime_core::{
|
||||||
backend::Backend,
|
backend::Backend,
|
||||||
cache::{Artifact, Cache, WasmHash, WASMER_VERSION_HASH},
|
cache::{Artifact, Cache, WasmHash, WASMER_VERSION},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Representation of a directory that contains compiled wasm artifacts.
|
/// Representation of a directory that contains compiled wasm artifacts.
|
||||||
@ -49,12 +49,7 @@ impl FileSystemCache {
|
|||||||
/// 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 = {
|
let path: PathBuf = path.into();
|
||||||
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()?;
|
||||||
if metadata.is_dir() {
|
if metadata.is_dir() {
|
||||||
|
@ -18,7 +18,7 @@ use wasmer_clif_backend::CraneliftCompiler;
|
|||||||
#[cfg(feature = "backend-llvm")]
|
#[cfg(feature = "backend-llvm")]
|
||||||
use wasmer_llvm_backend::LLVMCompiler;
|
use wasmer_llvm_backend::LLVMCompiler;
|
||||||
use wasmer_runtime::{
|
use wasmer_runtime::{
|
||||||
cache::{Cache as BaseCache, FileSystemCache, WasmHash, WASMER_VERSION_HASH},
|
cache::{Cache as BaseCache, FileSystemCache, WasmHash, WASMER_VERSION},
|
||||||
Func, Value,
|
Func, Value,
|
||||||
};
|
};
|
||||||
use wasmer_runtime_core::{
|
use wasmer_runtime_core::{
|
||||||
@ -216,12 +216,16 @@ fn read_file_contents(path: &PathBuf) -> Result<Vec<u8>, io::Error> {
|
|||||||
|
|
||||||
fn get_cache_dir() -> PathBuf {
|
fn get_cache_dir() -> PathBuf {
|
||||||
match env::var("WASMER_CACHE_DIR") {
|
match env::var("WASMER_CACHE_DIR") {
|
||||||
Ok(dir) => PathBuf::from(dir),
|
Ok(dir) => {
|
||||||
|
let mut path = PathBuf::from(dir);
|
||||||
|
path.push(WASMER_VERSION);
|
||||||
|
path
|
||||||
|
},
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// 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.push(WASMER_VERSION);
|
||||||
temp_dir
|
temp_dir
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -270,10 +274,6 @@ fn get_env_var_args(input: &[String]) -> Result<Vec<(&str, &str)>, String> {
|
|||||||
|
|
||||||
/// Execute a wasm/wat file
|
/// Execute a wasm/wat file
|
||||||
fn execute_wasm(options: &Run) -> Result<(), String> {
|
fn execute_wasm(options: &Run) -> Result<(), String> {
|
||||||
// force disable caching on windows
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
let disable_cache = true;
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
|
||||||
let disable_cache = options.disable_cache;
|
let disable_cache = options.disable_cache;
|
||||||
|
|
||||||
let mapped_dirs = get_mapped_dirs(&options.mapped_dirs[..])?;
|
let mapped_dirs = get_mapped_dirs(&options.mapped_dirs[..])?;
|
||||||
@ -401,7 +401,6 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
|
|||||||
.map_err(|e| format!("Can't compile module: {:?}", e))?
|
.map_err(|e| format!("Can't compile module: {:?}", e))?
|
||||||
} else {
|
} else {
|
||||||
// If we have cache enabled
|
// If we have cache enabled
|
||||||
|
|
||||||
let wasmer_cache_dir = get_cache_dir();
|
let wasmer_cache_dir = get_cache_dir();
|
||||||
|
|
||||||
// We create a new cache instance.
|
// We create a new cache instance.
|
||||||
@ -421,7 +420,6 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
|
|||||||
return Ok(module);
|
return Ok(module);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
||||||
@ -796,7 +794,6 @@ fn main() {
|
|||||||
CLIOptions::SelfUpdate => {
|
CLIOptions::SelfUpdate => {
|
||||||
println!("Self update is not supported on Windows. Use install instructions on the Wasmer homepage: https://wasmer.io");
|
println!("Self update is not supported on Windows. Use install instructions on the Wasmer homepage: https://wasmer.io");
|
||||||
}
|
}
|
||||||
#[cfg(not(target_os = "windows"))]
|
|
||||||
CLIOptions::Cache(cache) => match cache {
|
CLIOptions::Cache(cache) => match cache {
|
||||||
Cache::Clean => {
|
Cache::Clean => {
|
||||||
use std::fs;
|
use std::fs;
|
||||||
@ -813,9 +810,5 @@ fn main() {
|
|||||||
CLIOptions::Validate(validate_options) => {
|
CLIOptions::Validate(validate_options) => {
|
||||||
validate(validate_options);
|
validate(validate_options);
|
||||||
}
|
}
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
CLIOptions::Cache(_) => {
|
|
||||||
println!("Caching is disabled for Windows.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user