From c7dacca4661c6ddf937c1a3dd3ace896d5baf40c Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Tue, 18 Jul 2023 06:19:01 -0700 Subject: [PATCH 1/3] feat(cli): expose iOS project path and app name as env vars (#7446) --- .changes/cli-ios-metadata-env-var.md | 6 ++++++ tooling/cli/src/mobile/ios.rs | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changes/cli-ios-metadata-env-var.md diff --git a/.changes/cli-ios-metadata-env-var.md b/.changes/cli-ios-metadata-env-var.md new file mode 100644 index 000000000000..9399155b05f9 --- /dev/null +++ b/.changes/cli-ios-metadata-env-var.md @@ -0,0 +1,6 @@ +--- +"tauri-cli": patch:feat +"@tauri-apps/cli": patch:feat +--- + +Expose the `TAURI_IOS_PROJECT_PATH` and `TAURI_IOS_APP_NAME` environment variables when using `ios` commands. diff --git a/tooling/cli/src/mobile/ios.rs b/tooling/cli/src/mobile/ios.rs index 725c04254aff..05401a5bfda2 100644 --- a/tooling/cli/src/mobile/ios.rs +++ b/tooling/cli/src/mobile/ios.rs @@ -30,7 +30,7 @@ use super::{ }; use crate::{helpers::config::Config as TauriConfig, Result}; -use std::{process::exit, thread::sleep, time::Duration}; +use std::{env::set_var, process::exit, thread::sleep, time::Duration}; mod build; mod dev; @@ -140,6 +140,9 @@ pub fn get_config( macos: Default::default(), }; + set_var("TAURI_IOS_PROJECT_PATH", config.project_dir()); + set_var("TAURI_IOS_APP_NAME", config.app().name()); + (config, metadata) } From aa94f7197e4345a7cab1617272b10895859674f9 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Tue, 18 Jul 2023 06:20:32 -0700 Subject: [PATCH 2/3] feat(ios): add empty entitlements file to iOS project (#7445) --- .changes/ios-entitlements.md | 6 +++++ tooling/bundler/src/bundle/macos/app.rs | 1 - tooling/cli/src/mobile/ios/project.rs | 27 +++++--------------- tooling/cli/templates/mobile/ios/project.yml | 3 +++ 4 files changed, 15 insertions(+), 22 deletions(-) create mode 100644 .changes/ios-entitlements.md diff --git a/.changes/ios-entitlements.md b/.changes/ios-entitlements.md new file mode 100644 index 000000000000..5bf13ff57098 --- /dev/null +++ b/.changes/ios-entitlements.md @@ -0,0 +1,6 @@ +--- +"tauri-cli": patch:feat +"@tauri-apps/cli": patch:feat +--- + +Generate empty entitlements file for the iOS project. diff --git a/tooling/bundler/src/bundle/macos/app.rs b/tooling/bundler/src/bundle/macos/app.rs index 5b22cbbb50b5..9defdb96a393 100644 --- a/tooling/bundler/src/bundle/macos/app.rs +++ b/tooling/bundler/src/bundle/macos/app.rs @@ -31,7 +31,6 @@ use crate::Settings; use anyhow::Context; use log::{info, warn}; -use tauri_utils::config::BundleTypeRole; use std::{ fs, diff --git a/tooling/cli/src/mobile/ios/project.rs b/tooling/cli/src/mobile/ios/project.rs index 4b83cd5899e9..d1b1a74171c1 100644 --- a/tooling/cli/src/mobile/ios/project.rs +++ b/tooling/cli/src/mobile/ios/project.rs @@ -164,28 +164,13 @@ pub fn gen( ) .with_context(|| "failed to process template")?; - let asset_dir = dest.join(DEFAULT_ASSET_DIR); - if !asset_dir.is_dir() { - create_dir_all(&asset_dir).map_err(|cause| { - anyhow::anyhow!( - "failed to create asset dir {path}: {cause}", - path = asset_dir.display() - ) - })?; - } - - let externals_dir = dest.join("Externals"); - if !externals_dir.is_dir() { - create_dir_all(&externals_dir).map_err(|cause| { - anyhow::anyhow!( - "failed to create Externals dir {path}: {cause}", - path = externals_dir.display() - ) - })?; - } + let mut dirs_to_create = asset_catalogs.to_vec(); + dirs_to_create.push(dest.join(DEFAULT_ASSET_DIR)); + dirs_to_create.push(dest.join("Externals")); + dirs_to_create.push(dest.join(format!("{}_iOS", config.app().name()))); - // Create all asset catalog directories if they don't already exist - for dir in asset_catalogs { + // Create all required project directories if they don't already exist + for dir in &dirs_to_create { std::fs::create_dir_all(dir).map_err(|cause| { anyhow::anyhow!( "failed to create directory at {path}: {cause}", diff --git a/tooling/cli/templates/mobile/ios/project.yml b/tooling/cli/templates/mobile/ios/project.yml index 8d98197cf58a..1caacb1e26b7 100644 --- a/tooling/cli/templates/mobile/ios/project.yml +++ b/tooling/cli/templates/mobile/ios/project.yml @@ -32,6 +32,7 @@ targets: - path: Sources - path: Assets.xcassets - path: Externals + - path: {{app.name}}_iOS - path: {{app.asset-dir}} buildPhase: resources type: folder @@ -58,6 +59,8 @@ targets: CFBundleVersion: {{apple.bundle-version}} {{~#each apple.plist-pairs}} {{this.key}}: {{this.value}}{{/each}} + entitlements: + path: {{app.name}}_iOS/{{app.name}}_iOS.entitlements scheme: environmentVariables: RUST_BACKTRACE: full From aba04fa823d70ff8df9bd22f8e6a25184689c3cb Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Tue, 18 Jul 2023 06:20:55 -0700 Subject: [PATCH 3/3] feat(build): add API to update the iOS entitlements file (#7448) --- .changes/update-entitlements-api.md | 5 +++++ core/tauri-build/Cargo.toml | 1 + core/tauri-build/src/mobile.rs | 34 +++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 .changes/update-entitlements-api.md diff --git a/.changes/update-entitlements-api.md b/.changes/update-entitlements-api.md new file mode 100644 index 000000000000..ccf53a63edf0 --- /dev/null +++ b/.changes/update-entitlements-api.md @@ -0,0 +1,5 @@ +--- +"tauri-build": patch:feat +--- + +Added the `mobile::update_entitlements` function for iOS. diff --git a/core/tauri-build/Cargo.toml b/core/tauri-build/Cargo.toml index e3d514607dbb..cb59fea4ce73 100644 --- a/core/tauri-build/Cargo.toml +++ b/core/tauri-build/Cargo.toml @@ -32,6 +32,7 @@ semver = "1" [target."cfg(target_os = \"macos\")".dependencies] swift-rs = { version = "1.0.5", features = [ "build" ] } +plist = "1" [features] codegen = [ "tauri-codegen", "quote" ] diff --git a/core/tauri-build/src/mobile.rs b/core/tauri-build/src/mobile.rs index 9b4e0b87e812..e10aef33b525 100644 --- a/core/tauri-build/src/mobile.rs +++ b/core/tauri-build/src/mobile.rs @@ -146,6 +146,40 @@ fn copy_folder(source: &Path, target: &Path, ignore_paths: &[&str]) -> Result<() Ok(()) } +#[cfg(target_os = "macos")] +fn update_plist_file, F: FnOnce(&mut plist::Dictionary)>( + path: P, + f: F, +) -> Result<()> { + let path = path.as_ref(); + if path.exists() { + let mut plist = plist::Value::from_file(path)?; + if let Some(dict) = plist.as_dictionary_mut() { + f(dict); + plist::to_file_xml(path, &plist)?; + } + } + + Ok(()) +} + +#[cfg(target_os = "macos")] +pub fn update_entitlements(f: F) -> Result<()> { + if let (Some(project_path), Ok(app_name)) = ( + var_os("TAURI_IOS_PROJECT_PATH").map(PathBuf::from), + var("TAURI_IOS_APP_NAME"), + ) { + update_plist_file( + project_path + .join(format!("{app_name}_iOS")) + .join(format!("{app_name}_iOS.entitlements")), + f, + )?; + } + + Ok(()) +} + pub(crate) fn generate_gradle_files(project_dir: PathBuf) -> Result<()> { let gradle_settings_path = project_dir.join("tauri.settings.gradle"); let app_build_gradle_path = project_dir.join("app").join("tauri.build.gradle.kts");