From 6593f267b369b638d7f4b3ea6bff8740005e6711 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Wed, 31 Aug 2022 21:40:51 -0300 Subject: [PATCH] feat(cli): iOS simulator support on Intel based devices (#5112) --- core/tauri/src/manager.rs | 2 +- tooling/cli/Cargo.lock | 2 +- .../mobile/android/android_studio_script.rs | 5 +- tooling/cli/src/mobile/ios/project.rs | 14 +-- tooling/cli/src/mobile/ios/xcode_script.rs | 33 +---- tooling/cli/templates/mobile/ios/project.yml | 114 +----------------- 6 files changed, 14 insertions(+), 156 deletions(-) diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index 7cf82e59a..ef59d5453 100644 --- a/core/tauri/src/manager.rs +++ b/core/tauri/src/manager.rs @@ -858,7 +858,7 @@ impl WindowManager { builder.status(r.status()).body(r.bytes()?)? } Err(e) => { - debug_eprintln!("Failed to request {}: {}", url.path(), e); + debug_eprintln!("Failed to request {}: {}", url.as_str(), e); return Err(Box::new(e)); } } diff --git a/tooling/cli/Cargo.lock b/tooling/cli/Cargo.lock index 2d0cec6b2..1692bb078 100644 --- a/tooling/cli/Cargo.lock +++ b/tooling/cli/Cargo.lock @@ -293,7 +293,7 @@ checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" [[package]] name = "cargo-mobile" version = "0.1.0" -source = "git+https://github.com/tauri-apps/cargo-mobile?branch=dev#ff88cc91fbf008ee0b9b33c8e4bcb5c9b5b743e6" +source = "git+https://github.com/tauri-apps/cargo-mobile?branch=dev#4a28c9e2370c07b4cb83458e58da0d7bfe4e9b1e" dependencies = [ "cocoa", "colored 1.9.3", diff --git a/tooling/cli/src/mobile/android/android_studio_script.rs b/tooling/cli/src/mobile/android/android_studio_script.rs index cf3bc974a..be7bd52ac 100644 --- a/tooling/cli/src/mobile/android/android_studio_script.rs +++ b/tooling/cli/src/mobile/android/android_studio_script.rs @@ -1,4 +1,4 @@ -use super::{detect_target_ok, ensure_init, env, init_dot_cargo, with_config, MobileTarget}; +use super::{detect_target_ok, ensure_init, env, with_config, MobileTarget}; use crate::Result; use clap::Parser; @@ -32,11 +32,10 @@ pub fn command(options: Options) -> Result<()> { Profile::Debug }; - with_config(None, |app, config, metadata, cli_options| { + with_config(None, |_app, config, metadata, cli_options| { ensure_init(config.project_dir(), MobileTarget::Android)?; let env = env()?; - init_dot_cargo(app, Some((&env, config)))?; call_for_targets_with_fallback( options.targets.unwrap_or_default().iter(), diff --git a/tooling/cli/src/mobile/ios/project.rs b/tooling/cli/src/mobile/ios/project.rs index 5a44bb11b..841f8488e 100644 --- a/tooling/cli/src/mobile/ios/project.rs +++ b/tooling/cli/src/mobile/ios/project.rs @@ -50,18 +50,14 @@ pub fn gen( let ios_pods = metadata.ios().pods().unwrap_or_default(); let macos_pods = metadata.macos().pods().unwrap_or_default(); - let default_archs = [ - String::from("arm64"), - String::from("arm64-sim"), - String::from("x86_64"), - ]; + #[cfg(target_arch = "aarch64")] + let default_archs = ["arm64", "arm64-sim"]; + #[cfg(not(target_arch = "aarch64"))] + let default_archs = ["arm64", "x86_64"]; map.insert("file-groups", &source_dirs); map.insert("ios-frameworks", metadata.ios().frameworks()); - map.insert( - "ios-valid-archs", - metadata.ios().valid_archs().unwrap_or(&default_archs), - ); + map.insert("ios-valid-archs", default_archs); map.insert("ios-vendor-frameworks", metadata.ios().vendor_frameworks()); map.insert("ios-vendor-sdks", metadata.ios().vendor_sdks()); map.insert("macos-frameworks", metadata.macos().frameworks()); diff --git a/tooling/cli/src/mobile/ios/xcode_script.rs b/tooling/cli/src/mobile/ios/xcode_script.rs index ded473c65..1f2da48e3 100644 --- a/tooling/cli/src/mobile/ios/xcode_script.rs +++ b/tooling/cli/src/mobile/ios/xcode_script.rs @@ -1,4 +1,4 @@ -use super::{env, init_dot_cargo, with_config}; +use super::{env, with_config}; use crate::Result; use clap::Parser; @@ -41,9 +41,8 @@ pub fn command(options: Options) -> Result<()> { let profile = profile_from_configuration(&options.configuration); let macos = macos_from_platform(&options.platform); - with_config(None, |root_conf, config, metadata, cli_options| { + with_config(None, |_root_conf, config, metadata, cli_options| { let env = env()?; - init_dot_cargo(root_conf, None)?; // The `PATH` env var Xcode gives us is missing any additions // made by the user's profile, so we'll manually add cargo's // `PATH`. @@ -65,31 +64,6 @@ pub fn command(options: Options) -> Result<()> { let mut host_env = HashMap::<&str, &OsStr>::new(); - // Host flags that are used by build scripts - let (macos_isysroot, library_path) = { - let macos_sdk_root = options - .sdk_root - .join("../../../../MacOSX.platform/Developer/SDKs/MacOSX.sdk"); - if !macos_sdk_root.is_dir() { - return Err(anyhow::anyhow!( - "macOS SDK root was invalid. {0} doesn't exist or isn't a directory", - macos_sdk_root.display() - )); - } - ( - format!("-isysroot {}", macos_sdk_root.display()), - format!("{}/usr/lib", macos_sdk_root.display()), - ) - }; - host_env.insert("MAC_FLAGS", macos_isysroot.as_ref()); - host_env.insert("CFLAGS_x86_64_apple_darwin", macos_isysroot.as_ref()); - host_env.insert("CXXFLAGS_x86_64_apple_darwin", macos_isysroot.as_ref()); - - host_env.insert( - "OBJC_INCLUDE_PATH_x86_64_apple_darwin", - include_dir.as_os_str(), - ); - host_env.insert("RUST_BACKTRACE", "1".as_ref()); let macos_target = Target::macos(); @@ -116,9 +90,6 @@ pub fn command(options: Options) -> Result<()> { target_env.insert(cflags.as_ref(), isysroot.as_ref()); target_env.insert(cxxflags.as_ref(), isysroot.as_ref()); target_env.insert(objc_include_path.as_ref(), include_dir.as_ref()); - // Prevents linker errors in build scripts and proc macros: - // https://github.com/signalapp/libsignal-client/commit/02899cac643a14b2ced7c058cc15a836a2165b6d - target_env.insert("LIBRARY_PATH", library_path.as_ref()); let target = if macos { &macos_target diff --git a/tooling/cli/templates/mobile/ios/project.yml b/tooling/cli/templates/mobile/ios/project.yml index fb72413cb..af7263b22 100644 --- a/tooling/cli/templates/mobile/ios/project.yml +++ b/tooling/cli/templates/mobile/ios/project.yml @@ -3,7 +3,6 @@ options: bundleIdPrefix: {{reverse-domain app.domain}} deploymentTarget: iOS: {{apple.ios-version}} - macOS: {{apple.macos-version}} fileGroups: [{{join file-groups}}] configs: debug: debug @@ -71,8 +70,9 @@ targets: ENABLE_BITCODE: false ARCHS: [{{join ios-valid-archs}}] VALID_ARCHS: {{~#each ios-valid-archs}} {{this}} {{/each}} - LIBRARY_SEARCH_PATHS[sdk=iphoneos*]: $(inherited) "{{prefix-path "target/aarch64-apple-ios/$(CONFIGURATION)"}}" - LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*]: $(inherited) "{{prefix-path "target/aarch64-apple-ios-sim/$(CONFIGURATION)"}}" + 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)"}}" ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES: true groups: [app] dependencies: @@ -158,106 +158,6 @@ targets: {{~/each~}} {{~/if}} - {{app.name}}_macOS: - type: application - platform: macOS - sources: Sources - {{~#each macos-additional-targets}} - - path: {{prefix-path this}}{{/each}} - info: - path: {{app.name}}_macOS/Info.plist - properties: - NSHighResolutionCapable: true - scheme: - environmentVariables: - RUST_BACKTRACE: full - RUST_LOG: info - {{~#if ios-command-line-arguments}} - commandLineArguments: - {{~#each ios-command-line-arguments}} - "{{this}}": true - {{/each}}{{~/if}} - settings: - base: - LIBRARY_SEARCH_PATHS: $(inherited) "{{prefix-path "target/x86_64-apple-darwin/$(CONFIGURATION)"}}" - groups: [app] - dependencies: - - target: lib_{{app.name}}_macOS - embed: false - link: false - - framework: lib{{snake-case app.name}}.a - embed: false - {{~#each macos-vendor-frameworks}} - - framework: {{prefix-path this}}{{/each}} - {{~#each macos-vendor-sdks}} - - sdk: {{prefix-path this}}{{/each}} - - sdk: Metal.framework - {{~#each macos-frameworks}} - - sdk: {{this}}.framework{{/each}} - {{~#if macos-pre-build-scripts}} - preBuildScripts: - {{~#each macos-pre-build-scripts}}{{#if this.path}} - - path {{this.path}}{{/if}}{{#if this.script}} - - script: {{this.script}}{{/if}}{{#if this.name}} - name: {{this.name}}{{/if}}{{#if this.input-files}} - inputFiles: {{~#each this.input-files}} - - {{this}}{{/each}}{{/if}}{{#if this.output-files}} - outputFiles: {{~#each this.output-files}} - - {{this}}{{/each}}{{/if}}{{#if this.input-file-lists}} - inputFileLists: {{~#each this.output-files}} - - {{this}}{{/each}}{{/if}}{{#if this.output-file-lists}} - outputFileLists: {{~#each this.output-files}} - - {{this}}{{/each}}{{/if}}{{#if this.shell}} - shell: {{this.shell}}{{/if}}{{#if this.show-env-vars}} - showEnvVars: {{this.show_env_vars}}{{/if}}{{#if this.run-only-when-installing}} - runOnlyWhenInstalling: {{this.run-only-when-installing}}{{/if}}{{#if this.based-on-dependency-analysis}} - basedOnDependencyAnalysis: {{this.based-on-dependency-analysis}}{{/if}}{{#if this.discovered-dependency-file}} - discoveredDependencyFile: {{this.discovered-dependency-file}}{{/if}} - {{~/each~}} - {{~/if~}} - {{#if macos-post-compile-scripts}} - postCompileScripts: - {{~#each macos-post-compile-scripts}}{{#if this.path}} - - path {{this.path}}{{/if}}{{#if this.script}} - - script: {{this.script}}{{/if}}{{#if this.name}} - name: {{this.name}}{{/if}}{{#if this.input-files}} - inputFiles: {{~#each this.input-files}} - - {{this}}{{/each}}{{/if}}{{#if this.output-files}} - outputFiles: {{~#each this.output-files}} - - {{this}}{{/each}}{{/if}}{{#if this.input-file-lists}} - inputFileLists: {{~#each this.output-files}} - - {{this}}{{/each}}{{/if}}{{#if this.output-file-lists}} - outputFileLists: {{~#each this.output-files}} - - {{this}}{{/each}}{{/if}}{{#if this.shell}} - shell: {{this.shell}}{{/if}}{{#if this.show-env-vars}} - showEnvVars: {{this.show_env_vars}}{{/if}}{{#if this.run-only-when-installing}} - runOnlyWhenInstalling: {{this.run-only-when-installing}}{{/if}}{{#if this.based-on-dependency-analysis}} - basedOnDependencyAnalysis: {{this.based-on-dependency-analysis}}{{/if}}{{#if this.discovered-dependency-file}} - discoveredDependencyFile: {{this.discovered-dependency-file}}{{/if}} - {{~/each~}} - {{~/if~}} - {{#if macos-post-build-scripts}} - postBuildScripts: - {{~#each macos-post-build-scripts}}{{#if this.path}} - - path {{this.path}}{{/if}}{{#if this.script}} - - script: {{this.script}}{{/if}}{{#if this.name}} - name: {{this.name}}{{/if}}{{#if this.input-files}} - inputFiles: {{~#each this.input-files}} - - {{this}}{{/each}}{{/if}}{{#if this.output-files}} - outputFiles: {{~#each this.output-files}} - - {{this}}{{/each}}{{/if}}{{#if this.input-file-lists}} - inputFileLists: {{~#each this.output-files}} - - {{this}}{{/each}}{{/if}}{{#if this.output-file-lists}} - outputFileLists: {{~#each this.output-files}} - - {{this}}{{/each}}{{/if}}{{#if this.shell}} - shell: {{this.shell}}{{/if}}{{#if this.show-env-vars}} - showEnvVars: {{this.show_env_vars}}{{/if}}{{#if this.run-only-when-installing}} - runOnlyWhenInstalling: {{this.run-only-when-installing}}{{/if}}{{#if this.based-on-dependency-analysis}} - basedOnDependencyAnalysis: {{this.based-on-dependency-analysis}}{{/if}}{{#if this.discovered-dependency-file}} - discoveredDependencyFile: {{this.discovered-dependency-file}}{{/if}} - {{~/each~}} - {{~/if}} - lib_{{app.name}}_iOS: type: "" platform: iOS @@ -270,11 +170,3 @@ targets: arguments: {{ tauri-binary-args-str }} -v --platform ${PLATFORM_DISPLAY_NAME:?} --sdk-root ${SDKROOT:?} --configuration ${CONFIGURATION:?} ${FORCE_COLOR} ${ARCHS:?} passSettings: false # prevents evil linker errors workingDirectory: $(SRCROOT)/../.. - lib_{{app.name}}_macOS: - type: "" - platform: macOS - legacy: - toolPath: {{ tauri-binary }} - arguments: {{ tauri-binary-args-str }} -v --platform ${PLATFORM_DISPLAY_NAME:?} --sdk-root ${SDKROOT:?} --configuration ${CONFIGURATION:?} ${FORCE_COLOR} ${ARCHS:?} - passSettings: false - workingDirectory: $(SRCROOT)/../..