Remove usage of CompilationStrategy from Config (#764)

* Remove usage of `CompilationStrategy` from `Config`

This commit removes the public API usage of the internal
`CompilationStrategy` enumeration from the `Config` type in the
`wasmtime` crate. To do this the `enum` was copied locally into the
crate and renamed `Strategy`. The high-level description of this change
is:

* The `Config::strategy` method now takes a locally-defined `Strategy`
  enumeration instead of an internal type.

* The contents of `Strategy` are always the same, not relying on Cargo
  features to indicate which variants are present. This avoids
  unnecessary downstream `#[cfg]`.

* A `lightbeam` feature was added to the `wasmtime` crate itself to
  lightbeam compilation support.

* The `Config::strategy` method is now fallible. It returns a runtime
  error if support for the selected strategy wasn't compiled in.

* The `Strategy` enum is listed as `#[non_exhaustive]` so we can safely
  add variants over time to it.

This reduces the public crate dependencies of the `wasmtime` crate
itself, removing the need to reach into internal crates even more!

cc #708

* Fix fuzz targets

* Update nightly used to build releases

* Run rustfmt
This commit is contained in:
Alex Crichton
2020-01-06 18:08:13 -06:00
committed by GitHub
parent 787f50e107
commit 7474633cca
24 changed files with 173 additions and 153 deletions

View File

@@ -1,6 +1,7 @@
//! Module for configuring the cache system.
use super::worker;
use anyhow::{anyhow, bail, Context, Result};
use directories::ProjectDirs;
use lazy_static::lazy_static;
use log::{debug, error, trace, warn};
@@ -137,32 +138,32 @@ pub fn init<P: AsRef<Path> + Debug>(
/// Creates a new configuration file at specified path, or default path if None is passed.
/// Fails if file already exists.
pub fn create_new_config<P: AsRef<Path> + Debug>(
config_file: Option<P>,
) -> Result<PathBuf, String> {
pub fn create_new_config<P: AsRef<Path> + Debug>(config_file: Option<P>) -> Result<PathBuf> {
trace!("Creating new config file, path: {:?}", config_file);
let config_file = config_file.as_ref().map_or_else(
|| DEFAULT_CONFIG_PATH.as_ref().map(|p| p.as_ref()),
|p| Ok(p.as_ref()),
)?;
let config_file = config_file
.as_ref()
.map_or_else(
|| DEFAULT_CONFIG_PATH.as_ref().map(|p| p.as_ref()),
|p| Ok(p.as_ref()),
)
.map_err(|s| anyhow!("{}", s))?;
if config_file.exists() {
return Err(format!(
bail!(
"Specified config file already exists! Path: {}",
config_file.display()
));
);
}
let parent_dir = config_file
.parent()
.ok_or_else(|| format!("Invalid cache config path: {}", config_file.display()))?;
.ok_or_else(|| anyhow!("Invalid cache config path: {}", config_file.display()))?;
fs::create_dir_all(parent_dir).map_err(|err| {
fs::create_dir_all(parent_dir).with_context(|| {
format!(
"Failed to create config directory, config path: {}, error: {}",
"Failed to create config directory, config path: {}",
config_file.display(),
err
)
})?;
@@ -175,11 +176,10 @@ pub fn create_new_config<P: AsRef<Path> + Debug>(
enabled = true
";
fs::write(&config_file, &content).map_err(|err| {
fs::write(&config_file, &content).with_context(|| {
format!(
"Failed to flush config to the disk, path: {}, msg: {}",
"Failed to flush config to the disk, path: {}",
config_file.display(),
err
)
})?;