Skip to content

Commit

Permalink
Add SignextLowering pass to wasm-opt (#1280)
Browse files Browse the repository at this point in the history
* Add `SignextLowering` pass to `wasm-opt`

* Remove check for Rust version
  • Loading branch information
ascjones authored Aug 18, 2023
1 parent d1efce8 commit 756aa38
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
10 changes: 0 additions & 10 deletions crates/build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,6 @@ fn exec_cargo_for_onchain_target(
env.push(("RUSTC_BOOTSTRAP", Some("1".to_string())))
}

// newer rustc versions might emit unsupported instructions
if rustc_version::version_meta()?.semver >= Version::new(1, 70, 0) {
eprintln!(
"{} {}",
"warning:".yellow().bold(),
"You are using a rustc version that might emit unsupported wasm instructions. Build using a version lower than 1.70.0 to make sure your contract will deploy."
.bold()
);
}

// merge target specific flags with the common flags (defined here)
// We want to disable warnings here as they will be duplicates of the clippy pass.
// However, if we want to do so with either `--cap-lints allow` or `-A
Expand Down
8 changes: 7 additions & 1 deletion crates/build/src/wasm_opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use anyhow::Result;
use wasm_opt::{
Feature,
OptimizationOptions,
Pass,
};

use std::{
Expand Down Expand Up @@ -68,9 +69,14 @@ impl WasmOptHandler {
);

OptimizationOptions::from(self.optimization_level)
// Since rustc 1.70 `SignExt` can't be disabled anymore. Hence we have to allow it.
.mvp_features_only()
// Since rustc 1.70 `SignExt` can't be disabled anymore. Hence we have to allow it,
// in order that the Wasm binary containing these instructions can be loaded.
.enable_feature(Feature::SignExt)
// This pass will then remove any `signext` instructions in order that the resulting
// Wasm binary is compatible with older versions of `pallet-contracts` which do not
// support the `signext` instruction.
.add_pass(Pass::SignextLowering)
// 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.
Expand Down

0 comments on commit 756aa38

Please sign in to comment.