Skip to content

Commit

Permalink
Use integrated wasm-opt (use-ink#766)
Browse files Browse the repository at this point in the history
* Change wasm-opt installation suggestion to favor 'cargo install wasm-opt'

* Use integrated wasm-opt API

* Remove option to use wasm-opt CLI

* Remove binaryen from prereqs

* Update changelog for wasm-opt crate

* Mention c++17 in readme
  • Loading branch information
brson authored Oct 5, 2022
1 parent 6626f56 commit 6c425de
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 278 deletions.
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 _;

#[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

0 comments on commit 6c425de

Please sign in to comment.