Commit aa2bfd80 authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

[ios] Fix compiler and linker flags for "catalyst" environment

The compiler needs additional flags `-isystem ...` and `-iframework ...`
to point to the iOS support headers and libraries to build iOS apps with
the macOS SDK (which is how "catalyst" builds work).

The app build for "catalyst" environment have the same bundle structure
as a regular macOS app, so the linker flag for `-rpath ...` needs to be
adjusted to work in that environment.

Bug: 1138425
Change-Id: I4cb8126d111a825408d5a63f248e56cfca99de8a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2498546
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarMike Pinkerton <pinkerton@chromium.org>
Auto-Submit: Sylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821760}
parent ec9ffdf5
......@@ -133,7 +133,8 @@ config("debug") {
# builds, and we have to tell it to turn it off.
defines += [ "_HAS_ITERATOR_DEBUGGING=0" ]
}
} else if ((is_linux || is_chromeos) && current_cpu == "x64" && enable_iterator_debugging) {
} else if ((is_linux || is_chromeos) && current_cpu == "x64" &&
enable_iterator_debugging) {
# Enable libstdc++ debugging facilities to help catch problems early, see
# http://crbug.com/65151 .
# TODO(phajdan.jr): Should we enable this for all of POSIX?
......@@ -347,7 +348,10 @@ config("shared_library_config") {
} else if (is_mac) {
configs += [ "//build/config/mac:mac_dynamic_flags" ]
} else if (is_ios) {
configs += [ "//build/config/ios:ios_dynamic_flags" ]
configs += [
"//build/config/ios:ios_dynamic_flags",
"//build/config/ios:ios_shared_library_flags",
]
} else if (is_chromecast) {
configs += [ "//build/config/chromecast:shared_library_config" ]
} else if (is_linux || is_chromeos || current_os == "aix") {
......
......@@ -3,7 +3,6 @@
# found in the LICENSE file.
import("//build/config/ios/ios_sdk.gni")
import("//build/config/sysroot.gni")
import("//build/toolchain/toolchain.gni")
declare_args() {
......@@ -27,7 +26,7 @@ declare_args() {
# is applied to all targets. It is here to separate out the logic.
config("compiler") {
# These flags are shared between the C compiler and linker.
common_ios_flags = []
common_flags = []
# CPU architecture.
if (current_cpu == "x64") {
......@@ -45,15 +44,19 @@ config("compiler") {
# Environment.
if (target_environment == "simulator") {
triplet_environment = "-simulator"
} else {
} else if (target_environment == "device") {
triplet_environment = ""
} else if (target_environment == "catalyst") {
triplet_environment = "-macabi"
} else {
assert(false, "unsupported environment: $target_environment")
}
# OS.
triplet_os = "apple-ios"
# Set target.
common_ios_flags = [
common_flags = [
"-target",
"$triplet_cpu-$triplet_os$ios_deployment_target$triplet_environment",
]
......@@ -63,9 +66,9 @@ config("compiler") {
# when their commandline changes). Nothing should ever read this define.
defines = [ "CR_XCODE_VERSION=$xcode_version" ]
asmflags = common_ios_flags
cflags = common_ios_flags
swiftflags = common_ios_flags
asmflags = common_flags
cflags = common_flags
swiftflags = common_flags
swiftflags += [
"-swift-version",
......@@ -76,7 +79,7 @@ config("compiler") {
# an Objective C struct won't be called, which is very bad.
cflags_objcc = [ "-fobjc-call-cxx-cdtors" ]
ldflags = common_ios_flags
ldflags = common_flags
}
# This is included by reference in the //build/config/compiler:runtime_library
......@@ -84,20 +87,33 @@ config("compiler") {
# that is iOS-only. Please see that target for advice on what should go in
# :runtime_library vs. :compiler.
config("runtime_library") {
_sysroot_path = sysroot
# The variable ios_sdk_path may be relative to root_out_dir on the bots. As
# it is passed to the compiler via cflags, ldflags which do not rebase the
# values (since they are compiler flags, not paths), it may be required to
# rebase it. Use a local variable to avoid repeating the rebase invocation.
_sdk_root = ios_sdk_path
if (ios_enable_relative_sdk_path) {
_sysroot_path = rebase_path(sysroot, root_build_dir)
_sdk_root = rebase_path(ios_sdk_path, root_build_dir)
}
common_flags = [
"-isysroot",
_sysroot_path,
_sdk_root,
]
swiftflags = [
"-sdk",
_sysroot_path,
_sdk_root,
]
if (target_environment == "catalyst") {
common_flags += [
"-isystem",
"$_sdk_root/System/iOSSupport/usr/include",
"-iframework",
"$_sdk_root/System/iOSSupport/System/Library/Frameworks",
]
}
if (use_xcode_clang && enable_ios_bitcode && target_environment == "device") {
if (is_debug) {
common_flags += [ "-fembed-bitcode-marker" ]
......@@ -112,11 +128,52 @@ config("runtime_library") {
}
config("ios_executable_flags") {
ldflags = []
# On "catalyst", the bundle structure is different (uses the same structure
# as a regular macOS app), so an additional -rpath is required.
if (target_environment == "catalyst") {
ldflags += [ "-Wl,-rpath,@loader_path/../Frameworks" ]
}
ldflags += [ "-Wl,-rpath,@executable_path/Frameworks" ]
}
config("ios_extension_executable_flags") {
configs = default_executable_configs
ldflags = [
"-e",
"_NSExtensionMain",
"-fapplication-extension",
]
# On "catalyst", the bundle structure is different (uses the same structure
# as a regular macOS app), so an additional -rpath is required.
if (target_environment == "catalyst") {
ldflags += [ "-Wl,-rpath,@loader_path/../Frameworks" ]
}
ldflags += [ "-Wl,-rpath,@executable_path/Frameworks" ]
}
config("ios_dynamic_flags") {
ldflags = [ "-Wl,-ObjC" ] # Always load Objective-C categories and class.
lib_dirs = [ "$sysroot/usr/lib/swift" ]
ldflags = [
# Always load Objective-C categories and class.
"-Wl,-ObjC",
# Uses version 2 of Objective-C ABI.
"-Wl,-objc_abi_version,2",
]
lib_dirs = [ "$ios_sdk_path/usr/lib/swift" ]
}
config("ios_shared_library_flags") {
ldflags = [
"-Wl,-rpath,@executable_path/Frameworks",
"-Wl,-rpath,@loader_path/Frameworks",
]
}
config("xctest_config") {
......
......@@ -126,8 +126,11 @@ if (ios_sdk_path == "") {
} else if (target_environment == "device") {
ios_sdk_name = "iphoneos"
ios_sdk_platform = "iPhoneOS"
} else if (target_environment == "catalyst") {
ios_sdk_name = "macosx"
ios_sdk_platform = "MacOSX"
} else {
assert("unsupported target_environment: $target_environment")
assert(false, "unsupported environment: $target_environment")
}
ios_sdk_info_args = [ "--get_sdk_info" ]
......
......@@ -696,32 +696,6 @@ template("ios_app_bundle") {
}
frameworks += [ "UIKit.framework" ]
if (!defined(ldflags)) {
ldflags = []
}
ldflags += [
"-Xlinker",
"-rpath",
"-Xlinker",
"@executable_path/Frameworks",
"-Xlinker",
"-objc_abi_version",
"-Xlinker",
"2",
]
# Application extension may share private frameworks with the application
# itself, so they need to look in both their own bundle and the surrounding
# app bundle for the frameworks.
if (!_is_app_bundle) {
ldflags += [
"-Xlinker",
"-rpath",
"-Xlinker",
"@executable_path/../../Frameworks",
]
}
if (target_environment == "simulator") {
deps += [ ":$_generate_entitlements_target($default_toolchain)" ]
......@@ -733,16 +707,8 @@ template("ios_app_bundle") {
if (!defined(ldflags)) {
ldflags = []
}
ldflags += [
"-Xlinker",
"-sectcreate",
"-Xlinker",
"__TEXT",
"-Xlinker",
"__entitlements",
"-Xlinker",
rebase_path(_generate_entitlements_output, root_build_dir),
]
ldflags += [ "-Wl,-sectcreate,__TEXT,__entitlements," +
rebase_path(_generate_entitlements_output, root_build_dir) ]
}
output_name = _output_name
......@@ -979,22 +945,11 @@ template("ios_appex_bundle") {
"product_type",
])
product_type = _ios_xcode_appex_bundle_id
# Add linker flags required for an application extension (determined by
# inspecting the link command-line when using Xcode 9.0+).
if (!defined(ldflags)) {
ldflags = []
}
ldflags += [
"-e",
"_NSExtensionMain",
"-fapplication-extension",
]
}
}
set_defaults("ios_appex_bundle") {
configs = default_executable_configs
configs = [ "//build/config/ios:ios_extension_executable_flags" ]
}
# Template to compile .xib and .storyboard files.
......@@ -1354,16 +1309,8 @@ template("ios_framework_bundle") {
if (!defined(ldflags)) {
ldflags = []
}
ldflags += [
"-Xlinker",
"-install_name",
"-Xlinker",
"@rpath/$_output_name.framework/$_output_name",
"-Xlinker",
"-objc_abi_version",
"-Xlinker",
"2",
]
ldflags +=
[ "-Wl,-install_name,@rpath/$_output_name.framework/$_output_name" ]
output_extension = ""
output_name = _output_name
......@@ -1889,20 +1836,6 @@ template("ios_xctest_test") {
}
bundle_deps += [ ":$_xctest_bundle" ]
}
if (!defined(ldflags)) {
ldflags = []
}
ldflags += [
"-Xlinker",
"-rpath",
"-Xlinker",
"@executable_path/Frameworks",
"-Xlinker",
"-rpath",
"-Xlinker",
"@loader_path/Frameworks",
]
}
}
......
......@@ -41,14 +41,8 @@ template("ios_eg2_test_app_host") {
ldflags = []
}
ldflags += [
"-Xlinker",
"-rpath",
"-Xlinker",
"@executable_path/Frameworks",
"-Xlinker",
"-rpath",
"-Xlinker",
"@loader_path/Frameworks",
"-Wl,-rpath,@executable_path/Frameworks",
"-Wl,-rpath,@loader_path/Frameworks",
]
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment