(input: &Path, output: &Path)
| 450 | |
| 451 | #[cfg(feature = "aot-serializer")] |
| 452 | fn 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")] |
| 484 | fn llvm_aot_engine() -> wasmer::Engine { |
no test coverage detected