Skip to content

Commit

Permalink
Merge branch 'dev' into feat/plugin-config-env-var
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Jul 18, 2023
2 parents 813fe97 + aba04fa commit 7062b06
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 23 deletions.
6 changes: 6 additions & 0 deletions .changes/cli-ios-metadata-env-var.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 6 additions & 0 deletions .changes/ios-entitlements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-cli": patch:feat
"@tauri-apps/cli": patch:feat
---

Generate empty entitlements file for the iOS project.
5 changes: 5 additions & 0 deletions .changes/update-entitlements-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-build": patch:feat
---

Added the `mobile::update_entitlements` function for iOS.
1 change: 1 addition & 0 deletions core/tauri-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
34 changes: 34 additions & 0 deletions core/tauri-build/src/mobile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,40 @@ fn copy_folder(source: &Path, target: &Path, ignore_paths: &[&str]) -> Result<()
Ok(())
}

#[cfg(target_os = "macos")]
fn update_plist_file<P: AsRef<Path>, 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: FnOnce(&mut plist::Dictionary)>(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");
Expand Down
1 change: 0 additions & 1 deletion tooling/bundler/src/bundle/macos/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use crate::Settings;

use anyhow::Context;
use log::{info, warn};
use tauri_utils::config::BundleTypeRole;

use std::{
fs,
Expand Down
5 changes: 4 additions & 1 deletion tooling/cli/src/mobile/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}

Expand Down
27 changes: 6 additions & 21 deletions tooling/cli/src/mobile/ios/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
3 changes: 3 additions & 0 deletions tooling/cli/templates/mobile/ios/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ targets:
- path: Sources
- path: Assets.xcassets
- path: Externals
- path: {{app.name}}_iOS
- path: {{app.asset-dir}}
buildPhase: resources
type: folder
Expand All @@ -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
Expand Down

0 comments on commit 7062b06

Please sign in to comment.