You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

27 lines
732 B

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(())
}