The build and packaging process for Tauri applications involves multiple steps, here is a detailed explanation:
1. Development Environment Setup
Install Dependencies
bash# Install Rust curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Install Node.js and package manager # Install system dependencies (macOS) xcode-select --install # Install system dependencies (Linux) sudo apt update sudo apt install libwebkit2gtk-4.0-dev \ build-essential \ curl \ wget \ file \ libssl-dev \ libayatana-appindicator3-dev \ librsvg2-dev
Install Tauri CLI
bashcargo install tauri-cli
2. Project Configuration
tauri.conf.json Configuration
json{ "build": { "beforeDevCommand": "npm run dev", "beforeBuildCommand": "npm run build", "devPath": "http://localhost:1420", "distDir": "../dist", "withGlobalTauri": false }, "package": { "productName": "MyApp", "version": "1.0.0" }, "tauri": { "bundle": { "identifier": "com.example.myapp", "icon": ["icons/32x32.png", "icons/128x128.png", "icons/128x128@2x.png", "icons/icon.icns", "icons/icon.ico"], "targets": ["dmg", "msi", "appimage"], "category": "Developer Tool" } } }
3. Development Mode
bashnpm run tauri dev
This command will:
- Run
beforeDevCommandto start the development server - Compile Rust code
- Start the application and connect to the development server
- Support hot reload
4. Build Production Version
Basic Build
bashnpm run tauri build
Build process:
- Run
beforeBuildCommandto build frontend resources - Compile Rust code to binary files
- Package frontend resources into the application
- Generate platform-specific installation packages
Build for Specific Platform
bash# macOS npm run tauri build -- --target universal-apple-darwin # Windows npm run tauri build -- --target x86_64-pc-windows-msvc # Linux npm run tauri build -- --target x86_64-unknown-linux-gnu
5. Packaging Options
macOS Packaging
json{ "bundle": { "targets": ["dmg", "app"], "macOS": { "signingIdentity": "Developer ID Application: Your Name", "entitlements": "entitlements.plist", "hardenedRuntime": true, "minimumSystemVersion": "10.13" } } }
Windows Packaging
json{ "bundle": { "targets": ["msi", "nsis"], "windows": { "certificateThumbprint": "YOUR_CERTIFICATE_THUMBPRINT", "digestAlgorithm": "sha256", "timestampUrl": "http://timestamp.digicert.com" } } }
Linux Packaging
json{ "bundle": { "targets": ["appimage", "deb"], "linux": { "deb": { "depends": ["libwebkit2gtk-4.0-37"] } } } }
6. Code Signing
macOS Signing
bash# Import certificate security import certificate.p12 -k ~/Library/Keychains/login.keychain # Auto-signing (set in configuration)
Windows Signing
bash# Use signtool signtool sign /f certificate.pfx /p password /t http://timestamp.digicert.com app.exe
7. Release Process
GitHub Actions Automation
yamlname: Release on: push: tags: - 'v*' jobs: release: strategy: matrix: os: [macos-latest, ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 - uses: dtolnay/rust-toolchain@stable - run: npm install - run: npm run tauri build - uses: softprops/action-gh-release@v1 with: files: src-tauri/target/release/bundle/*
8. Build Optimization
Reduce Package Size
toml[profile.release] opt-level = "z" lto = true codegen-units = 1 strip = true
Parallel Build
bashcargo build --release -j $(nproc)
9. Common Issues
Build Failure
- Check if system dependencies are complete
- Confirm Rust and Node.js version compatibility
- View detailed error logs
Signing Issues
- Ensure certificate is valid
- Check signing configuration
- Verify timestamp server availability
Cross-Platform Build
- Use GitHub Actions or CI/CD
- Configure different build targets
- Test platform compatibility