Skip to content

Commit

Permalink
Use release-lto profile for the uploader canister (#332)
Browse files Browse the repository at this point in the history
Co-authored-by: Dimitris Sarlis <[email protected]>
  • Loading branch information
berestovskyy and dsarlis authored Oct 4, 2024
1 parent 2cdc183 commit 708eb8b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ serde_bytes = "0.11"
serde_json = "1.0.94"
tempfile = "3.10.1"
tokio = { version = "1.29.1", features = ["full"] }

[profile.release-lto]
inherits = "release"
lto = true
opt-level = "s"
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ RUN scripts/build-canister.sh ic-btc-canister ${BTC_FEATURES} && \
RUN if [ -n "$CHUNK_HASHES_PATH" ]; then export CHUNK_HASHES_PATH="$CHUNK_HASHES_PATH"; fi

# Building uploader canister...
RUN scripts/build-canister.sh uploader && \
cp target/wasm32-unknown-unknown/release/uploader.wasm.gz uploader.wasm.gz
RUN scripts/build-canister.sh uploader "" "release-lto" && \
cp target/wasm32-unknown-unknown/release-lto/uploader.wasm.gz uploader.wasm.gz

# Building watchdog canister...
RUN scripts/build-canister.sh watchdog && \
Expand Down
11 changes: 6 additions & 5 deletions scripts/build-canister.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

CANISTER=$1
FEATURES=${2:-}
PROFILE=${3:-release}

pushd "$SCRIPT_DIR"

Expand All @@ -22,10 +23,10 @@ fi
# that aren't needed in production.
if [[ -z "$FEATURES" ]]; then
# No features provided
cargo build -p "$CANISTER" --target "$TARGET" --release
cargo build -p "$CANISTER" --target "$TARGET" --profile="${PROFILE}"
else
# Features provided
cargo build -p "$CANISTER" --target "$TARGET" --release --features "$FEATURES"
cargo build -p "$CANISTER" --target "$TARGET" --profile="${PROFILE}" --features "$FEATURES"
fi

# Navigate to root directory.
Expand All @@ -35,8 +36,8 @@ cargo install ic-wasm --version 0.2.0 --root ./target
STATUS=$?
if [[ "$STATUS" -eq "0" ]]; then
./target/bin/ic-wasm \
"./target/$TARGET/release/$CANISTER.wasm" \
-o "./target/$TARGET/release/$CANISTER.wasm" shrink
"./target/$TARGET/${PROFILE}/$CANISTER.wasm" \
-o "./target/$TARGET/${PROFILE}/$CANISTER.wasm" shrink

if [[ "$CANISTER" == "ic-btc-canister" ]]; then
./target/bin/ic-wasm \
Expand All @@ -58,6 +59,6 @@ else
false
fi

gzip -n -f "./target/$TARGET/release/$CANISTER.wasm"
gzip -n -f "./target/$TARGET/${PROFILE}/$CANISTER.wasm"

popd

0 comments on commit 708eb8b

Please sign in to comment.