multiversx_sc_meta_lib/tools/
wasm_opt.rs

1use std::process::Command;
2
3pub const WASM_OPT_NAME: &str = "wasm-opt";
4
5pub fn is_wasm_opt_installed() -> bool {
6    Command::new(WASM_OPT_NAME)
7        .args(["--version"])
8        .output()
9        .is_ok()
10}
11
12pub fn install_wasm_opt() {
13    let cmd = Command::new("cargo")
14        .args(["install", "wasm-opt"])
15        .status()
16        .expect("failed to execute `cargo`");
17
18    assert!(cmd.success(), "failed to install wasm-opt");
19
20    println!("wasm-opt installed successfully");
21}
22
23pub fn run_wasm_opt(output_wasm_path: &str) {
24    let exit_status = Command::new(WASM_OPT_NAME)
25        .arg(output_wasm_path)
26        .arg("-Oz")
27        .arg("--enable-bulk-memory")
28        .arg("--output")
29        .arg(output_wasm_path)
30        .spawn()
31        .expect("failed to spawn wasm-opt process")
32        .wait()
33        .expect("wasm-opt was not running");
34
35    assert!(exit_status.success(), "wasm-opt process failed");
36}