Skip to content

Commit

Permalink
feat(wasm-builder): optimized used functions of metawasm
Browse files Browse the repository at this point in the history
  • Loading branch information
clearloop committed Nov 7, 2023
1 parent 5ae3b19 commit 1bfaa39
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
19 changes: 4 additions & 15 deletions utils/wasm-builder/src/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use gear_core::code::{Code, TryNewCodeConfig};
use gear_wasm_instrument::{rules::CustomConstantCostRules, STACK_END_EXPORT_NAME};
use pwasm_utils::{
parity_wasm,
parity_wasm::elements::{Internal, Module, Section, Serialize},
parity_wasm::elements::{Module, Section, Serialize},
};
#[cfg(not(feature = "wasm-opt"))]
use std::process::Command;
Expand All @@ -31,6 +31,8 @@ const OPTIMIZED_EXPORTS: [&str; 7] = [
STACK_END_EXPORT_NAME,
];

const OPTIMIZED_META_EXPORTS: [&str; 1] = ["metadata"];

/// Type of the output wasm.
#[derive(PartialEq, Eq)]
pub enum OptType {
Expand Down Expand Up @@ -88,20 +90,7 @@ impl Optimizer {
let exports = if ty == OptType::Opt {
OPTIMIZED_EXPORTS.to_vec()
} else {
self.module
.export_section()
.ok_or_else(|| anyhow::anyhow!("Export section not found"))?
.entries()
.iter()
.flat_map(|entry| {
if let Internal::Function(_) = entry.internal() {
let entry = entry.field();
(!OPTIMIZED_EXPORTS.contains(&entry)).then_some(entry)
} else {
None
}
})
.collect()
OPTIMIZED_META_EXPORTS.to_vec()
};

pwasm_utils::optimize(&mut module, exports)
Expand Down
2 changes: 2 additions & 0 deletions utils/wasm-builder/src/wasm_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ extern "C" fn metahash() {{
)?;
}

optimize::optimize_wasm(meta_wasm_path.clone(), meta_wasm_path.clone(), "4", false)?;

smart_fs::write(
self.out_dir.join("wasm_binary.rs"),
format!(
Expand Down

0 comments on commit 1bfaa39

Please sign in to comment.