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