Skip to content

Conversation

@HCastano
Copy link
Contributor

This PR adds a WasmOptHandler struct, which wraps all the functions related to
wasm-opt. This lets us ensure that our wasm-opt binary is there and valid before we
even try and optimize a binary.

It also makes it easier to pull out certain information about the wasm-opt instance
we're using (such as the wasm-opt version, which I need for #680).

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";
Copy link
Collaborator

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,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why prefix with _?

Copy link
Contributor Author

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

@cmichi
Copy link
Collaborator

cmichi commented Aug 15, 2022

I think you should put WasmOptHandler in its own file, that's just the next consequence of abstracting away from what is happening in that handler and it will make the build.rs file less cluttered.

src/cmd/build.rs Outdated
version_stdout,
github_note,
)
})?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

rustfmt you're drunk

@HCastano HCastano requested review from ascjones and cmichi August 15, 2022 16:48
Copy link
Collaborator

@cmichi cmichi left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

@ascjones ascjones left a 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
Comment on lines 106 to 115
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");
Copy link
Collaborator

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?

Copy link
Contributor Author

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
Comment on lines 217 to 233
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
)
})?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should also be indented

@HCastano HCastano merged commit ebd388e into master Aug 16, 2022
@HCastano HCastano deleted the hc-refactor-wasm-opt-pass branch August 16, 2022 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants