Browse Source

fix(cli): run on iOS device on Xcode 14 (#5807)

Lucas Fernandes Nogueira 2 years ago
parent
commit
1e4a675843

+ 6 - 0
.changes/fix-ios-run-xcode14.md

@@ -0,0 +1,6 @@
+---
+"cli.rs": patch
+"cli.js": patch
+---
+
+Fixes running on device using Xcode 14.

+ 7 - 7
examples/api/src-tauri/Cargo.lock

@@ -2935,7 +2935,7 @@ dependencies = [
 
 [[package]]
 name = "tauri"
-version = "1.2.2"
+version = "2.0.0-alpha.0"
 dependencies = [
  "android_logger",
  "anyhow",
@@ -3001,7 +3001,7 @@ dependencies = [
 
 [[package]]
 name = "tauri-build"
-version = "1.2.1"
+version = "2.0.0-alpha.0"
 dependencies = [
  "anyhow",
  "cargo_toml",
@@ -3017,7 +3017,7 @@ dependencies = [
 
 [[package]]
 name = "tauri-codegen"
-version = "1.2.1"
+version = "2.0.0-alpha.0"
 dependencies = [
  "base64",
  "brotli",
@@ -3042,7 +3042,7 @@ dependencies = [
 
 [[package]]
 name = "tauri-macros"
-version = "1.2.1"
+version = "2.0.0-alpha.0"
 dependencies = [
  "heck 0.4.0",
  "proc-macro2",
@@ -3054,7 +3054,7 @@ dependencies = [
 
 [[package]]
 name = "tauri-runtime"
-version = "0.12.1"
+version = "0.13.0-alpha.0"
 dependencies = [
  "gtk",
  "http",
@@ -3072,7 +3072,7 @@ dependencies = [
 
 [[package]]
 name = "tauri-runtime-wry"
-version = "0.12.2"
+version = "0.13.0-alpha.0"
 dependencies = [
  "cocoa",
  "gtk",
@@ -3090,7 +3090,7 @@ dependencies = [
 
 [[package]]
 name = "tauri-utils"
-version = "1.2.1"
+version = "2.0.0-alpha.0"
 dependencies = [
  "aes-gcm",
  "brotli",

+ 0 - 1
tooling/cli/src/info.rs

@@ -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();

+ 10 - 0
tooling/cli/src/mobile/ios/project.rs

@@ -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| {

+ 44 - 9
tooling/cli/src/mobile/ios/xcode_script.rs

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

+ 4 - 3
tooling/cli/templates/mobile/ios/project.yml

@@ -31,6 +31,7 @@ targets:
     sources:
       - path: Sources
       - path: Assets.xcassets
+      - path: Externals
       - path: {{app.asset-dir}}
         buildPhase: resources
         type: folder
@@ -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: