MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / compile_cranelift

Function compile_cranelift

tests/all/native_debug/obj.rs:7–29  ·  view source on GitHub ↗
(
    wasm: &[u8],
    path: Option<&Path>,
    target: Option<Triple>,
    output: impl AsRef<Path>,
)

Source from the content-addressed store, hash-verified

5use wasmtime::{CodeBuilder, Config, Engine, Result, error::Context as _};
6
7pub 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}

Callers 2

check_wasmFunction · 0.85
check_watFunction · 0.85

Calls 11

OkFunction · 0.85
compile_moduleMethod · 0.80
wasm_binary_or_textMethod · 0.80
write_allMethod · 0.80
newFunction · 0.50
createFunction · 0.50
debug_infoMethod · 0.45
targetMethod · 0.45
to_stringMethod · 0.45
serializeMethod · 0.45
contextMethod · 0.45

Tested by

no test coverage detected