### Main Build Script Logic Source: https://docs.rs/crate/tauri/latest/source/build.rs The main function orchestrates the build process by checking for features like 'custom-protocol' and 'dev', setting corresponding CFG aliases, and determining platform-specific configurations like 'mobile' or 'desktop'. It also writes the list of checked features to an output file for debugging or inspection. ```rust fn main() { let custom_protocol = has_feature("custom-protocol"); let dev = !custom_protocol; alias("custom_protocol", custom_protocol); alias("dev", dev); println!("cargo:dev={dev}"); let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap(); let mobile = target_os == "ios" || target_os == "android"; alias("desktop", !mobile); alias("mobile", mobile); let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); let checked_features_out_path = out_dir.join("checked_features"); std::fs::write( checked_features_out_path, CHECKED_FEATURES.get().unwrap().lock().unwrap().join(","), ) .expect("failed to write checked_features file"); // workaround needed to prevent `STATUS_ENTRYPOINT_NOT_FOUND` error in tests // see https://github.com/tauri-apps/tauri/pull/4383#issuecomment-1212221864 let target_env = std::env::var("CARGO_CFG_TARGET_ENV"); let is_tauri_workspace = std::env::var("__TAURI_WORKSPACE__").is_ok_and(|v| v == "true"); } ``` -------------------------------- ### Define Plugin Permissions (Rust) Source: https://docs.rs/crate/tauri/latest/source/build.rs Generates and defines permissions for Tauri plugins. It iterates through defined plugins, creates directories for permission files, autogenerates command permissions, and defines default permissions in TOML format. It also generates documentation for these permissions. ```rust fn define_permissions( out_dir: &Path, ) -> BTreeMap> { let mut all_permissions = BTreeMap::new(); for (plugin, commands) in PLUGINS { let plugin_directory_name = plugin.strip_prefix("core:").unwrap_or(plugin); let permissions_out_dir = out_dir.join("permissions").join(plugin_directory_name); let autogenerated = permissions_out_dir.join(tauri_utils::acl::build::AUTOGENERATED_FOLDER_NAME); let commands_dir = autogenerated.join("commands"); tauri_utils::acl::build::autogenerate_command_permissions( &commands_dir, &commands.iter().map(|(cmd, _)| *cmd).collect::>(), LICENSE_HEADER, false, ); let default_permissions: Vec<_> = commands.iter().filter(|(_cmd, default)| *default).collect(); let all_commands_enabled_by_default = commands.len() == default_permissions.len(); let default_permissions = default_permissions .into_iter() .map(|(cmd, _)| { let slugified_command = cmd.replace('_', "-"); format!("\"allow-{slugified_command}\"") }) .collect::>() .join(", "); let all_enable_by_default = if all_commands_enabled_by_default { ", which enables all commands" } else { "" }; let default_toml = format!( r#"{LICENSE_HEADER}# Automatically generated - DO NOT EDIT!\n\n[default]\ndescription = \"Default permissions for the plugin{all_enable_by_default}.\"\npermissions = [{default_permissions}]\n"#, ); let out_path = autogenerated.join("default.toml"); write_if_changed(out_path, default_toml) .unwrap_or_else(|_| panic!("unable to autogenerate default permissions")); let permissions = tauri_utils::acl::build::define_permissions( &PathBuf::from(glob::Pattern::escape( &permissions_out_dir.to_string_lossy(), )) .join("**") .join("*.toml") .to_string_lossy(), &format!("tauri:{plugin}"), out_dir, |_| true, ) .unwrap_or_else(|e| panic!("failed to define permissions for {plugin}: {e}")); let docs_out_dir = Path::new("permissions") .join(plugin_directory_name) .join("autogenerated"); fs::create_dir_all(&docs_out_dir).expect("failed to create plugin documentation directory"); tauri_utils::acl::build::generate_docs( &permissions, &docs_out_dir, plugin.strip_prefix("tauri-plugin-").unwrap_or(plugin), ) .expect("failed to generate plugin documentation page"); all_permissions.insert(plugin.to_string(), permissions); } let default_permissions = define_default_permission_set(out_dir); all_permissions.insert("core".to_string(), default_permissions); all_permissions } ``` -------------------------------- ### macOS/iOS Library Linking and Path Configuration Source: https://docs.rs/crate/tauri/latest/source/build.rs Configures the build for macOS and iOS by linking the 'Tauri' Apple library and setting the iOS library path. This is done conditionally based on the target operating system. ```Rust "#[cfg(target_os = \"macos\")]" { if target_os == "ios" { let lib_path = PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").unwrap()).join("mobile/ios-api"); tauri_utils::build::link_apple_library("Tauri", &lib_path); println!("cargo:ios_library_path={}", lib_path.display()); } } ``` -------------------------------- ### Android Kotlin File Generation and Configuration Source: https://docs.rs/crate/tauri/latest/source/build.rs Generates Kotlin files for Android builds by reading templates and replacing placeholders with package and library information. It also configures ProGuard rules and sets the Android library path. Requires environment variables like WRY_ANDROID_KOTLIN_FILES_OUT_DIR, WRY_ANDROID_PACKAGE, and WRY_ANDROID_LIBRARY. ```Rust if target_os == "android" { fn env_var(var: &str) -> String { std::env::var(var).unwrap_or_else(|_| { panic!("`{var}` is not set, which is needed to generate the kotlin files for android.") }) } if let Ok(kotlin_out_dir) = std::env::var("WRY_ANDROID_KOTLIN_FILES_OUT_DIR") { let package = env_var("WRY_ANDROID_PACKAGE"); let library = env_var("WRY_ANDROID_LIBRARY"); let kotlin_out_dir = PathBuf::from(&kotlin_out_dir) .canonicalize() .unwrap_or_else(move |_| { panic!("Failed to canonicalize `WRY_ANDROID_KOTLIN_FILES_OUT_DIR` path {kotlin_out_dir}") }); let kotlin_files_path = PathBuf::from(env_var("CARGO_MANIFEST_DIR")).join("mobile/android-codegen"); println!("cargo:rerun-if-changed={}", kotlin_files_path.display()); let kotlin_files = fs::read_dir(kotlin_files_path).expect("failed to read Android codegen directory"); for file in kotlin_files { let file = file.unwrap(); let content = fs::read_to_string(file.path()) .expect("failed to read kotlin file as string") .replace("{{package}}", &package) .replace("{{library}}", &library); let out_path = kotlin_out_dir.join(file.file_name()); // Overwrite only if changed to not trigger rebuilds write_if_changed(&out_path, &content).expect("Failed to write kotlin file"); println!("cargo:rerun-if-changed={}", out_path.display()); } } if let Some(project_dir) = env::var_os("TAURI_ANDROID_PROJECT_PATH").map(PathBuf::from) { let package_unescaped = env::var("TAURI_ANDROID_PACKAGE_UNESCAPED") .unwrap_or_else(|_| env_var("WRY_ANDROID_PACKAGE").replace('`', "")); let tauri_proguard = include_str!("./mobile/proguard-tauri.pro").replace("$PACKAGE", &package_unescaped); std::fs::write( project_dir.join("app").join("proguard-tauri.pro"), tauri_proguard, ) .expect("failed to write proguard-tauri.pro"); } let lib_path = PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").unwrap()).join("mobile/android"); println!("cargo:android_library_path={}", lib_path.display()); } ``` -------------------------------- ### Configure Tauri Project Dependencies and Metadata Source: https://docs.rs/crate/tauri/latest/source/Cargo.toml.orig This Cargo.toml snippet defines the package metadata, documentation build features for docs.rs, and a comprehensive list of dependencies required for cross-platform desktop application development using Tauri. ```toml [package] name = "tauri" version = "2.10.3" description = "Make tiny, secure apps for all desktop platforms with Tauri" [package.metadata.docs.rs] no-default-features = true features = [ "wry", "unstable", "custom-protocol", "tray-icon", "devtools", "image-png", "protocol-asset", "test", "specta", "dynamic-acl", ] [dependencies] serde_json = { version = "1", features = ["raw_value"] } serde = { version = "1", features = ["derive", "rc"] } tokio = { version = "1", features = ["rt", "rt-multi-thread", "sync", "fs", "io-util"] } url = "2" anyhow = "1" thiserror = "2" tauri-runtime = { version = "2.10.1", path = "../tauri-runtime" } [target.'cfg(target_os = "macos")'.dependencies] embed_plist = "1.2" plist = "1" ``` -------------------------------- ### Docker Commands for Container Management Source: https://docs.rs/crate/tauri/latest/builds/2963776/x86_64-unknown-linux-gnu_json.txt This snippet shows Docker commands used within the project. It includes commands for inspecting a Docker container by its ID and for forcefully removing a Docker container. ```bash running `Command { std: "docker" "inspect" "837e4c0dc9d51eaac16da20b4528c97419bf7e516942a51b95f0d0f7b51d0e27", kill_on_drop: false }` running `Command { std: "docker" "rm" "-f" "837e4c0dc9d51eaac16da20b4528c97419bf7e516942a51b95f0d0f7b51d0e27", kill_on_drop: false }` [INFO] [stdout] 837e4c0dc9d51eaac16da20b4528c97419bf7e516942a51b95f0d0f7b51d0e27 ``` -------------------------------- ### Embed Windows Manifest for Tests (Rust) Source: https://docs.rs/crate/tauri/latest/source/build.rs Configures the Rust compiler to embed a Windows application manifest file during the build process, specifically for testing. It prints cargo build commands to rerun if the manifest file changes and specifies linker arguments for embedding and error handling. ```rust fn embed_manifest_for_tests() { static WINDOWS_MANIFEST_FILE: &str = "windows-app-manifest.xml"; let manifest = std::env::current_dir() .unwrap() .join("../tauri-build/src") .join(WINDOWS_MANIFEST_FILE); println!("cargo:rerun-if-changed={}", manifest.display()); // Embed the Windows application manifest file. println!("cargo:rustc-link-arg=/MANIFEST:EMBED"); println!( "cargo:rustc-link-arg=/MANIFESTINPUT:{}", manifest.to_str().unwrap() ); // Turn linker warnings into errors. println!("cargo:rustc-link-arg=/WX"); } ``` -------------------------------- ### Tauri Plugin Definitions (Rust) Source: https://docs.rs/crate/tauri/latest/source/build.rs Defines the available plugins for Tauri, including their commands and default enabled status. This Rust code snippet structures plugin data for use within the Tauri framework, enabling or disabling specific functionalities based on configuration. ```rust use heck::AsShoutySnakeCase; use tauri_utils::write_if_changed; use std::{ collections::BTreeMap, env, fs, path::{Path, PathBuf}, sync::{Mutex, OnceLock}, }; static CHECKED_FEATURES: OnceLock>> = OnceLock::new(); const PLUGINS: &[(&str, &[(&str, bool)])] = &[ // (plugin_name, &[(command, enabled-by_default)]) // TODO: Enable this in v3 // ("core:channel", &[( "fetch", true)]), ( "core:path", &[ ("resolve_directory", true), ("resolve", true), ("normalize", true), ("join", true), ("dirname", true), ("extname", true), ("basename", true), ("is_absolute", true), ], ), ( "core:event", &[ ("listen", true), ("unlisten", true), ("emit", true), ("emit_to", true), ], ), ( "core:window", &[ ("create", false), // getters ("get_all_windows", true), ("scale_factor", true), ("inner_position", true), ("outer_position", true), ("inner_size", true), ("outer_size", true), ("is_fullscreen", true), ("is_minimized", true), ("is_maximized", true), ("is_focused", true), ("is_decorated", true), ("is_resizable", true), ("is_maximizable", true), ("is_minimizable", true), ("is_closable", true), ("is_visible", true), ("is_enabled", true), ("title", true), ("current_monitor", true), ("primary_monitor", true), ("monitor_from_point", true), ("available_monitors", true), ("cursor_position", true), ("theme", true), ("is_always_on_top", true), // setters ("center", false), ("request_user_attention", false), ("set_enabled", false), ("set_resizable", false), ("set_maximizable", false), ("set_minimizable", false), ("set_closable", false), ("set_title", false), ("maximize", false), ("unmaximize", false), ("minimize", false), ("unminimize", false), ("show", false), ("hide", false), ("close", false), ("destroy", false), ("set_decorations", false), ("set_shadow", false), ("set_effects", false), ("set_always_on_top", false), ("set_always_on_bottom", false), ("set_visible_on_all_workspaces", false), ("set_content_protected", false), ("set_size", false), ("set_min_size", false), ("set_size_constraints", false), ("set_max_size", false), ("set_position", false), ("set_fullscreen", false), ("set_simple_fullscreen", false), ``` -------------------------------- ### Tauri Global API Script Definition and Saving Source: https://docs.rs/crate/tauri/latest/source/build.rs Defines and saves the path to the global API script for Tauri. This is crucial for enabling global JavaScript APIs within the application. The script path is canonicalized, and the paths are saved to the output directory, especially for workspace builds. ```Rust let tauri_global_scripts = PathBuf::from("./scripts/bundle.global.js") .canonicalize() .expect("failed to canonicalize tauri global API script path"); tauri_utils::plugin::define_global_api_script_path(&tauri_global_scripts); // This should usually be done in `tauri-build`, // but we need to do this here for the examples in this workspace to work as they don't have build scripts if is_tauri_workspace { tauri_utils::plugin::save_global_api_scripts_paths(&out_dir, Some(tauri_global_scripts)); } ``` -------------------------------- ### Define Core Default Permissions Set (Rust) Source: https://docs.rs/crate/tauri/latest/source/build.rs Defines the default permission set for the core Tauri application. It creates a 'default.toml' file within the permissions directory, listing default permissions for core plugins. This function is crucial for setting up basic access control. ```rust fn define_default_permission_set( out_dir: &Path, ) -> Vec { let permissions_out_dir = out_dir.join("permissions"); fs::create_dir_all(&permissions_out_dir) .expect("failed to create core:default permissions directory"); let default_toml = permissions_out_dir.join("default.toml"); let toml_content = format!( r#"{LICENSE_HEADER}\n\n[default]\ndescription = \"Default core plugins set.\"\npermissions = [{}]\n"#, PLUGINS .iter() .map(|(k, _)| format!("\"{k}:default\"")) .collect::>() .join(",") ); write_if_changed(default_toml, toml_content) .unwrap_or_else(|_| panic!("unable to autogenerate core:default set")); tauri_utils::acl::build::define_permissions( &PathBuf::from(glob::Pattern::escape( &permissions_out_dir.to_string_lossy(), )) .join("*.toml") .to_string_lossy(), "tauri:core", out_dir, |_| true, ) .unwrap_or_else(|e| panic!("failed to define permissions for `core:default` : {e}")) } ``` -------------------------------- ### Conditional Manifest Embedding for Windows MSVC Source: https://docs.rs/crate/tauri/latest/source/build.rs Embeds manifest for tests specifically when building for Windows with the MSVC toolchain. This ensures correct manifest information is available during testing on Windows. ```Rust if is_tauri_workspace && target_os == "windows" && Ok("msvc") == target_env.as_deref() { embed_manifest_for_tests(); } ``` -------------------------------- ### ACL Command Generation Source: https://docs.rs/crate/tauri/latest/source/build.rs Generates allowed commands for the Access Control List (ACL) based on defined permissions. This function ensures that only authorized commands can be executed within the Tauri application, enhancing security. ```Rust let permissions = define_permissions(&out_dir); tauri_utils::acl::build::generate_allowed_commands(&out_dir, None, permissions).unwrap(); ``` -------------------------------- ### Rust Specta Crate Build Error and Resolution Source: https://docs.rs/crate/tauri/latest/builds/2963776/x86_64-unknown-linux-gnu_json.txt This snippet details a common Rust compilation error (E0599) related to the 'specta' crate. It explains that items from traits might be unavailable if the trait is not implemented or in scope. It suggests enabling feature flags for crates with official Specta support or using a new-type wrapper for external crates lacking Specta support. ```rust error: could not compile `specta` (lib) due to 2 previous errors = help: items from traits can only be used if the trait is implemented and in scope note: `r#type::Type` defines an item `definition`, perhaps you need to implement it --> /opt/rustwide/cargo-home/registry/src/index.crates.io-1949cf8c6b5b557f/specta-2.0.0-rc.23/src/type.rs:23:1 | 23 | pub trait Type { | ^^^^^^^^^^^^^^ = note: this error originates in the macro `impl_passthrough` (in Nightly builds, run with -Z macro-backtrace for more info) For more information about this error, try `rustc --explain E0599`. ``` -------------------------------- ### Create CFG Alias Based on Feature Source: https://docs.rs/crate/tauri/latest/source/build.rs Generates a `cargo:rustc-cfg` directive to define a compile-time configuration alias. If the provided `has_feature` boolean is true, the alias is activated, allowing for conditional compilation using `#[cfg(...)]` attributes in the Rust code. ```rust fn alias(alias: &str, has_feature: bool) { println!("cargo:rustc-check-cfg=cfg({alias})"); if has_feature { println!("cargo:rustc-cfg={alias}"); } } ``` -------------------------------- ### Check Cargo Feature Status Source: https://docs.rs/crate/tauri/latest/source/build.rs Determines if a specific Cargo feature is enabled for the current build. It checks environment variables set by Cargo and stores the checked features for later use. This function is crucial for enabling or disabling code paths based on build configurations. ```rust fn has_feature(feature: &str) -> bool { CHECKED_FEATURES .get_or_init(Default::default) .lock() .unwrap() .push(feature.to_string()); // when a feature is enabled, Cargo sets the `CARGO_FEATURE_` env var to 1 // std::env::var(format!("CARGO_FEATURE_{}", AsShoutySnakeCase(feature))) .map(|x| x == "1") .unwrap_or(false) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.