Remove all global state from the caching system (#863)
* Remove all global state from the caching system This commit is a continuation of an effort to remove usages of `lazy_static!` and similar global state macros which can otherwise be accomodated with passing objects around. Previously there was a global cache system initialized per-process, but it was initialized in a bit of a roundabout way and wasn't actually reachable from the `wasmtime` crate itself. The changes here remove all global state, refactor many of the internals in the cache system, and makes configuration possible through the `wasmtime` crate. Specifically some changes here are: * Usage of `lazy_static!` and many `static` items in the cache module have all been removed. * Global `cache_config()`, `worker()`, and `init()` functions have all been removed. Instead a `CacheConfig` is a "root object" which internally owns its worker and passing around the `CacheConfig` is required for cache usage. * The `wasmtime::Config` structure has grown options to load and parse cache files at runtime. Currently only loading files is supported, although we can likely eventually support programmatically configuring APIs as well. * Usage of the `spin` crate has been removed and the dependency is removed. * The internal `errors` field of `CacheConfig` is removed, instead changing all relevant methods to return a `Result<()>` instead of storing errors internally. * Tests have all been updated with the new interfaces and APIs. Functionally no real change is intended here. Usage of the `wasmtime` CLI, for example, should still enable the cache by default. * Fix lightbeam compilation
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
//! The module that implements the `wasmtime wast` command.
|
||||
|
||||
use crate::{init_file_per_thread_logger, pick_compilation_strategy, CommonOptions};
|
||||
use anyhow::{bail, Context as _, Result};
|
||||
use std::{fmt::Write, path::PathBuf};
|
||||
use anyhow::{Context as _, Result};
|
||||
use std::path::PathBuf;
|
||||
use structopt::{clap::AppSettings, StructOpt};
|
||||
use wasmtime::{Config, Engine, Store};
|
||||
use wasmtime_environ::cache_init;
|
||||
use wasmtime_wast::WastContext;
|
||||
|
||||
/// Runs a WebAssembly test script file
|
||||
@@ -27,28 +26,11 @@ pub struct WastCommand {
|
||||
impl WastCommand {
|
||||
/// Executes the command.
|
||||
pub fn execute(&self) -> Result<()> {
|
||||
let log_config = if self.common.debug {
|
||||
if self.common.debug {
|
||||
pretty_env_logger::init();
|
||||
None
|
||||
} else {
|
||||
let prefix = "wast.dbg.";
|
||||
init_file_per_thread_logger(prefix);
|
||||
Some(prefix)
|
||||
};
|
||||
|
||||
let errors = cache_init(
|
||||
!self.common.disable_cache,
|
||||
self.common.config.as_ref(),
|
||||
log_config,
|
||||
);
|
||||
|
||||
if !errors.is_empty() {
|
||||
let mut message = String::new();
|
||||
writeln!(message, "Cache initialization failed. Errors:")?;
|
||||
for e in errors {
|
||||
writeln!(message, " -> {}", e)?;
|
||||
}
|
||||
bail!(message);
|
||||
}
|
||||
|
||||
let mut config = Config::new();
|
||||
@@ -60,6 +42,7 @@ impl WastCommand {
|
||||
self.common.cranelift,
|
||||
self.common.lightbeam,
|
||||
)?)?;
|
||||
self.common.configure_cache(&mut config)?;
|
||||
|
||||
if self.common.optimize {
|
||||
config.cranelift_opt_level(wasmtime::OptLevel::Speed);
|
||||
|
||||
Reference in New Issue
Block a user