From d461fbb8bd9e916944460a29a3bb3bd55fccaee8 Mon Sep 17 00:00:00 2001 From: clearloop Date: Tue, 29 Dec 2020 13:43:35 +0800 Subject: [PATCH 1/6] feat(cmd/build): add debug flag to command build --- src/cmd/build.rs | 14 +++++++++++--- src/cmd/metadata.rs | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 39c628dd..7b0a9202 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -62,6 +62,9 @@ pub struct BuildCommand { verbosity: VerbosityFlags, #[structopt(flatten)] unstable_options: UnstableOptions, + /// Emit debug info into wasm file + #[structopt(long, short)] + debug: bool, } impl BuildCommand { @@ -76,6 +79,7 @@ impl BuildCommand { true, self.build_artifact, unstable_flags, + self.debug, ) } } @@ -104,6 +108,7 @@ impl CheckCommand { false, BuildArtifacts::CheckOnly, unstable_flags, + true, ) } } @@ -254,7 +259,7 @@ fn post_process_wasm(crate_metadata: &CrateMetadata) -> Result<()> { /// /// The intention is to reduce the size of bloated wasm binaries as a result of missing /// optimizations (or bugs?) between Rust and Wasm. -fn optimize_wasm(crate_metadata: &CrateMetadata) -> Result { +fn optimize_wasm(crate_metadata: &CrateMetadata, debug_info: bool) -> Result { let mut optimized = crate_metadata.dest_wasm.clone(); optimized.set_file_name(format!("{}-opt.wasm", crate_metadata.package_name)); @@ -264,7 +269,7 @@ fn optimize_wasm(crate_metadata: &CrateMetadata) -> Result { // the default shrink_level: 1, // the default - debug_info: false, + debug_info, }; let mut dest_wasm_file = File::open(crate_metadata.dest_wasm.as_os_str())?; @@ -299,6 +304,7 @@ fn execute( optimize_contract: bool, build_artifact: BuildArtifacts, unstable_flags: UnstableFlags, + debug: bool, ) -> Result { let crate_metadata = CrateMetadata::collect(manifest_path)?; if build_artifact == BuildArtifacts::CodeOnly || build_artifact == BuildArtifacts::CheckOnly { @@ -308,6 +314,7 @@ fn execute( optimize_contract, build_artifact, unstable_flags, + debug, )?; let res = BuildResult { dest_wasm: maybe_dest_wasm, @@ -339,6 +346,7 @@ pub(crate) fn execute_with_crate_metadata( optimize_contract: bool, build_artifact: BuildArtifacts, unstable_flags: UnstableFlags, + debug: bool, ) -> Result<(Option, Option)> { println!( " {} {}", @@ -360,7 +368,7 @@ pub(crate) fn execute_with_crate_metadata( format!("[3/{}]", build_artifact.steps()).bold(), "Optimizing wasm file".bright_green().bold() ); - let optimization_result = optimize_wasm(&crate_metadata)?; + let optimization_result = optimize_wasm(&crate_metadata, debug)?; Ok(( Some(crate_metadata.dest_wasm.clone()), Some(optimization_result), diff --git a/src/cmd/metadata.rs b/src/cmd/metadata.rs index 8ca48262..b25c1a33 100644 --- a/src/cmd/metadata.rs +++ b/src/cmd/metadata.rs @@ -236,6 +236,7 @@ impl GenerateMetadataCommand { true, // for the hash we always use the optimized version of the contract self.build_artifact, self.unstable_options.clone(), + false, // for the hash we always not emit the debug info into wasm )?; let wasm = fs::read(&self.crate_metadata.dest_wasm)?; -- GitLab From fef6c7a84329250a4226000a0585215c6066d9d6 Mon Sep 17 00:00:00 2001 From: clearloop Date: Tue, 29 Dec 2020 17:20:53 +0800 Subject: [PATCH 2/6] feat(cmd/metadata): add debug field to metadata command --- Cargo.lock | 4 ---- Cargo.toml | 3 ++- src/cmd/build.rs | 43 +++++++++++++++++++++++++++++++------------ src/cmd/metadata.rs | 5 ++++- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fefd0086..a41d8910 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -342,8 +342,6 @@ checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" [[package]] name = "binaryen" version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a9b407f52d0b918c6ea41d7a328321496b315f61da99a309b375dfbbd04bc9a" dependencies = [ "binaryen-sys", ] @@ -351,8 +349,6 @@ dependencies = [ [[package]] name = "binaryen-sys" version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86e9636d01b92f2df45dce29c35a9e3724687c1055bb4472fb4b829cc4a5a561" dependencies = [ "cc", "cmake", diff --git a/Cargo.toml b/Cargo.toml index 0e0a7618..2559eb03 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,8 @@ serde = { version = "1.0.117", default-features = false, features = ["derive"] } serde_json = "1.0.59" tempfile = "3.1.0" url = { version = "2.2.0", features = ["serde"] } -binaryen = "0.12.0" +# binaryen = "0.12.0" +binaryen = { path = "../binaryen-rs" } # dependencies for optional extrinsics feature async-std = { version = "1.8.0", optional = true } diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 7b0a9202..632b61aa 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -62,7 +62,7 @@ pub struct BuildCommand { verbosity: VerbosityFlags, #[structopt(flatten)] unstable_options: UnstableOptions, - /// Emit debug info into wasm file + /// Emits debug info into wasm file #[structopt(long, short)] debug: bool, } @@ -108,7 +108,7 @@ impl CheckCommand { false, BuildArtifacts::CheckOnly, unstable_flags, - true, + false, ) } } @@ -223,17 +223,17 @@ fn ensure_maximum_memory_pages(module: &mut Module, maximum_allowed_pages: u32) /// Strips all custom sections. /// /// Presently all custom sections are not required so they can be stripped safely. -fn strip_custom_sections(module: &mut Module) { +fn strip_custom_sections(module: &mut Module, debug: bool) { module.sections_mut().retain(|section| match section { Section::Custom(_) => false, - Section::Name(_) => false, + Section::Name(_) => debug, Section::Reloc(_) => false, _ => true, }); } /// Performs required post-processing steps on the wasm artifact. -fn post_process_wasm(crate_metadata: &CrateMetadata) -> Result<()> { +fn post_process_wasm(crate_metadata: &CrateMetadata, debug: bool) -> Result<()> { // Deserialize wasm module from a file. let mut module = parity_wasm::deserialize_file(&crate_metadata.original_wasm).context(format!( @@ -249,7 +249,7 @@ fn post_process_wasm(crate_metadata: &CrateMetadata) -> Result<()> { anyhow::bail!("Optimizer failed"); } ensure_maximum_memory_pages(&mut module, MAX_MEMORY_PAGES)?; - strip_custom_sections(&mut module); + strip_custom_sections(&mut module, debug); parity_wasm::serialize_to_file(&crate_metadata.dest_wasm, module)?; Ok(()) @@ -287,6 +287,19 @@ fn optimize_wasm(crate_metadata: &CrateMetadata, debug_info: bool) -> Result Result { let crate_metadata = CrateMetadata::collect(manifest_path)?; if build_artifact == BuildArtifacts::CodeOnly || build_artifact == BuildArtifacts::CheckOnly { @@ -314,7 +327,7 @@ fn execute( optimize_contract, build_artifact, unstable_flags, - debug, + debug_info, )?; let res = BuildResult { dest_wasm: maybe_dest_wasm, @@ -327,7 +340,13 @@ fn execute( return Ok(res); } - let res = super::metadata::execute(&manifest_path, verbosity, build_artifact, unstable_flags)?; + let res = super::metadata::execute( + &manifest_path, + verbosity, + build_artifact, + unstable_flags, + debug_info, + )?; Ok(res) } @@ -346,7 +365,7 @@ pub(crate) fn execute_with_crate_metadata( optimize_contract: bool, build_artifact: BuildArtifacts, unstable_flags: UnstableFlags, - debug: bool, + debug_info: bool, ) -> Result<(Option, Option)> { println!( " {} {}", @@ -359,7 +378,7 @@ pub(crate) fn execute_with_crate_metadata( format!("[2/{}]", build_artifact.steps()).bold(), "Post processing wasm file".bright_green().bold() ); - post_process_wasm(&crate_metadata)?; + post_process_wasm(&crate_metadata, debug_info)?; if !optimize_contract { return Ok((None, None)); } @@ -368,7 +387,7 @@ pub(crate) fn execute_with_crate_metadata( format!("[3/{}]", build_artifact.steps()).bold(), "Optimizing wasm file".bright_green().bold() ); - let optimization_result = optimize_wasm(&crate_metadata, debug)?; + let optimization_result = optimize_wasm(&crate_metadata, optimize_contract)?; Ok(( Some(crate_metadata.dest_wasm.clone()), Some(optimization_result), diff --git a/src/cmd/metadata.rs b/src/cmd/metadata.rs index b25c1a33..13d77dd2 100644 --- a/src/cmd/metadata.rs +++ b/src/cmd/metadata.rs @@ -40,6 +40,7 @@ struct GenerateMetadataCommand { verbosity: Option, build_artifact: BuildArtifacts, unstable_options: UnstableFlags, + debug: bool, } /// Result of generating the extended contract project metadata @@ -236,7 +237,7 @@ impl GenerateMetadataCommand { true, // for the hash we always use the optimized version of the contract self.build_artifact, self.unstable_options.clone(), - false, // for the hash we always not emit the debug info into wasm + self.debug, )?; let wasm = fs::read(&self.crate_metadata.dest_wasm)?; @@ -263,6 +264,7 @@ pub(crate) fn execute( verbosity: Option, build_artifact: BuildArtifacts, unstable_options: UnstableFlags, + debug: bool, ) -> Result { let crate_metadata = CrateMetadata::collect(manifest_path)?; let res = GenerateMetadataCommand { @@ -270,6 +272,7 @@ pub(crate) fn execute( verbosity, build_artifact, unstable_options, + debug, } .exec()?; Ok(res) -- GitLab From 25e709af031784e5259c234514a308d17be90265 Mon Sep 17 00:00:00 2001 From: clearloop Date: Tue, 29 Dec 2020 17:57:14 +0800 Subject: [PATCH 3/6] chore(lock): clean Cargo.lock --- Cargo.lock | 4 ++++ Cargo.toml | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a41d8910..fefd0086 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -342,6 +342,8 @@ checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" [[package]] name = "binaryen" version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a9b407f52d0b918c6ea41d7a328321496b315f61da99a309b375dfbbd04bc9a" dependencies = [ "binaryen-sys", ] @@ -349,6 +351,8 @@ dependencies = [ [[package]] name = "binaryen-sys" version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86e9636d01b92f2df45dce29c35a9e3724687c1055bb4472fb4b829cc4a5a561" dependencies = [ "cc", "cmake", diff --git a/Cargo.toml b/Cargo.toml index 2559eb03..0e0a7618 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,8 +40,7 @@ serde = { version = "1.0.117", default-features = false, features = ["derive"] } serde_json = "1.0.59" tempfile = "3.1.0" url = { version = "2.2.0", features = ["serde"] } -# binaryen = "0.12.0" -binaryen = { path = "../binaryen-rs" } +binaryen = "0.12.0" # dependencies for optional extrinsics feature async-std = { version = "1.8.0", optional = true } -- GitLab From 7b997ff9f41f4cf1f9533616ecad3ebf7e609421 Mon Sep 17 00:00:00 2001 From: clearloop Date: Wed, 30 Dec 2020 11:18:07 +0800 Subject: [PATCH 4/6] feat(debug): support collecting metadata under debug directory --- src/cmd/build.rs | 9 ++++----- src/cmd/metadata.rs | 2 +- src/crate_metadata.rs | 6 +++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 632b61aa..02a7fd71 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -181,7 +181,6 @@ fn build_cargo_project( // clear RUSTFLAGS std::env::remove_var("RUSTFLAGS"); - Ok(()) } @@ -317,9 +316,9 @@ fn execute( optimize_contract: bool, build_artifact: BuildArtifacts, unstable_flags: UnstableFlags, - debug_info: bool, + debug: bool, ) -> Result { - let crate_metadata = CrateMetadata::collect(manifest_path)?; + let crate_metadata = CrateMetadata::collect(manifest_path, debug)?; if build_artifact == BuildArtifacts::CodeOnly || build_artifact == BuildArtifacts::CheckOnly { let (maybe_dest_wasm, maybe_optimization_result) = execute_with_crate_metadata( &crate_metadata, @@ -327,7 +326,7 @@ fn execute( optimize_contract, build_artifact, unstable_flags, - debug_info, + debug, )?; let res = BuildResult { dest_wasm: maybe_dest_wasm, @@ -345,7 +344,7 @@ fn execute( verbosity, build_artifact, unstable_flags, - debug_info, + debug, )?; Ok(res) } diff --git a/src/cmd/metadata.rs b/src/cmd/metadata.rs index 13d77dd2..61a9852b 100644 --- a/src/cmd/metadata.rs +++ b/src/cmd/metadata.rs @@ -266,7 +266,7 @@ pub(crate) fn execute( unstable_options: UnstableFlags, debug: bool, ) -> Result { - let crate_metadata = CrateMetadata::collect(manifest_path)?; + let crate_metadata = CrateMetadata::collect(manifest_path, debug)?; let res = GenerateMetadataCommand { crate_metadata, verbosity, diff --git a/src/crate_metadata.rs b/src/crate_metadata.rs index 1e57e950..0bab30e3 100644 --- a/src/crate_metadata.rs +++ b/src/crate_metadata.rs @@ -41,7 +41,7 @@ pub struct CrateMetadata { impl CrateMetadata { /// Parses the contract manifest and returns relevant metadata. - pub fn collect(manifest_path: &ManifestPath) -> Result { + pub fn collect(manifest_path: &ManifestPath, debug: bool) -> Result { let (metadata, root_package) = get_cargo_metadata(manifest_path)?; let mut target_directory = metadata.target_directory.clone(); @@ -50,10 +50,10 @@ impl CrateMetadata { // Normalize the package name. let package_name = root_package.name.replace("-", "_"); - // {target_dir}/wasm32-unknown-unknown/release/{package_name}.wasm + // {target_dir}/wasm32-unknown-unknown/{debug/release}/{package_name}.wasm let mut original_wasm = target_directory.clone(); original_wasm.push("wasm32-unknown-unknown"); - original_wasm.push("release"); + original_wasm.push(if debug { "debug" } else { "release" }); original_wasm.push(package_name.clone()); original_wasm.set_extension("wasm"); -- GitLab From c6390c31d5c2b173749d96e989a8a9697777e709 Mon Sep 17 00:00:00 2001 From: clearloop Date: Wed, 30 Dec 2020 11:55:16 +0800 Subject: [PATCH 5/6] feat(display): display the path of src.wasm in debug model --- src/cmd/build.rs | 63 ++++++++++++++++++++++++++------------------- src/cmd/metadata.rs | 32 +++++++++++++++-------- src/main.rs | 9 +++++++ 3 files changed, 66 insertions(+), 38 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 02a7fd71..c14e37e1 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -258,7 +258,10 @@ fn post_process_wasm(crate_metadata: &CrateMetadata, debug: bool) -> Result<()> /// /// The intention is to reduce the size of bloated wasm binaries as a result of missing /// optimizations (or bugs?) between Rust and Wasm. -fn optimize_wasm(crate_metadata: &CrateMetadata, debug_info: bool) -> Result { +fn optimize_wasm( + crate_metadata: &CrateMetadata, + debug_info: bool, +) -> Result<(OptimizationResult, Option)> { let mut optimized = crate_metadata.dest_wasm.clone(); optimized.set_file_name(format!("{}-opt.wasm", crate_metadata.package_name)); @@ -287,24 +290,27 @@ fn optimize_wasm(crate_metadata: &CrateMetadata, debug_info: bool) -> Result Result { let crate_metadata = CrateMetadata::collect(manifest_path, debug)?; if build_artifact == BuildArtifacts::CodeOnly || build_artifact == BuildArtifacts::CheckOnly { - let (maybe_dest_wasm, maybe_optimization_result) = execute_with_crate_metadata( - &crate_metadata, - verbosity, - optimize_contract, - build_artifact, - unstable_flags, - debug, - )?; + let (maybe_dest_wasm, maybe_dest_debug_wasm, maybe_optimization_result) = + execute_with_crate_metadata( + &crate_metadata, + verbosity, + optimize_contract, + build_artifact, + unstable_flags, + debug, + )?; let res = BuildResult { dest_wasm: maybe_dest_wasm, + maybe_dest_debug_wasm, dest_metadata: None, dest_bundle: None, target_directory: crate_metadata.target_directory, @@ -364,8 +372,8 @@ pub(crate) fn execute_with_crate_metadata( optimize_contract: bool, build_artifact: BuildArtifacts, unstable_flags: UnstableFlags, - debug_info: bool, -) -> Result<(Option, Option)> { + debug: bool, +) -> Result<(Option, Option, Option)> { println!( " {} {}", format!("[1/{}]", build_artifact.steps()).bold(), @@ -377,18 +385,19 @@ pub(crate) fn execute_with_crate_metadata( format!("[2/{}]", build_artifact.steps()).bold(), "Post processing wasm file".bright_green().bold() ); - post_process_wasm(&crate_metadata, debug_info)?; + post_process_wasm(&crate_metadata, debug)?; if !optimize_contract { - return Ok((None, None)); + return Ok((None, None, None)); } println!( " {} {}", format!("[3/{}]", build_artifact.steps()).bold(), "Optimizing wasm file".bright_green().bold() ); - let optimization_result = optimize_wasm(&crate_metadata, optimize_contract)?; + let (optimization_result, maybe_dest_debug_wasm) = optimize_wasm(&crate_metadata, debug)?; Ok(( Some(crate_metadata.dest_wasm.clone()), + maybe_dest_debug_wasm, Some(optimization_result), )) } diff --git a/src/cmd/metadata.rs b/src/cmd/metadata.rs index 61a9852b..d3e5e7f4 100644 --- a/src/cmd/metadata.rs +++ b/src/cmd/metadata.rs @@ -46,6 +46,7 @@ struct GenerateMetadataCommand { /// Result of generating the extended contract project metadata struct ExtendedMetadataResult { dest_wasm: Option, + maybe_dest_debug_wasm: Option, source: Source, contract: Contract, user: Option, @@ -65,6 +66,7 @@ impl GenerateMetadataCommand { // build the extended contract project metadata let ExtendedMetadataResult { dest_wasm, + maybe_dest_debug_wasm, source, contract, user, @@ -141,6 +143,7 @@ impl GenerateMetadataCommand { Ok(BuildResult { dest_metadata: Some(out_path_metadata), dest_wasm, + maybe_dest_debug_wasm, dest_bundle, optimization_result, target_directory, @@ -166,7 +169,7 @@ impl GenerateMetadataCommand { .transpose()?; let homepage = self.crate_metadata.homepage.clone(); let license = contract_package.license.clone(); - let (dest_wasm, hash, optimization_result) = self.wasm_hash()?; + let (dest_wasm, maybe_dest_debug_wasm, hash, optimization_result) = self.wasm_hash()?; let source = { let lang = SourceLanguage::new(Language::Ink, ink_version.clone()); let compiler = SourceCompiler::new(Compiler::RustC, rust_version); @@ -220,6 +223,7 @@ impl GenerateMetadataCommand { Ok(ExtendedMetadataResult { dest_wasm: Some(dest_wasm), + maybe_dest_debug_wasm, source, contract, user, @@ -230,20 +234,26 @@ impl GenerateMetadataCommand { /// Compile the contract and then hash the resulting Wasm. /// /// Return a tuple of `(dest_wasm, hash, optimization_result)`. - fn wasm_hash(&self) -> Result<(PathBuf, CodeHash, OptimizationResult)> { - let (maybe_dest_wasm, maybe_optimization_res) = super::build::execute_with_crate_metadata( - &self.crate_metadata, - self.verbosity, - true, // for the hash we always use the optimized version of the contract - self.build_artifact, - self.unstable_options.clone(), - self.debug, - )?; + fn wasm_hash(&self) -> Result<(PathBuf, Option, CodeHash, OptimizationResult)> { + let (maybe_dest_wasm, maybe_dest_debug_wasm, maybe_optimization_res) = + super::build::execute_with_crate_metadata( + &self.crate_metadata, + self.verbosity, + true, // for the hash we always use the optimized version of the contract + self.build_artifact, + self.unstable_options.clone(), + self.debug, + )?; let wasm = fs::read(&self.crate_metadata.dest_wasm)?; let dest_wasm = maybe_dest_wasm.expect("dest wasm must exist"); let optimization_res = maybe_optimization_res.expect("optimization result must exist"); - Ok((dest_wasm, blake2_hash(wasm.as_slice()), optimization_res)) + Ok(( + dest_wasm, + maybe_dest_debug_wasm, + blake2_hash(wasm.as_slice()), + optimization_res, + )) } } diff --git a/src/main.rs b/src/main.rs index 6619d580..8e293075 100644 --- a/src/main.rs +++ b/src/main.rs @@ -192,6 +192,8 @@ pub struct BuildResult { pub dest_metadata: Option, /// Path to the resulting Wasm file. pub dest_wasm: Option, + /// Path to the debug Wasm file. + pub maybe_dest_debug_wasm: Option, /// Path to the bundled file. pub dest_bundle: Option, /// Path to the directory where output files are written to. @@ -252,6 +254,13 @@ impl BuildResult { ); out.push_str(&wasm); } + if let Some(dest_debug_wasm) = self.maybe_dest_debug_wasm.as_ref() { + let wasm = format!( + " - {} (the contract's debug code)\n", + util::base_name(&dest_debug_wasm).bold() + ); + out.push_str(&wasm); + } if let Some(dest_metadata) = self.dest_metadata.as_ref() { let metadata = format!( " - {} (the contract's metadata)", -- GitLab From 2ed86d97630aa643fab7158be19d08bdd39dcd42 Mon Sep 17 00:00:00 2001 From: clearloop Date: Wed, 30 Dec 2020 12:19:55 +0800 Subject: [PATCH 6/6] feat(opt-level): keep debug info with opt-level --- src/cmd/build.rs | 15 +++++++++------ src/cmd/metadata.rs | 2 +- src/crate_metadata.rs | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index c14e37e1..866d192f 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -132,15 +132,18 @@ fn build_cargo_project( crate_metadata: &CrateMetadata, verbosity: Option, unstable_flags: UnstableFlags, + debug: bool, ) -> Result<()> { util::assert_channel()?; // set linker args via RUSTFLAGS. // Currently will override user defined RUSTFLAGS from .cargo/config. See https://github.com/paritytech/cargo-contract/issues/98. - std::env::set_var( - "RUSTFLAGS", - "-C link-arg=-z -C link-arg=stack-size=65536 -C link-arg=--import-memory", - ); + let mut flags = + "-C link-arg=-z -C link-arg=stack-size=65536 -C link-arg=--import-memory".to_string(); + if debug { + flags.push_str(" -C opt-level=1"); + } + std::env::set_var("RUSTFLAGS", flags); let cargo_build = |manifest_path: &ManifestPath| { let target_dir = &crate_metadata.target_directory; @@ -324,7 +327,7 @@ fn execute( unstable_flags: UnstableFlags, debug: bool, ) -> Result { - let crate_metadata = CrateMetadata::collect(manifest_path, debug)?; + let crate_metadata = CrateMetadata::collect(manifest_path)?; if build_artifact == BuildArtifacts::CodeOnly || build_artifact == BuildArtifacts::CheckOnly { let (maybe_dest_wasm, maybe_dest_debug_wasm, maybe_optimization_result) = execute_with_crate_metadata( @@ -379,7 +382,7 @@ pub(crate) fn execute_with_crate_metadata( format!("[1/{}]", build_artifact.steps()).bold(), "Building cargo project".bright_green().bold() ); - build_cargo_project(&crate_metadata, verbosity, unstable_flags)?; + build_cargo_project(&crate_metadata, verbosity, unstable_flags, debug)?; println!( " {} {}", format!("[2/{}]", build_artifact.steps()).bold(), diff --git a/src/cmd/metadata.rs b/src/cmd/metadata.rs index d3e5e7f4..d853dfe3 100644 --- a/src/cmd/metadata.rs +++ b/src/cmd/metadata.rs @@ -276,7 +276,7 @@ pub(crate) fn execute( unstable_options: UnstableFlags, debug: bool, ) -> Result { - let crate_metadata = CrateMetadata::collect(manifest_path, debug)?; + let crate_metadata = CrateMetadata::collect(manifest_path)?; let res = GenerateMetadataCommand { crate_metadata, verbosity, diff --git a/src/crate_metadata.rs b/src/crate_metadata.rs index 0bab30e3..8cbc2f55 100644 --- a/src/crate_metadata.rs +++ b/src/crate_metadata.rs @@ -41,7 +41,7 @@ pub struct CrateMetadata { impl CrateMetadata { /// Parses the contract manifest and returns relevant metadata. - pub fn collect(manifest_path: &ManifestPath, debug: bool) -> Result { + pub fn collect(manifest_path: &ManifestPath) -> Result { let (metadata, root_package) = get_cargo_metadata(manifest_path)?; let mut target_directory = metadata.target_directory.clone(); @@ -53,7 +53,7 @@ impl CrateMetadata { // {target_dir}/wasm32-unknown-unknown/{debug/release}/{package_name}.wasm let mut original_wasm = target_directory.clone(); original_wasm.push("wasm32-unknown-unknown"); - original_wasm.push(if debug { "debug" } else { "release" }); + original_wasm.push("release"); original_wasm.push(package_name.clone()); original_wasm.set_extension("wasm"); -- GitLab