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

feat: Add --release flag to wasm_builder #5209

Open
wants to merge 67 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
a7e2a5f
feat: add option to build wasm with optimizations
aoyako Oct 30, 2024
acddbdc
fix: rename optimize to release in build_wasm.sh
aoyako Oct 30, 2024
1fdecf7
Merge branch 'main' into wasm_builder_flags
aoyako Oct 30, 2024
5384b00
chore: cargo fmt
aoyako Oct 30, 2024
986a835
fix: use correct binary directory for debug
aoyako Oct 30, 2024
7a5b957
chore: cargo fmt
aoyako Oct 30, 2024
3e6eb1f
fix: use profile env from compose files
aoyako Oct 31, 2024
65e547f
Merge branch 'main' into wasm_builder_flags
aoyako Oct 31, 2024
5c6e4a8
fix: stack overflow caused by compact
aoyako Nov 7, 2024
ade7dc3
Merge branch 'main' into wasm_builder_flags
aoyako Nov 7, 2024
441d939
feat: add help message to build wasm readme
aoyako Nov 7, 2024
fc8f661
feat: add help message to build wasm readme
aoyako Nov 7, 2024
77b8d44
fix: update failing tests
aoyako Nov 11, 2024
66465f7
Merge branch 'main' into wasm_builder_flags
aoyako Nov 11, 2024
afcf368
fix: revert changes in ci
aoyako Nov 11, 2024
a252e68
fix: update ci files
aoyako Nov 12, 2024
c2a1b94
chore: fmt
aoyako Nov 12, 2024
93e9a8c
Merge branch 'main' into wasm_builder_flags
aoyako Nov 12, 2024
b7820e4
feat: use correct profile from cargo
aoyako Nov 12, 2024
45df4a6
chore: fmt
aoyako Nov 12, 2024
dc2034e
fix: rename profile test->release
aoyako Nov 12, 2024
dbea8cc
fix: make release a default profile
aoyako Nov 13, 2024
4000ece
Merge branch 'main' into wasm_builder_flags
aoyako Nov 13, 2024
9f5db48
chore: fmt
aoyako Nov 13, 2024
ab3054a
fix: readme for wasm builder
aoyako Nov 13, 2024
e3edc40
fix: use shell instead of bash
aoyako Nov 13, 2024
20545b9
fix: reorder optimization process in build
aoyako Nov 13, 2024
89d1535
feat: add release profile
aoyako Nov 13, 2024
bd5ea86
fix: chec profile in ci
aoyako Nov 13, 2024
0fb6a4f
fix: revert
aoyako Nov 13, 2024
fe1189f
feat: get logs from failing ci
aoyako Nov 14, 2024
3182ebd
feat: advanced logging
aoyako Nov 14, 2024
5cfe4df
Merge branch 'main' into wasm_builder_flags
aoyako Nov 19, 2024
c7fe1ce
chore:cleanup
aoyako Nov 19, 2024
5547421
Merge branch 'main' into wasm_builder_flags
aoyako Nov 19, 2024
bd8c70f
chore: cleanup + fmt
aoyako Nov 19, 2024
cac56fb
fix: revert error reporting
aoyako Nov 19, 2024
532bcef
fix: increase executor fuel
aoyako Nov 19, 2024
44892a8
fix: use deploy wasm as default
aoyako Nov 19, 2024
892cdfd
fix: output dir
aoyako Nov 20, 2024
171fbd3
fix: fnt
aoyako Nov 20, 2024
6f76e30
fix: use release
aoyako Nov 20, 2024
d1fac84
fix: cfg changes
aoyako Nov 20, 2024
6079321
fix: add default tests
aoyako Nov 21, 2024
68e8c3b
fix: bump executor fuel
aoyako Nov 21, 2024
e3a6b43
fix: revert genesis
aoyako Nov 22, 2024
e6b7d24
fix: include wasm binaries
aoyako Nov 22, 2024
303b6a9
fix: remove wasms
aoyako Nov 22, 2024
7a79ee0
fix: use ubuntu runner
aoyako Nov 22, 2024
22a17ff
fix: use optimized debug
aoyako Nov 22, 2024
13efce4
fix: update genesis in tests
aoyako Nov 23, 2024
0b80178
fix: revert test changes
aoyako Nov 23, 2024
b05c1f7
fix: revert additional pipeline items
aoyako Nov 23, 2024
d56b644
Merge branch 'main' into wasm_builder_flags
aoyako Nov 25, 2024
92e2228
chore: remove unused profile
aoyako Nov 25, 2024
7980eae
fix: optional output
aoyako Dec 2, 2024
b7b783c
Merge branch 'main' into wasm_builder_flags
aoyako Dec 2, 2024
da9f63e
fix: remove spinner from lib
aoyako Dec 4, 2024
40416e0
fix: fmt
aoyako Dec 4, 2024
0cba0b8
fix: update porfile parsing
aoyako Dec 7, 2024
a10f446
fix: use profiles for custom executors
aoyako Dec 7, 2024
07cb9fe
Merge branch 'main' into wasm_builder_flags
aoyako Dec 7, 2024
2c14c7f
chore: fmt
aoyako Dec 7, 2024
b462b2f
Merge branch 'main' into wasm_builder_flags
aoyako Dec 12, 2024
1e759d2
perf: read build config
aoyako Dec 12, 2024
111824b
fix: parse lowercase
aoyako Dec 13, 2024
fc74888
Merge branch 'main' into wasm_builder_flags
aoyako Dec 13, 2024
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: 2 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions crates/iroha_wasm_builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ eyre = { workspace = true }
serde_json = { workspace = true, features = ["std"] }
sha256 = "1.5.0"
path-absolutize = { workspace = true }
strum = { workspace = true, features = ["derive", "std"] }
wasm-opt = "0.116.1"

