Skip to content

Commit 8dc81b6

Browse files
authored
feat(core): add option for custom Xcode project template (XcodeGen) (#10496)
1 parent 02c00ab commit 8dc81b6

File tree

6 files changed

+40
-1
lines changed

6 files changed

+40
-1
lines changed
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-cli": patch:feat
4+
"@tauri-apps/cli": patch:feat
5+
---
6+
7+
Added `bundle > ios > template` configuration option for custom Xcode project YML Handlebars template using XcodeGen.

core/tauri-config-schema/schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,6 +2900,13 @@
29002900
"description": "General configuration for the iOS target.",
29012901
"type": "object",
29022902
"properties": {
2903+
"template": {
2904+
"description": "A custom [XcodeGen] project.yml template to use.\n\n [XcodeGen]: <https://github.com/yonaskolb/XcodeGen>",
2905+
"type": [
2906+
"string",
2907+
"null"
2908+
]
2909+
},
29032910
"frameworks": {
29042911
"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.",
29052912
"type": [

core/tauri-utils/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,10 @@ pub struct TrayIconConfig {
18931893
#[cfg_attr(feature = "schema", derive(JsonSchema))]
18941894
#[serde(rename_all = "camelCase", deny_unknown_fields)]
18951895
pub struct IosConfig {
1896+
/// A custom [XcodeGen] project.yml template to use.
1897+
///
1898+
/// [XcodeGen]: <https://github.com/yonaskolb/XcodeGen>
1899+
pub template: Option<PathBuf>,
18961900
/// A list of strings indicating any iOS frameworks that need to be bundled with the application.
18971901
///
18981902
/// Note that you need to recreate the iOS project for the changes to be applied.

tooling/cli/schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,6 +2900,13 @@
29002900
"description": "General configuration for the iOS target.",
29012901
"type": "object",
29022902
"properties": {
2903+
"template": {
2904+
"description": "A custom [XcodeGen] project.yml template to use.\n\n [XcodeGen]: <https://github.com/yonaskolb/XcodeGen>",
2905+
"type": [
2906+
"string",
2907+
"null"
2908+
]
2909+
},
29032910
"frameworks": {
29042911
"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.",
29052912
"type": [

tooling/cli/src/mobile/init.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ pub fn exec(
221221
super::ios::get_config(&app, tauri_config_, None, &Default::default());
222222
map.insert("apple", &config);
223223
super::ios::project::gen(
224+
tauri_config_,
224225
&config,
225226
&metadata,
226227
(handlebars, map),

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
use crate::{helpers::template, Result};
5+
use crate::{
6+
helpers::{config::Config as TauriConfig, template},
7+
Result,
8+
};
69
use anyhow::Context;
710
use cargo_mobile2::{
811
apple::{
@@ -27,6 +30,7 @@ const TEMPLATE_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/templates/mobile
2730
// unprefixed app_root seems pretty dangerous!!
2831
// TODO: figure out what cargo-mobile meant by that
2932
pub fn gen(
33+
tauri_config: &TauriConfig,
3034
config: &Config,
3135
metadata: &Metadata,
3236
(handlebars, mut map): (Handlebars, template::JsonMap),
@@ -164,6 +168,15 @@ pub fn gen(
164168
)
165169
.with_context(|| "failed to process template")?;
166170

171+
if let Some(template_path) = tauri_config.bundle.ios.template.as_ref() {
172+
let template = std::fs::read_to_string(template_path)
173+
.context("failed to read custom Xcode project template")?;
174+
let mut output_file = std::fs::File::create(dest.join("project.yml"))?;
175+
handlebars
176+
.render_template_to_write(&template, map.inner(), &mut output_file)
177+
.expect("Failed to render template");
178+
}
179+
167180
let mut dirs_to_create = asset_catalogs.to_vec();
168181
dirs_to_create.push(dest.join(DEFAULT_ASSET_DIR));
169182
dirs_to_create.push(dest.join("Externals"));

0 commit comments

Comments
 (0)