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
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- Removed requirement to install binaryen. The `wasm-opt` tool is now compiled into `cargo-contract`.

## [2.0.0-alpha.4] - 2022-10-03

### Fixed
Expand Down
154 changes: 150 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 6 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,18 @@ More relevant links:

## Installation

* Step 1: `rustup component add rust-src`.

* Step 2: Install `binaryen` in a version >= 99:
In addition to Rust, installation requires a C++ compiler that supports C++17.
Modern releases of gcc and clang, as well as Visual Studio 2019+ should work.

* [Debian/Ubuntu](https://tracker.debian.org/pkg/binaryen): `apt-get install binaryen`
* [Homebrew](https://formulae.brew.sh/formula/binaryen): `brew install binaryen`
* [Arch Linux](https://archlinux.org/packages/community/x86_64/binaryen/): `pacman -S binaryen`
* Windows: [binary releases are available](https://github.com/WebAssembly/binaryen/releases)

There's only an old version in your distributions package manager? Just use a
[binary release](https://github.com/WebAssembly/binaryen/releases).
* Step 1: `rustup component add rust-src`.

* Step 3: Install `dylint`
* Step 2: Install `dylint`
* (MacOS) `brew install openssl`
* `cargo install cargo-dylint dylint-link`.

* Step 4: `cargo install --force --locked cargo-contract`.
* Step 3: `cargo install --force --locked cargo-contract`.

You can always update the `cargo-contract` binary to the latest version by running the Step 4.
You can always update the `cargo-contract` binary to the latest version by running the Step 3.

### Installation using Docker Image

Expand Down
2 changes: 1 addition & 1 deletion crates/cargo-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ serde_json = "1.0.85"
tempfile = "3.3.0"
url = { version = "2.3.1", features = ["serde"] }
impl-serde = "0.4.0"
regex = "1.6.0"
wasm-opt = "0.110.0"

# dependencies for extrinsics (deploying and calling a contract)
async-std = { version = "1.12.0", features = ["attributes", "tokio1"] }
Expand Down
23 changes: 23 additions & 0 deletions crates/cargo-contract/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ use std::{
str::FromStr,
};

use ::wasm_opt::OptimizationOptions;
use anyhow::{
anyhow,
Error,
Expand All @@ -71,6 +72,12 @@ use assert_cmd as _;
#[cfg(test)]
use predicates as _;

#[cfg(test)]
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.


#[derive(Debug, Parser)]
#[clap(bin_name = "cargo")]
#[clap(version = env!("CARGO_CONTRACT_CLI_IMPL_VERSION"))]
Expand Down Expand Up @@ -158,6 +165,22 @@ impl From<String> for OptimizationPasses {
}
}

impl From<OptimizationPasses> for OptimizationOptions {
fn from(passes: OptimizationPasses) -> OptimizationOptions {
match passes {
OptimizationPasses::Zero => OptimizationOptions::new_opt_level_0(),
OptimizationPasses::One => OptimizationOptions::new_opt_level_1(),
OptimizationPasses::Two => OptimizationOptions::new_opt_level_2(),
OptimizationPasses::Three => OptimizationOptions::new_opt_level_3(),
OptimizationPasses::Four => OptimizationOptions::new_opt_level_4(),
OptimizationPasses::S => OptimizationOptions::new_optimize_for_size(),
OptimizationPasses::Z => {
OptimizationOptions::new_optimize_for_size_aggressively()
}
}
}
}

#[derive(Default, Clone, Debug, Args)]
pub struct VerbosityFlags {
/// No output printed to stdout
Expand Down
Loading