From ec206fca6428d64b724a8668b431977f833e3fef Mon Sep 17 00:00:00 2001 From: holygits Date: Thu, 24 Jan 2019 15:46:01 +1300 Subject: [PATCH] Preserve deploy symbol on optimize for substrate target --- src/build.rs | 11 ++++++----- src/pack.rs | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/build.rs b/src/build.rs index 7c89139..65846b0 100644 --- a/src/build.rs +++ b/src/build.rs @@ -96,10 +96,7 @@ pub fn build( let mut public_api_entries = public_api_entries.to_vec(); public_api_entries.push(target_runtime.symbols().call); if !skip_optimization { - optimize( - &mut module, - public_api_entries, - )?; + optimize(&mut module, public_api_entries)?; } if !has_ctor(&ctor_module, target_runtime) { @@ -107,7 +104,11 @@ pub fn build( } if !skip_optimization { - optimize(&mut ctor_module, vec![target_runtime.symbols().create])?; + let preserved_exports = match target_runtime { + TargetRuntime::PWasm(_) => vec![target_runtime.symbols().call], + TargetRuntime::Substrate(_) => vec![target_runtime.symbols().call, target_runtime.symbols().create], + }; + optimize(&mut ctor_module, preserved_exports)?; } if let TargetRuntime::PWasm(_) = target_runtime { diff --git a/src/pack.rs b/src/pack.rs index b2d6c03..4a148f8 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -41,7 +41,7 @@ impl fmt::Display for Error { } } -/// If module has an exported function matching "create" symbol we want to pack it into "constructor". +/// If a pwasm module has an exported function matching "create" symbol we want to pack it into "constructor". /// `raw_module` is the actual contract code /// `ctor_module` is the constructor which should return `raw_module` pub fn pack_instance(raw_module: Vec, mut ctor_module: elements::Module, target: &TargetRuntime) -> Result {