From 053b1ac17e827f0c21d12297476f5ea61ea4ef60 Mon Sep 17 00:00:00 2001 From: Noa Date: Fri, 13 Dec 2024 11:16:03 -0600 Subject: [PATCH] Use a spinner to show that wasm is compiling in spacetime generate --- crates/cli/src/subcommands/generate/mod.rs | 25 ++++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/crates/cli/src/subcommands/generate/mod.rs b/crates/cli/src/subcommands/generate/mod.rs index c2b75983c2a..d82f51ecf9e 100644 --- a/crates/cli/src/subcommands/generate/mod.rs +++ b/crates/cli/src/subcommands/generate/mod.rs @@ -132,7 +132,12 @@ pub async fn exec(config: Config, args: &clap::ArgMatches) -> anyhow::Result<()> } else { build::exec_with_argstring(config.clone(), project_path, build_options).await? }; - extract_descriptions(&wasm_path)? + let spinner = indicatif::ProgressBar::new_spinner(); + spinner.enable_steady_tick(60); + spinner.set_message("Compiling wasm..."); + let module = compile_wasm(&wasm_path)?; + spinner.set_message("Extracting schema from wasm..."); + extract_descriptions_from_module(module)? }; fs::create_dir_all(out_dir)?; @@ -372,16 +377,22 @@ impl GenItem { } pub fn extract_descriptions(wasm_file: &Path) -> anyhow::Result { - let engine = wasmtime::Engine::default(); - let t = std::time::Instant::now(); - let module = wasmtime::Module::from_file(&engine, wasm_file)?; - println!("compilation took {:?}", t.elapsed()); + let module = compile_wasm(wasm_file)?; + extract_descriptions_from_module(module) +} + +fn compile_wasm(wasm_file: &Path) -> anyhow::Result { + wasmtime::Module::from_file(&wasmtime::Engine::default(), wasm_file) +} + +fn extract_descriptions_from_module(module: wasmtime::Module) -> anyhow::Result { + let engine = module.engine(); let ctx = WasmCtx { mem: None, sink: Vec::new(), }; - let mut store = wasmtime::Store::new(&engine, ctx); - let mut linker = wasmtime::Linker::new(&engine); + let mut store = wasmtime::Store::new(engine, ctx); + let mut linker = wasmtime::Linker::new(engine); linker.allow_shadowing(true).define_unknown_imports_as_traps(&module)?; let module_name = &*format!("spacetime_{MODULE_ABI_MAJOR_VERSION}.0"); linker.func_wrap(