Skip to content

Commit

Permalink
feat: add iOS frameworks config option, closes #9962 (#10393)
Browse files Browse the repository at this point in the history
* feat: add iOS frameworks config option, closes #9962

* fix template

* typo
  • Loading branch information
lucasfernog authored Aug 2, 2024
1 parent b32295d commit a5bfbaa
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 14 deletions.
7 changes: 7 additions & 0 deletions .changes/ios-frameworks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri-utils": patch:feat
"@tauri-apps/cli": patch:feat
"tauri-cli": patch:feat
---

Added `bundle > iOS > frameworks` configuration to define a list of frameworks that are linked to the Xcode project when it is generated.
10 changes: 10 additions & 0 deletions core/tauri-config-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2896,6 +2896,16 @@
"description": "General configuration for the iOS target.",
"type": "object",
"properties": {
"frameworks": {
"description": "A list of strings indicating any iOS frameworks that need to be bundled with the application.\n\n Note that you need to recreate the iOS project for the changes to be applied.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"developmentTeam": {
"description": "The development team. This value is required for iOS development because code signing is enforced.\n The `APPLE_DEVELOPMENT_TEAM` environment variable can be set to overwrite it.",
"type": [
Expand Down
4 changes: 4 additions & 0 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1889,6 +1889,10 @@ pub struct TrayIconConfig {
#[cfg_attr(feature = "schema", derive(JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct IosConfig {
/// A list of strings indicating any iOS frameworks that need to be bundled with the application.
///
/// Note that you need to recreate the iOS project for the changes to be applied.
pub frameworks: Option<Vec<String>>,
/// The development team. This value is required for iOS development because code signing is enforced.
/// The `APPLE_DEVELOPMENT_TEAM` environment variable can be set to overwrite it.
#[serde(alias = "development-team")]
Expand Down
10 changes: 10 additions & 0 deletions tooling/cli/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2896,6 +2896,16 @@
"description": "General configuration for the iOS target.",
"type": "object",
"properties": {
"frameworks": {
"description": "A list of strings indicating any iOS frameworks that need to be bundled with the application.\n\n Note that you need to recreate the iOS project for the changes to be applied.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"developmentTeam": {
"description": "The development team. This value is required for iOS development because code signing is enforced.\n The `APPLE_DEVELOPMENT_TEAM` environment variable can be set to overwrite it.",
"type": [
Expand Down
49 changes: 43 additions & 6 deletions tooling/cli/src/mobile/ios/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use cargo_mobile2::{
env::Env,
opts::NoiseLevel,
os,
util::prompt,
util::{prompt, relativize_path},
};
use clap::{Parser, Subcommand};
use sublime_fuzzy::best_match;
Expand All @@ -27,7 +27,10 @@ use super::{
log_finished, read_options, setup_dev_config, CliOptions, OptionsHandle, Target as MobileTarget,
MIN_DEVICE_MATCH_SCORE,
};
use crate::{helpers::config::Config as TauriConfig, Result};
use crate::{
helpers::{app_paths::tauri_dir, config::Config as TauriConfig},
Result,
};

use std::{
env::{set_var, var_os},
Expand Down Expand Up @@ -104,7 +107,7 @@ pub fn command(cli: Cli, verbosity: u8) -> Result<()> {

pub fn get_config(
app: &App,
config: &TauriConfig,
tauri_config: &TauriConfig,
features: Option<&Vec<String>>,
cli_options: &CliOptions,
) -> (AppleConfig, AppleMetadata) {
Expand All @@ -119,7 +122,7 @@ pub fn get_config(
let raw = RawAppleConfig {
development_team: std::env::var(APPLE_DEVELOPMENT_TEAM_ENV_VAR_NAME)
.ok()
.or_else(|| config.bundle.ios.development_team.clone())
.or_else(|| tauri_config.bundle.ios.development_team.clone())
.or_else(|| {
let teams = find_development_teams().unwrap_or_default();
match teams.len() {
Expand All @@ -135,18 +138,52 @@ pub fn get_config(
}
}),
ios_features: ios_options.features.clone(),
bundle_version: config.version.clone(),
bundle_version_short: config.version.clone(),
bundle_version: tauri_config.version.clone(),
bundle_version_short: tauri_config.version.clone(),
ios_version: Some(TARGET_IOS_VERSION.into()),
..Default::default()
};
let config = AppleConfig::from_raw(app.clone(), Some(raw)).unwrap();

let tauri_dir = tauri_dir();

let mut vendor_frameworks = Vec::new();
let mut frameworks = Vec::new();
for framework in tauri_config
.bundle
.ios
.frameworks
.clone()
.unwrap_or_default()
{
let framework_path = PathBuf::from(&framework);
let ext = framework_path.extension().unwrap_or_default();
if ext.is_empty() {
frameworks.push(framework);
} else if ext == "framework" {
frameworks.push(
framework_path
.file_stem()
.unwrap()
.to_string_lossy()
.to_string(),
);
} else {
vendor_frameworks.push(
relativize_path(tauri_dir.join(framework_path), config.project_dir())
.to_string_lossy()
.to_string(),
);
}
}

let metadata = AppleMetadata {
supported: true,
ios: ApplePlatform {
cargo_args: Some(ios_options.args),
features: ios_options.features,
frameworks: Some(frameworks),
vendor_frameworks: Some(vendor_frameworks),
..Default::default()
},
macos: Default::default(),
Expand Down
13 changes: 5 additions & 8 deletions tooling/cli/templates/mobile/ios/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,16 @@ targets:
embed: false
{{~#each ios-libraries}}
- framework: {{this}}
embed: false{{/each}}
{{~#each ios-vendor-frameworks}}
- framework: {{prefix-path this}}{{/each}}
{{~#each ios-vendor-sdks}}
- sdk: {{prefix-path this}}{{/each}}
embed: false{{/each}}{{#if ios-vendor-frameworks}}{{~#each ios-vendor-frameworks}}
- framework: {{this}}{{/each}}{{/if}}{{#if ios-vendor-sdks}}{{~#each ios-vendor-sdks}}
- sdk: {{prefix-path this}}{{/each}}{{/if}}
- sdk: CoreGraphics.framework
- sdk: Metal.framework
- sdk: MetalKit.framework
- sdk: QuartzCore.framework
- sdk: Security.framework
- sdk: UIKit.framework
{{~#each ios-frameworks}}
- sdk: {{this}}.framework{{/each}}
- sdk: UIKit.framework{{#if this.ios-frameworks}}{{~#each ios-frameworks}}
- sdk: {{this}}.framework{{/each}}{{/if}}
- sdk: WebKit.framework
preBuildScripts:
{{~#each ios-pre-build-scripts}}{{#if this.path}}
Expand Down

0 comments on commit a5bfbaa

Please sign in to comment.