* 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
28 lines
732 B
Rust
28 lines
732 B
Rust
use anyhow::{Context as _, Result};
|
|
use std::fs::File;
|
|
use std::io::Write;
|
|
use std::path::Path;
|
|
use target_lexicon::Triple;
|
|
use wasmtime::{Config, Engine, Module};
|
|
|
|
pub fn compile_cranelift(
|
|
wasm: &[u8],
|
|
target: Option<Triple>,
|
|
output: impl AsRef<Path>,
|
|
) -> Result<()> {
|
|
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(&bytes)
|
|
.context("failed to write object file")?;
|
|
|
|
Ok(())
|
|
}
|