Skip to content

Commit

Permalink
Add verbose option to scrypto compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
lrubasze committed Oct 24, 2024
1 parent a2d5295 commit a6bb25f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions radix-clis/src/scrypto/cmd_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ pub struct Build {
/// Pass any additional option to `cargo build` call.
#[clap(long)]
custom_option: Option<Vec<String>>,

/// Prints compilation steps.
#[clap(short, long)]
verbose: bool,
}

impl Build {
Expand Down Expand Up @@ -115,6 +119,7 @@ impl Build {
compiler_builder.package(p);
});
}
compiler_builder.debug(self.verbose);

if let Some(env) = &self.env {
let env_variables_decoded: Vec<Vec<&str>> = env
Expand Down
16 changes: 14 additions & 2 deletions scrypto-compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ pub struct ScryptoCompilerInputParams {
/// Default configuration is equivalent to running the following commands in the CLI:
/// wasm-opt -0z --strip-debug --strip-dwarf --strip-producers --dce $some_path $some_path
pub wasm_optimization: Option<wasm_opt::OptimizationOptions>,
/// If set to true then compiler informs about the compilation progress
pub verbose: bool,
}
impl Default for ScryptoCompilerInputParams {
/// Definition of default `ScryptoCompiler` configuration.
Expand Down Expand Up @@ -120,6 +122,7 @@ impl Default for ScryptoCompilerInputParams {
ignore_locked_env_var: false,
locked: false,
wasm_optimization,
verbose: false,
};
// Apply default log level features
ret.features
Expand Down Expand Up @@ -769,7 +772,9 @@ impl ScryptoCompiler {

fn wasm_optimize(&self, wasm_path: &Path) -> Result<(), ScryptoCompilerError> {
if let Some(wasm_opt_config) = &self.input_params.wasm_optimization {
println!("optimizing WASM {:?}", wasm_opt_config);
if self.input_params.verbose {
println!("Optimizing WASM {:?}", wasm_opt_config);
}
wasm_opt_config
.run(wasm_path, wasm_path)
.map_err(ScryptoCompilerError::WasmOptimizationError)
Expand Down Expand Up @@ -1020,7 +1025,9 @@ impl ScryptoCompiler {
}

fn cargo_command_call(&mut self, command: &mut Command) -> Result<(), ScryptoCompilerError> {
println!("executing command: {}", cmd_to_string(command));
if self.input_params.verbose {
println!("Executing command: {}", cmd_to_string(command));
}
let status = command.status().map_err(|e| {
ScryptoCompilerError::IOError(e, Some(String::from("Cargo build command failed.")))
})?;
Expand Down Expand Up @@ -1377,6 +1384,11 @@ impl ScryptoCompilerBuilder {
self
}

pub fn debug(&mut self, verbose: bool) -> &mut Self {
self.input_params.verbose = verbose;
self
}

pub fn build(&mut self) -> Result<ScryptoCompiler, ScryptoCompilerError> {
ScryptoCompiler::from_input_params(&mut self.input_params)
}
Expand Down

0 comments on commit a6bb25f

Please sign in to comment.