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 3 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
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.

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