Skip to content

Commit

Permalink
Remove the wasmtime wasm2obj command (#3301)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alexcrichton authored Sep 8, 2021
1 parent 164835e commit 8ebaaf9
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 182 deletions.
10 changes: 0 additions & 10 deletions docs/cli-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,6 @@ $ wasmtime config new

And that'll print out the path to the file you can edit.

## `wasm2obj`

This is an experimental subcommand to compile a WebAssembly module to native
code. Work for this is still heavily under development, but you can execute this
with:

```sh
$ wasmtime wasm2obj foo.wasm foo.o
```

## `compile`

This subcommand is used to Ahead-Of-Time (AOT) compile a WebAssembly module to produce
Expand Down
6 changes: 1 addition & 5 deletions src/bin/wasmtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use anyhow::Result;
use structopt::{clap::AppSettings, clap::ErrorKind, StructOpt};
use wasmtime_cli::commands::{
CompileCommand, ConfigCommand, RunCommand, SettingsCommand, WasmToObjCommand, WastCommand,
CompileCommand, ConfigCommand, RunCommand, SettingsCommand, WastCommand,
};

/// Wasmtime WebAssembly Runtime
Expand Down Expand Up @@ -44,9 +44,6 @@ enum WasmtimeApp {
Run(RunCommand),
/// Displays available Cranelift settings for a target.
Settings(SettingsCommand),
/// Translates a WebAssembly module to native object file
#[structopt(name = "wasm2obj")]
WasmToObj(WasmToObjCommand),
/// Runs a WebAssembly test script file
Wast(WastCommand),
}
Expand All @@ -59,7 +56,6 @@ impl WasmtimeApp {
Self::Compile(c) => c.execute(),
Self::Run(c) => c.execute(),
Self::Settings(c) => c.execute(),
Self::WasmToObj(c) => c.execute(),
Self::Wast(c) => c.execute(),
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod compile;
mod config;
mod run;
mod settings;
mod wasm2obj;
mod wast;

pub use self::{compile::*, config::*, run::*, settings::*, wasm2obj::*, wast::*};
pub use self::{compile::*, config::*, run::*, settings::*, wast::*};
5 changes: 3 additions & 2 deletions src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}
}
Expand Down
76 changes: 0 additions & 76 deletions src/commands/wasm2obj.rs

This file was deleted.

9 changes: 0 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,13 @@ lazy_static::lazy_static! {
}

pub mod commands;
mod obj;

use anyhow::{bail, Result};
use std::collections::HashMap;
use std::path::PathBuf;
use structopt::StructOpt;
use target_lexicon::Triple;
use wasmtime::{Config, ProfilingStrategy, Strategy};

pub use obj::compile_to_obj;

fn pick_compilation_strategy(cranelift: bool, lightbeam: bool) -> Result<Strategy> {
Ok(match (lightbeam, cranelift) {
(true, false) => Strategy::Lightbeam,
Expand Down Expand Up @@ -528,11 +524,6 @@ fn parse_cranelift_flag(name_and_value: &str) -> Result<(String, String)> {
Ok((name, value))
}

fn parse_target(s: &str) -> Result<Triple> {
use std::str::FromStr;
Triple::from_str(&s).map_err(|e| anyhow::anyhow!(e))
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
67 changes: 0 additions & 67 deletions src/obj.rs

This file was deleted.

21 changes: 10 additions & 11 deletions tests/all/debug/obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@ use std::fs::File;
use std::io::Write;
use std::path::Path;
use target_lexicon::Triple;
use wasmtime::Strategy;
use wasmtime_cli::compile_to_obj;
use wasmtime::{Config, Engine, Module};

pub fn compile_cranelift(
wasm: &[u8],
target: Option<Triple>,
output: impl AsRef<Path>,
) -> Result<()> {
let obj = compile_to_obj(
wasm,
target.as_ref(),
Strategy::Cranelift,
false,
wasmtime::OptLevel::None,
true,
)?;
let mut config = Config::new();
config.debug_info(true);
if let Some(target) = target {
config.target(&target.to_string())?;
}
let engine = Engine::new(&config)?;
let module = Module::new(&engine, wasm)?;
let bytes = module.serialize()?;

let mut file = File::create(output).context("failed to create object file")?;
file.write_all(&obj)
file.write_all(&bytes)
.context("failed to write object file")?;

Ok(())
Expand Down

0 comments on commit 8ebaaf9

Please sign in to comment.