xref: /aosp_15_r20/external/angle/build/config/ios/ios_sdk.gni (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1# Copyright 2015 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/config/apple/mobile_config.gni")
6import("//build/config/ios/ios_sdk_overrides.gni")
7import("//build/toolchain/rbe.gni")
8import("//build/toolchain/siso.gni")
9import("//build/toolchain/toolchain.gni")
10import("//build_overrides/build.gni")
11
12assert(current_os == "ios")
13assert(use_system_xcode, "Hermetic xcode doesn't work for ios.")
14
15declare_args() {
16  # SDK path to use. When empty this will use the default SDK based on the
17  # value of target_environment.
18  ios_bin_path = ""
19  ios_sdk_path = ""
20  ios_sdk_name = ""
21  ios_sdk_version = ""
22  ios_sdk_platform = ""
23  ios_sdk_platform_path = ""
24  ios_toolchains_path = ""
25  xcode_version = ""
26  xcode_version_int = 0
27  xcode_build = ""
28  machine_os_build = ""
29
30  # Set DEVELOPER_DIR while running sdk_info.py.
31  ios_sdk_developer_dir = ""
32
33  # Set to true if building an app extension.
34  ios_is_app_extension = false
35}
36
37# Building XCTests requires copying XCTRunner.app which is part of the iOS
38# SDK (and shipped inside Xcode.app) into the application. When using the
39# system installation of Xcode, those files are outside of the checkout.
40# Using absolute path works with gn, however the distributed build system
41# requires that all paths are relative to the checkout. This is faked by
42# using symbolic links to the SDK inside of Xcode. Additionally, each build
43# directory may use a distinct version of Xcode (e.g. to build with beta),
44# so the symlink needs to be present in the $root_build_dir. However, when
45# doing that, we need to list inputs pointing to file in $root_build_dir,
46# and gn requires all files in $root_build_dir to be listed as outputs of
47# another target.
48#
49# To fulfill all of those requirements, we 1. create symlinks pointing to
50# the SDK files in Xcode, 2. declare a target listing the files as outputs
51# (the target is a script that does nothing, it only pretends to create
52# the files but they already exists).
53#
54# This works, but results in some files in $root_build_dir being links to
55# files outside of the build directory. Running `ninja -t clean` will try
56# to delete those files breaking Xcode installation. The recommendation is
57# to use `gn clean` or `ninja -t cleandead` instead.
58#
59# This variable controls whether we create the symlink and the workaround
60# is needed or not. See https://crbug.com/336382863#comment16 for details.
61ios_use_xcode_symlinks =
62    ios_sdk_path == "" && use_system_xcode && use_remoteexec
63
64if (ios_sdk_path == "") {
65  # Compute default target.
66  if (target_environment == "simulator") {
67    ios_sdk_name = "iphonesimulator"
68    ios_sdk_platform = "iPhoneSimulator"
69  } else if (target_environment == "device") {
70    ios_sdk_name = "iphoneos"
71    ios_sdk_platform = "iPhoneOS"
72  } else if (target_environment == "catalyst") {
73    ios_sdk_name = "macosx"
74    ios_sdk_platform = "MacOSX"
75  } else {
76    assert(false, "unsupported environment: $target_environment")
77  }
78
79  ios_sdk_info_args = [
80    "--get_sdk_info",
81    "--get_machine_info",
82  ]
83  ios_sdk_info_args += [ ios_sdk_name ]
84  if (ios_sdk_developer_dir != "") {
85    ios_sdk_info_args += [
86      "--developer_dir",
87      ios_sdk_developer_dir,
88    ]
89  }
90  if (ios_use_xcode_symlinks) {
91    ios_sdk_info_args += [
92      "--create_symlink_at",
93      "sdk/xcode_links",
94      "--root_build_dir",
95      root_build_dir,
96    ]
97  }
98  script_name = "//build/config/apple/sdk_info.py"
99  _ios_sdk_result = exec_script(script_name, ios_sdk_info_args, "scope")
100  ios_bin_path =
101      rebase_path("${_ios_sdk_result.toolchains_path}/usr/bin/", root_build_dir)
102  ios_sdk_path = _ios_sdk_result.sdk_path
103  ios_sdk_platform_path = _ios_sdk_result.sdk_platform_path
104  ios_sdk_version = _ios_sdk_result.sdk_version
105  ios_sdk_build = _ios_sdk_result.sdk_build
106  ios_toolchains_path = _ios_sdk_result.toolchains_path
107  xcode_version = _ios_sdk_result.xcode_version
108  xcode_version_int = _ios_sdk_result.xcode_version_int
109  xcode_build = _ios_sdk_result.xcode_build
110  machine_os_build = _ios_sdk_result.machine_os_build
111  if (target_environment == "simulator") {
112    # This is weird, but Xcode sets DTPlatformBuild to an empty field for
113    # simulator builds.
114    ios_platform_build = ""
115  } else {
116    ios_platform_build = ios_sdk_build
117  }
118}
119
120_sdk_root = rebase_path(ios_sdk_path, root_build_dir)
121ios_sdk_logs = [ "ios_sdk_path=${_sdk_root}" ]
122