Skip to content
This repository was archived by the owner on Jan 17, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions cli/build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ fn do_main() -> Result<(), Error> {

let (module, ctor_module) = build(
module,
true,
source_input.target(),
runtime_type_version,
&public_api_entries,
Expand All @@ -174,10 +173,13 @@ fn do_main() -> Result<(), Error> {
parity_wasm::serialize_to_file(save_raw_path, module.clone()).map_err(Error::Encoding)?;
}

parity_wasm::serialize_to_file(
&path,
ctor_module.expect("ctor_module can't be None, because 'constructor' argument is set to true in build"),
).map_err(Error::Encoding)?;
if let Some(ctor_module) = ctor_module {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a grumble -- this interface looks a little bit confusing to me: if no deploy symbol is defined, and we run wasm-build without --save-raw, then no file will be written? Maybe we can return a warning in the above case or just change it so that "no deploy symbol" is equivalent to --save-raw?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it worked like you say before the #97

parity_wasm::serialize_to_file(
&path,
ctor_module,
).map_err(Error::Encoding)?;
}

Ok(())
}

Expand Down
8 changes: 1 addition & 7 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use parity_wasm::elements;
pub enum Error {
Encoding(elements::Error),
Packing(PackingError),
NoCreateSymbolFound,
Optimizer,
}

Expand Down Expand Up @@ -47,7 +46,6 @@ impl std::fmt::Display for Error {
Encoding(ref err) => write!(f, "Encoding error ({})", err),
Optimizer => write!(f, "Optimization error due to missing export section. Pointed wrong file?"),
Packing(ref e) => write!(f, "Packing failed due to module structure error: {}. Sure used correct libraries for building contracts?", e),
NoCreateSymbolFound => write!(f, "Packing failed: no \"{}\" symbol found?", CREATE_SYMBOL),
}
}
}
Expand All @@ -62,7 +60,6 @@ fn has_ctor(module: &elements::Module) -> bool {

pub fn build(
mut module: elements::Module,
constructor: bool,
source_target: SourceTarget,
runtime_type_version: Option<([u8; 4], u32)>,
public_api_entries: &[&str],
Expand Down Expand Up @@ -105,10 +102,7 @@ pub fn build(
)?;
}

if constructor {
if !has_ctor(&ctor_module) {
Err(Error::NoCreateSymbolFound)?
}
if has_ctor(&ctor_module) {
if !skip_optimization {
optimize(&mut ctor_module, vec![CREATE_SYMBOL])?;
}
Expand Down