MCPcopy Create free account
hub / github.com/f0rr0/oliphaunt / serialize_aot_module

Function serialize_aot_module

xtask/src/main.rs:452–481  ·  view source on GitHub ↗
(input: &Path, output: &Path)

Source from the content-addressed store, hash-verified

450
451#[cfg(feature = "aot-serializer")]
452fn serialize_aot_module(input: &Path, output: &Path) -> Result<()> {
453 let engine = llvm_aot_engine();
454 print_aot_engine_config(&engine);
455 println!("host-target: {}-{}", env::consts::OS, env::consts::ARCH);
456
457 let store = wasmer::Store::new(engine);
458 let bytes = fs::read(input).with_context(|| format!("read {}", input.display()))?;
459 let module = wasmer::Module::new(&store, &bytes)
460 .with_context(|| format!("compile {}", input.display()))?;
461 let serialized = module.serialize().context("serialize module")?;
462
463 if let Some(parent) = output.parent() {
464 fs::create_dir_all(parent).with_context(|| format!("create {}", parent.display()))?;
465 }
466 let file = fs::File::create(output).with_context(|| format!("create {}", output.display()))?;
467 let mut encoder = ZstdEncoder::new(file, 19)
468 .with_context(|| format!("create zstd encoder for {}", output.display()))?;
469 let mut serialized_slice = serialized.as_ref();
470 io::copy(&mut serialized_slice, &mut encoder)
471 .with_context(|| format!("write {}", output.display()))?;
472 encoder
473 .finish()
474 .with_context(|| format!("finish {}", output.display()))?;
475 println!(
476 "serialized {} bytes to {}",
477 serialized.len(),
478 output.display()
479 );
480 Ok(())
481}
482
483#[cfg(feature = "aot-serializer")]
484fn llvm_aot_engine() -> wasmer::Engine {

Callers 1

serialize_aot_cliFunction · 0.85

Calls 4

llvm_aot_engineFunction · 0.85
print_aot_engine_configFunction · 0.85
serializeMethod · 0.80
finishMethod · 0.80

Tested by

no test coverage detected