-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrap wasm-opt
related functions in struct
#687
Conversation
Just a basic copy-pasta of what's in the existing optimization code
I think it makes sense to have this be associated with the handler instead of just floating around on its own.
src/cmd/build.rs
Outdated
* Debian/Ubuntu: apt-get install binaryen\n\ | ||
* Homebrew: brew install binaryen\n\ | ||
* Arch Linux: pacman -S binaryen\n\ | ||
* Windows: binary releases at https://github.com/WebAssembly/binaryen/releases"; |
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 indentation seems to mismatch the other indentations in the file.
src/cmd/build.rs
Outdated
/// Whether or not to keep debugging information in the final Wasm binary. | ||
keep_debug_symbols: bool, | ||
/// The version number of the `wasm-opt` binary being executed. | ||
_version: u32, |
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.
Why prefix with _
?
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.
It's not used in this PR, but will be used in #680
I think you should put |
src/cmd/build.rs
Outdated
version_stdout, | ||
github_note, | ||
) | ||
})?; |
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.
rustfmt you're drunk
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 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.
LGTM, rustfmt
still on a bender though
src/wasm_opt.rs
Outdated
let mut command = Command::new(self.wasm_opt_path.as_path()); | ||
command | ||
.arg(dest_wasm.as_os_str()) | ||
.arg(format!("-O{}", self.optimization_level)) | ||
.arg("-o") | ||
.arg(dest_optimized.as_os_str()) | ||
// the memory in our module is imported, `wasm-opt` needs to be told that | ||
// the memory is initialized to zeroes, otherwise it won't run the | ||
// memory-packing pre-pass. | ||
.arg("--zero-filled-memory"); |
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.
Surely this whole block should be indented?
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.
RustFmt seems indifferent, but yeah I've indented it
src/wasm_opt.rs
Outdated
let version_number: u32 = captures | ||
.get(1) // first capture group is at index 1 | ||
.ok_or_else(|| { | ||
anyhow::anyhow!( | ||
"Unable to extract version number from '{:?}'", | ||
version_stdout | ||
) | ||
})? | ||
.as_str() | ||
.parse() | ||
.map_err(|err| { | ||
anyhow::anyhow!( | ||
"Parsing version number failed with '{:?}' for '{:?}'", | ||
err, | ||
version_stdout | ||
) | ||
})?; |
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 also be indented
This PR adds a
WasmOptHandler
struct, which wraps all the functions related towasm-opt
. This lets us ensure that ourwasm-opt
binary is there and valid before weeven try and optimize a binary.
It also makes it easier to pull out certain information about the
wasm-opt
instancewe're using (such as the
wasm-opt
version, which I need for #680).