Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a spinner to show that wasm is compiling in spacetime generate #2057

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 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)?
coolreader18 marked this conversation as resolved.
Show resolved Hide resolved
};

fs::create_dir_all(out_dir)?;
Expand Down Expand Up @@ -372,16 +377,22 @@ 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());
coolreader18 marked this conversation as resolved.
Show resolved Hide resolved
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(),
};
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(
Expand Down
Loading