Skip to content

Commit 1e4a675

Browse files
authored
fix(cli): run on iOS device on Xcode 14 (#5807)
1 parent 2620ab2 commit 1e4a675

File tree

6 files changed

+71
-20
lines changed

6 files changed

+71
-20
lines changed

.changes/fix-ios-run-xcode14.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"cli.rs": patch
3+
"cli.js": patch
4+
---
5+
6+
Fixes running on device using Xcode 14.

examples/api/src-tauri/Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/cli/src/info.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,6 @@ pub fn command(_options: Options) -> Result<()> {
901901
.map(|t| format!("{} (ID: {})", t.name, t.id))
902902
.collect::<Vec<String>>()
903903
.join(", ")
904-
.to_string()
905904
},
906905
)
907906
.display();

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ pub fn gen(
158158
})?;
159159
}
160160

161+
let externals_dir = dest.join("Externals");
162+
if !externals_dir.is_dir() {
163+
create_dir_all(&externals_dir).map_err(|cause| {
164+
anyhow::anyhow!(
165+
"failed to create Externals dir {path}: {cause}",
166+
path = externals_dir.display()
167+
)
168+
})?;
169+
}
170+
161171
// Create all asset catalog directories if they don't already exist
162172
for dir in asset_catalogs {
163173
std::fs::create_dir_all(dir).map_err(|cause| {

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

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
use super::{env, with_config};
2-
use crate::Result;
3-
use clap::Parser;
2+
use crate::{
3+
helpers::config::get as get_config,
4+
interface::{AppInterface, AppSettings, Interface, Options as InterfaceOptions},
5+
Result,
6+
};
47

8+
use clap::Parser;
9+
use heck::AsSnakeCase;
510
use tauri_mobile::{apple::target::Target, opts::Profile, util};
611

712
use std::{collections::HashMap, ffi::OsStr, path::PathBuf};
@@ -124,12 +129,14 @@ pub fn command(options: Options) -> Result<()> {
124129

125130
let isysroot = format!("-isysroot {}", options.sdk_root.display());
126131

132+
let tauri_config = get_config(None)?;
133+
127134
for arch in options.arches {
128135
// Set target-specific flags
129-
let triple = match arch.as_str() {
130-
"arm64" => "aarch64_apple_ios",
131-
"arm64-sim" => "aarch64_apple_ios_sim",
132-
"x86_64" => "x86_64_apple_ios",
136+
let (env_triple, rust_triple) = match arch.as_str() {
137+
"arm64" => ("aarch64_apple_ios", "aarch64-apple-ios"),
138+
"arm64-sim" => ("aarch64_apple_ios_sim", "aarch64-apple-ios-sim"),
139+
"x86_64" => ("x86_64_apple_ios", "x86_64-apple-ios"),
133140
"Simulator" => continue,
134141
_ => {
135142
return Err(anyhow::anyhow!(
@@ -138,9 +145,15 @@ pub fn command(options: Options) -> Result<()> {
138145
))
139146
}
140147
};
141-
let cflags = format!("CFLAGS_{}", triple);
142-
let cxxflags = format!("CFLAGS_{}", triple);
143-
let objc_include_path = format!("OBJC_INCLUDE_PATH_{}", triple);
148+
149+
let interface = AppInterface::new(
150+
tauri_config.lock().unwrap().as_ref().unwrap(),
151+
Some(rust_triple.into()),
152+
)?;
153+
154+
let cflags = format!("CFLAGS_{}", env_triple);
155+
let cxxflags = format!("CFLAGS_{}", env_triple);
156+
let objc_include_path = format!("OBJC_INCLUDE_PATH_{}", env_triple);
144157
let mut target_env = host_env.clone();
145158
target_env.insert(cflags.as_ref(), isysroot.as_ref());
146159
target_env.insert(cxxflags.as_ref(), isysroot.as_ref());
@@ -165,6 +178,28 @@ pub fn command(options: Options) -> Result<()> {
165178
&env,
166179
target_env,
167180
)?;
181+
182+
let bin_path = interface
183+
.app_settings()
184+
.app_binary_path(&InterfaceOptions {
185+
debug: matches!(profile, Profile::Debug),
186+
target: Some(rust_triple.into()),
187+
..Default::default()
188+
})?;
189+
let out_dir = bin_path.parent().unwrap();
190+
191+
std::fs::create_dir_all(format!(
192+
"gen/apple/Externals/{rust_triple}/{}",
193+
profile.as_str()
194+
))?;
195+
std::fs::copy(
196+
out_dir.join(format!("lib{}.a", AsSnakeCase(config.app().name()))),
197+
format!(
198+
"gen/apple/Externals/{rust_triple}/{}/lib{}.a",
199+
profile.as_str(),
200+
AsSnakeCase(config.app().name())
201+
),
202+
)?;
168203
}
169204
Ok(())
170205
})

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ targets:
3131
sources:
3232
- path: Sources
3333
- path: Assets.xcassets
34+
- path: Externals
3435
- path: {{app.asset-dir}}
3536
buildPhase: resources
3637
type: folder
@@ -71,9 +72,9 @@ targets:
7172
ENABLE_BITCODE: false
7273
ARCHS: [{{join ios-valid-archs}}]
7374
VALID_ARCHS: {{~#each ios-valid-archs}} {{this}} {{/each}}
74-
LIBRARY_SEARCH_PATHS[arch=x86_64]: $(inherited) "{{prefix-path "target/x86_64-apple-ios/$(CONFIGURATION)"}}"
75-
LIBRARY_SEARCH_PATHS[arch=arm64]: $(inherited) "{{prefix-path "target/aarch64-apple-ios/$(CONFIGURATION)"}}"
76-
LIBRARY_SEARCH_PATHS[arch=arm64-sim]: $(inherited) "{{prefix-path "target/aarch64-apple-ios-sim/$(CONFIGURATION)"}}"
75+
LIBRARY_SEARCH_PATHS[arch=x86_64]: $(inherited) $(PROJECT_DIR)/Externals/x86_64-apple-ios/$(CONFIGURATION)
76+
LIBRARY_SEARCH_PATHS[arch=arm64]: $(inherited) $(PROJECT_DIR)/Externals/aarch64-apple-ios/$(CONFIGURATION)
77+
LIBRARY_SEARCH_PATHS[arch=arm64-sim]: $(inherited) $(PROJECT_DIR)/Externals/aarch64-apple-ios-sim/$(CONFIGURATION)
7778
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES: true
7879
groups: [app]
7980
dependencies:

0 commit comments

Comments
 (0)