Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/tests/all/native_debug/obj.rs
3060 views
1
use std::fs::File;
2
use std::io::Write;
3
use std::path::Path;
4
use target_lexicon::Triple;
5
use wasmtime::{CodeBuilder, Config, Engine, Result, error::Context as _};
6
7
pub fn compile_cranelift(
8
wasm: &[u8],
9
path: Option<&Path>,
10
target: Option<Triple>,
11
output: impl AsRef<Path>,
12
) -> Result<()> {
13
let mut config = Config::new();
14
config.debug_info(true);
15
if let Some(target) = target {
16
config.target(&target.to_string())?;
17
}
18
let engine = Engine::new(&config)?;
19
let module = CodeBuilder::new(&engine)
20
.wasm_binary_or_text(wasm, path)?
21
.compile_module()?;
22
let bytes = module.serialize()?;
23
24
let mut file = File::create(output).context("failed to create object file")?;
25
file.write_all(&bytes)
26
.context("failed to write object file")?;
27
28
Ok(())
29
}
30
31