new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Tauri · Develop · all subjects

build

179 notes in this subject, read out of this brain and free to use. This is page 1 of 3.

Cargo profile for nightly Rust toolchain with optimized flags

When using the nightly Rust toolchain, the profile.release section can include additional settings: trim-paths = "all" (removes potentially privileged information from binaries) and rustflags = ["-Cdebuginfo=0", "-Zthreads=8"] (disables debug info and uses 8 compilation threads). The profile.dev section should include rustflags = ["-Zthreads=8"].

Cargo panic setting behavior

The panic setting in Cargo profiles controls how panics are handled. Setting panic = "abort" removes panic unwinding support, reducing binary size and improving performance.

How removeUnusedCommands works internally

When removeUnusedCommands is enabled, tauri-cli communicates with tauri-build and tauri's build script through an environment variable named REMOVE_UNUSED_COMMANDS (set to the project's src-tauri directory) to generate a list of allowed commands from capability files. This list is then used by the generate_handler macro to remove unused commands from the binary. The environment variable implementation is an internal detail without stability guarantees.

Cargo profile for release binary size optimization

Add a profile.release section to src-tauri/Cargo.toml with the following settings: codegen-units = 1 (allows LLVM to perform better optimization), lto = true (enables link-time-optimizations), opt-level = "s" (prioritizes small binary size; use "3" if preferring speed instead), panic = "abort" (higher performance by disabling panic handlers), strip = true (ensures debug symbols are removed).

opt-level Cargo setting options and their effects

The opt-level setting in Cargo profiles determines compiler optimization focus. Use opt-level = "3" to optimize for performance, opt-level = "z" to optimize for size, or opt-level = "s" for a balance between the two.

Cargo profile for dev compilation speed with incremental builds

Add a profile.dev section to src-tauri/Cargo.toml with incremental = true to compile the binary in smaller steps, improving compilation speed during development.

removeUnusedCommands configuration for removing unused IPC commands

Add "removeUnusedCommands": true to the "build" section of tauri.conf.json to remove commands that are never allowed in capability files (ACL), reducing binary size. This feature requires tauri@2.4, tauri-build@2.1, tauri-plugin@2.1 and tauri-cli@2.4. To maximize benefit, only include commands actually used in the ACL instead of using defaults. This feature does not account for dynamically added ACLs at runtime.

Create a debug build with Tauri

Run `tauri build --debug` to create a debug build. The final bundled app has the development console enabled and is placed in `src-tauri/target/debug/bundle`. This build takes time initially but is significantly faster on subsequent runs.

Plugin initialization with CLI flags

The `plugin new` command supports `--no-api` flag to skip NPM package generation, `--android` flag to include Android support, and `--ios` flag to include iOS support. Existing plugins can be extended with `plugin android add` and `plugin ios add` commands.

Android 16KB memory pages configuration

Google requires 16KB memory pages for new Android app submissions. Building with NDK version 28 or higher automatically generates compliant bundles. For older NDK versions, add the following to .cargo/config.toml: ```toml [target.aarch64-linux-android] rustflags = ["-C", "link-arg=-Wl,-z,max-page-size=16384"] ```

Initialize mobile capabilities on existing plugin

To add Android or iOS capabilities to an existing plugin, use the commands `plugin android init` and `plugin ios init` to bootstrap the mobile library projects and guide you through the necessary changes.

WebdriverIO Tauri scaffolding

The quickest way to scaffold a WebdriverIO project for Tauri testing is using npm create wdio@latest ./, selecting Desktop Testing at the framework prompt, and choosing Tauri.

Cargo.toml tauri and tauri-build version alignment

The tauri-build and tauri dependencies must generally both be on the same latest minor versions as the Tauri CLI, though this is not strictly required. If issues occur when running the app, check that any Tauri versions (tauri and tauri-cli) are on the latest versions for their respective minor releases. Running cargo update in the src-tauri folder will pull the latest Semver-compatible versions of all dependencies. You can use exact versions by prepending = to the version number (e.g., tauri-build = { version = "=2.0.0" }).

