Skip to main content

Crate tauri_build

Crate tauri_build 

Source
Expand description

Build-time helpers for Tauri applications.

Every Tauri application must run build() (or try_build()) from its build.rs, on every target platform. It sets up everything the tauri crate expects to find at compile time and at runtime:

  • emits cargo:rerun-if-changed instructions for the Tauri configuration files;
  • defines the dev, desktop and mobile cfg aliases used across the Tauri crates;
  • parses the permissions of the application and of its plugins, resolves the capabilities (from the capabilities directory and from app > security > capabilities in the configuration file) and validates them, writing the resulting Access Control List to the OUT_DIR so tauri::generate_context! can embed it; it also writes the capability JSON schemas to gen/schemas;
  • copies the configured bundle > externalBin sidecars and bundle > resources next to the compiled binary so they are available when running the app with cargo run;
  • on macOS and iOS, sets the deployment target from the configuration and links the configured frameworks;
  • on Windows, compiles a resource file with the application icon, version information and the application manifest, and optionally statically links the Visual C++ runtime (see WindowsAttributes);
  • on Android, generates the Gradle files of the mobile project and updates the Android manifest with the configured file associations;
  • optionally runs the context code generation at build time instead of at macro expansion time (see Attributes::codegen, requires the codegen Cargo feature).

§Examples

The default build.rs of a Tauri application:

ⓘ
// build.rs
fn main() {
  tauri_build::build()
}

Customizing the build with Attributes:

ⓘ
// build.rs
fn main() {
  let attributes = tauri_build::Attributes::new()
    // the app commands that get a `allow-$command`/`deny-$command` permission generated
    .app_manifest(tauri_build::AppManifest::new().commands(&["my_command"]))
    // a plugin that lives in the app crate instead of its own crate
    .plugin(
      "my-plugin",
      tauri_build::InlinedPlugin::new().commands(&["do_something"]),
    )
    .windows_attributes(
      tauri_build::WindowsAttributes::new().window_icon_path("icons/icon.ico"),
    );
  tauri_build::try_build(attributes).expect("failed to run tauri-build");
}

See Attributes for the complete list of options: Attributes::config_path, Attributes::capabilities_path_pattern, Attributes::plugin / InlinedPlugin, Attributes::app_manifest / AppManifest, Attributes::windows_attributes / WindowsAttributes and Attributes::codegen / CodegenContext (codegen feature).

§Environment variables

In addition to the environment variables set by cargo for build scripts, the following variables are read:

  • TAURI_CONFIG: a JSON string that is merged into the parsed configuration file. Set by the Tauri CLI when the configuration is changed from the command line (e.g. tauri build --config). The build script reruns when it changes.
  • TAURI_ANDROID_PROJECT_PATH: path to the Android Studio project of the application, set by the Tauri CLI on Android builds. When set, the Gradle files of the project are regenerated and the Android manifest is updated with the configured file associations. (the tauri-plugin crate reads the matching TAURI_IOS_PROJECT_PATH for iOS projects).
  • STATIC_VCRUNTIME: deprecated, use build > windows > staticVCRuntime in the Tauri configuration or WindowsAttributes::static_vc_runtime instead. Any value other than false statically links the Visual C++ runtime.

Structs§

AppManifest
Tauri application permission manifest.
Attributes
The attributes used on the build.
CodegenContextcodegen
A builder for generating a Tauri application context during compile time.
InlinedPlugin
Definition of a plugin that is part of the Tauri application instead of having its own crate.
WindowsAttributes
Attributes used on Windows.

Enums§

DefaultPermissionRule
Variants of a generated default permission that can be used on an InlinedPlugin.

Functions§

build
Run all build time helpers for your Tauri Application.
is_dev
Whether the app is being compiled for development (tauri dev) or not.
try_build
Same as build(), but takes an extra configuration argument, and does not panic.

Type Aliases§

Result
Result<T, Error>