-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into digital-cash-multi-fee
- Loading branch information
Showing
11 changed files
with
122 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +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; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::process::{Command, Stdio}; | ||
|
||
pub const TWIGGY_NAME: &str = "twiggy"; | ||
|
||
pub fn is_twiggy_installed() -> bool { | ||
Command::new(TWIGGY_NAME) | ||
.args(["--version"]) | ||
.output() | ||
.is_ok() | ||
} | ||
|
||
fn run_with_stdout_file<I, S>(stdout_file_name: &str, args: I) | ||
where | ||
I: IntoIterator<Item = S>, | ||
S: AsRef<std::ffi::OsStr>, | ||
{ | ||
let stdout_file = std::fs::File::create(stdout_file_name).unwrap(); | ||
let _ = Command::new(TWIGGY_NAME) | ||
.args(args) | ||
.stdout(Stdio::from(stdout_file)) | ||
.spawn() | ||
.expect("failed to spawn twiggy process") | ||
.wait() | ||
.expect("twiggy was not running"); | ||
} | ||
|
||
pub(crate) fn run_twiggy_top(output_wasm_path: &str, output_twiggy_top_path: &str) { | ||
run_with_stdout_file( | ||
output_twiggy_top_path, | ||
["top", "-n", "1000", output_wasm_path], | ||
); | ||
} | ||
|
||
pub(crate) fn run_twiggy_paths(output_wasm_path: &str, output_twiggy_paths_path: &str) { | ||
run_with_stdout_file(output_twiggy_paths_path, ["paths", output_wasm_path]); | ||
} | ||
|
||
pub(crate) fn run_twiggy_monos(output_wasm_path: &str, output_twiggy_monos_path: &str) { | ||
run_with_stdout_file(output_twiggy_monos_path, ["monos", output_wasm_path]); | ||
} | ||
|
||
pub(crate) fn run_twiggy_dominators(output_wasm_path: &str, output_twiggy_dominators_path: &str) { | ||
run_with_stdout_file( | ||
output_twiggy_dominators_path, | ||
["dominators", output_wasm_path], | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use anyhow::Result; | ||
use std::fs; | ||
|
||
/// Converts a .wasm file on the disk to .wat. | ||
pub fn wasm_to_wat(output_wasm_path: &str, output_wat_path: &str) -> Result<()> { | ||
let wat_string = wasmprinter::print_file(output_wasm_path)?; | ||
fs::write(output_wat_path, wat_string)?; | ||
Ok(()) | ||
} |