package.json lock files ensure consistent dependencies

In addition to package.json, you may see yarn.lock, pnpm-lock.yaml, or package-lock.json files. These assist in ensuring that when dependencies are downloaded later, you get the exact same versions that were used during development, similar to Cargo.lock in Rust.

Cargo.lock file should be committed to source repository

When building a Tauri application, a Cargo.lock file is produced and used to ensure the same dependencies are used across machines during development, similar to yarn.lock, pnpm-lock.yaml, or package-lock.json in Node.js. It is recommended to commit this file to the source repository for consistent builds.

tauri Cargo feature flags managed automatically

The features=[] portion of the tauri dependency in Cargo.toml is automatically managed by tauri dev and tauri build commands, which will enable the necessary features based on the Tauri configuration. Manual feature flag management is generally not required.

Example Cargo.toml for Tauri project

Example Cargo.toml showing basic Tauri project structure: ```toml [package] name = "app" version = "0.1.0" description = "A Tauri App" authors = ["you"] license = "" repository = "" default-run = "app" edition = "2021" rust-version = "1.57" [build-dependencies] tauri-build = { version = "2.0.0" } [dependencies] serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } tauri = { version = "2.0.0", features = [ ] } ```

Manual ico icon requirements

The icon.ico file must include layers for 16, 24, 32, 48, 64 and 256 pixels. For optimal display during development, the 32px layer should be the first layer.

tauri icon command usage

