Files
wasmtime/tests/all/debug/obj.rs
Yury Delendik e5b81bbc28 Migrating code to object (from faerie) (#1848)
* Using the "object" library everywhere in wasmtime.
* scroll_derive
2020-06-10 11:27:00 -05:00

31 lines
731 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::Strategy;
use wasmtime_cli::compile_to_obj;
use wasmtime_environ::CacheConfig;
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,
&CacheConfig::new_cache_disabled(),
)?;
let mut file = File::create(output).context("failed to create object file")?;
file.write_all(&obj.write()?)
.context("failed to write object file")?;
Ok(())
}