-
Notifications
You must be signed in to change notification settings - Fork 47
Move build logic to lib #97
Conversation
|
don't quite understand a reason why But locally it passes. And also there is no changes in optimizer code.. |
|
so, it failing in master too https://travis-ci.org/paritytech/wasm-utils/builds/410384083 |
|
The error seems to come from the newest parity-wasm library, in particular this change. |
bea81dc to
e84600d
Compare
cli/build/main.rs
Outdated
| matches.is_present("enforce_stack_adjustment"), | ||
| matches.value_of("shrink_stack").unwrap_or_else(|| "49152").parse() | ||
| .expect("New stack size is not valid u32"), | ||
| matches.is_present("skip_optimization")).map_err(Error::Build)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
).map_err should be on the next line
cli/build/main.rs
Outdated
|
|
||
| parity_wasm::serialize_to_file( | ||
| &path, | ||
| ctor_module.expect("ctor_module shouldn't be None, b/c 'constructor' argument is set to true in build") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b/c ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we avoid non-obvious abbreviations?
src/build.rs
Outdated
| target: Target, | ||
| runtime_type: Option<&[u8]>, | ||
| runtime_version: Option<u32>, | ||
| mut public_api_entries: Vec<&str>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a bad choice for this argument in signature for public api
&[&str] would be ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain? I'd better to use [u8; 4] or u32, not &str
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because it allows wider use of types when invoking the function
&vec!["a", "b"][..], &["a", "b"], &["a", "b"][1..], etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to use the type system soundness here. So I'd better use [u8; 4] here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is [u8; 4]? how it is related to Vec<&str>?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so for user it will be more descriptive API which could help to avoid the runtime error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how can you put a string in [u8; 4] ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cause for runtime_type we use exactly 4 bytes. Would be nice to declare it as it is 🤗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the conversation is about strings for public_api_entries argument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, ok 🙈
| if constructor { | ||
| if !has_ctor(&ctor_module) { | ||
| Err(Error::NoCreateSymbolFound)? | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are the identation here? some spaces + tab?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cant find any spaces in indentation in this snippet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm.. probably github changed the way how it displays the diff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks ok, sorry
| } | ||
|
|
||
| pub fn build( | ||
| mut module: elements::Module, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad identations everywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand, why you think so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like tabs everywhere, sorry
e84600d to
03e4df3
Compare
src/build.rs
Outdated
| mut public_api_entries: Vec<&str>, | ||
| enforce_stack_adjustment: bool, | ||
| stack_size: u32, | ||
| skip_optimization: bool) -> Result<(elements::Module, Option<elements::Module>), Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but this is bad should be
skip_optimization: bool,
) -> Result<(elements::Module, Option<elements::Module>), Error> {
src/build.rs
Outdated
| inject_runtime_type, | ||
| PackingError, | ||
| OptimizerError | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be at the beginning of the line
src/build.rs
Outdated
| use parity_wasm; | ||
| use parity_wasm::elements; | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant empty line
src/build.rs
Outdated
| } | ||
| let ctor_module = | ||
| pack_instance( | ||
| parity_wasm::serialize(module.clone()).map_err(Error::Encoding)?, ctor_module.clone())?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad indentations
should use smth like
pack_instance(
... arguments
)?;
5e4dd63 to
1694e6f
Compare
src/build.rs
Outdated
| } | ||
| let ctor_module = pack_instance( | ||
| parity_wasm::serialize(module.clone()).map_err(Error::Encoding)?, | ||
| ctor_module.clone() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there should be a comma after the last argument
1694e6f to
d2749e6
Compare
src/build.rs
Outdated
| } | ||
|
|
||
| #[derive(Debug, Clone, Copy)] | ||
| pub enum Target { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think Target is better name that SourceTarget, since SourceTarget outlines that it is the target which we take as a source to process further
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure.
But because now it lives in build.rs, which don't care know about "files" and now it doesn't require such a context clarification, IMO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the logic retained
Why not call it "source" then?
cli/build/main.rs
Outdated
|
|
||
| parity_wasm::serialize_to_file( | ||
| &path, | ||
| ctor_module.expect("ctor_module can't be None, because 'constructor' argument is set to true in build") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there should be a comma after the last argument when each is on a dedicated line
d2749e6 to
1124b50
Compare
src/build.rs
Outdated
| pub fn build( | ||
| mut module: elements::Module, | ||
| constructor: bool, | ||
| target: SourceTarget, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source_target as well?
ecb5fa6 to
e97ccd7
Compare
src/build.rs
Outdated
| mut module: elements::Module, | ||
| constructor: bool, | ||
| source_target: SourceTarget, | ||
| runtime_type: Option<[u8; 4]>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be runtime_spec: Option<([u8; 4], u32)> (or dedicated struct inside Option) instead of two parameters?
it's even parsed from cli this way - either both are present, or both are None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sense. I'd like also add a struct for additional params (flags)
src/build.rs
Outdated
| shrink_unknown_stack, | ||
| inject_runtime_type, | ||
| PackingError, | ||
| OptimizerError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comma
src/build.rs
Outdated
| public_api_entries: &[&str], | ||
| enforce_stack_adjustment: bool, | ||
| stack_size: u32, | ||
| skip_optimization: bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comma
cli/build/main.rs
Outdated
| fn from(err: utils::PackingError) -> Self { | ||
| Error::Packing(err) | ||
| } | ||
| Build(BuildError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comma
326b271 to
4dcab78
Compare
d6cdf08 to
dc2b350
Compare
|
Great job |
Just a subtraction of build logic to a lib