Skip to content

Commit

Permalink
Showing 6 changed files with 49 additions and 46 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@ vm/**/Cargo.lock
# Others
my-vm-tests.sh
quick.sh
twiggy*
template-test

# Zip output with example wasm binaries
2 changes: 1 addition & 1 deletion framework/meta/src/cmd/contract/meta_config.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ use std::fs;

use multiversx_sc::abi::ContractAbi;

use crate::{cli_args::BuildArgs, tools::post_build::check_tools_installed, CargoTomlContents};
use crate::{cli_args::BuildArgs, tools::check_tools_installed, CargoTomlContents};

use super::output_contract::{OutputContract, OutputContractGlobalConfig};

12 changes: 6 additions & 6 deletions framework/meta/src/cmd/contract/output_contract/wasm_build.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ use crate::{
ei::EIVersion,
mxsc_file_json::{save_mxsc_file_json, MxscFileJson},
print_util::*,
tools::{self, post_build},
tools,
};

impl OutputContract {
@@ -108,7 +108,7 @@ impl OutputContract {

let output_wasm_path = format!("{output_path}/{}", self.wasm_output_name(build_args));
print_call_wasm_opt(&output_wasm_path);
post_build::run_wasm_opt(output_wasm_path.as_str());
tools::run_wasm_opt(output_wasm_path.as_str());
}

fn run_wasm2wat(&self, build_args: &BuildArgs, output_path: &str) {
@@ -173,31 +173,31 @@ impl OutputContract {
if build_args.twiggy_top {
let output_twiggy_top_path =
format!("{output_path}/{}", self.twiggy_top_name(build_args));
post_build::run_twiggy_top(
tools::twiggy::run_twiggy_top(
output_wasm_path.as_str(),
output_twiggy_top_path.as_str(),
);
}
if build_args.twiggy_paths {
let output_twiggy_paths_path =
format!("{output_path}/{}", self.twiggy_paths_name(build_args));
post_build::run_twiggy_paths(
tools::twiggy::run_twiggy_paths(
output_wasm_path.as_str(),
output_twiggy_paths_path.as_str(),
);
}
if build_args.twiggy_monos {
let output_twiggy_monos_path =
format!("{output_path}/{}", self.twiggy_monos_name(build_args));
post_build::run_twiggy_monos(
tools::twiggy::run_twiggy_monos(
output_wasm_path.as_str(),
output_twiggy_monos_path.as_str(),
);
}
if build_args.twiggy_dominators {
let output_twiggy_dominators_path =
format!("{output_path}/{}", self.twiggy_dominators_name(build_args));
post_build::run_twiggy_dominators(
tools::twiggy::run_twiggy_dominators(
output_wasm_path.as_str(),
output_twiggy_dominators_path.as_str(),
);
20 changes: 19 additions & 1 deletion framework/meta/src/tools.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
mod git_describe;
pub mod post_build;
pub mod twiggy;
mod wasm_imports;
mod wasm_opt;
mod wasm_to_wat;

pub use git_describe::git_describe;
pub use wasm_imports::extract_wasm_imports;
pub use wasm_opt::run_wasm_opt;
pub use wasm_to_wat::wasm_to_wat;

use crate::cli_args::BuildArgs;

pub fn check_tools_installed(build_args: &mut BuildArgs) {
if build_args.wasm_opt && !wasm_opt::is_wasm_opt_installed() {
println!("Warning: {} not installed", wasm_opt::WASM_OPT_NAME);
build_args.wasm_opt = false;
}
if build_args.has_twiggy_call() && !twiggy::is_twiggy_installed() {
println!("Warning: {} not installed", twiggy::TWIGGY_NAME);
build_args.twiggy_top = false;
build_args.twiggy_paths = false;
build_args.twiggy_monos = false;
build_args.twiggy_dominators = false;
}
}
Original file line number Diff line number Diff line change
@@ -1,49 +1,14 @@
use std::process::{Command, Stdio};

use crate::cli_args::BuildArgs;
pub const TWIGGY_NAME: &str = "twiggy";

const WASM_OPT_NAME: &str = "wasm-opt";
const TWIGGY_NAME: &str = "twiggy";

pub(crate) fn check_tools_installed(build_args: &mut BuildArgs) {
if build_args.wasm_opt && !is_wasm_opt_installed() {
println!("Warning: {WASM_OPT_NAME} not installed");
build_args.wasm_opt = false;
}
if build_args.has_twiggy_call() && !is_twiggy_installed() {
println!("Warning: {TWIGGY_NAME} not installed");
build_args.twiggy_top = false;
build_args.twiggy_paths = false;
build_args.twiggy_monos = false;
build_args.twiggy_dominators = false;
}
}

fn is_wasm_opt_installed() -> bool {
Command::new(WASM_OPT_NAME)
.args(["--version"])
.output()
.is_ok()
}

fn is_twiggy_installed() -> bool {
pub fn is_twiggy_installed() -> bool {
Command::new(TWIGGY_NAME)
.args(["--version"])
.output()
.is_ok()
}

pub(crate) fn run_wasm_opt(output_wasm_path: &str) {
let exit_status = Command::new(WASM_OPT_NAME)
.args([output_wasm_path, "-Oz", "--output", output_wasm_path])
.spawn()
.expect("failed to spawn wasm-opt process")
.wait()
.expect("wasm-opt was not running");

assert!(exit_status.success(), "wasm-opt process failed");
}

fn run_with_stdout_file<I, S>(stdout_file_name: &str, args: I)
where
I: IntoIterator<Item = S>,
21 changes: 21 additions & 0 deletions framework/meta/src/tools/wasm_opt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::process::Command;

pub const WASM_OPT_NAME: &str = "wasm-opt";

pub fn is_wasm_opt_installed() -> bool {
Command::new(WASM_OPT_NAME)
.args(["--version"])
.output()
.is_ok()
}

pub fn run_wasm_opt(output_wasm_path: &str) {
let exit_status = Command::new(WASM_OPT_NAME)
.args([output_wasm_path, "-Oz", "--output", output_wasm_path])
.spawn()
.expect("failed to spawn wasm-opt process")
.wait()
.expect("wasm-opt was not running");

assert!(exit_status.success(), "wasm-opt process failed");
}

0 comments on commit d9cae84

Please sign in to comment.