diff --git a/lib/src/wasm/builder.rs b/lib/src/wasm/builder.rs index 551caec01..4e809172f 100644 --- a/lib/src/wasm/builder.rs +++ b/lib/src/wasm/builder.rs @@ -344,6 +344,15 @@ impl WasmModuleBuilder { self.main_func.finish(Vec::new(), &mut self.module.funcs); self.module.exports.add("main", main_func); + + // WasmModuleBuilder::new adds to the WASM module all the functions + // that are labeled as #[wasm_export] or #[module_export]. However, + // not all the functions are used in the final WASM code because + // (ie: some YARA modules are not imported by the rules). This removes + // the functions that are not actually used, reducing the size of the + // compiled rules. + walrus::passes::gc::run(&mut self.module); + self.module } }