Skip to content

Commit

Permalink
Support .wat files in the explore command (#8314)
Browse files Browse the repository at this point in the history
* Support `.wat` files in the `explore` command

Many on the `wasmtime` subcommands work with either `.wasm` or `.wat`
files, but `explore` only works with `.wasm`. This change accepts `.wat`
as well.

* use wat feature
  • Loading branch information
adambratschikaye authored Apr 9, 2024
1 parent 72a3b8b commit b3cadb4
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/commands/explore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use anyhow::{Context, Result};
use clap::Parser;
use std::path::PathBuf;
use std::{borrow::Cow, path::PathBuf};
use wasmtime_cli_flags::CommonOptions;

/// Explore the compilation of a WebAssembly module to native code.
Expand Down Expand Up @@ -32,8 +32,15 @@ impl ExploreCommand {

let config = self.common.config(self.target.as_deref())?;

let wasm = std::fs::read(&self.module)
.with_context(|| format!("failed to read Wasm module: {}", self.module.display()))?;
let bytes =
Cow::Owned(std::fs::read(&self.module).with_context(|| {
format!("failed to read Wasm module: {}", self.module.display())
})?);
#[cfg(feature = "wat")]
let bytes = wat::parse_bytes(&bytes).map_err(|mut e| {
e.set_path(&self.module);
e
})?;

let output = self
.output
Expand All @@ -43,7 +50,7 @@ impl ExploreCommand {
.with_context(|| format!("failed to create file: {}", output.display()))?;
let mut output_file = std::io::BufWriter::new(output_file);

wasmtime_explorer::generate(&config, self.target.as_deref(), &wasm, &mut output_file)?;
wasmtime_explorer::generate(&config, self.target.as_deref(), &bytes, &mut output_file)?;
println!("Exploration written to {}", output.display());
Ok(())
}
Expand Down

0 comments on commit b3cadb4

Please sign in to comment.