Skip to content

Commit

Permalink
Use a spinner to show that wasm is compiling in spacetime generate
Browse files Browse the repository at this point in the history
  • Loading branch information
coolreader18 committed Dec 13, 2024
1 parent 9211708 commit d9bb6d7
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions crates/cli/src/subcommands/generate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -372,10 +377,16 @@ impl GenItem {
}

pub fn extract_descriptions(wasm_file: &Path) -> anyhow::Result<RawModuleDef> {
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> {
wasmtime::Module::from_file(&wasmtime::Engine::default(), wasm_file)
}

fn extract_descriptions_from_module(module: wasmtime::Module) -> anyhow::Result<RawModuleDef> {
let engine = module.engine();
let ctx = WasmCtx {
mem: None,
sink: Vec::new(),
Expand Down

0 comments on commit d9bb6d7

Please sign in to comment.