(
runtime: &TokioRuntime,
engine: &Engine,
module_cache: &Arc<SharedCache>,
wasm_path: &Path,
artifact_name: &str,
label: &str,
)
| 2605 | } |
| 2606 | |
| 2607 | fn seed_wasix_module_cache( |
| 2608 | runtime: &TokioRuntime, |
| 2609 | engine: &Engine, |
| 2610 | module_cache: &Arc<SharedCache>, |
| 2611 | wasm_path: &Path, |
| 2612 | artifact_name: &str, |
| 2613 | label: &str, |
| 2614 | ) -> Result<()> { |
| 2615 | let wasm = { |
| 2616 | let _phase = timing::phase("wasix.seed_side_module.read_wasm"); |
| 2617 | fs::read(wasm_path).with_context(|| format!("read WASIX module {}", wasm_path.display()))? |
| 2618 | }; |
| 2619 | let module_hash = { |
| 2620 | let _phase = timing::phase("wasix.seed_side_module.module_hash"); |
| 2621 | ModuleHash::new(&wasm) |
| 2622 | }; |
| 2623 | let seed_key = format!("{artifact_name}:{}:{module_hash}", aot::engine_identity()); |
| 2624 | let mut seeded_side_modules = SEEDED_SIDE_MODULES |
| 2625 | .get_or_init(|| Mutex::new(HashSet::new())) |
| 2626 | .lock() |
| 2627 | .expect("seeded side module cache poisoned"); |
| 2628 | if seeded_side_modules.contains(&seed_key) { |
| 2629 | return Ok(()); |
| 2630 | } |
| 2631 | |
| 2632 | // Keep the process-wide seed check and SharedCache write atomic. Wasmer's |
| 2633 | // shared cache is global to all concurrent PGlite instances in this process. |
| 2634 | let module = { |
| 2635 | let _phase = timing::phase("wasix.seed_side_module.load_aot"); |
| 2636 | aot::load_artifact_module(engine, artifact_name)? |
| 2637 | }; |
| 2638 | { |
| 2639 | let _phase = timing::phase("wasix.seed_side_module.save_cache"); |
| 2640 | block_on_tokio_runtime(runtime, module_cache.save(module_hash, engine, &module)) |
| 2641 | .with_context(|| format!("seed Wasmer module cache for {label} ({module_hash})"))?; |
| 2642 | } |
| 2643 | seeded_side_modules.insert(seed_key); |
| 2644 | Ok(()) |
| 2645 | } |
| 2646 | |
| 2647 | fn block_on_tokio_runtime<F, T>(runtime: &TokioRuntime, future: F) -> T |
| 2648 | where |
no test coverage detected