diff --git a/lib/runtime-core/src/cache.rs b/lib/runtime-core/src/cache.rs index 57f36e7ea..6b63e77b3 100644 --- a/lib/runtime-core/src/cache.rs +++ b/lib/runtime-core/src/cache.rs @@ -241,3 +241,5 @@ pub trait Cache { /// 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")); + +pub const WASMER_VERSION: &'static str = env!("CARGO_PKG_VERSION"); diff --git a/lib/runtime/src/cache.rs b/lib/runtime/src/cache.rs index 015212e1b..620ccaf58 100644 --- a/lib/runtime/src/cache.rs +++ b/lib/runtime/src/cache.rs @@ -9,7 +9,7 @@ use std::{ use wasmer_runtime_core::cache::Error as CacheError; pub use wasmer_runtime_core::{ backend::Backend, - cache::{Artifact, Cache, WasmHash, WASMER_VERSION_HASH}, + cache::{Artifact, Cache, WasmHash, WASMER_VERSION}, }; /// 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 /// stored in this cache haven't been corrupted or tampered with. pub unsafe fn new>(path: P) -> io::Result { - let path: PathBuf = { - let mut path = path.into(); - path.push(WASMER_VERSION_HASH); - path - }; - + let path: PathBuf = path.into(); if path.exists() { let metadata = path.metadata()?; if metadata.is_dir() { diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 0ac460dfc..ccc972d72 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -18,7 +18,7 @@ use wasmer_clif_backend::CraneliftCompiler; #[cfg(feature = "backend-llvm")] use wasmer_llvm_backend::LLVMCompiler; use wasmer_runtime::{ - cache::{Cache as BaseCache, FileSystemCache, WasmHash, WASMER_VERSION_HASH}, + cache::{Cache as BaseCache, FileSystemCache, WasmHash, WASMER_VERSION}, Func, Value, }; use wasmer_runtime_core::{ @@ -216,12 +216,16 @@ fn read_file_contents(path: &PathBuf) -> Result, io::Error> { fn get_cache_dir() -> PathBuf { 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(_) => { // We use a temporal directory for saving cache files let mut temp_dir = env::temp_dir(); temp_dir.push("wasmer"); - temp_dir.push(WASMER_VERSION_HASH); + temp_dir.push(WASMER_VERSION); temp_dir } } @@ -270,10 +274,6 @@ fn get_env_var_args(input: &[String]) -> Result, String> { /// Execute a wasm/wat file 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 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))? } else { // If we have cache enabled - let wasmer_cache_dir = get_cache_dir(); // We create a new cache instance. @@ -421,7 +420,6 @@ fn execute_wasm(options: &Run) -> Result<(), String> { return Ok(module); } } - // We generate a hash for the given binary, so we can use it as key // for the Filesystem cache let hash = WasmHash::generate(&wasm_binary); @@ -796,7 +794,6 @@ fn main() { CLIOptions::SelfUpdate => { 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 { Cache::Clean => { use std::fs; @@ -813,9 +810,5 @@ fn main() { CLIOptions::Validate(validate_options) => { validate(validate_options); } - #[cfg(target_os = "windows")] - CLIOptions::Cache(_) => { - println!("Caching is disabled for Windows."); - } } }