From 8bd5afa6b1a7b6ce570852102a931d2233b0dba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Mon, 19 Jul 2021 08:59:06 +0200 Subject: [PATCH 01/10] Add `--keep-symbols` flag --- src/cmd/build.rs | 53 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index fbbc6514..24a90ac1 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -86,8 +86,13 @@ pub struct BuildCommand { /// - It is possible to define the number of optimization passes in the /// `[package.metadata.contract]` of your `Cargo.toml` as e.g. `optimization-passes = "3"`. /// The CLI argument always takes precedence over the profile value. - #[structopt(long = "optimization-passes")] + #[structopt(long)] optimization_passes: Option, + /// Do not remove symbols (wasm name section) when optimizing. + /// + /// This is useful if one want to analyze or debug the optimized binary. + #[structopt(long)] + keep_symbols: bool, } impl BuildCommand { @@ -118,6 +123,7 @@ impl BuildCommand { self.build_artifact, unstable_flags, optimization_passes, + self.keep_symbols, ) } } @@ -146,6 +152,7 @@ impl CheckCommand { BuildArtifacts::CheckOnly, unstable_flags, OptimizationPasses::Zero, + false, ) } } @@ -260,13 +267,15 @@ 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. +/// The name section is already stripped by wasm-opt. fn strip_custom_sections(module: &mut Module) { - module.sections_mut().retain(|section| { - !matches!( - section, - Section::Custom(_) | Section::Name(_) | Section::Reloc(_) - ) - }); + module.sections_mut().retain(|section| + match section { + Section::Reloc(_) => false, + Section::Custom(custom) if custom.name() != "name" => false, + _ => true, + } + ) } /// Performs required post-processing steps on the wasm artifact. @@ -306,6 +315,7 @@ fn post_process_wasm(crate_metadata: &CrateMetadata) -> Result<()> { fn optimize_wasm( crate_metadata: &CrateMetadata, optimization_passes: OptimizationPasses, + keep_symbols: bool, ) -> Result { let mut dest_optimized = crate_metadata.dest_wasm.clone(); dest_optimized.set_file_name(format!( @@ -316,6 +326,7 @@ fn optimize_wasm( crate_metadata.dest_wasm.as_os_str(), dest_optimized.as_os_str(), optimization_passes, + keep_symbols, )?; if !dest_optimized.exists() { @@ -348,6 +359,7 @@ fn do_optimization( dest_wasm: &OsStr, dest_optimized: &OsStr, optimization_level: OptimizationPasses, + keep_symbols: bool, ) -> Result<()> { // check `wasm-opt` is installed let which = which::which("wasm-opt"); @@ -379,7 +391,8 @@ fn do_optimization( "Optimization level passed to wasm-opt: {}", optimization_level ); - let output = Command::new(wasm_opt_path) + let mut command = Command::new(wasm_opt_path); + command .arg(dest_wasm) .arg(format!("-O{}", optimization_level)) .arg("-o") @@ -387,15 +400,17 @@ fn do_optimization( // the memory in our module is imported, `wasm-opt` needs to be told that // the memory is initialized to zeroes, otherwise it won't run the // memory-packing pre-pass. - .arg("--zero-filled-memory") - .output() - .map_err(|err| { - anyhow::anyhow!( - "Executing {} failed with {:?}", - wasm_opt_path.display(), - err - ) - })?; + .arg("--zero-filled-memory"); + if keep_symbols { + command.arg("-g"); + } + let output = command.output().map_err(|err| { + anyhow::anyhow!( + "Executing {} failed with {:?}", + wasm_opt_path.display(), + err + ) + })?; if !output.status.success() { let err = str::from_utf8(&output.stderr) @@ -529,6 +544,7 @@ pub(crate) fn execute( build_artifact: BuildArtifacts, unstable_flags: UnstableFlags, optimization_passes: OptimizationPasses, + keep_symbols: bool, ) -> Result { let crate_metadata = CrateMetadata::collect(manifest_path)?; @@ -557,7 +573,8 @@ pub(crate) fn execute( format!("[3/{}]", build_artifact.steps()).bold(), "Optimizing wasm file".bright_green().bold() ); - let optimization_result = optimize_wasm(&crate_metadata, optimization_passes)?; + let optimization_result = + optimize_wasm(&crate_metadata, optimization_passes, keep_symbols)?; Ok(optimization_result) }; -- GitLab From d8851cb70b4c5d84e3ffb6f00624a4c58acc22f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Mon, 19 Jul 2021 09:57:31 +0200 Subject: [PATCH 02/10] Replace pwasm_utils::optimize by a simple export stripper --- Cargo.lock | 12 ------------ Cargo.toml | 1 - src/cmd/build.rs | 34 +++++++++++++++++++--------------- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a1bdf328..8a138b88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -507,7 +507,6 @@ dependencies = [ "parity-wasm 0.42.2", "platforms", "pretty_assertions", - "pwasm-utils", "regex", "rustc_version", "semver", @@ -2332,17 +2331,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "pwasm-utils" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c1a2f10b47d446372a4f397c58b329aaea72b2daf9395a623a411cb8ccb54f" -dependencies = [ - "byteorder", - "log", - "parity-wasm 0.42.2", -] - [[package]] name = "quote" version = "1.0.9" diff --git a/Cargo.toml b/Cargo.toml index bfb9a42e..d819a8f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,6 @@ structopt = "0.3.22" log = "0.4.14" heck = "0.3.3" zip = { version = "0.5.13", default-features = false } -pwasm-utils = "0.18.1" parity-wasm = "0.42.2" cargo_metadata = "0.14.0" codec = { package = "parity-scale-codec", version = "2.1", features = ["derive"] } diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 24a90ac1..0bcc1634 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -23,7 +23,7 @@ use crate::{ }; use anyhow::{Context, Result}; use colored::Colorize; -use parity_wasm::elements::{External, MemoryType, Module, Section}; +use parity_wasm::elements::{External, Internal, MemoryType, Module, Section}; use regex::Regex; use std::{ convert::TryFrom, @@ -269,13 +269,23 @@ fn ensure_maximum_memory_pages(module: &mut Module, maximum_allowed_pages: u32) /// Presently all custom sections are not required so they can be stripped safely. /// The name section is already stripped by wasm-opt. fn strip_custom_sections(module: &mut Module) { - module.sections_mut().retain(|section| - match section { - Section::Reloc(_) => false, - Section::Custom(custom) if custom.name() != "name" => false, - _ => true, - } - ) + module.sections_mut().retain(|section| match section { + Section::Reloc(_) => false, + Section::Custom(custom) if custom.name() != "name" => false, + _ => true, + }) +} + +/// A contract should export nothing but the "call" and "deploy" functions. +/// +/// Any elements referenced by these exports become orphaned and are removed by wasm-opt. +fn strip_exports(module: &mut Module) { + module.export_section_mut().map(|section| { + section.entries_mut().retain(|entry| { + matches!(entry.internal(), Internal::Function(_)) + && (entry.field() == "call" || entry.field() == "deploy") + }) + }); } /// Performs required post-processing steps on the wasm artifact. @@ -287,13 +297,7 @@ fn post_process_wasm(crate_metadata: &CrateMetadata) -> Result<()> { crate_metadata.original_wasm.display() ))?; - // Perform optimization. - // - // In practice only tree-shaking is performed, i.e transitively removing all symbols that are - // NOT used by the specified entrypoints. - if pwasm_utils::optimize(&mut module, ["call", "deploy"].to_vec()).is_err() { - anyhow::bail!("Optimizer failed"); - } + strip_exports(&mut module); ensure_maximum_memory_pages(&mut module, MAX_MEMORY_PAGES)?; strip_custom_sections(&mut module); -- GitLab From c8118edf820cc2d671d65eededcda5589eee90c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Mon, 19 Jul 2021 10:19:48 +0200 Subject: [PATCH 03/10] Satisfy clippy --- src/cmd/build.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 0bcc1634..d36ab96b 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -280,12 +280,12 @@ fn strip_custom_sections(module: &mut Module) { /// /// Any elements referenced by these exports become orphaned and are removed by wasm-opt. fn strip_exports(module: &mut Module) { - module.export_section_mut().map(|section| { + if let Some(section) = module.export_section_mut() { section.entries_mut().retain(|entry| { matches!(entry.internal(), Internal::Function(_)) && (entry.field() == "call" || entry.field() == "deploy") }) - }); + } } /// Performs required post-processing steps on the wasm artifact. -- GitLab From 69ef58ddbe6f018bd2b77182df507504d30ac87d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Mon, 19 Jul 2021 10:27:41 +0200 Subject: [PATCH 04/10] Fix typos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michael Müller --- src/cmd/build.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index d36ab96b..576b19bb 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -88,9 +88,9 @@ pub struct BuildCommand { /// The CLI argument always takes precedence over the profile value. #[structopt(long)] optimization_passes: Option, - /// Do not remove symbols (wasm name section) when optimizing. + /// Do not remove symbols (Wasm name section) when optimizing. /// - /// This is useful if one want to analyze or debug the optimized binary. + /// This is useful if one wants to analyze or debug the optimized binary. #[structopt(long)] keep_symbols: bool, } @@ -267,7 +267,7 @@ 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. -/// The name section is already stripped by wasm-opt. +/// The name section is already stripped by `wasm-opt`. fn strip_custom_sections(module: &mut Module) { module.sections_mut().retain(|section| match section { Section::Reloc(_) => false, @@ -278,7 +278,7 @@ fn strip_custom_sections(module: &mut Module) { /// A contract should export nothing but the "call" and "deploy" functions. /// -/// Any elements referenced by these exports become orphaned and are removed by wasm-opt. +/// Any elements referenced by these exports become orphaned and are removed by `wasm-opt`. fn strip_exports(module: &mut Module) { if let Some(section) = module.export_section_mut() { section.entries_mut().retain(|entry| { -- GitLab From 776a020c44e688edc0e0dd6bc002df9ce68d9049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Mon, 19 Jul 2021 10:40:37 +0200 Subject: [PATCH 05/10] Fix test build errors --- src/cmd/build.rs | 5 +++++ src/cmd/metadata.rs | 1 + 2 files changed, 6 insertions(+) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 576b19bb..318adaaa 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -681,6 +681,7 @@ mod tests_ci_only { BuildArtifacts::CodeOnly, UnstableFlags::default(), OptimizationPasses::default(), + false, ) .expect("build failed"); @@ -720,6 +721,7 @@ mod tests_ci_only { BuildArtifacts::CheckOnly, UnstableFlags::default(), OptimizationPasses::default(), + false, ) .expect("build failed"); @@ -752,6 +754,7 @@ mod tests_ci_only { // we choose zero optimization passes as the "cli" parameter optimization_passes: Some(OptimizationPasses::Zero), + keep_symbols: false, }; // when @@ -792,6 +795,7 @@ mod tests_ci_only { // we choose no optimization passes as the "cli" parameter optimization_passes: None, + keep_symbols: false, }; // when @@ -951,6 +955,7 @@ mod tests_ci_only { verbosity: VerbosityFlags::default(), unstable_options: UnstableOptions::default(), optimization_passes: None, + keep_symbols: false, }; let res = cmd.exec().expect("build failed"); diff --git a/src/cmd/metadata.rs b/src/cmd/metadata.rs index 2a0d2e2b..8cd8184e 100644 --- a/src/cmd/metadata.rs +++ b/src/cmd/metadata.rs @@ -328,6 +328,7 @@ mod tests { BuildArtifacts::All, UnstableFlags::default(), OptimizationPasses::default(), + false, )?; let dest_bundle = build_result .metadata_result -- GitLab From 89f776b39a20306001538eb06c6a7aaf742680ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Mon, 19 Jul 2021 12:52:51 +0200 Subject: [PATCH 06/10] Fix tests --- src/cmd/build.rs | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 318adaaa..73ab4315 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -757,24 +757,19 @@ mod tests_ci_only { keep_symbols: false, }; - // when let res = cmd.exec().expect("build failed"); let optimization = res .optimization_result .expect("no optimization result available"); - // then - // we have to truncate here to account for a possible small delta - // in the floating point numbers - let optimized_size = optimization.optimized_size.trunc(); - let original_size = optimization.original_size.trunc(); + // The size does not exactly match the original size even without optimization + // passed because there is still some post processing happening. + let size_diff = optimization.original_size - optimization.optimized_size; assert!( - optimized_size == original_size, - "The optimized size {:?} differs from the original size {:?}", - optimized_size, - original_size + 0.0 < size_diff && size_diff < 10.0, + "The optimized size savings are larger than allowed or negative: {}", + size_diff, ); - Ok(()) }) } @@ -798,22 +793,18 @@ mod tests_ci_only { keep_symbols: false, }; - // when let res = cmd.exec().expect("build failed"); let optimization = res .optimization_result .expect("no optimization result available"); - // then - // we have to truncate here to account for a possible small delta - // in the floating point numbers - let optimized_size = optimization.optimized_size.trunc(); - let original_size = optimization.original_size.trunc(); + // The size does not exactly match the original size even without optimization + // passed because there is still some post processing happening. + let size_diff = optimization.original_size - optimization.optimized_size; assert!( - optimized_size < original_size, - "The optimized size DOES NOT {:?} differ from the original size {:?}", - optimized_size, - original_size + size_diff > (optimization.original_size / 2.0), + "The optimized size savings are to small: {}", + size_diff, ); Ok(()) -- GitLab From a05545886babbbfd80c2426fd9665d08852635dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Mon, 19 Jul 2021 12:53:36 +0200 Subject: [PATCH 07/10] Rename to `--keep-debug-symbols` --- src/cmd/build.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 73ab4315..4a185de5 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -92,7 +92,7 @@ pub struct BuildCommand { /// /// This is useful if one wants to analyze or debug the optimized binary. #[structopt(long)] - keep_symbols: bool, + keep_debug_symbols: bool, } impl BuildCommand { @@ -123,7 +123,7 @@ impl BuildCommand { self.build_artifact, unstable_flags, optimization_passes, - self.keep_symbols, + self.keep_debug_symbols, ) } } @@ -319,7 +319,7 @@ fn post_process_wasm(crate_metadata: &CrateMetadata) -> Result<()> { fn optimize_wasm( crate_metadata: &CrateMetadata, optimization_passes: OptimizationPasses, - keep_symbols: bool, + keep_debug_symbols: bool, ) -> Result { let mut dest_optimized = crate_metadata.dest_wasm.clone(); dest_optimized.set_file_name(format!( @@ -330,7 +330,7 @@ fn optimize_wasm( crate_metadata.dest_wasm.as_os_str(), dest_optimized.as_os_str(), optimization_passes, - keep_symbols, + keep_debug_symbols, )?; if !dest_optimized.exists() { @@ -363,7 +363,7 @@ fn do_optimization( dest_wasm: &OsStr, dest_optimized: &OsStr, optimization_level: OptimizationPasses, - keep_symbols: bool, + keep_debug_symbols: bool, ) -> Result<()> { // check `wasm-opt` is installed let which = which::which("wasm-opt"); @@ -405,7 +405,7 @@ fn do_optimization( // the memory is initialized to zeroes, otherwise it won't run the // memory-packing pre-pass. .arg("--zero-filled-memory"); - if keep_symbols { + if keep_debug_symbols { command.arg("-g"); } let output = command.output().map_err(|err| { @@ -548,7 +548,7 @@ pub(crate) fn execute( build_artifact: BuildArtifacts, unstable_flags: UnstableFlags, optimization_passes: OptimizationPasses, - keep_symbols: bool, + keep_debug_symbols: bool, ) -> Result { let crate_metadata = CrateMetadata::collect(manifest_path)?; @@ -578,7 +578,7 @@ pub(crate) fn execute( "Optimizing wasm file".bright_green().bold() ); let optimization_result = - optimize_wasm(&crate_metadata, optimization_passes, keep_symbols)?; + optimize_wasm(&crate_metadata, optimization_passes, keep_debug_symbols)?; Ok(optimization_result) }; @@ -754,7 +754,7 @@ mod tests_ci_only { // we choose zero optimization passes as the "cli" parameter optimization_passes: Some(OptimizationPasses::Zero), - keep_symbols: false, + keep_debug_symbols: false, }; let res = cmd.exec().expect("build failed"); @@ -790,7 +790,7 @@ mod tests_ci_only { // we choose no optimization passes as the "cli" parameter optimization_passes: None, - keep_symbols: false, + keep_debug_symbols: false, }; let res = cmd.exec().expect("build failed"); @@ -946,7 +946,7 @@ mod tests_ci_only { verbosity: VerbosityFlags::default(), unstable_options: UnstableOptions::default(), optimization_passes: None, - keep_symbols: false, + keep_debug_symbols: false, }; let res = cmd.exec().expect("build failed"); -- GitLab From bf46eed935d25753ca11ca8cb01e04f80045085a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Mon, 19 Jul 2021 17:07:38 +0200 Subject: [PATCH 08/10] Add test for `--keep-debug-symbols` --- src/cmd/build.rs | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 4a185de5..44b90acd 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -288,14 +288,20 @@ fn strip_exports(module: &mut Module) { } } +/// Load and parse a wasm file from disk. +fn load_module>(path: P) -> Result { + let path = path.as_ref(); + parity_wasm::deserialize_file(path).context(format!( + "Loading of wasm module at '{}' failed", + path.display(), + )) +} + /// Performs required post-processing steps on the wasm artifact. fn post_process_wasm(crate_metadata: &CrateMetadata) -> Result<()> { // Deserialize wasm module from a file. let mut module = - parity_wasm::deserialize_file(&crate_metadata.original_wasm).context(format!( - "Loading original wasm file '{}'", - crate_metadata.original_wasm.display() - ))?; + load_module(&crate_metadata.original_wasm).context("Loading of original wasm failed")?; strip_exports(&mut module); ensure_maximum_memory_pages(&mut module, MAX_MEMORY_PAGES)?; @@ -621,7 +627,7 @@ pub(crate) fn execute( mod tests_ci_only { use super::{assert_compatible_ink_dependencies, check_wasm_opt_version_compatibility}; use crate::{ - cmd::BuildCommand, + cmd::{build::load_module, BuildCommand}, util::tests::{with_new_contract_project, with_tmp_dir}, workspace::Manifest, BuildArtifacts, ManifestPath, OptimizationPasses, UnstableFlags, UnstableOptions, @@ -652,6 +658,13 @@ mod tests_ci_only { .expect("writing manifest failed"); } + fn has_debug_symbols>(p: P) -> bool { + load_module(p) + .unwrap() + .custom_sections() + .any(|e| e.name() == "name") + } + /// Creates an executable `wasm-opt-mocked` file which outputs /// "wasm-opt version `version`". /// @@ -704,6 +717,10 @@ mod tests_ci_only { // our optimized contract template should always be below 3k. assert!(optimized_size < 3.0); + // we specified that debug symbols should be removed + // original code should have some but the optimized version should have them removed + assert!(!has_debug_symbols(&res.dest_wasm.unwrap())); + Ok(()) }) } @@ -961,4 +978,24 @@ mod tests_ci_only { Ok(()) }) } + + #[test] + fn keep_debug_symbols() { + with_new_contract_project(|manifest_path| { + let res = super::execute( + &manifest_path, + Verbosity::Default, + BuildArtifacts::CodeOnly, + UnstableFlags::default(), + OptimizationPasses::default(), + true, + ) + .expect("build failed"); + + // we specified that debug symbols should be kept + assert!(has_debug_symbols(&res.dest_wasm.unwrap())); + + Ok(()) + }) + } } -- GitLab From eff9d87defe09ae9b3e01f58b6087b2b2acf114f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Tue, 20 Jul 2021 10:51:23 +0200 Subject: [PATCH 09/10] Fix typos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Andrew Jones Co-authored-by: Michael Müller --- src/cmd/build.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 44b90acd..48312a51 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -278,7 +278,7 @@ fn strip_custom_sections(module: &mut Module) { /// A contract should export nothing but the "call" and "deploy" functions. /// -/// Any elements referenced by these exports become orphaned and are removed by `wasm-opt`. +/// Any elements not referenced by these exports become orphaned and are removed by `wasm-opt`. fn strip_exports(module: &mut Module) { if let Some(section) = module.export_section_mut() { section.entries_mut().retain(|entry| { @@ -820,7 +820,7 @@ mod tests_ci_only { let size_diff = optimization.original_size - optimization.optimized_size; assert!( size_diff > (optimization.original_size / 2.0), - "The optimized size savings are to small: {}", + "The optimized size savings are too small: {}", size_diff, ); -- GitLab From e1a68df3dc4565a3fc256f47c0f50f880ce2f068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Tue, 20 Jul 2021 10:57:13 +0200 Subject: [PATCH 10/10] Restore when/then --- src/cmd/build.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 48312a51..416eaa28 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -774,11 +774,13 @@ mod tests_ci_only { keep_debug_symbols: false, }; + // when let res = cmd.exec().expect("build failed"); let optimization = res .optimization_result .expect("no optimization result available"); + // then // The size does not exactly match the original size even without optimization // passed because there is still some post processing happening. let size_diff = optimization.original_size - optimization.optimized_size; @@ -810,11 +812,13 @@ mod tests_ci_only { keep_debug_symbols: false, }; + // when let res = cmd.exec().expect("build failed"); let optimization = res .optimization_result .expect("no optimization result available"); + // then // The size does not exactly match the original size even without optimization // passed because there is still some post processing happening. let size_diff = optimization.original_size - optimization.optimized_size; -- GitLab