Skip to content
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

Use integrated wasm-opt #766

Merged
merged 6 commits into from
Oct 5, 2022
Merged

Use integrated wasm-opt #766

merged 6 commits into from
Oct 5, 2022

Conversation

brson
Copy link
Contributor

@brson brson commented Oct 5, 2022

Compile wasm-opt and call it as a library instead of as an external binary.

This PR has three patches that result in completely removing support for the wasm-opt CLI in favor of the crate. If desired, the third commit can be excluded, leaving support for both methods.

Documentation for the wasm-opt bindings:

Things to be aware of about the wasm-opt crate:

  • It depends on Rust 1.48+
  • It depends on a c++17 compiler, and should emit a readable error if one is not available.
  • The wasm-opt-sys crate takes a non-negligible amount of time to build (minutes on my underpowered laptop). It also does not do any incremental recompilation, so if the build is invalidated it will rebuild the C++ code from scratch. The lack of incremental recompilation is a limitation self-imposed by not using cmake or other external build system.
  • wasm-opt on windows does not support extended unicode paths (probably anything non-ascii, maybe latin-1, it's unclear). This is a limitation of binaryen and not a regression of the bindings. It may or may not be fixed in the future. The API will return an error if this occurs.
  • cargo tarpaulin (code coverage) segfaults running any wasm-opt crates (Investigate tarpaulin segfault brson/wasm-opt-rs#59), reason unknown. This behavior could infect other crates that link to wasm-opt. If you use tarpaulin, you might check it.

Fixes #733

@cla-bot-2021
Copy link

cla-bot-2021 bot commented Oct 5, 2022

User @brson, please sign the CLA here.

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.

This is absolutely fantastic thank you @brson, it removes some major friction from our installation process!

It depends on a c++17 compiler, and should emit a readable error if one is not available.

I wonder whether we should include that as a prerequisite. Which reminds me, we should remove Step 2: install binaryen from https://github.com/paritytech/cargo-contract#installation

@brson
Copy link
Contributor Author

brson commented Oct 5, 2022

I have updated the readme to remove the binaryen installation step, and added an entry to the changelog.

I am not sure where in the readme to mention the c++17 prerequisite.

@brson brson force-pushed the wasm-opt-rs branch 3 times, most recently from 5a1e76f to bce2f16 Compare October 5, 2022 13:32
@brson
Copy link
Contributor Author

brson commented Oct 5, 2022

I've also added a mention of c++17 to the installation section.

@ascjones ascjones merged commit 6c425de into use-ink:master Oct 5, 2022
use regex as _;

// Only used on windows.
use which as _;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it not possible to prefix with #[cfg(target_os = "windows")] here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so. This is intentionally doing the opposite - making it look like which is used on not-windows. cargo-contract has a clippy lint turned on to check that linked crates are actually used, and which is only used on windows, so clippy doesn't see it on unix. What could be done is to change the Cargo.toml to only link to which on windows.

@cmichi
Copy link
Collaborator

cmichi commented Oct 5, 2022

This is a great achievement, that hopefully will also benefit the broader Rust+Wasm ecosystem.

Thanks a lot, @brson!

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.

Integrating wasm-opt via wasm-opt-rs
4 participants