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 68 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
68 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
02a19b9
Merge branch 'main' into wasm_builder_flags
aoyako Dec 26, 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
24 changes: 20 additions & 4 deletions crates/iroha_wasm_builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct Builder<'path, 'out_dir> {
out_dir: Option<&'out_dir Path>,
/// Flag controlling whether to show output of the build process
show_output: bool,
release: bool,
}

impl<'path, 'out_dir> Builder<'path, 'out_dir> {
Expand All @@ -59,6 +60,7 @@ impl<'path, 'out_dir> Builder<'path, 'out_dir> {
path: relative_path.as_ref(),
out_dir: None,
show_output: false,
release: false,
}
}

Expand All @@ -83,6 +85,14 @@ impl<'path, 'out_dir> Builder<'path, 'out_dir> {
self
}

/// Enable release build optimizations.
///
/// Disabled by default.
pub fn release(mut self) -> Self {
self.release = true;
self
}

/// Apply `cargo check` to the smartcontract.
///
/// # Errors
Expand Down Expand Up @@ -114,6 +124,7 @@ impl<'path, 'out_dir> Builder<'path, 'out_dir> {
|out_dir| Ok(Cow::Borrowed(out_dir)),
)?,
show_output: self.show_output,
release: self.release,
})
}

Expand Down Expand Up @@ -167,6 +178,7 @@ mod internal {
pub absolute_path: PathBuf,
pub out_dir: Cow<'out_dir, Path>,
pub show_output: bool,
pub release: bool,
}

impl Builder<'_> {
Expand All @@ -189,9 +201,9 @@ mod internal {
})
}

fn build_options() -> impl Iterator<Item = &'static str> {
fn build_options(&self) -> impl Iterator<Item = &'static str> {
[
"--release",
if self.release { "--release" } else { "" },
mversic marked this conversation as resolved.
Show resolved Hide resolved
"-Z",
"build-std",
"-Z",
Expand All @@ -202,6 +214,7 @@ mod internal {
"wasm32-unknown-unknown",
]
.into_iter()
.filter(|&arg| !arg.is_empty())
}

fn get_base_command(&self, cmd: &'static str) -> std::process::Command {
Expand All @@ -210,7 +223,7 @@ mod internal {
.current_dir(&self.absolute_path)
.stderr(Stdio::inherit())
.arg(cmd)
.args(Self::build_options());
.args(self.build_options());

command
}
Expand All @@ -226,7 +239,10 @@ mod internal {
.retrieve_package_name()
.wrap_err("Failed to retrieve package name")?;

let full_out_dir = self.out_dir.join("wasm32-unknown-unknown/release/");
let build_mode_dir = if self.release { "release" } else { "debug" };
let full_out_dir = self
.out_dir
.join(format!("wasm32-unknown-unknown/{build_mode_dir}/"));
let wasm_file = full_out_dir.join(package_name).with_extension("wasm");

let previous_hash = if wasm_file.exists() {
Expand Down
8 changes: 5 additions & 3 deletions crates/iroha_wasm_builder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ enum Cli {
common: CommonArgs,
/// Optimize WASM output.
#[arg(long)]
optimize: bool,
release: bool,
/// Where to store the output WASM. If the file exists, it will be overwritten.
#[arg(long)]
out_file: PathBuf,
Expand All @@ -44,11 +44,13 @@ fn main() -> color_eyre::Result<()> {
}
Cli::Build {
common: CommonArgs { path },
optimize,
release,
out_file,
} => {
let builder = Builder::new(&path).show_output();

let builder = if release { builder.release() } else { builder };

let output = {
// not showing the spinner here, cargo does a progress bar for us

Expand All @@ -58,7 +60,7 @@ fn main() -> color_eyre::Result<()> {
}
};

let output = if optimize {
let output = if release {
let sp = if std::env::var("CI").is_err() {
Some(spinoff::Spinner::new_with_stream(
spinoff::spinners::Binary,
Expand Down
74 changes: 58 additions & 16 deletions scripts/build_wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,46 @@ DEFAULTS_DIR="defaults"
CRATES_DIR="wasm"
TARGET_DIR="wasm/target/prebuilt"

# Default options
DEFAULT_RELEASE_FLAG=""
DEFAULT_SHOW_HELP=false

# Build options
RELEASE_FLAG=$DEFAULT_RELEASE_FLAG
SHOW_HELP=$DEFAULT_SHOW_HELP

main() {
# Parse args
for arg in "$@"; do
case $arg in
"--release")
RELEASE_FLAG="--release"
;;
"--help")
SHOW_HELP=true
esac
done

if $SHOW_HELP; then
print_help
exit 0
fi

# Parse target
case ${!#} in
"libs")
command "libs"
;;
"samples")
command "samples"
;;
*)
command "libs"
command "samples"
;;
esac
}

build() {
case $1 in
"libs")
Expand All @@ -26,7 +66,7 @@ build() {
mkdir -p "$TARGET_DIR/$1"
for name in ${NAMES[@]}; do
out_file="$TARGET_DIR/$1/$name.wasm"
cargo run --bin iroha_wasm_builder -- build "$CRATES_DIR/$1/$name" --optimize --out-file "$out_file"
cargo run --bin iroha_wasm_builder -- build "$CRATES_DIR/$1/$name" $RELEASE_FLAG --out-file "$out_file"
done
echo "info: WASM $1 build complete"
echo "artifacts written to $TARGET_DIR/$1/"
Expand All @@ -46,18 +86,20 @@ command() {
esac
}

case $1 in
"")
command "libs"
command "samples"
;;
"libs")
command "libs"
;;
"samples")
command "samples"
;;
*)
echo "error: arg must be 'libs', 'samples', or empty to build both"
exit 1
mversic marked this conversation as resolved.
Show resolved Hide resolved
esac

print_help() {
cat << END
Usage: build_wasm.sh [OPTIONS] [TARGET]

Options:
--help Show help message.
--release Enable release and size optimizations for the build.

Targets:
libs Specify to build libs.
samples Specify to build samples.
If omitted, both libraries and samples will be built.
mversic marked this conversation as resolved.
Show resolved Hide resolved
END
}

main "$@"; exit
Loading