From 9b691c57628c6b398f517842780147f6ce49ffb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Fri, 10 May 2024 23:34:30 +0200 Subject: [PATCH 01/11] Added CompileProfile --- radix-engine-tests/src/common.rs | 9 ++++- .../tests/flash/crypto_utils.rs | 7 +++- .../tests/vm/system_wasm_buffers.rs | 5 ++- scrypto-test/src/ledger_simulator/compile.rs | 39 +++++++++++++++---- .../src/ledger_simulator/ledger_simulator.rs | 6 ++- scrypto-test/src/sdk/package.rs | 32 ++------------- scrypto-test/tests/tuple_return.rs | 1 + 7 files changed, 58 insertions(+), 41 deletions(-) diff --git a/radix-engine-tests/src/common.rs b/radix-engine-tests/src/common.rs index 91f76c5fd0..a7ab3a0217 100644 --- a/radix-engine-tests/src/common.rs +++ b/radix-engine-tests/src/common.rs @@ -38,6 +38,7 @@ pub mod package_loader { pub mod package_loader { use radix_common::prelude::*; use radix_substate_store_queries::typed_substate_layout::*; + use scrypto_test::ledger_simulator::CompileProfile; use std::path::PathBuf; pub struct PackageLoader; @@ -45,7 +46,13 @@ pub mod package_loader { pub fn get(name: &str) -> (Vec, PackageDefinition) { let manifest_dir = PathBuf::from_str(env!("CARGO_MANIFEST_DIR")).unwrap(); let package_dir = manifest_dir.join("assets").join("blueprints").join(name); - scrypto_test::prelude::Compile::compile(package_dir) + scrypto_test::prelude::Compile::compile(package_dir, CompileProfile::FastWithTraceLogs) + } + + pub fn get_using_default_compiler_options(name: &str) -> (Vec, PackageDefinition) { + let manifest_dir = PathBuf::from_str(env!("CARGO_MANIFEST_DIR")).unwrap(); + let package_dir = manifest_dir.join("assets").join("blueprints").join(name); + scrypto_test::prelude::Compile::compile(package_dir, CompileProfile::Default) } } } diff --git a/radix-engine-tests/tests/flash/crypto_utils.rs b/radix-engine-tests/tests/flash/crypto_utils.rs index 9f64adfd85..9cc8505b5a 100644 --- a/radix-engine-tests/tests/flash/crypto_utils.rs +++ b/radix-engine-tests/tests/flash/crypto_utils.rs @@ -89,8 +89,11 @@ fn run_flash_test_test_environment(enable_bls: bool, expect_success: bool) { .build(); // Act - let result = - PackageFactory::compile_and_publish(path_local_blueprint!("crypto_scrypto"), &mut test_env); + let result = PackageFactory::compile_and_publish( + path_local_blueprint!("crypto_scrypto"), + &mut test_env, + CompileProfile::Fast, + ); // Assert if expect_success { diff --git a/radix-engine-tests/tests/vm/system_wasm_buffers.rs b/radix-engine-tests/tests/vm/system_wasm_buffers.rs index 1c7777a7ad..3ca0978b05 100644 --- a/radix-engine-tests/tests/vm/system_wasm_buffers.rs +++ b/radix-engine-tests/tests/vm/system_wasm_buffers.rs @@ -14,7 +14,10 @@ fn get_ledger() -> ( LedgerSimulator, ComponentAddress, ) { - let (code, definition) = Compile::compile(path_local_blueprint!("system_wasm_buffers")); + let (code, definition) = Compile::compile( + path_local_blueprint!("system_wasm_buffers"), + CompileProfile::FastWithTraceLogs, + ); // Arrange let mut ledger = LedgerSimulatorBuilder::new().build(); diff --git a/scrypto-test/src/ledger_simulator/compile.rs b/scrypto-test/src/ledger_simulator/compile.rs index 8e65be1151..6169003923 100644 --- a/scrypto-test/src/ledger_simulator/compile.rs +++ b/scrypto-test/src/ledger_simulator/compile.rs @@ -2,16 +2,31 @@ use crate::prelude::*; use scrypto_compiler::*; use std::path::Path; +pub enum CompileProfile { + /// Uses default compilation options - same as `scrypto build`. Should be used in all cases which requires + /// compilation results to be as close to production as possible (for instance costing related tests). + Default, + /// Disables WASM optimization to speed-up compilation process, by default used by SDK PackageFactory. + Fast, + /// Disables WASM optimization and enables all logs from error to trace level, by default used by Ledger Simulator. + FastWithTraceLogs, +} + pub struct Compile; impl Compile { - pub fn compile>(package_dir: P) -> (Vec, PackageDefinition) { + pub fn compile>( + package_dir: P, + compile_profile: CompileProfile, + ) -> (Vec, PackageDefinition) { Self::compile_with_env_vars( package_dir, btreemap! { "RUSTFLAGS".to_owned() => "".to_owned(), "CARGO_ENCODED_RUSTFLAGS".to_owned() => "".to_owned(), }, + compile_profile, + true, ) } @@ -19,20 +34,30 @@ impl Compile { pub fn compile_with_env_vars>( package_dir: P, env_vars: sbor::rust::collections::BTreeMap, + compile_profile: CompileProfile, + use_coverage: bool, ) -> (Vec, PackageDefinition) { // Initialize compiler let mut compiler_builder = ScryptoCompiler::builder(); - compiler_builder - .manifest_path(package_dir.as_ref()) - .optimize_with_wasm_opt(None) - .log_level(Level::Trace); // all logs from error to trace + compiler_builder.manifest_path(package_dir.as_ref()); + + match compile_profile { + CompileProfile::Default => (), + CompileProfile::Fast => { + compiler_builder.optimize_with_wasm_opt(None); + } + CompileProfile::FastWithTraceLogs => { + compiler_builder.optimize_with_wasm_opt(None); + compiler_builder.log_level(Level::Trace); // all logs from error to trace + } + } env_vars.iter().for_each(|(name, value)| { compiler_builder.env(name, EnvironmentVariableAction::Set(value.clone())); }); #[cfg(feature = "coverage")] - { + if use_coverage { compiler_builder.coverage(); } @@ -42,7 +67,7 @@ impl Compile { #[cfg(feature = "coverage")] // Check if binary exists in coverage directory, if it doesn't only then build it - { + if use_coverage { let mut coverage_path = compiler.target_binary_path(); if coverage_path.is_file() { let code = fs::read(&coverage_path).unwrap_or_else(|err| { diff --git a/scrypto-test/src/ledger_simulator/ledger_simulator.rs b/scrypto-test/src/ledger_simulator/ledger_simulator.rs index bea9822391..096af402f3 100644 --- a/scrypto-test/src/ledger_simulator/ledger_simulator.rs +++ b/scrypto-test/src/ledger_simulator/ledger_simulator.rs @@ -1238,7 +1238,7 @@ impl LedgerSimulator { } pub fn compile>(&mut self, package_dir: P) -> (Vec, PackageDefinition) { - Compile::compile(package_dir) + Compile::compile(package_dir, CompileProfile::FastWithTraceLogs) } // Doesn't need to be here - kept for backward compatibility @@ -2614,7 +2614,9 @@ impl From<(Vec, PackageDefinition)> for PackagePublishingSource { impl PackagePublishingSource { pub fn code_and_definition(self) -> (Vec, PackageDefinition) { match self { - Self::CompileAndPublishFromSource(path) => Compile::compile(path), + Self::CompileAndPublishFromSource(path) => { + Compile::compile(path, CompileProfile::FastWithTraceLogs) + } Self::PublishExisting(code, definition) => (code, definition), } } diff --git a/scrypto-test/src/sdk/package.rs b/scrypto-test/src/sdk/package.rs index 963237a7c9..549eb447aa 100644 --- a/scrypto-test/src/sdk/package.rs +++ b/scrypto-test/src/sdk/package.rs @@ -1,7 +1,6 @@ use std::path::Path; use crate::prelude::*; -use scrypto_compiler::*; pub struct PackageFactory; @@ -59,12 +58,13 @@ impl PackageFactory { pub fn compile_and_publish( path: P, env: &mut TestEnvironment, + compile_profile: CompileProfile, ) -> Result where P: AsRef, D: SubstateDatabase + CommittableSubstateDatabase + 'static, { - let (wasm, package_definition) = Self::compile(path); + let (wasm, package_definition) = Self::compile(path, compile_profile); Self::publish_advanced( OwnerRole::None, package_definition, @@ -75,34 +75,10 @@ impl PackageFactory { ) } - pub fn compile

(path: P) -> (Vec, PackageDefinition) + pub fn compile

(path: P, compile_profile: CompileProfile) -> (Vec, PackageDefinition) where P: AsRef, { - // Initialize compiler - let mut compiler = ScryptoCompiler::builder() - .manifest_path(path.as_ref()) - .optimize_with_wasm_opt(None) - .build() - .unwrap_or_else(|err| panic!("Failed to initialize Scrypto Compiler {:?}", err)); - - // Build - let mut build_artifacts = compiler.compile().unwrap_or_else(|err| { - panic!( - "Failed to compile package: {:?}, error: {:?}", - path.as_ref(), - err - ) - }); - - if !build_artifacts.is_empty() { - let build_artifact = build_artifacts.remove(0); // take first element - ( - build_artifact.wasm.content, - build_artifact.package_definition.content, - ) - } else { - panic!("Build artifacts list is empty: {:?}", path.as_ref(),); - } + Compile::compile_with_env_vars(path, BTreeMap::new(), compile_profile, false) } } diff --git a/scrypto-test/tests/tuple_return.rs b/scrypto-test/tests/tuple_return.rs index 03b8516079..e4b426bfce 100644 --- a/scrypto-test/tests/tuple_return.rs +++ b/scrypto-test/tests/tuple_return.rs @@ -8,6 +8,7 @@ fn tuple_returns_work_with_scrypto_test() { let package_address = PackageFactory::compile_and_publish( concat!(env!("CARGO_MANIFEST_DIR"), "/tests/blueprints/tuple-return"), &mut env, + CompileProfile::Fast, ) .unwrap(); From 9901b77db398b552fba2f596c7ca7eef794a29e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Sat, 11 May 2024 01:22:16 +0200 Subject: [PATCH 02/11] Added test --- scrypto-test/src/ledger_simulator/compile.rs | 88 +++++++++++++++++++- 1 file changed, 85 insertions(+), 3 deletions(-) diff --git a/scrypto-test/src/ledger_simulator/compile.rs b/scrypto-test/src/ledger_simulator/compile.rs index 6169003923..4f6f0322a0 100644 --- a/scrypto-test/src/ledger_simulator/compile.rs +++ b/scrypto-test/src/ledger_simulator/compile.rs @@ -35,7 +35,7 @@ impl Compile { package_dir: P, env_vars: sbor::rust::collections::BTreeMap, compile_profile: CompileProfile, - use_coverage: bool, + _use_coverage: bool, ) -> (Vec, PackageDefinition) { // Initialize compiler let mut compiler_builder = ScryptoCompiler::builder(); @@ -57,7 +57,7 @@ impl Compile { }); #[cfg(feature = "coverage")] - if use_coverage { + if _use_coverage { compiler_builder.coverage(); } @@ -67,7 +67,7 @@ impl Compile { #[cfg(feature = "coverage")] // Check if binary exists in coverage directory, if it doesn't only then build it - if use_coverage { + if _use_coverage { let mut coverage_path = compiler.target_binary_path(); if coverage_path.is_file() { let code = fs::read(&coverage_path).unwrap_or_else(|err| { @@ -120,3 +120,85 @@ impl Compile { } } } + +#[cfg(test)] +mod tests { + use super::{Compile, CompileProfile}; + use std::process::Command; + + fn compile_blueprint() -> Vec { + // Build `scrypto` cli + Command::new("cargo") + .arg("build") + .arg("--release") + .arg("--bin") + .arg("scrypto") + .current_dir(concat!(env!("CARGO_MANIFEST_DIR"), "/../radix-clis")) + .output() + .inspect_err(|e| println!("Scrypto cli build failed: {}", e)) + .unwrap(); + + // Run `scrypto build` for example blueprit + Command::new(concat!( + env!("CARGO_MANIFEST_DIR"), + "/../radix-clis/target/release/scrypto" + )) + .arg("build") + .current_dir(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/blueprints/tuple-return" + )) + .output() + .inspect_err(|e| println!("Blueprint compilation falied: {}", e)) + .unwrap(); + + let output_file = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/blueprints/target/wasm32-unknown-unknown/release/tuple_return.wasm" + ); + std::fs::read(output_file) + .inspect_err(|e| println!("Failed to load file: {}, error: {}", output_file, e)) + .unwrap() + } + + #[test] + fn validate_compile_profile_default() { + // Compile blueprint using `scrypto compile` command + let output_file_content = compile_blueprint(); + + // Compile same blueprint using Compile object + let (bin, _) = Compile::compile( + concat!(env!("CARGO_MANIFEST_DIR"), "/tests/blueprints/tuple-return"), + CompileProfile::Default, + ); + + // Assert + assert_eq!( + output_file_content.len(), + bin.len(), + "Wasm files should have same size." + ); + assert_eq!( + output_file_content, bin, + "Wasm files should have same content." + ) + } + + #[test] + fn validate_compile_profile_fast_with_log() { + // Compile blueprint using `scrypto compile` command + let output_file_content = compile_blueprint(); + + // Compile same blueprint using Compile object + let (bin, _) = Compile::compile( + concat!(env!("CARGO_MANIFEST_DIR"), "/tests/blueprints/tuple-return"), + CompileProfile::FastWithTraceLogs, + ); + + // Assert + assert!( + output_file_content.len() < bin.len(), + "Size of Wasm file compiled by `scrypto build` command should be smaller." + ); + } +} From b92c5d59340ce102cf53c94b1a4854188444e0ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Sat, 11 May 2024 01:28:55 +0200 Subject: [PATCH 03/11] Small refactor --- radix-engine-tests/src/common.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/radix-engine-tests/src/common.rs b/radix-engine-tests/src/common.rs index a7ab3a0217..cdfda3ec57 100644 --- a/radix-engine-tests/src/common.rs +++ b/radix-engine-tests/src/common.rs @@ -44,15 +44,20 @@ pub mod package_loader { pub struct PackageLoader; impl PackageLoader { pub fn get(name: &str) -> (Vec, PackageDefinition) { - let manifest_dir = PathBuf::from_str(env!("CARGO_MANIFEST_DIR")).unwrap(); - let package_dir = manifest_dir.join("assets").join("blueprints").join(name); - scrypto_test::prelude::Compile::compile(package_dir, CompileProfile::FastWithTraceLogs) + Self::get_internal(name, CompileProfile::FastWithTraceLogs) } pub fn get_using_default_compiler_options(name: &str) -> (Vec, PackageDefinition) { + Self::get_internal(name, CompileProfile::Default) + } + + fn get_internal( + name: &str, + compile_profile: CompileProfile, + ) -> (Vec, PackageDefinition) { let manifest_dir = PathBuf::from_str(env!("CARGO_MANIFEST_DIR")).unwrap(); let package_dir = manifest_dir.join("assets").join("blueprints").join(name); - scrypto_test::prelude::Compile::compile(package_dir, CompileProfile::Default) + scrypto_test::prelude::Compile::compile(package_dir, compile_profile) } } } From 982d4db7447e4c7446ce50ab3c38b1c3dd68d089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Mon, 13 May 2024 09:02:58 +0200 Subject: [PATCH 04/11] Fixed tests --- examples/hello-world/tests/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/hello-world/tests/lib.rs b/examples/hello-world/tests/lib.rs index 50a5674058..31bc36a063 100644 --- a/examples/hello-world/tests/lib.rs +++ b/examples/hello-world/tests/lib.rs @@ -52,7 +52,8 @@ fn test_hello() { fn test_hello_with_test_environment() -> Result<(), RuntimeError> { // Arrange let mut env = TestEnvironment::new(); - let package_address = PackageFactory::compile_and_publish(this_package!(), &mut env)?; + let package_address = + PackageFactory::compile_and_publish(this_package!(), &mut env, CompileProfile::Fast)?; let mut hello = Hello::instantiate_hello(package_address, &mut env)?; From ad2bf64228fa485578c825182c5ec657074bb8c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Mon, 13 May 2024 09:27:12 +0200 Subject: [PATCH 05/11] Fixed cli tests --- radix-clis/assets/template/tests/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/radix-clis/assets/template/tests/lib.rs b/radix-clis/assets/template/tests/lib.rs index 3775d690df..5bdc32bcd9 100644 --- a/radix-clis/assets/template/tests/lib.rs +++ b/radix-clis/assets/template/tests/lib.rs @@ -52,7 +52,8 @@ fn test_hello() { fn test_hello_with_test_environment() -> Result<(), RuntimeError> { // Arrange let mut env = TestEnvironment::new(); - let package_address = PackageFactory::compile_and_publish(this_package!(), &mut env)?; + let package_address = + PackageFactory::compile_and_publish(this_package!(), &mut env, CompileProfile::Fast)?; let mut hello = Hello::instantiate_hello(package_address, &mut env)?; From af6c1130afb30260ef6699ee2a4d5bedff48222a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Mon, 13 May 2024 10:03:01 +0200 Subject: [PATCH 06/11] Added new tests --- scrypto-test/src/ledger_simulator/compile.rs | 72 +++++++++++++++++++- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/scrypto-test/src/ledger_simulator/compile.rs b/scrypto-test/src/ledger_simulator/compile.rs index 4f6f0322a0..031161c8ba 100644 --- a/scrypto-test/src/ledger_simulator/compile.rs +++ b/scrypto-test/src/ledger_simulator/compile.rs @@ -126,7 +126,7 @@ mod tests { use super::{Compile, CompileProfile}; use std::process::Command; - fn compile_blueprint() -> Vec { + fn compile_blueprint(additional_args: &[&str]) -> Vec { // Build `scrypto` cli Command::new("cargo") .arg("build") @@ -144,6 +144,7 @@ mod tests { "/../radix-clis/target/release/scrypto" )) .arg("build") + .args(additional_args) .current_dir(concat!( env!("CARGO_MANIFEST_DIR"), "/tests/blueprints/tuple-return" @@ -164,7 +165,7 @@ mod tests { #[test] fn validate_compile_profile_default() { // Compile blueprint using `scrypto compile` command - let output_file_content = compile_blueprint(); + let output_file_content = compile_blueprint(&[]); // Compile same blueprint using Compile object let (bin, _) = Compile::compile( @@ -184,10 +185,28 @@ mod tests { ) } + #[test] + fn validate_compile_profile_fast() { + // Compile blueprint using `scrypto compile` command + let output_file_content = compile_blueprint(&[]); + + // Compile same blueprint using Compile object + let (bin, _) = Compile::compile( + concat!(env!("CARGO_MANIFEST_DIR"), "/tests/blueprints/tuple-return"), + CompileProfile::Fast, + ); + + // Assert + assert!( + output_file_content.len() < bin.len(), + "Size of Wasm file compiled by `scrypto build` command should be smaller." + ); + } + #[test] fn validate_compile_profile_fast_with_log() { // Compile blueprint using `scrypto compile` command - let output_file_content = compile_blueprint(); + let output_file_content = compile_blueprint(&[]); // Compile same blueprint using Compile object let (bin, _) = Compile::compile( @@ -201,4 +220,51 @@ mod tests { "Size of Wasm file compiled by `scrypto build` command should be smaller." ); } + + #[test] + fn verify_scrypto_build_with_args_for_compile_profile_fast() { + // Compile blueprint using `scrypto compile` command + let output_file_content = compile_blueprint(&["--disable-wasm-opt"]); + + // Compile same blueprint using Compile object + let (bin, _) = Compile::compile( + concat!(env!("CARGO_MANIFEST_DIR"), "/tests/blueprints/tuple-return"), + CompileProfile::Fast, + ); + + // Assert + assert_eq!( + output_file_content.len(), + bin.len(), + "Wasm files should have same size." + ); + assert_eq!( + output_file_content, bin, + "Wasm files should have same content." + ) + } + + #[test] + fn verify_scrypto_build_with_args_for_compile_profile_fast_with_log() { + // Compile blueprint using `scrypto compile` command + let output_file_content = + compile_blueprint(&["--disable-wasm-opt", "--log-level", "TRACE"]); + + // Compile same blueprint using Compile object + let (bin, _) = Compile::compile( + concat!(env!("CARGO_MANIFEST_DIR"), "/tests/blueprints/tuple-return"), + CompileProfile::FastWithTraceLogs, + ); + + // Assert + assert_eq!( + output_file_content.len(), + bin.len(), + "Wasm files should have same size." + ); + assert_eq!( + output_file_content, bin, + "Wasm files should have same content." + ) + } } From 6457b8eef28c9fe3c4d58dd10065720a99279624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Mon, 13 May 2024 11:57:52 +0200 Subject: [PATCH 07/11] Changed compiler profile names --- radix-engine-tests/src/common.rs | 8 ++- scrypto-test/src/ledger_simulator/compile.rs | 58 ++++++++++++++++++-- 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/radix-engine-tests/src/common.rs b/radix-engine-tests/src/common.rs index cdfda3ec57..8b47cdee19 100644 --- a/radix-engine-tests/src/common.rs +++ b/radix-engine-tests/src/common.rs @@ -30,6 +30,10 @@ pub mod package_loader { panic!("Package \"{}\" not found. Are you sure that this package is: a) in the blueprints folder, b) that this is the same as the package name in the Cargo.toml file?", name) } } + + pub fn get_using_standard_compiler_profile(name: &str) -> (Vec, PackageDefinition) { + panic!("Package \"{}\" already compiled. Cannot use specific compiler profile in compile-blueprints-at-build-time mode.", name) + } } } @@ -47,8 +51,8 @@ pub mod package_loader { Self::get_internal(name, CompileProfile::FastWithTraceLogs) } - pub fn get_using_default_compiler_options(name: &str) -> (Vec, PackageDefinition) { - Self::get_internal(name, CompileProfile::Default) + pub fn get_using_standard_compiler_profile(name: &str) -> (Vec, PackageDefinition) { + Self::get_internal(name, CompileProfile::Standard) } fn get_internal( diff --git a/scrypto-test/src/ledger_simulator/compile.rs b/scrypto-test/src/ledger_simulator/compile.rs index 031161c8ba..aefad239b7 100644 --- a/scrypto-test/src/ledger_simulator/compile.rs +++ b/scrypto-test/src/ledger_simulator/compile.rs @@ -5,7 +5,9 @@ use std::path::Path; pub enum CompileProfile { /// Uses default compilation options - same as `scrypto build`. Should be used in all cases which requires /// compilation results to be as close to production as possible (for instance costing related tests). - Default, + Standard, + /// Same as Standard with enabled all logs from error to trace level. + StandardWithTraceLogs, /// Disables WASM optimization to speed-up compilation process, by default used by SDK PackageFactory. Fast, /// Disables WASM optimization and enables all logs from error to trace level, by default used by Ledger Simulator. @@ -42,7 +44,10 @@ impl Compile { compiler_builder.manifest_path(package_dir.as_ref()); match compile_profile { - CompileProfile::Default => (), + CompileProfile::Standard => (), + CompileProfile::StandardWithTraceLogs => { + compiler_builder.log_level(Level::Trace); // all logs from error to trace + } CompileProfile::Fast => { compiler_builder.optimize_with_wasm_opt(None); } @@ -163,14 +168,14 @@ mod tests { } #[test] - fn validate_compile_profile_default() { + fn validate_compile_profile_standard() { // Compile blueprint using `scrypto compile` command let output_file_content = compile_blueprint(&[]); // Compile same blueprint using Compile object let (bin, _) = Compile::compile( concat!(env!("CARGO_MANIFEST_DIR"), "/tests/blueprints/tuple-return"), - CompileProfile::Default, + CompileProfile::Standard, ); // Assert @@ -185,6 +190,24 @@ mod tests { ) } + #[test] + fn validate_compile_profile_standard_with_logs() { + // Compile blueprint using `scrypto compile` command + let output_file_content = compile_blueprint(&[]); + + // Compile same blueprint using Compile object + let (bin, _) = Compile::compile( + concat!(env!("CARGO_MANIFEST_DIR"), "/tests/blueprints/tuple-return"), + CompileProfile::StandardWithTraceLogs, + ); + + // Assert + assert!( + output_file_content.len() < bin.len(), + "Size of Wasm file compiled by `scrypto build` command should be smaller." + ); + } + #[test] fn validate_compile_profile_fast() { // Compile blueprint using `scrypto compile` command @@ -204,7 +227,7 @@ mod tests { } #[test] - fn validate_compile_profile_fast_with_log() { + fn validate_compile_profile_fast_with_logs() { // Compile blueprint using `scrypto compile` command let output_file_content = compile_blueprint(&[]); @@ -221,6 +244,29 @@ mod tests { ); } + #[test] + fn verify_scrypto_build_with_args_for_compile_profile_standard_with_logs() { + // Compile blueprint using `scrypto compile` command + let output_file_content = compile_blueprint(&["--log-level", "TRACE"]); + + // Compile same blueprint using Compile object + let (bin, _) = Compile::compile( + concat!(env!("CARGO_MANIFEST_DIR"), "/tests/blueprints/tuple-return"), + CompileProfile::StandardWithTraceLogs, + ); + + // Assert + assert_eq!( + output_file_content.len(), + bin.len(), + "Wasm files should have same size." + ); + assert_eq!( + output_file_content, bin, + "Wasm files should have same content." + ) + } + #[test] fn verify_scrypto_build_with_args_for_compile_profile_fast() { // Compile blueprint using `scrypto compile` command @@ -245,7 +291,7 @@ mod tests { } #[test] - fn verify_scrypto_build_with_args_for_compile_profile_fast_with_log() { + fn verify_scrypto_build_with_args_for_compile_profile_fast_with_logs() { // Compile blueprint using `scrypto compile` command let output_file_content = compile_blueprint(&["--disable-wasm-opt", "--log-level", "TRACE"]); From 7189ca80a13c06ec8db5ab15a4141327761ed6e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Mon, 13 May 2024 15:37:00 +0200 Subject: [PATCH 08/11] Update after review --- radix-engine-tests/src/common.rs | 17 +------------ .../src/ledger_simulator/ledger_simulator.rs | 24 ++++++++++++------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/radix-engine-tests/src/common.rs b/radix-engine-tests/src/common.rs index 8b47cdee19..8c41534768 100644 --- a/radix-engine-tests/src/common.rs +++ b/radix-engine-tests/src/common.rs @@ -30,10 +30,6 @@ pub mod package_loader { panic!("Package \"{}\" not found. Are you sure that this package is: a) in the blueprints folder, b) that this is the same as the package name in the Cargo.toml file?", name) } } - - pub fn get_using_standard_compiler_profile(name: &str) -> (Vec, PackageDefinition) { - panic!("Package \"{}\" already compiled. Cannot use specific compiler profile in compile-blueprints-at-build-time mode.", name) - } } } @@ -48,20 +44,9 @@ pub mod package_loader { pub struct PackageLoader; impl PackageLoader { pub fn get(name: &str) -> (Vec, PackageDefinition) { - Self::get_internal(name, CompileProfile::FastWithTraceLogs) - } - - pub fn get_using_standard_compiler_profile(name: &str) -> (Vec, PackageDefinition) { - Self::get_internal(name, CompileProfile::Standard) - } - - fn get_internal( - name: &str, - compile_profile: CompileProfile, - ) -> (Vec, PackageDefinition) { let manifest_dir = PathBuf::from_str(env!("CARGO_MANIFEST_DIR")).unwrap(); let package_dir = manifest_dir.join("assets").join("blueprints").join(name); - scrypto_test::prelude::Compile::compile(package_dir, compile_profile) + scrypto_test::prelude::Compile::compile(package_dir, CompileProfile::FastWithTraceLogs) } } } diff --git a/scrypto-test/src/ledger_simulator/ledger_simulator.rs b/scrypto-test/src/ledger_simulator/ledger_simulator.rs index 096af402f3..0070a6e961 100644 --- a/scrypto-test/src/ledger_simulator/ledger_simulator.rs +++ b/scrypto-test/src/ledger_simulator/ledger_simulator.rs @@ -1238,7 +1238,15 @@ impl LedgerSimulator { } pub fn compile>(&mut self, package_dir: P) -> (Vec, PackageDefinition) { - Compile::compile(package_dir, CompileProfile::FastWithTraceLogs) + self.compile_with_option(package_dir, CompileProfile::FastWithTraceLogs) + } + + pub fn compile_with_option>( + &mut self, + package_dir: P, + compile_profile: CompileProfile, + ) -> (Vec, PackageDefinition) { + Compile::compile(package_dir, compile_profile) } // Doesn't need to be here - kept for backward compatibility @@ -2577,31 +2585,31 @@ pub fn assert_receipt_events_can_be_typed(commit_result: &CommitResult) { } pub enum PackagePublishingSource { - CompileAndPublishFromSource(PathBuf), + CompileAndPublishFromSource(PathBuf, CompileProfile), PublishExisting(Vec, PackageDefinition), } impl From for PackagePublishingSource { fn from(value: String) -> Self { - Self::CompileAndPublishFromSource(value.into()) + Self::CompileAndPublishFromSource(value.into(), CompileProfile::FastWithTraceLogs) } } impl<'g> From<&'g str> for PackagePublishingSource { fn from(value: &'g str) -> Self { - Self::CompileAndPublishFromSource(value.into()) + Self::CompileAndPublishFromSource(value.into(), CompileProfile::FastWithTraceLogs) } } impl From for PackagePublishingSource { fn from(value: PathBuf) -> Self { - Self::CompileAndPublishFromSource(value) + Self::CompileAndPublishFromSource(value, CompileProfile::FastWithTraceLogs) } } impl<'g> From<&'g Path> for PackagePublishingSource { fn from(value: &'g Path) -> Self { - Self::CompileAndPublishFromSource(value.into()) + Self::CompileAndPublishFromSource(value.into(), CompileProfile::FastWithTraceLogs) } } @@ -2614,9 +2622,7 @@ impl From<(Vec, PackageDefinition)> for PackagePublishingSource { impl PackagePublishingSource { pub fn code_and_definition(self) -> (Vec, PackageDefinition) { match self { - Self::CompileAndPublishFromSource(path) => { - Compile::compile(path, CompileProfile::FastWithTraceLogs) - } + Self::CompileAndPublishFromSource(path, profile) => Compile::compile(path, profile), Self::PublishExisting(code, definition) => (code, definition), } } From e43aaa5964bd371196b7186c9384181da8dfb26a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Mon, 13 May 2024 23:11:07 +0200 Subject: [PATCH 09/11] Fixes related to coverage --- radix-clis/src/utils/cargo.rs | 4 +++ scrypto-compiler/src/lib.rs | 15 ++++++---- scrypto-test/Cargo.toml | 2 ++ scrypto-test/src/ledger_simulator/compile.rs | 31 ++++++++++++-------- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/radix-clis/src/utils/cargo.rs b/radix-clis/src/utils/cargo.rs index ce207a8359..75e420f2bb 100644 --- a/radix-clis/src/utils/cargo.rs +++ b/radix-clis/src/utils/cargo.rs @@ -64,6 +64,10 @@ pub fn build_package>( } if coverage { compiler_builder.coverage(); + + let mut target_path = PathBuf::from(base_path.as_ref()); + target_path.push("coverage"); + compiler_builder.target_directory(target_path); } env.iter().for_each(|(name, value)| { compiler_builder.env(name, EnvironmentVariableAction::Set(value.clone())); diff --git a/scrypto-compiler/src/lib.rs b/scrypto-compiler/src/lib.rs index 7a4c752cf4..596c12dd06 100644 --- a/scrypto-compiler/src/lib.rs +++ b/scrypto-compiler/src/lib.rs @@ -201,15 +201,15 @@ pub struct BuildArtifact { } #[derive(Debug, Clone)] -struct CompilerManifestDefinition { +pub struct CompilerManifestDefinition { /// Path to Cargo.toml file. - manifest_path: PathBuf, + pub manifest_path: PathBuf, /// Path to directory where compilation artifacts are stored. - target_directory: PathBuf, + pub target_directory: PathBuf, /// Path to target binary WASM file. - target_binary_wasm_path: PathBuf, + pub target_binary_wasm_path: PathBuf, /// Path to target binary RPD file. - target_binary_rpd_path: PathBuf, + pub target_binary_rpd_path: PathBuf, } /// Programmatic implementation of Scrypto compiler which is a wrapper around rust cargo tool. @@ -771,6 +771,11 @@ impl ScryptoCompiler { .then_some(()) .ok_or(ScryptoCompilerError::CargoBuildFailure(status)) } + + /// Returns information about the main manifest + pub fn get_main_manifest_definition(&self) -> CompilerManifestDefinition { + self.main_manifest.clone() + } } #[derive(Default)] diff --git a/scrypto-test/Cargo.toml b/scrypto-test/Cargo.toml index 3894f7ec84..a444742664 100644 --- a/scrypto-test/Cargo.toml +++ b/scrypto-test/Cargo.toml @@ -41,6 +41,8 @@ resource_tracker = ["radix-engine/resource_tracker", "radix-common/resource_trac rocksdb = ["radix-substate-store-impls/rocksdb"] post_run_db_check = [] +coverage = ["radix-common/coverage", "radix-engine/coverage"] + [lib] doctest = false bench = false \ No newline at end of file diff --git a/scrypto-test/src/ledger_simulator/compile.rs b/scrypto-test/src/ledger_simulator/compile.rs index aefad239b7..383c41fc1e 100644 --- a/scrypto-test/src/ledger_simulator/compile.rs +++ b/scrypto-test/src/ledger_simulator/compile.rs @@ -64,6 +64,10 @@ impl Compile { #[cfg(feature = "coverage")] if _use_coverage { compiler_builder.coverage(); + + let mut coverage_dir = std::path::PathBuf::from(package_dir.as_ref()); + coverage_dir.push("coverage"); + compiler_builder.target_directory(coverage_dir); } let mut compiler = compiler_builder @@ -73,30 +77,31 @@ impl Compile { #[cfg(feature = "coverage")] // Check if binary exists in coverage directory, if it doesn't only then build it if _use_coverage { - let mut coverage_path = compiler.target_binary_path(); - if coverage_path.is_file() { - let code = fs::read(&coverage_path).unwrap_or_else(|err| { + let manifest = compiler.get_main_manifest_definition(); + if manifest.target_binary_rpd_path.exists() && manifest.target_binary_wasm_path.exists() + { + let code = std::fs::read(&manifest.target_binary_wasm_path).unwrap_or_else(|err| { panic!( "Failed to read built WASM from path {:?} - {:?}", - &path, err - ) - }); - coverage_path.set_extension("rpd"); - let definition = fs::read(&coverage_path).unwrap_or_else(|err| { - panic!( - "Failed to read package definition from path {:?} - {:?}", - &coverage_path, err + &manifest.target_binary_wasm_path, err ) }); + let definition = + std::fs::read(&manifest.target_binary_rpd_path).unwrap_or_else(|err| { + panic!( + "Failed to read package definition from path {:?} - {:?}", + &manifest.target_binary_rpd_path, err + ) + }); let definition = manifest_decode(&definition).unwrap_or_else(|err| { panic!( "Failed to parse package definition from path {:?} - {:?}", - &coverage_path, err + &manifest.target_binary_rpd_path, err ) }); return (code, definition); } - }; + } // Build let mut build_artifacts = compiler.compile().unwrap_or_else(|error| { From 18ffc3b3d48f208fa7cee14b263b293662df6207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Tue, 14 May 2024 00:53:57 +0200 Subject: [PATCH 10/11] Fixed scrypto coverage command --- radix-clis/src/scrypto/cmd_coverage.rs | 14 +---- scrypto-compiler/src/lib.rs | 84 ++++++++++++++++++++++++-- 2 files changed, 82 insertions(+), 16 deletions(-) diff --git a/radix-clis/src/scrypto/cmd_coverage.rs b/radix-clis/src/scrypto/cmd_coverage.rs index d5bcf9702a..6018b639e2 100644 --- a/radix-clis/src/scrypto/cmd_coverage.rs +++ b/radix-clis/src/scrypto/cmd_coverage.rs @@ -106,18 +106,8 @@ impl Coverage { // Build package let path = self.path.clone().unwrap_or(current_dir().unwrap()); - let build_artifacts = build_package( - &path, - true, - Level::Trace, - true, - &[( - "CARGO_ENCODED_RUSTFLAGS".to_owned(), - "-Clto=off\x1f-Cinstrument-coverage\x1f-Zno-profiler-runtime\x1f--emit=llvm-ir" - .to_owned(), - )], - ) - .map_err(Error::BuildError)?; + let build_artifacts = + build_package(&path, true, Level::Trace, true, &[]).map_err(Error::BuildError)?; if build_artifacts.len() > 1 { return Err(Error::BuildError(BuildError::WorkspaceNotSupported).into()); } diff --git a/scrypto-compiler/src/lib.rs b/scrypto-compiler/src/lib.rs index 596c12dd06..d54f21522f 100644 --- a/scrypto-compiler/src/lib.rs +++ b/scrypto-compiler/src/lib.rs @@ -11,6 +11,10 @@ use std::{env, io}; const MANIFEST_FILE: &str = "Cargo.toml"; const BUILD_TARGET: &str = "wasm32-unknown-unknown"; const SCRYPTO_NO_SCHEMA: &str = "scrypto/no-schema"; +const SCRYPTO_COVERAGE: &str = "scrypto/coverage"; +const CARGO_ENCODED_RUSTFLAGS: &str = "CARGO_ENCODED_RUSTFLAGS"; +const CARGO_ENCODED_RUSTFLAGS_COVERAGE: &str = + "-Clto=off\x1f-Cinstrument-coverage\x1f-Zno-profiler-runtime\x1f--emit=llvm-ir"; #[derive(Debug)] pub enum ScryptoCompilerError { @@ -540,6 +544,20 @@ impl ScryptoCompiler { } else if !for_package_extract { features.push(["--features", SCRYPTO_NO_SCHEMA]); } + + let coverage_build = if let Some(idx) = features + .iter() + .position(|[_tag, value]| *value == SCRYPTO_COVERAGE) + { + if for_package_extract { + // for schema extract 'scrypto/coverage' flag must be removed + features.remove(idx); + } + true + } else { + false + }; + let features: Vec<&str> = features.into_iter().flatten().collect(); let package: Vec<&str> = self @@ -574,13 +592,23 @@ impl ScryptoCompiler { command.arg("--all_features"); } + if coverage_build && !for_package_extract { + // for coverage WASM file build (2nd phase) add these Rustflags + command.env(CARGO_ENCODED_RUSTFLAGS, CARGO_ENCODED_RUSTFLAGS_COVERAGE); + } self.input_params .environment_variables .iter() .for_each(|(name, action)| { match action { - EnvironmentVariableAction::Set(value) => command.env(name, value), - EnvironmentVariableAction::Unset => command.env_remove(name), + EnvironmentVariableAction::Set(value) => { + if !(coverage_build && name == CARGO_ENCODED_RUSTFLAGS) { + command.env(name, value); + } + } + EnvironmentVariableAction::Unset => { + command.env_remove(name); + } }; }); @@ -873,7 +901,7 @@ impl ScryptoCompilerBuilder { pub fn coverage(&mut self) -> &mut Self { self.input_params .features - .insert(String::from("scrypto/coverage")); + .insert(String::from(SCRYPTO_COVERAGE)); self } @@ -922,7 +950,23 @@ mod tests { .map(|arg| arg.to_str().unwrap()) .collect::>() .join(" "); - let mut ret = cmd.get_program().to_str().unwrap().to_string(); + let envs = cmd + .get_envs() + .into_iter() + .map(|(name, value)| { + if let Some(value) = value { + format!("{}={}", name.to_str().unwrap(), value.to_str().unwrap()) + } else { + format!("{}", name.to_str().unwrap()) + } + }) + .collect::>() + .join(" "); + let mut ret = envs; + if !ret.is_empty() { + ret.push(' '); + } + ret.push_str(cmd.get_program().to_str().unwrap()); ret.push(' '); ret.push_str(&args); ret @@ -1218,4 +1262,36 @@ mod tests { assert_eq!(cmd_to_string(&cmd_phase_2), format!("cargo build --target wasm32-unknown-unknown --target-dir {} --manifest-path {} --features scrypto/log-error --features scrypto/log-warn --features scrypto/log-info --features scrypto/no-schema --profile release", default_target_path.display(), manifest_path.display())); } + + #[test] + fn test_command_coverage() { + // Arrange + let mut manifest_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let mut target_path = manifest_path.clone(); + manifest_path.push("Cargo.toml"); + target_path.pop(); // ScryptoCompiler dir + target_path.push("coverage"); + let mut cmd_phase_1 = Command::new("cargo"); + let mut cmd_phase_2 = Command::new("cargo"); + + // Act + ScryptoCompiler::builder() + .coverage() + .target_directory(target_path.clone()) + .build() + .unwrap() + .prepare_command_phase_1(&mut cmd_phase_1); + ScryptoCompiler::builder() + .coverage() + .target_directory(target_path.clone()) + .build() + .unwrap() + .prepare_command_phase_2(&mut cmd_phase_2); + + // Assert + assert_eq!(cmd_to_string(&cmd_phase_1), + format!("cargo build --target wasm32-unknown-unknown --target-dir {} --manifest-path {} --features scrypto/log-error --features scrypto/log-warn --features scrypto/log-info --release", target_path.display(), manifest_path.display())); + assert_eq!(cmd_to_string(&cmd_phase_2), + format!("CARGO_ENCODED_RUSTFLAGS=-Clto=off\x1f-Cinstrument-coverage\x1f-Zno-profiler-runtime\x1f--emit=llvm-ir cargo build --target wasm32-unknown-unknown --target-dir {} --manifest-path {} --features scrypto/log-error --features scrypto/log-warn --features scrypto/log-info --features scrypto/coverage --features scrypto/no-schema --profile release", target_path.display(), manifest_path.display())); + } } From 09196939d6fca557cd83d904a12e903043312765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Tue, 14 May 2024 11:22:36 +0200 Subject: [PATCH 11/11] Moved back coverage rustflags to scrypto command --- radix-clis/src/scrypto/cmd_coverage.rs | 14 +++++- scrypto-compiler/src/lib.rs | 64 +++++++++++++++++++------- 2 files changed, 59 insertions(+), 19 deletions(-) diff --git a/radix-clis/src/scrypto/cmd_coverage.rs b/radix-clis/src/scrypto/cmd_coverage.rs index 6018b639e2..d5bcf9702a 100644 --- a/radix-clis/src/scrypto/cmd_coverage.rs +++ b/radix-clis/src/scrypto/cmd_coverage.rs @@ -106,8 +106,18 @@ impl Coverage { // Build package let path = self.path.clone().unwrap_or(current_dir().unwrap()); - let build_artifacts = - build_package(&path, true, Level::Trace, true, &[]).map_err(Error::BuildError)?; + let build_artifacts = build_package( + &path, + true, + Level::Trace, + true, + &[( + "CARGO_ENCODED_RUSTFLAGS".to_owned(), + "-Clto=off\x1f-Cinstrument-coverage\x1f-Zno-profiler-runtime\x1f--emit=llvm-ir" + .to_owned(), + )], + ) + .map_err(Error::BuildError)?; if build_artifacts.len() > 1 { return Err(Error::BuildError(BuildError::WorkspaceNotSupported).into()); } diff --git a/scrypto-compiler/src/lib.rs b/scrypto-compiler/src/lib.rs index d54f21522f..90493f832d 100644 --- a/scrypto-compiler/src/lib.rs +++ b/scrypto-compiler/src/lib.rs @@ -12,9 +12,6 @@ const MANIFEST_FILE: &str = "Cargo.toml"; const BUILD_TARGET: &str = "wasm32-unknown-unknown"; const SCRYPTO_NO_SCHEMA: &str = "scrypto/no-schema"; const SCRYPTO_COVERAGE: &str = "scrypto/coverage"; -const CARGO_ENCODED_RUSTFLAGS: &str = "CARGO_ENCODED_RUSTFLAGS"; -const CARGO_ENCODED_RUSTFLAGS_COVERAGE: &str = - "-Clto=off\x1f-Cinstrument-coverage\x1f-Zno-profiler-runtime\x1f--emit=llvm-ir"; #[derive(Debug)] pub enum ScryptoCompilerError { @@ -545,18 +542,17 @@ impl ScryptoCompiler { features.push(["--features", SCRYPTO_NO_SCHEMA]); } - let coverage_build = if let Some(idx) = features - .iter() - .position(|[_tag, value]| *value == SCRYPTO_COVERAGE) - { - if for_package_extract { + let mut remove_cargo_rustflags_env = false; + if for_package_extract { + if let Some(idx) = features + .iter() + .position(|[_tag, value]| *value == SCRYPTO_COVERAGE) + { // for schema extract 'scrypto/coverage' flag must be removed features.remove(idx); + remove_cargo_rustflags_env = true; } - true - } else { - false - }; + } let features: Vec<&str> = features.into_iter().flatten().collect(); @@ -592,17 +588,14 @@ impl ScryptoCompiler { command.arg("--all_features"); } - if coverage_build && !for_package_extract { - // for coverage WASM file build (2nd phase) add these Rustflags - command.env(CARGO_ENCODED_RUSTFLAGS, CARGO_ENCODED_RUSTFLAGS_COVERAGE); - } self.input_params .environment_variables .iter() .for_each(|(name, action)| { match action { EnvironmentVariableAction::Set(value) => { - if !(coverage_build && name == CARGO_ENCODED_RUSTFLAGS) { + // CARGO_ENCODED_RUSTFLAGS for coverage build must be removed for 1st phase compilation + if !(remove_cargo_rustflags_env && name == "CARGO_ENCODED_RUSTFLAGS") { command.env(name, value); } } @@ -1288,6 +1281,43 @@ mod tests { .unwrap() .prepare_command_phase_2(&mut cmd_phase_2); + // Assert + assert_eq!(cmd_to_string(&cmd_phase_1), + format!("cargo build --target wasm32-unknown-unknown --target-dir {} --manifest-path {} --features scrypto/log-error --features scrypto/log-warn --features scrypto/log-info --release", target_path.display(), manifest_path.display())); + assert_eq!(cmd_to_string(&cmd_phase_2), + format!("cargo build --target wasm32-unknown-unknown --target-dir {} --manifest-path {} --features scrypto/log-error --features scrypto/log-warn --features scrypto/log-info --features scrypto/coverage --features scrypto/no-schema --profile release", target_path.display(), manifest_path.display())); + } + + #[test] + fn test_command_coverage_with_env() { + // Arrange + let mut manifest_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let mut target_path = manifest_path.clone(); + manifest_path.push("Cargo.toml"); + target_path.pop(); // ScryptoCompiler dir + target_path.push("coverage"); + let action = EnvironmentVariableAction::Set(String::from( + "-Clto=off\x1f-Cinstrument-coverage\x1f-Zno-profiler-runtime\x1f--emit=llvm-ir", + )); + let mut cmd_phase_1 = Command::new("cargo"); + let mut cmd_phase_2 = Command::new("cargo"); + + // Act + ScryptoCompiler::builder() + .coverage() + .target_directory(target_path.clone()) + .env("CARGO_ENCODED_RUSTFLAGS", action.clone()) // CARGO_ENCODED_RUSTFLAGS must be removed for 1st phase + .build() + .unwrap() + .prepare_command_phase_1(&mut cmd_phase_1); + ScryptoCompiler::builder() + .coverage() + .target_directory(target_path.clone()) + .env("CARGO_ENCODED_RUSTFLAGS", action.clone()) + .build() + .unwrap() + .prepare_command_phase_2(&mut cmd_phase_2); + // Assert assert_eq!(cmd_to_string(&cmd_phase_1), format!("cargo build --target wasm32-unknown-unknown --target-dir {} --manifest-path {} --features scrypto/log-error --features scrypto/log-warn --features scrypto/log-info --release", target_path.display(), manifest_path.display()));