[ios] Fix example ios toolchain
If the minimum deployment target is not equal to the SDK version
(say deployment target of 14.0 using iOS 15.0 SDK) linking swift
code requires using compatibility libraries. Those are part of
the toolchain and not the SDK.
Fix the example to add the necessary path to `lib_dirs`.
Bug: none
Change-Id: Ie3ce15f851896f6623c09c88645e409b236754e8
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/11700
Reviewed-by: Brett Wilson <brettw@chromium.org>
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
diff --git a/examples/ios/build/BUILD.gn b/examples/ios/build/BUILD.gn
index 2831117..b6bb6de 100644
--- a/examples/ios/build/BUILD.gn
+++ b/examples/ios/build/BUILD.gn
@@ -82,7 +82,21 @@
],
"json")
+ _lib_swift_dir = "${_sdk_info.toolchain_path}/usr/lib/swift"
+ if (current_os == "ios") {
+ if (_sdk_info.is_simulator) {
+ _system_lib_swift_dir = "$_lib_swift_dir/iphonesimulator"
+ } else {
+ _system_lib_swift_dir = "$_lib_swift_dir/iphoneos"
+ }
+ } else {
+ _system_lib_swift_dir = "$_lib_swift_dir/macosx"
+ }
+
config("swift_libdir") {
- lib_dirs = [ "${_sdk_info.sdk_path}/usr/lib/swift" ]
+ lib_dirs = [
+ "${_sdk_info.sdk_path}/usr/lib/swift",
+ _system_lib_swift_dir,
+ ]
}
}
diff --git a/examples/ios/build/config/ios/scripts/sdk_info.py b/examples/ios/build/config/ios/scripts/sdk_info.py
index 827aee0..831a3ed 100644
--- a/examples/ios/build/config/ios/scripts/sdk_info.py
+++ b/examples/ios/build/config/ios/scripts/sdk_info.py
@@ -6,6 +6,7 @@
import argparse
import json
+import os
import re
import subprocess
import sys
@@ -75,6 +76,11 @@
['xcrun', '--sdk', sdk, '--show-sdk-' + info]).strip()
+def GetDeveloperDir():
+ """Returns the developer dir."""
+ return subprocess.check_output(['xcode-select', '-print-path']).strip()
+
+
def GetSDKInfoForCpu(target_cpu, sdk_version, deployment_target):
"""Returns a dictionary with information about the SDK."""
platform = GetPlatform(target_cpu)
@@ -97,6 +103,8 @@
sdk_info['sdk'] = effective_sdk
sdk_info['sdk_build'] = ExtractSDKInfo('build-version', effective_sdk)
sdk_info['sdk_path'] = ExtractSDKInfo('path', effective_sdk)
+ sdk_info['toolchain_path'] = os.path.join(
+ GetDeveloperDir(), 'Toolchains/XcodeDefault.xctoolchain')
sdk_info['sdk_version'] = sdk_version
sdk_info['target'] = target
sdk_info['xcode_build'] = xcode_build