diff --git a/CHANGELOG.md b/CHANGELOG.md index fec4d2b9e4501fc850c5248394cd1a73f9c992f3..ca1ce2f450adc0354570cc7ebbd50dc2d5f622d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Removed +- Remove support for `--binaryen-as-dependency` - [#251](https://github.com/paritytech/cargo-contract/pull/251) + ## [0.11.1] - 2021-04-06 ### Fixed diff --git a/Cargo.toml b/Cargo.toml index 632b22b5fb6b0546be3c6e5411a2a2a98f4bb8af..c8ff617ef936b0ce586112e9833d5b415085844a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,7 +68,6 @@ wabt = "0.10.0" [features] default = [] -binaryen-as-dependency = ["binaryen"] # Enable this for (experimental) commands to deploy, instantiate and call contracts. # diff --git a/README.md b/README.md index ce3512f3dbf898da0f03a6f5a3161229c7e1271d..5869c4f65edc19817ae33c8c6631b4f49c576968 100644 --- a/README.md +++ b/README.md @@ -10,22 +10,17 @@ A CLI tool for helping setting up and managing WebAssembly smart contracts writt `rust-src` is a prerequisite: `rustup component add rust-src`. -We optimize the resulting contract Wasm using `binaryen`. You have two options for installing it: - - - _The preferred way:_ - Install [`binaryen`](https://github.com/WebAssembly/binaryen#tools) with a version >= 99. - Many package managers have it available nowadays: - - * [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) - - After you've installed the package execute `cargo install --force cargo-contract`. - - - _Build `binaryen` as a dependency when installing `cargo-contract`:_ - A C++14 compiler and python >= 3.5 is required. - Execute `cargo install --force --features binaryen-as-dependency cargo-contract`. +`binaryen` is a prerequisite as well, we use it for optimizing the contract Wasm. + +Install [`binaryen`](https://github.com/WebAssembly/binaryen#tools) with a version >= 99. +Many package managers have it available nowadays: + +* [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) + +After you've installed the package execute `cargo install --force cargo-contract`. ## Usage diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 5ae8c8dc85ead8a8479886dd5540012b4a2c32c3..a0a19a76172331e10cfb89968ac0393111970f77 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -14,18 +14,6 @@ // You should have received a copy of the GNU General Public License // along with cargo-contract. If not, see . -use regex::Regex; -use std::{convert::TryFrom, ffi::OsStr, fs::metadata, path::PathBuf}; - -#[cfg(feature = "binaryen-as-dependency")] -use std::{ - fs::File, - io::{Read, Write}, -}; - -#[cfg(any(test, not(feature = "binaryen-as-dependency")))] -use std::{path::Path, process::Command, str}; - use crate::{ crate_metadata::CrateMetadata, maybe_println, util, validate_wasm, @@ -36,6 +24,15 @@ use crate::{ use anyhow::{Context, Result}; use colored::Colorize; use parity_wasm::elements::{External, MemoryType, Module, Section}; +use regex::Regex; +use std::{ + convert::TryFrom, + ffi::OsStr, + fs::metadata, + path::{Path, PathBuf}, + process::Command, + str, +}; use structopt::StructOpt; /// This is the maximum number of pages available for a contract to allocate. @@ -337,54 +334,6 @@ fn optimize_wasm( }) } -/// Optimizes the Wasm supplied as `wasm` using the `binaryen-rs` dependency. -/// -/// The supplied `optimization_level` denotes the number of optimization passes, -/// resulting in potentially a lot of time spent optimizing. -/// -/// If successful, the optimized wasm is written to `dest_optimized`. -#[cfg(feature = "binaryen-as-dependency")] -fn do_optimization( - dest_wasm: &OsStr, - dest_optimized: &OsStr, - optimization_level: OptimizationPasses, -) -> Result<()> { - let mut dest_wasm_file = File::open(dest_wasm)?; - let mut dest_wasm_file_content = Vec::new(); - dest_wasm_file.read_to_end(&mut dest_wasm_file_content)?; - - let codegen_config = binaryen::CodegenConfig { - // Number of optimization passes (spends potentially a lot of time optimizing) - optimization_level: optimization_level.to_passes(), - // The default - shrink_level: optimization_level.to_shrink(), - // The default - debug_info: false, - }; - log::info!( - "Optimization level passed to `binaryen` dependency: {}", - codegen_config.optimization_level - ); - log::info!( - "Shrink level passed to `binaryen` dependency: {}", - codegen_config.shrink_level - ); - let mut module = binaryen::Module::read(&dest_wasm_file_content) - .map_err(|_| anyhow::anyhow!("binaryen failed to read file content"))?; - - if optimization_level != OptimizationPasses::Zero { - // binaryen-rs still uses the default optimization passes, even if zero - // is passed. this is the ticket for it: https://github.com/pepyakin/binaryen-rs/issues/56. - // we can remove the if condition here once the issue is fixed. - module.optimize(&codegen_config); - } - - let mut optimized_wasm_file = File::create(dest_optimized)?; - optimized_wasm_file.write_all(&module.write())?; - - Ok(()) -} - /// Optimizes the Wasm supplied as `crate_metadata.dest_wasm` using /// the `wasm-opt` binary. /// @@ -392,7 +341,6 @@ fn do_optimization( /// resulting in potentially a lot of time spent optimizing. /// /// If successful, the optimized wasm is written to `dest_optimized`. -#[cfg(not(feature = "binaryen-as-dependency"))] fn do_optimization( dest_wasm: &OsStr, dest_optimized: &OsStr, @@ -463,7 +411,6 @@ fn do_optimization( /// compatible with `cargo-contract`. /// /// Currently this must be a version >= 99. -#[cfg(any(test, not(feature = "binaryen-as-dependency")))] fn check_wasm_opt_version_compatibility(wasm_opt_path: &Path) -> Result<()> { let cmd = Command::new(wasm_opt_path) .arg("--version") diff --git a/src/main.rs b/src/main.rs index 3ce2b55d6b7d9ca02ffa007dcd6046b2863afb69..321a4ebceca232b07015a6fbce79c67fcd3d376b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -159,32 +159,6 @@ impl From for OptimizationPasses { } } -impl OptimizationPasses { - /// Returns the number of optimization passes to do - #[cfg(feature = "binaryen-as-dependency")] - pub(crate) fn to_passes(&self) -> u32 { - match self { - OptimizationPasses::Zero => 0, - OptimizationPasses::One => 1, - OptimizationPasses::Two => 2, - OptimizationPasses::Three => 3, - OptimizationPasses::Four => 4, - _ => 3, // Default to three for shrink settings - } - } - - /// Returns amount of shrinkage to do - #[cfg(feature = "binaryen-as-dependency")] - pub(crate) fn to_shrink(&self) -> u32 { - match self { - OptimizationPasses::Zero => 0, - OptimizationPasses::S => 1, - OptimizationPasses::Z => 2, - _ => 1, - } - } -} - #[derive(Default, Clone, Debug, StructOpt)] pub struct VerbosityFlags { /// No output printed to stdout