Skip to content

Commit a5bfbaa

Browse files
authored
feat: add iOS frameworks config option, closes #9962 (#10393)
* feat: add iOS frameworks config option, closes #9962 * fix template * typo
1 parent b32295d commit a5bfbaa

File tree

6 files changed

+79
-14
lines changed

6 files changed

+79
-14
lines changed

.changes/ios-frameworks.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri-utils": patch:feat
3+
"@tauri-apps/cli": patch:feat
4+
"tauri-cli": patch:feat
5+
---
6+
7+
Added `bundle > iOS > frameworks` configuration to define a list of frameworks that are linked to the Xcode project when it is generated.

core/tauri-config-schema/schema.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2896,6 +2896,16 @@
28962896
"description": "General configuration for the iOS target.",
28972897
"type": "object",
28982898
"properties": {
2899+
"frameworks": {
2900+
"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.",
2901+
"type": [
2902+
"array",
2903+
"null"
2904+
],
2905+
"items": {
2906+
"type": "string"
2907+
}
2908+
},
28992909
"developmentTeam": {
29002910
"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.",
29012911
"type": [

core/tauri-utils/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,6 +1889,10 @@ pub struct TrayIconConfig {
18891889
#[cfg_attr(feature = "schema", derive(JsonSchema))]
18901890
#[serde(rename_all = "camelCase", deny_unknown_fields)]
18911891
pub struct IosConfig {
1892+
/// A list of strings indicating any iOS frameworks that need to be bundled with the application.
1893+
///
1894+
/// Note that you need to recreate the iOS project for the changes to be applied.
1895+
pub frameworks: Option<Vec<String>>,
18921896
/// The development team. This value is required for iOS development because code signing is enforced.
18931897
/// The `APPLE_DEVELOPMENT_TEAM` environment variable can be set to overwrite it.
18941898
#[serde(alias = "development-team")]

tooling/cli/schema.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2896,6 +2896,16 @@
28962896
"description": "General configuration for the iOS target.",
28972897
"type": "object",
28982898
"properties": {
2899+
"frameworks": {
2900+
"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.",
2901+
"type": [
2902+
"array",
2903+
"null"
2904+
],
2905+
"items": {
2906+
"type": "string"
2907+
}
2908+
},
28992909
"developmentTeam": {
29002910
"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.",
29012911
"type": [

tooling/cli/src/mobile/ios/mod.rs

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use cargo_mobile2::{
1616
env::Env,
1717
opts::NoiseLevel,
1818
os,
19-
util::prompt,
19+
util::{prompt, relativize_path},
2020
};
2121
use clap::{Parser, Subcommand};
2222
use sublime_fuzzy::best_match;
@@ -27,7 +27,10 @@ use super::{
2727
log_finished, read_options, setup_dev_config, CliOptions, OptionsHandle, Target as MobileTarget,
2828
MIN_DEVICE_MATCH_SCORE,
2929
};
30-
use crate::{helpers::config::Config as TauriConfig, Result};
30+
use crate::{
31+
helpers::{app_paths::tauri_dir, config::Config as TauriConfig},
32+
Result,
33+
};
3134

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

105108
pub fn get_config(
106109
app: &App,
107-
config: &TauriConfig,
110+
tauri_config: &TauriConfig,
108111
features: Option<&Vec<String>>,
109112
cli_options: &CliOptions,
110113
) -> (AppleConfig, AppleMetadata) {
@@ -119,7 +122,7 @@ pub fn get_config(
119122
let raw = RawAppleConfig {
120123
development_team: std::env::var(APPLE_DEVELOPMENT_TEAM_ENV_VAR_NAME)
121124
.ok()
122-
.or_else(|| config.bundle.ios.development_team.clone())
125+
.or_else(|| tauri_config.bundle.ios.development_team.clone())
123126
.or_else(|| {
124127
let teams = find_development_teams().unwrap_or_default();
125128
match teams.len() {
@@ -135,18 +138,52 @@ pub fn get_config(
135138
}
136139
}),
137140
ios_features: ios_options.features.clone(),
138-
bundle_version: config.version.clone(),
139-
bundle_version_short: config.version.clone(),
141+
bundle_version: tauri_config.version.clone(),
142+
bundle_version_short: tauri_config.version.clone(),
140143
ios_version: Some(TARGET_IOS_VERSION.into()),
141144
..Default::default()
142145
};
143146
let config = AppleConfig::from_raw(app.clone(), Some(raw)).unwrap();
144147

148+
let tauri_dir = tauri_dir();
149+
150+
let mut vendor_frameworks = Vec::new();
151+
let mut frameworks = Vec::new();
152+
for framework in tauri_config
153+
.bundle
154+
.ios
155+
.frameworks
156+
.clone()
157+
.unwrap_or_default()
158+
{
159+
let framework_path = PathBuf::from(&framework);
160+
let ext = framework_path.extension().unwrap_or_default();
161+
if ext.is_empty() {
162+
frameworks.push(framework);
163+
} else if ext == "framework" {
164+
frameworks.push(
165+
framework_path
166+
.file_stem()
167+
.unwrap()
168+
.to_string_lossy()
169+
.to_string(),
170+
);
171+
} else {
172+
vendor_frameworks.push(
173+
relativize_path(tauri_dir.join(framework_path), config.project_dir())
174+
.to_string_lossy()
175+
.to_string(),
176+
);
177+
}
178+
}
179+
145180
let metadata = AppleMetadata {
146181
supported: true,
147182
ios: ApplePlatform {
148183
cargo_args: Some(ios_options.args),
149184
features: ios_options.features,
185+
frameworks: Some(frameworks),
186+
vendor_frameworks: Some(vendor_frameworks),
150187
..Default::default()
151188
},
152189
macos: Default::default(),

tooling/cli/templates/mobile/ios/project.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,16 @@ targets:
9797
embed: false
9898
{{~#each ios-libraries}}
9999
- framework: {{this}}
100-
embed: false{{/each}}
101-
{{~#each ios-vendor-frameworks}}
102-
- framework: {{prefix-path this}}{{/each}}
103-
{{~#each ios-vendor-sdks}}
104-
- sdk: {{prefix-path this}}{{/each}}
100+
embed: false{{/each}}{{#if ios-vendor-frameworks}}{{~#each ios-vendor-frameworks}}
101+
- framework: {{this}}{{/each}}{{/if}}{{#if ios-vendor-sdks}}{{~#each ios-vendor-sdks}}
102+
- sdk: {{prefix-path this}}{{/each}}{{/if}}
105103
- sdk: CoreGraphics.framework
106104
- sdk: Metal.framework
107105
- sdk: MetalKit.framework
108106
- sdk: QuartzCore.framework
109107
- sdk: Security.framework
110-
- sdk: UIKit.framework
111-
{{~#each ios-frameworks}}
112-
- sdk: {{this}}.framework{{/each}}
108+
- sdk: UIKit.framework{{#if this.ios-frameworks}}{{~#each ios-frameworks}}
109+
- sdk: {{this}}.framework{{/each}}{{/if}}
113110
- sdk: WebKit.framework
114111
preBuildScripts:
115112
{{~#each ios-pre-build-scripts}}{{#if this.path}}

0 commit comments

Comments
 (0)