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-changedinstructions for the Tauri configuration files; - defines the
dev,desktopandmobilecfg aliases used across the Tauri crates; - parses the permissions of the application and of its plugins, resolves the capabilities
(from the
capabilitiesdirectory and fromapp > security > capabilitiesin the configuration file) and validates them, writing the resulting Access Control List to theOUT_DIRsotauri::generate_context!can embed it; it also writes the capability JSON schemas togen/schemas; - copies the configured
bundle > externalBinsidecars andbundle > resourcesnext to the compiled binary so they are available when running the app withcargo 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 thecodegenCargo 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. (thetauri-plugincrate reads the matchingTAURI_IOS_PROJECT_PATHfor iOS projects).STATIC_VCRUNTIME: deprecated, usebuild > windows > staticVCRuntimein the Tauri configuration orWindowsAttributes::static_vc_runtimeinstead. Any value other thanfalsestatically links the Visual C++ runtime.
Structs§
- AppManifest
- Tauri application permission manifest.
- Attributes
- The attributes used on the build.
- Codegen
Context codegen - A builder for generating a Tauri application context during compile time.
- Inlined
Plugin - Definition of a plugin that is part of the Tauri application instead of having its own crate.
- Windows
Attributes - Attributes used on Windows.
Enums§
- Default
Permission Rule - 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>