This skill guides you to minimize Tauri binary size using cargo profile optimizations and build configurations for lean desktop apps.
npx playbooks add skill dchuk/claude-code-tauri-skills --skill tauri-binary-size
This skill provides guidance on optimizing Tauri application binary sizes for production releases.
Tauri is designed from the ground up to produce minimal binaries:
| Framework | Minimum Binary Size |
|-----------|---------------------|
| Tauri | ~3-6 MB |
| Electron | ~120-180 MB |
| NW.js | ~80-100 MB |
The dramatic size difference comes from Tauri's architectural decision to use native system webviews rather than bundling a full browser engine.
Configure release profile settings in src-tauri/Cargo.toml to minimize binary size.
[profile.release]
codegen-units = 1 # Compile crates one at a time for better LLVM optimization
lto = true # Enable link-time optimization across all crates
opt-level = "s" # Optimize for binary size (alternative: "z" for even smaller)
panic = "abort" # Remove panic unwinding code
strip = true # Strip debug symbols from final binary
| Option | Values | Description |
|--------|--------|-------------|
| codegen-units | 1 | Reduces parallelism but allows LLVM to perform better whole-program optimization |
| lto | true, "thin", "fat" | Link-time optimization; true or "fat" produces smallest binaries |
| opt-level | "s", "z", "3" | "s" balances size/speed, "z" prioritizes size, "3" prioritizes speed |
| panic | "abort" | Removes panic handler code, reducing binary size |
| strip | true, "symbols", "debuginfo" | Removes symbols and debug information from binary |
For projects using the nightly Rust toolchain, additional optimizations are available:
[profile.release]
codegen-units = 1
lto = true
opt-level = "s"
panic = "abort"
strip = true
trim-paths = "all" # Remove file path information from binary
[profile.release.build-override]
opt-level = "s" # Also optimize build scripts
You can also set rustflags for additional control:
[profile.release]
rustflags = ["-Cdebuginfo=0", "-Zthreads=8"]
Tauri 2.4 introduced the ability to automatically remove code for commands not permitted in your Access Control List (ACL). Add this to tauri.conf.json:
{
"build": {
"removeUnusedCommands": true
}
}
This feature:
Only enable Tauri features you actually need in src-tauri/Cargo.toml:
[dependencies]
tauri = { version = "2", features = ["macos-private-api"] }
# Avoid enabling unnecessary features like:
# - "devtools" in production
# - "protocol-asset" if not serving local assets
# - "tray-icon" if not using system tray
While this skill focuses on Rust/Tauri optimization, frontend bundle size also affects the final application:
cd src-tauri
cargo tauri build --release
cd src-tauri
cargo +nightly tauri build --release
After building, check your binary size:
# macOS
ls -lh src-tauri/target/release/bundle/macos/*.app/Contents/MacOS/*
# Linux
ls -lh src-tauri/target/release/bundle/appimage/*.AppImage
# Windows
dir src-tauri\target\release\bundle\msi\*.msi
Here is a complete src-tauri/Cargo.toml optimized for minimal binary size:
[package]
name = "my-tauri-app"
version = "0.1.0"
edition = "2021"
[dependencies]
tauri = { version = "2", features = [] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
[build-dependencies]
tauri-build = { version = "2", features = [] }
[profile.release]
codegen-units = 1
lto = true
opt-level = "s"
panic = "abort"
strip = true
[profile.release.package."*"]
opt-level = "s"
And corresponding tauri.conf.json:
{
"productName": "my-tauri-app",
"version": "0.1.0",
"identifier": "com.example.my-tauri-app",
"build": {
"removeUnusedCommands": true,
"beforeBuildCommand": "npm run build",
"frontendDist": "../dist"
},
"bundle": {
"active": true,
"targets": "all",
"icon": ["icons/icon.png"]
}
}
| Setting | Size Impact | Build Time | Runtime Performance |
|---------|-------------|------------|---------------------|
| codegen-units = 1 | Smaller | Slower | Better |
| lto = true | Smaller | Much slower | Better |
| opt-level = "s" | Smaller | Similar | Slightly slower |
| opt-level = "z" | Smallest | Similar | Slower |
| panic = "abort" | Smaller | Faster | No unwinding |
| strip = true | Smaller | Similar | No impact |
--release flagcargo tree to see dependency graphfile command to check for debug symbolsIf lto = true causes build failures:
lto = "thin" as a fallbackEnsure nightly is installed and active:
rustup install nightly
rustup default nightly
# Or use +nightly flag with cargo commands
Weekly roundup of top Claude Code skills, MCP servers, and AI coding tips.