Skip to content

Commit

Permalink
Merge branch 'brent/improve-wasm-build' (#2795)
Browse files Browse the repository at this point in the history
* origin/brent/improve-wasm-build:
  changelog: add #2795
  script/release: update wasm_for_tests path
  improve wasm build
  • Loading branch information
tzemanovic committed Apr 10, 2024
2 parents 1f81fb8 + f3dbb47 commit d70d49f
Show file tree
Hide file tree
Showing 107 changed files with 2,547 additions and 1,581 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/2795-improve-wasm-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Split up WASM transaction and validity-predicates into individual crates to
improve build time. ([\#2795](https://github.com/anoma/namada/pull/2795))
39 changes: 24 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ debug-cargo := $(env) $(debug-env) cargo
nightly := $(shell cat rust-nightly-version)

# Path to the wasm source for the provided txs and VPs
wasms := wasm/wasm_source
wasms_for_tests := wasm_for_tests/wasm_source
# Paths for all the wasm templates
wasm_templates := wasm/tx_template wasm/vp_template
wasms := wasm
wasms_for_tests := wasm_for_tests

ifdef JOBS
jobs := -j $(JOBS)
Expand Down Expand Up @@ -93,16 +91,17 @@ check-wasm = $(cargo) check --target wasm32-unknown-unknown --manifest-path $(wa
check:
$(cargo) check --workspace && \
make -C $(wasms) check && \
make -C $(wasms_for_tests) check && \
$(foreach wasm,$(wasm_templates),$(check-wasm) && ) true
make -C $(wasms_for_tests) check

check-mainnet:
$(cargo) check --workspace --features "mainnet"

# Check that every crate can be built with default features and that namada crate
# can be built for wasm
check-crates:
rustup target add --toolchain $(nightly) wasm32-unknown-unknown
$(foreach p,$(crates), echo "Checking $(p)" && cargo +$(nightly) check -Z unstable-options --tests -p $(p) && ) \
make -C $(wasms) check && \
make -C $(wasms_for_tests) check && \
cargo check --package namada --target wasm32-unknown-unknown --no-default-features --features "namada-sdk" && \
cargo check --package namada_sdk --all-features
Expand All @@ -114,8 +113,7 @@ clippy:
$(cargo) +$(nightly) clippy $(jobs) --all-targets --workspace --exclude namada_benchmarks -- -D warnings && \
$(cargo) +$(nightly) clippy $(jobs) --all-targets --package namada_benchmarks -- -D warnings && \
make -C $(wasms) clippy && \
make -C $(wasms_for_tests) clippy && \
$(foreach wasm,$(wasm_templates),$(clippy-wasm) && ) true
make -C $(wasms_for_tests) clippy

clippy-mainnet:
$(cargo) +$(nightly) clippy --all-targets --features "mainnet" -- -D warnings
Expand Down Expand Up @@ -255,15 +253,11 @@ test-pos-sm:

fmt-wasm = $(cargo) +$(nightly) fmt --manifest-path $(wasm)/Cargo.toml
fmt:
$(cargo) +$(nightly) fmt --all && \
make -C $(wasms) fmt && \
$(foreach wasm,$(wasm_templates),$(fmt-wasm) && ) true
$(cargo) +$(nightly) fmt --all && make -C $(wasms) fmt

fmt-check-wasm = $(cargo) +$(nightly) fmt --manifest-path $(wasm)/Cargo.toml -- --check
fmt-check:
$(cargo) +$(nightly) fmt --all -- --check && \
make -C $(wasms) fmt-check && \
$(foreach wasm,$(wasm_templates),$(fmt-check-wasm) && ) true
$(cargo) +$(nightly) fmt --all -- --check && make -C $(wasms) fmt-check

watch:
$(cargo) watch
Expand Down Expand Up @@ -292,7 +286,7 @@ debug-wasm-scripts-docker: build-wasm-image-docker

# Build the validity predicate and transactions wasm
build-wasm-scripts:
rm wasm/*.wasm || true
rm $(wasms)/*.wasm || true
make -C $(wasms)
make opt-wasm
make checksum-wasm
Expand All @@ -304,6 +298,18 @@ debug-wasm-scripts:
make opt-wasm
make checksum-wasm

# Build the validity predicate and transactions wasm for tests
build-wasm-tests-scripts:
rm $(wasms_for_tests)/*.wasm || true
make -C $(wasms_for_tests)
make opt-wasm-tests

# Debug build the validity predicate and transactions wasm for tests
debug-wasm-tests-scripts:
rm $(wasms_for_tests)/*.wasm || true
make -C $(wasms_for_tests) debug
make opt-wasm-tests

# need python
checksum-wasm:
python3 wasm/checksums.py
Expand All @@ -312,6 +318,9 @@ checksum-wasm:
opt-wasm:
@for file in $(shell ls wasm/*.wasm); do wasm-opt -Oz -o $${file} $${file}; done

opt-wasm-tests:
@for file in $(shell ls wasm_for_tests/*.wasm); do wasm-opt -Oz -o $${file} $${file}; done

clean-wasm-scripts:
make -C $(wasms) clean

Expand Down
6 changes: 3 additions & 3 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ HASH_BEFORE=$(git rev-parse HEAD)
cargo release --execute $VERSION
HASH_AFTER=$(git rev-parse HEAD)

# update the wasm crate versions (2 fixups)
# update the wasm workspace crate versions (2 fixups)
cd $REPO_ROOT/wasm
cargo update -w
git add Cargo.lock
git commit --fixup=$HASH_AFTER
cargo release --execute $VERSION

# update the wasm_for_tests crate version, and rebuild them (3 fixups)
cd $REPO_ROOT/wasm_for_tests/wasm_source
# update the wasm_for_tests workspace crate version, and rebuild them (3 fixups)
cd $REPO_ROOT/wasm_for_tests
cargo update -w
git add Cargo.lock
git commit --fixup=$HASH_AFTER
Expand Down
Loading

0 comments on commit d70d49f

Please sign in to comment.