Code review feedback.

* Remove `Config::for_target` in favor of setter `Config::target`.
* Remove explicit setting of Cranelift flags in `Config::new` in favor of
  calling the `Config` methods that do the same thing.
* Serialize the package version independently of the data when serializing a
  module.
* Use struct deconstructing in module serialization to ensure tunables and
  features aren't missed.
* Move common log initialization in the CLI into `CommonOptions`.
This commit is contained in:
Peter Huene
2021-03-30 17:20:15 -07:00
parent 273597903b
commit 1ce2a87149
9 changed files with 180 additions and 178 deletions

View File

@@ -1,6 +1,6 @@
//! The module that implements the `wasmtime wast` command.
use crate::{init_file_per_thread_logger, CommonOptions};
use crate::CommonOptions;
use anyhow::{anyhow, bail, Context, Result};
use std::fs::{self, File};
use std::io::BufWriter;
@@ -148,14 +148,7 @@ pub struct CompileCommand {
impl CompileCommand {
/// Executes the command.
pub fn execute(mut self) -> Result<()> {
if !self.common.disable_logging {
if self.common.log_to_files {
let prefix = "wasmtime.dbg.";
init_file_per_thread_logger(prefix);
} else {
pretty_env_logger::init();
}
}
self.common.init_logging();
let target = self
.target

View File

@@ -1,6 +1,6 @@
//! The module that implements the `wasmtime run` command.
use crate::{init_file_per_thread_logger, CommonOptions};
use crate::CommonOptions;
use anyhow::{bail, Context as _, Result};
use std::thread;
use std::time::Duration;
@@ -126,14 +126,7 @@ pub struct RunCommand {
impl RunCommand {
/// Executes the command.
pub fn execute(&self) -> Result<()> {
if !self.common.disable_logging {
if self.common.log_to_files {
let prefix = "wasmtime.dbg.";
init_file_per_thread_logger(prefix);
} else {
pretty_env_logger::init();
}
}
self.common.init_logging();
let mut config = self.common.config(None)?;
if self.wasm_timeout.is_some() {

View File

@@ -1,7 +1,7 @@
//! The module that implements the `wasmtime wasm2obj` command.
use crate::obj::compile_to_obj;
use crate::{init_file_per_thread_logger, parse_target, pick_compilation_strategy, CommonOptions};
use crate::{parse_target, pick_compilation_strategy, CommonOptions};
use anyhow::{Context as _, Result};
use std::{
fs::File,
@@ -43,14 +43,7 @@ pub struct WasmToObjCommand {
impl WasmToObjCommand {
/// Executes the command.
pub fn execute(self) -> Result<()> {
if !self.common.disable_logging {
if self.common.log_to_files {
let prefix = "wasm2obj.dbg.";
init_file_per_thread_logger(prefix);
} else {
pretty_env_logger::init();
}
}
self.common.init_logging();
let strategy = pick_compilation_strategy(self.common.cranelift, self.common.lightbeam)?;

View File

@@ -1,6 +1,6 @@
//! The module that implements the `wasmtime wast` command.
use crate::{init_file_per_thread_logger, CommonOptions};
use crate::CommonOptions;
use anyhow::{Context as _, Result};
use std::path::PathBuf;
use structopt::{clap::AppSettings, StructOpt};
@@ -26,14 +26,7 @@ pub struct WastCommand {
impl WastCommand {
/// Executes the command.
pub fn execute(self) -> Result<()> {
if !self.common.disable_logging {
if self.common.log_to_files {
let prefix = "wast.dbg.";
init_file_per_thread_logger(prefix);
} else {
pretty_env_logger::init();
}
}
self.common.init_logging();
let config = self.common.config(None)?;
let store = Store::new(&Engine::new(&config)?);