Default generated rust project errors

If your building the generated rust project, you might get the message when you try to deploy to prod.

Message bytes 2162089 is bigger than the max allowed 2097152

as glinuxdev pointed out in dfinity-dev discord rust channel, you need to use this ic-cdk-optimizer to deploy to prod.

Installing optimizer

./build.sh

#!/usr/bin/env bash

cargo build --target wasm32-unknown-unknown --release --package society_rs && \
 ic-cdk-optimizer ./target/wasm32-unknown-unknown/release/rusthelloworld_rs.wasm -o ./target/wasm32-unknown-unknown/release/rusthelloworld-rs-opt.wasm

dfx.json

"rusthelloworld": {
      "candid": "src/rusthelloworld/rusthelloworld.did",
      "package": "rusthelloworld",
      "type": "rust",
      "build": "./build.sh"
    },

Root Cargo.toml

[workspace]
members = [
    "src/rusthelloworld",
]

[profile.release]
lto = true
opt-level = 'z'
codegen-units = 1

These are the settings I use, if anyone has better settings, please let me know.

7 Likes