clap = { workspace = true, features = ["derive"] }
Expand Down
73 changes: 38 additions & 35 deletions crates/iroha_wasm_builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,24 @@ use path_absolutize::Absolutize;

/// Current toolchain used to build smartcontracts
const TOOLCHAIN: &str = "+nightly-2024-09-09";
const OPTIMIZED_PROFILE: &str = "deploy";

/// Build profile for smartcontracts
#[derive(Debug, Copy, Clone, Eq, PartialEq, strum::Display, strum::EnumString, Default)]
#[strum(serialize_all = "snake_case")]
pub enum Profile {
/// Applies release optimization
#[default]
Release,
/// Applies release and size optimizations
Deploy,
}

impl Profile {
/// Checks whether profile uses optimizations from wasm-opt
pub fn is_optimized(profile: Self) -> bool {
return profile == Profile::Deploy;
}
}

/// WASM Builder for smartcontracts (e.g. triggers and executors).
///
Expand Down Expand Up @@ -46,22 +63,22 @@ pub struct Builder<'path, 'out_dir> {
/// Flag controlling whether to show output of the build process
show_output: bool,
/// Build profile
profile: String,
profile: Profile,
}

impl<'path, 'out_dir> Builder<'path, 'out_dir> {
/// Initialize [`Builder`] with path to smartcontract.
///
/// `relative_path` should be relative to `CARGO_MANIFEST_DIR`.
pub fn new<P>(relative_path: &'path P, profile: &str) -> Self
pub fn new<P>(relative_path: &'path P, profile: Profile) -> Self
where
P: AsRef<Path> + ?Sized,
{
Self {
path: relative_path.as_ref(),
out_dir: None,
show_output: false,
profile: profile.to_string(),
profile: profile,
}
}

Expand Down Expand Up @@ -103,6 +120,17 @@ impl<'path, 'out_dir> Builder<'path, 'out_dir> {
///
/// Will also return error if ran on workspace and not on the concrete package.
pub fn build(self) -> Result<Output> {
let optimize = Profile::is_optimized(self.profile);
let output = self.into_internal()?.build()?;
if optimize {
output.optimize()
} else {
Ok(output)
}
}

#[doc(hidden)]
pub fn build_unoptimized(self) -> Result<Output> {
self.into_internal()?.build()
}

Expand All @@ -117,7 +145,7 @@ impl<'path, 'out_dir> Builder<'path, 'out_dir> {
|out_dir| Ok(Cow::Borrowed(out_dir)),
)?,
show_output: self.show_output,
profile: self.profile.clone(),
profile: self.profile,
})
}

Expand Down Expand Up @@ -171,7 +199,7 @@ mod internal {
pub absolute_path: PathBuf,
pub out_dir: Cow<'out_dir, Path>,
pub show_output: bool,
pub profile: String,
pub profile: Profile,
}

impl Builder<'_> {
Expand All @@ -186,41 +214,16 @@ mod internal {

pub fn build(self) -> Result<Output> {
let absolute_path = self.absolute_path.clone();
let optimize = self.profile == OPTIMIZED_PROFILE;
let show_output = self.show_output;
let optimize = Profile::is_optimized(self.profile);
let output = self.build_smartcontract().wrap_err_with(|| {
format!(
"Failed to build the smartcontract at path: {}",
absolute_path.display()
)
})?;

if optimize {
let sp = if show_output && std::env::var("CI").is_err() {
Some(spinoff::Spinner::new_with_stream(
spinoff::spinners::Binary,
"Optimizing the output",
None,
spinoff::Streams::Stderr,
))
} else {
None
};

match output.optimize() {
Ok(optimized) => {
if let Some(mut sp) = sp {
sp.success("Output is optimized");
}
Ok(optimized)
}
err => {
if let Some(mut sp) = sp {
sp.fail("Optimization failed");
}
err
}
}
output.optimize()
} else {
Ok(output)
}
Expand Down Expand Up @@ -270,7 +273,7 @@ mod internal {
let full_out_dir = self
.out_dir
.join("wasm32-unknown-unknown")
.join(self.profile.clone());
.join(self.profile.to_string());
let wasm_file = full_out_dir.join(package_name).with_extension("wasm");

let previous_hash = if wasm_file.exists() {
Expand Down
40 changes: 36 additions & 4 deletions crates/iroha_wasm_builder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::path::PathBuf;

use clap::{Args, Parser};
use color_eyre::eyre::{eyre, Context};
use iroha_wasm_builder::Builder;
use iroha_wasm_builder::{Builder, Profile};
use owo_colors::OwoColorize;

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -42,24 +42,56 @@ fn main() -> color_eyre::Result<()> {
common: CommonArgs { path },
profile,
} => {
let builder = Builder::new(&path, &profile).show_output();
let profile: Profile = profile.parse().expect("Invalid profile provided");
let builder = Builder::new(&path, profile).show_output();
builder.check()?;
}
Cli::Build {
common: CommonArgs { path },
out_file,
profile,
} => {
let builder = Builder::new(&path, &profile).show_output();
let profile: Profile = profile.parse().expect("Invalid profile provided");
let builder = Builder::new(&path, profile).show_output();

let output = {
// not showing the spinner here, cargo does a progress bar for us
match builder.build() {
match builder.build_unoptimized() {
s8sato marked this conversation as resolved.
Show resolved Hide resolved
Ok(output) => output,
err => err?,
}
};

let output = if Profile::is_optimized(profile) {
let sp = if std::env::var("CI").is_err() {
Some(spinoff::Spinner::new_with_stream(
spinoff::spinners::Binary,
"Optimizing the output",
None,
spinoff::Streams::Stderr,
))
} else {
None
};

match output.optimize() {
Ok(optimized) => {
if let Some(mut sp) = sp {
sp.success("Output is optimized");
}
optimized
}
err => {
if let Some(mut sp) = sp {
sp.fail("Optimization failed");
}
err?
}
}
} else {
output
};

std::fs::copy(output.wasm_file_path(), &out_file).wrap_err_with(|| {
eyre!(
"Failed to write the resulting file into {}",
Expand Down
Loading