The tauri icon command generates various icons for all major platforms. Usage: tauri icon [OPTIONS] [INPUT]. Arguments: [INPUT] is the path to the source icon (squared PNG or SVG file with transparency), default './app-icon.png'. Options: -o/--output <OUTPUT> sets the output directory (default: 'icons' directory next to tauri.conf.json); -v/--verbose enables verbose logging; -p/--png <PNG> specifies custom PNG icon sizes to generate (when set, default icons are not generated); --ios-color <IOS_COLOR> sets the background color of iOS icon as W3C CSS Color Module Level 4 string (default: #fff).

Icon file formats by platform

icon.icns is for macOS, icon.ico is for Windows, and *.png files are for Linux. Square*Logo.png and StoreLogo.png are currently unused but intended for AppX/MS Store targets.

Manual icns icon requirements

The icon.icns file requires specific layer sizes and names as described in the Tauri repo at https://github.com/tauri-apps/tauri/blob/1.x/tooling/cli/src/helpers/icns.json

Desktop icons default location in tauri.conf.json

Desktop icons are placed in src-tauri/icons by default and are included in the built app automatically. The bundle.icon array in tauri.conf.json specifies icon paths to include: icons/32x32.png, icons/128x128.png, icons/128x128@2x.png, icons/icon.icns, and icons/icon.ico.

Manual PNG icon requirements

PNG icons must have width equal to height, use RGBA color mode (RGB plus transparency), and be 32 bits per pixel (8 bits per channel). Commonly expected sizes on desktop are 32, 128, 256, and 512 pixels. Recommended to match tauri icon output: 32x32.png, 128x128.png, 128x128@2x.png, and icon.png.

Android icon sizes and placement

Android icons must be PNG files with specific sizes placed in src-tauri/gen/android/app/src/main/res/. mipmap-mdpi: ic_launcher.png and ic_launcher_round.png (48x48px), ic_launcher_foreground.png (108x108px). mipmap-hdpi: ic_launcher.png and ic_launcher_round.png (49x49px), ic_launcher_foreground.png (162x162px). mipmap-xhdpi: ic_launcher.png and ic_launcher_round.png (96x96px), ic_launcher_foreground.png (216x216px). mipmap-xxhdpi: ic_launcher.png and ic_launcher_round.png (144x144px), ic_launcher_foreground.png (324x324px). mipmap-xxxhdpi: ic_launcher.png and ic_launcher_round.png (192x192px), ic_launcher_foreground.png (432x432px).

Mobile icons placement

Mobile icons are placed directly into the Xcode and Android Studio projects, not in the src-tauri/icons folder.

iOS icon requirements and placement

iOS icons must be PNG files without transparency placed in src-tauri/gen/apple/Assets.xcassets/AppIcon.appiconset/. Required sizes: 20px in 1x, 2x, 3x scales plus extra icon; 29px in 1x, 2x, 3x plus extra; 40px in 1x, 2x, 3x plus extra; 60px in 2x, 3x; 76px in 1x, 2x; 83.5px in 2x; 512px in 2x saved as AppIcon-512@2x.png. File naming format is AppIcon-{size}x{size}@{scaling}{extra}.png, for example AppIcon-20x20@1x.png, AppIcon-20x20@2x.png, AppIcon-20x20@3x.png with an extra icon AppIcon-20x20@2x-1.png.

Watch source code changes during development

By default, `tauri dev` watches the src-tauri folder and its dependent crates in the workspace for changes, automatically rebuilding and restarting the application when modifications are detected. This behavior can be disabled using the `--no-watch` flag.

Specify device or simulator for mobile dev command

You can specify a particular device or simulator to run on by providing its name as an argument to the dev command, for example `tauri ios dev 'iPhone 15'`. By default, the command tries to run on a connected device and falls back to prompting you to select a simulator.

Open Xcode or Android Studio for mobile development

Use the `--open` flag with the dev command to open Xcode or Android Studio instead of running on a connected device or simulator. The Tauri CLI process must remain running and cannot be killed while using the IDE. For physical iOS devices, also provide the `--host` argument.

Use .taurignore files to exclude files from watching

Create .taurignore files to specify files and folders that should not trigger rebuilds when changed. These files work like .gitignore files. Place them in the src-tauri directory or cargo workspace root folder. The tauri dev command looks for .taurignore files anywhere inside the common ancestor of watched folders and the Cargo workspace root folder.

Select iOS device for development with --force-ip-prompt

To use the iOS device's TUN address (more secure IPv6 address ending with ::2) for development, open Xcode first and ensure the device is connected via network in Window > Devices and Simulators menu. Then run `tauri ios dev --force-ip-prompt` to select the iOS device address.

Run tauri android dev or tauri ios dev for mobile development

To develop a Tauri mobile application, run either `tauri android dev` or `tauri ios dev` depending on the target platform. Like desktop development, the first build may take several minutes due to Rust dependencies, but subsequent builds are faster.

Configure iOS dev server to use TAURI_DEV_HOST for physical devices

When running on a physical iOS device, the development server must be configured to listen to the address provided in the TAURI_DEV_HOST environment variable. This address can be a public network address (default) or the iOS device TUN address (more secure, requires Xcode). For Vite, configure the server host, port, and hmr settings to use the TAURI_DEV_HOST value if provided.

Run tauri dev command for desktop development

To develop a Tauri desktop application, run the command `tauri dev`. The first build may take several minutes as the Rust package manager downloads and builds required packages, but subsequent builds are faster since dependencies are cached. Once Rust finishes building, the webview opens displaying the web app. Changes to the web app update automatically if your tooling supports hot reloading.

Vite configuration for iOS mobile development with TAURI_DEV_HOST

Example Vite configuration for iOS mobile development that uses TAURI_DEV_HOST environment variable: import { defineConfig } from 'vite'; const host = process.env.TAURI_DEV_HOST; export default defineConfig({ clearScreen: false, server: { host: host || false, port: 1420, strictPort: true, hmr: host ? { protocol: 'ws', host, port: 1421 } : undefined } });

Embedding files in Tauri bundle via resources configuration

To bundle additional files in your Tauri application, add the `resources` property to the `bundle` object in `tauri.conf.json`. The bundled files will be placed in the `$RESOURCE/` directory with the original directory structure preserved.

Permission syntax for resource paths with path replacement

When bundling resources with path replacement (like `../relative/path/to/jsonfile.json` which becomes `$RESOURCE/_up_/relative/path/to/jsonfile.json`), use `$RESOURCE/**/*` in permission scopes to allow recursive access to all files in the resource directory, including those in subdirectories created by path replacement.

Configure permissions for opening resource files via opener plugin

In `src-tauri/capabilities/default.json`, to allow opening resource files via the `opener` plugin, use: `{"identifier": "opener:allow-open-path", "allow": [{"path": "$RESOURCE/**/*"}]}`

Configure permissions for resource file access via fs plugin

In `src-tauri/capabilities/default.json`, to allow reading resource files via the `fs` plugin, include the permissions: `"fs:allow-read-text-file"` and `"fs:allow-resource-read-recursive"`. The latter allows full recursive read access to the complete `$RESOURCE` folder. Alternatively, use scoped permissions: `{"identifier": "fs:scope", "allow": ["$RESOURCE/**/*"], "deny": [...]}` for fine-grained control.

Reading resources in JavaScript example

Example of reading a resource file in JavaScript using the `fs` plugin: `import { resolveResource } from '@tauri-apps/api/path'; import { readTextFile } from '@tauri-apps/plugin-fs'; const resourcePath = await resolveResource('lang/de.json'); const langDe = JSON.parse(await readTextFile(resourcePath)); console.log(langDe.hello);`

Reading resources in Rust example

Example of reading a resource file in Rust. In setup: `tauri::Builder::default().setup(|app| { let resource_path = app.path().resolve("lang/de.json", BaseDirectory::Resource)?; let json = std::fs::read_to_string(&resource_path).unwrap(); let lang_de: serde_json::Value = serde_json::from_str(json).unwrap(); println!("{}", lang_de.get("hello").unwrap()); Ok(()) })`. In a command: `#[tauri::command] fn hello(handle: tauri::AppHandle) -> String { let resource_path = handle.path().resolve("lang/de.json", BaseDirectory::Resource)?; let json = std::fs::read_to_string(&resource_path).unwrap(); let lang_de: serde_json::Value = serde_json::from_str(json).unwrap(); lang_de.get("hello").unwrap() }`

Android resource file paths use asset URI prefix

On Android, resources are stored in the APK as assets and APIs return paths with the special URI prefix `asset://localhost/`. Use the `fs` plugin with `FsExt::fs` to read these files: `let resource_path = app.path().resolve("lang/de.json", BaseDirectory::Resource).unwrap(); let json = app.fs().read_to_string(&resource_path);`. Alternatively, copy resource contents manually through the `fs` plugin to real file system.

Resolve resource paths in JavaScript

In JavaScript, use the `resolveResource` function from `@tauri-apps/api/path`: `import { resolveResource } from '@tauri-apps/api/path'; const resourcePath = await resolveResource('lang/de.json');`

Resolve resource paths in Rust

In Rust, use `PathResolver` from `App` or `AppHandle` to resolve resource file paths. Call `app.path().resolve("lang/de.json", BaseDirectory::Resource)?` in setup or `handle.path().resolve("lang/de.json", BaseDirectory::Resource)?` in a command. The path syntax follows the same rules as defined in `tauri.conf.json > bundle > resources`.

Resource path syntax rules

When specifying resource paths: `"dir/file.txt"` copies the file into target; `"dir/"` copies all files and directories recursively preserving structure; `"dir/*"` copies files non-recursively (sub-directories ignored); `"dir/**"` throws error (matches directories only); `"dir/**/*"` copies all files recursively; `"dir/**/**"` throws error.

Resources map configuration for custom target paths

The `bundle.resources` property can also be configured as an object to fine-control where files are copied. Keys are source paths and values are target locations relative to `$RESOURCE/`. For example: `{"/absolute/path/to/textfile.txt": "resources/textfile.txt", "resources/": ""}`. When using glob patterns in the map, files are placed without preserving original directory structure.

Resources array syntax for bundling files

In `tauri.conf.json`, the `bundle.resources` property can be configured as an array of paths. Paths can be relative (e.g., `./path/to/some-file.txt`), absolute (e.g., `/absolute/path/to/textfile.txt`), contain relative traversal (e.g., `../relative/path/to/jsonfile.json`), reference directories (e.g., `some-folder/`), or use glob patterns (e.g., `resources/**/*.md`). Files are placed in `$RESOURCE/` preserving structure, except: absolute paths have their root replaced with `_root_`, relative traversals have `..` replaced with `_up_`, glob patterns preserve directory structure.

Sidecar target triple script limitation

The provided Node.js script to append target triple to binaries will not work if compiling for a different architecture than the one it is running on. It should only be used as a starting point for custom build scripts that handle cross-compilation scenarios.

Node.js script to append target triple to sidecar binary

import { execSync } from 'child_process'; import fs from 'fs'; const extension = process.platform === 'win32' ? '.exe' : ''; const targetTriple = execSync('rustc --print host-tuple').toString().trim(); if (!targetTriple) { console.error('Failed to determine platform target triple'); } fs.renameSync( `src-tauri/binaries/sidecar${extension}`, `src-tauri/binaries/sidecar-${targetTriple}${extension}` );

Sync npm and Cargo package versions

The JavaScript APIs in @tauri-apps/api rely on Rust code in the backend. You must keep the same minor version of the npm package @tauri-apps/api and the cargo crate tauri synchronized to ensure compatibility when adding new features.

Sync Tauri plugin versions exactly

For Tauri plugins, npm packages and cargo crates must be kept at exactly the same version (e.g., 2.2.1) because version changes may be introduced in patch releases. For example, the npm package @tauri-apps/plugin-fs and the cargo crate tauri-plugin-fs must have matching exact versions.

Update @tauri-apps/cli and @tauri-apps/api npm packages

To update the Tauri npm packages, use one of the following commands depending on your package manager: npm: npm install @tauri-apps/cli@latest @tauri-apps/api@latest yarn: yarn up @tauri-apps/cli @tauri-apps/api pnpm: pnpm update @tauri-apps/cli @tauri-apps/api --latest

Use cargo-edit to automatically upgrade Cargo packages

The cargo-edit crate provides a 'cargo upgrade' command that automatically updates all Tauri dependencies in Cargo.toml, replacing the manual editing step.

Update Cargo packages for Tauri

To update Tauri Cargo packages, modify src-tauri/Cargo.toml to set the desired version for tauri and tauri-build dependencies. In the [build-dependencies] section, set tauri-build to the new version. In the [dependencies] section, set tauri version. Then run 'cd src-tauri' followed by 'cargo update' to apply changes.

Check for outdated Cargo packages

Use the 'cargo outdated' command to check for outdated packages, or view the crates.io pages for tauri and tauri-build directly.

Check for outdated npm packages on command line

To detect the latest version of Tauri npm packages, use one of the following commands: npm: npm outdated @tauri-apps/cli yarn: yarn outdated @tauri-apps/cli pnpm: pnpm outdated @tauri-apps/cli

Mobile development requires a development server

For mobile development with Tauri, a development server of some kind is necessary that can host the frontend on your internal IP address.

Recommended JavaScript build tool for Tauri

Vite is recommended for most projects, especially for SPA frameworks such as React, Vue, Svelte, and Solid, as well as for plain JavaScript or TypeScript projects.

Vite configuration to prevent watching src-tauri directory

In vite.config.ts, configure the server.watch.ignored option to prevent Vite from watching the src-tauri directory. Example configuration: import { defineConfig } from "vite"; export default defineConfig({ server: { watch: { ignored: ["**/src-tauri/**"] } } });

Manual Tauri setup for existing projects

To add Tauri to an existing frontend project: (1) Install the Tauri CLI as a dev dependency using npm install -D @tauri-apps/cli@latest (or equivalent for your package manager), or globally with cargo install tauri-cli --version "^2.0.0" --locked. (2) Determine your frontend development server URL (e.g., http://localhost:5173 for Vite). (3) Run tauri init and provide configuration prompts: app name, window title, web assets location, dev server URL, frontend dev command, and frontend build command. (4) Configure vite.config.ts to ignore the src-tauri directory in watch: server.watch.ignored: ["**/src-tauri/**"]. (5) Run tauri dev to compile Rust code and open the app.

Give your agent this brain