Remove the wasmtime wasm2obj command (#3301)

* Remove the `wasmtime wasm2obj` command

This commit removes the `wasm2obj` subcommand of the `wasmtime` CLI.
This subcommand has a very long history and dates back quite far. While
it's existed, however, it's never been documented in terms of the output
it's produced. AFAIK it's only ever been used for debugging to see the
machine code output of Wasmtime on some modules. With recent changes to
the module serialization output the output of `wasmtime compile`, the
`*.cwasm` file, is now a native ELF file which can be fed to standard
tools like `objdump`. Consequently I dont think there's any remaining
need to keep `wasm2obj` around itself, so this commit removes the
subcommand.

* More code to delete

* Try to fix debuginfo tests
This commit is contained in:
Alex Crichton
2021-09-08 10:40:58 -05:00
committed by GitHub
parent 164835ecf5
commit 8ebaaf928d
8 changed files with 15 additions and 182 deletions

View File

@@ -22,8 +22,9 @@ use wasmtime_wasi_crypto::WasiCryptoCtx;
fn parse_module(s: &OsStr) -> Result<PathBuf, OsString> {
// Do not accept wasmtime subcommand names as the module name
match s.to_str() {
Some("help") | Some("config") | Some("run") | Some("wasm2obj") | Some("wast")
| Some("compile") => Err("module name cannot be the same as a subcommand".into()),
Some("help") | Some("config") | Some("run") | Some("wast") | Some("compile") => {
Err("module name cannot be the same as a subcommand".into())
}
_ => Ok(s.into()),
}
}

View File

@@ -1,76 +0,0 @@
//! The module that implements the `wasmtime wasm2obj` command.
use crate::obj::compile_to_obj;
use crate::{parse_target, pick_compilation_strategy, CommonOptions};
use anyhow::{Context as _, Result};
use std::{
fs::File,
io::Write,
path::{Path, PathBuf},
};
use structopt::{clap::AppSettings, StructOpt};
use target_lexicon::Triple;
lazy_static::lazy_static! {
static ref AFTER_HELP: String = {
format!(
"The translation is dependent on the environment chosen.\n\
The default is a dummy environment that produces placeholder values.\n\
\n\
{}",
crate::FLAG_EXPLANATIONS.as_str()
)
};
}
/// Translates a WebAssembly module to native object file
#[derive(StructOpt)]
#[structopt(
name = "wasm2obj",
version = env!("CARGO_PKG_VERSION"),
setting = AppSettings::ColoredHelp,
after_help = AFTER_HELP.as_str(),
)]
pub struct WasmToObjCommand {
#[structopt(flatten)]
common: CommonOptions,
/// The path of the WebAssembly module to translate
#[structopt(index = 1, value_name = "MODULE_PATH", parse(from_os_str))]
module: PathBuf,
/// The path of the output object file
#[structopt(index = 2, value_name = "OUTPUT_PATH")]
output: String,
/// The target triple; default is the host triple
#[structopt(long, value_name = "TARGET", parse(try_from_str = parse_target))]
target: Option<Triple>,
}
impl WasmToObjCommand {
/// Executes the command.
pub fn execute(self) -> Result<()> {
self.common.init_logging();
let strategy = pick_compilation_strategy(self.common.cranelift, self.common.lightbeam)?;
let data = wat::parse_file(&self.module).context("failed to parse module")?;
let obj = compile_to_obj(
&data,
self.target.as_ref(),
strategy,
self.common.enable_simd,
self.common.opt_level(),
self.common.debug_info,
)?;
let mut file =
File::create(Path::new(&self.output)).context("failed to create object file")?;
file.write_all(&obj)
.context("failed to write object file")?;
Ok(())
}
}