feat(cli): iOS simulator support on Intel based devices (#5112)

This commit is contained in:
Lucas Fernandes Nogueira 2022-08-31 21:40:51 -03:00 committed by GitHub
parent 5d3242c496
commit 6593f267b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 156 deletions

View File

@ -858,7 +858,7 @@ impl<R: Runtime> WindowManager<R> {
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));
}
}

View File

@ -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",

View File

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

View File

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

View File

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

View File

@ -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)/../..