Open-Source Wikis

/

Tauri

/

Crates

/

tauri-utils

tauri-apps/tauri

tauri-utils

Active contributors: Lucas Fernandes Nogueira, Amr Bashir, Tony

Purpose

crates/tauri-utils is the shared library that almost every other crate depends on. It owns:

  • The Rust types for tauri.conf.json (the source of truth — the JSON Schema is generated from these).
  • The ACL types: capabilities, permissions, scope values, identifier validation.
  • HTML/asset helpers: CSP injection, isolation pattern HTML rewriting, MIME type lookup.
  • Resource resolution helpers and platform helpers (target triple, OS detection).
  • A copy of the v1 config types for migration support.

crates/tauri-utils/src/config.rs is 4,738 lines of Rust types, second only to the WRY runtime crate.

Directory layout

crates/tauri-utils/
├── Cargo.toml
├── src/
│   ├── lib.rs              # 12,261 bytes
│   ├── config.rs           # 4,738 lines: every tauri.conf.json type
│   ├── config_v1/          # the v1 schema, kept for migration
│   ├── acl/                # 8 files: capability, permission, identifier, schema, manifest, …
│   ├── pattern/            # isolation helpers
│   ├── platform/           # platform helpers
│   ├── platform.rs         # current_exe(), target triple, os version
│   ├── assets.rs           # AssetKey, EmbeddedAssets trait, AssetsIter
│   ├── html.rs             # CSP injection, script tag rewriting, isolation HTML
│   ├── html2.rs            # newer HTML rewrite path (alternative impl)
│   ├── mime_type.rs        # extension → MIME
│   ├── resources.rs        # ResourcePaths used by bundler/codegen
│   ├── tokens.rs           # secure-token helpers
│   ├── plugin.rs
│   ├── io.rs
│   └── build.rs
└── tests/

Key abstractions

Type File Role
Config (and ~100 sub-types) crates/tauri-utils/src/config.rs The full deserialised shape of tauri.conf.json.
Pattern crates/tauri-utils/src/config.rs brownfield or isolation; drives runtime/codegen behaviour.
Theme, WindowEffectsConfig, Color crates/tauri-utils/src/config.rs Visual/theming primitives shared with the runtime.
Capability / CapabilityFile crates/tauri-utils/src/acl/capability.rs One JSON file under capabilities/. Local/Remote contexts, allow/deny.
Permission / PermissionSet / Scope crates/tauri-utils/src/acl/mod.rs The permission shape (a TOML file in a plugin's permissions/).
Resolved crates/tauri-utils/src/acl/resolved.rs The flattened, resolved ACL produced at build time and consumed at runtime.
Identifier crates/tauri-utils/src/acl/identifier.rs Validates plugin / permission / capability names (namespace:name format).
EmbeddedAssets (trait) + iterators crates/tauri-utils/src/assets.rs Abstracts over the phf map produced by tauri-codegen.
Csp / Hash / inject helpers crates/tauri-utils/src/html.rs Compute and inject CSP sha256-... hashes for embedded scripts/styles.
ResourcePaths crates/tauri-utils/src/resources.rs Glob and walk resource paths (used by the bundler).

How it works

tauri-utils is intentionally low-level and dependency-light. It exposes plain serde types and pure functions; it never starts a runtime or talks to OS APIs that would force a target. Every other crate in the workspace pulls these types through:

graph LR
    config["tauri-utils::config::Config"] --> codegen["tauri-codegen"]
    config --> build["tauri-build"]
    config --> bundler["tauri-bundler"]
    config --> cli["tauri-cli"]
    config --> core["tauri (runtime)"]
    acl["tauri-utils::acl"] --> build
    acl --> core
    acl --> plugin["tauri-plugin (build helpers)"]

Cargo features

  • build-2 — the v2 build-time feature surface used by tauri-build.
  • build-2-plugins — variant for plugin authors.
  • compression — propagate the compression flag through codegen.
  • resources — enable the resource-walking helpers used by the bundler.
  • isolation — opt-in to the isolation pattern types.
  • html-manipulation-2 — opt-in to the newer HTML rewriter (html2.rs).
  • process-relaunch-dangerous-allow-symlink-macos — propagate the macOS relaunch toggle.
  • schema — derive schemars::JsonSchema for the config types so tauri-schema-generator can produce JSON Schemas.

Integration points

  • Up: virtually every other crate in the workspace.
  • Down: depends only on serde, thiserror, serde_with, glob, phf, schemars (under feature flag), and a few platform helpers.

Entry points for modification

Goal Start here
Add a field to tauri.conf.json crates/tauri-utils/src/config.rs (then run cargo run -p tauri-schema-generator)
Add a new permission attribute crates/tauri-utils/src/acl/
Tighten capability validation crates/tauri-utils/src/acl/identifier.rs and capability.rs
Tweak CSP injection crates/tauri-utils/src/html.rs / html2.rs
Add a MIME type crates/tauri-utils/src/mime_type.rs

See tauri-schema-generator for how the JSON Schemas are derived from these types, and systems/acl-and-capabilities for the resolved ACL flow.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

tauri-utils – Tauri wiki | Factory