Skip to content

Commit

Permalink
fix(cli): run on iOS device on Xcode 14 (#5807)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Dec 12, 2022
1 parent 2620ab2 commit 1e4a675
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 20 deletions.
6 changes: 6 additions & 0 deletions .changes/fix-ios-run-xcode14.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"cli.rs": patch
"cli.js": patch
---

Fixes running on device using Xcode 14.
14 changes: 7 additions & 7 deletions examples/api/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion tooling/cli/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,6 @@ pub fn command(_options: Options) -> Result<()> {
.map(|t| format!("{} (ID: {})", t.name, t.id))
.collect::<Vec<String>>()
.join(", ")
.to_string()
},
)
.display();
Expand Down
10 changes: 10 additions & 0 deletions tooling/cli/src/mobile/ios/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ pub fn gen(
})?;
}

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()
)
})?;
}

// Create all asset catalog directories if they don't already exist
for dir in asset_catalogs {
std::fs::create_dir_all(dir).map_err(|cause| {
Expand Down
53 changes: 44 additions & 9 deletions tooling/cli/src/mobile/ios/xcode_script.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use super::{env, with_config};
use crate::Result;
use clap::Parser;
use crate::{
helpers::config::get as get_config,
interface::{AppInterface, AppSettings, Interface, Options as InterfaceOptions},
Result,
};

use clap::Parser;
use heck::AsSnakeCase;
use tauri_mobile::{apple::target::Target, opts::Profile, util};

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

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

let tauri_config = get_config(None)?;

for arch in options.arches {
// Set target-specific flags
let triple = match arch.as_str() {
"arm64" => "aarch64_apple_ios",
"arm64-sim" => "aarch64_apple_ios_sim",
"x86_64" => "x86_64_apple_ios",
let (env_triple, rust_triple) = match arch.as_str() {
"arm64" => ("aarch64_apple_ios", "aarch64-apple-ios"),
"arm64-sim" => ("aarch64_apple_ios_sim", "aarch64-apple-ios-sim"),
"x86_64" => ("x86_64_apple_ios", "x86_64-apple-ios"),
"Simulator" => continue,
_ => {
return Err(anyhow::anyhow!(
Expand All @@ -138,9 +145,15 @@ pub fn command(options: Options) -> Result<()> {
))
}
};
let cflags = format!("CFLAGS_{}", triple);
let cxxflags = format!("CFLAGS_{}", triple);
let objc_include_path = format!("OBJC_INCLUDE_PATH_{}", triple);

let interface = AppInterface::new(
tauri_config.lock().unwrap().as_ref().unwrap(),
Some(rust_triple.into()),
)?;

let cflags = format!("CFLAGS_{}", env_triple);
let cxxflags = format!("CFLAGS_{}", env_triple);
let objc_include_path = format!("OBJC_INCLUDE_PATH_{}", env_triple);
let mut target_env = host_env.clone();
target_env.insert(cflags.as_ref(), isysroot.as_ref());
target_env.insert(cxxflags.as_ref(), isysroot.as_ref());
Expand All @@ -165,6 +178,28 @@ pub fn command(options: Options) -> Result<()> {
&env,
target_env,
)?;

let bin_path = interface
.app_settings()
.app_binary_path(&InterfaceOptions {
debug: matches!(profile, Profile::Debug),
target: Some(rust_triple.into()),
..Default::default()
})?;
let out_dir = bin_path.parent().unwrap();

std::fs::create_dir_all(format!(
"gen/apple/Externals/{rust_triple}/{}",
profile.as_str()
))?;
std::fs::copy(
out_dir.join(format!("lib{}.a", AsSnakeCase(config.app().name()))),
format!(
"gen/apple/Externals/{rust_triple}/{}/lib{}.a",
profile.as_str(),
AsSnakeCase(config.app().name())
),
)?;
}
Ok(())
})
Expand Down
7 changes: 4 additions & 3 deletions tooling/cli/templates/mobile/ios/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ targets:
sources:
- path: Sources
- path: Assets.xcassets
- path: Externals
- path: {{app.asset-dir}}
buildPhase: resources
type: folder
Expand Down Expand Up @@ -71,9 +72,9 @@ targets:
ENABLE_BITCODE: false
ARCHS: [{{join ios-valid-archs}}]
VALID_ARCHS: {{~#each ios-valid-archs}} {{this}} {{/each}}
LIBRARY_SEARCH_PATHS[arch=x86_64]: $(inherited) "{{prefix-path "target/x86_64-apple-ios/$(CONFIGURATION)"}}"
LIBRARY_SEARCH_PATHS[arch=arm64]: $(inherited) "{{prefix-path "target/aarch64-apple-ios/$(CONFIGURATION)"}}"
LIBRARY_SEARCH_PATHS[arch=arm64-sim]: $(inherited) "{{prefix-path "target/aarch64-apple-ios-sim/$(CONFIGURATION)"}}"
LIBRARY_SEARCH_PATHS[arch=x86_64]: $(inherited) $(PROJECT_DIR)/Externals/x86_64-apple-ios/$(CONFIGURATION)
LIBRARY_SEARCH_PATHS[arch=arm64]: $(inherited) $(PROJECT_DIR)/Externals/aarch64-apple-ios/$(CONFIGURATION)
LIBRARY_SEARCH_PATHS[arch=arm64-sim]: $(inherited) $(PROJECT_DIR)/Externals/aarch64-apple-ios-sim/$(CONFIGURATION)
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES: true
groups: [app]
dependencies:
Expand Down

0 comments on commit 1e4a675

Please sign in to comment.