From 1e4a675843c486bddc11292d09fb766e98758514 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Mon, 12 Dec 2022 05:36:47 -0800 Subject: [PATCH] fix(cli): run on iOS device on Xcode 14 (#5807) --- .changes/fix-ios-run-xcode14.md | 6 +++ examples/api/src-tauri/Cargo.lock | 14 +++--- tooling/cli/src/info.rs | 1 - tooling/cli/src/mobile/ios/project.rs | 10 ++++ tooling/cli/src/mobile/ios/xcode_script.rs | 53 ++++++++++++++++---- tooling/cli/templates/mobile/ios/project.yml | 7 +-- 6 files changed, 71 insertions(+), 20 deletions(-) create mode 100644 .changes/fix-ios-run-xcode14.md diff --git a/.changes/fix-ios-run-xcode14.md b/.changes/fix-ios-run-xcode14.md new file mode 100644 index 000000000..592244de5 --- /dev/null +++ b/.changes/fix-ios-run-xcode14.md @@ -0,0 +1,6 @@ +--- +"cli.rs": patch +"cli.js": patch +--- + +Fixes running on device using Xcode 14. diff --git a/examples/api/src-tauri/Cargo.lock b/examples/api/src-tauri/Cargo.lock index 6f89c3e53..5c66e3081 100644 --- a/examples/api/src-tauri/Cargo.lock +++ b/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", diff --git a/tooling/cli/src/info.rs b/tooling/cli/src/info.rs index f63b620d8..b3e99cc0f 100644 --- a/tooling/cli/src/info.rs +++ b/tooling/cli/src/info.rs @@ -901,7 +901,6 @@ pub fn command(_options: Options) -> Result<()> { .map(|t| format!("{} (ID: {})", t.name, t.id)) .collect::>() .join(", ") - .to_string() }, ) .display(); diff --git a/tooling/cli/src/mobile/ios/project.rs b/tooling/cli/src/mobile/ios/project.rs index 4067be504..94ab10cf7 100644 --- a/tooling/cli/src/mobile/ios/project.rs +++ b/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| { diff --git a/tooling/cli/src/mobile/ios/xcode_script.rs b/tooling/cli/src/mobile/ios/xcode_script.rs index 7d2746f8c..5ce3443ab 100644 --- a/tooling/cli/src/mobile/ios/xcode_script.rs +++ b/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(()) }) diff --git a/tooling/cli/templates/mobile/ios/project.yml b/tooling/cli/templates/mobile/ios/project.yml index 31fe4bf97..92053c8fc 100644 --- a/tooling/cli/templates/mobile/ios/project.yml +++ b/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: