diff --git a/Cargo.toml b/Cargo.toml index dd2c489d..e2fe78b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/Dockerfile b/Dockerfile index 912bbfc2..e6e004c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 && \ diff --git a/scripts/build-canister.sh b/scripts/build-canister.sh index 14e38689..995a001a 100755 --- a/scripts/build-canister.sh +++ b/scripts/build-canister.sh @@ -6,6 +6,7 @@ SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) CANISTER=$1 FEATURES=${2:-} +PROFILE=${3:-release} pushd "$SCRIPT_DIR" @@ -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. @@ -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 \ @@ -58,6 +59,6 @@ else false fi -gzip -n -f "./target/$TARGET/release/$CANISTER.wasm" +gzip -n -f "./target/$TARGET/${PROFILE}/$CANISTER.wasm" popd