summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/build/config/ios/BUILD.gn
blob: 525c439e7ebd671266cf5df1a99e093981063837 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/ios/ios_sdk.gni")
import("//build/toolchain/goma.gni")
import("//build/toolchain/toolchain.gni")
import("//build_overrides/build.gni")

declare_args() {
  # Enabling this option makes clang compile to an intermediate
  # representation ("bitcode"), and not to native code. This is preferred
  # when including WebRTC in the apps that will be sent to Apple's App Store
  # and mandatory for the apps that run on watchOS or tvOS.
  # The option only works when building with Xcode (use_xcode_clang = true).
  # Mimicking how Xcode handles it, the production builds (is_debug = false)
  # get real bitcode sections added, while the debug builds (is_debug = true)
  # only get bitcode-section "markers" added in them.
  enable_ios_bitcode = false
}

# This is included by reference in the //build/config/compiler config that
# 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_flags = []

  # CPU architecture.
  if (target_cpu == "x64") {
    triplet_cpu = "x86_64"
  } else if (target_cpu == "x86") {
    triplet_cpu = "i386"
  } else if (target_cpu == "arm" || target_cpu == "armv7") {
    triplet_cpu = "armv7"
  } else if (target_cpu == "arm64") {
    triplet_cpu = "arm64"
  } else {
    assert(false, "unsupported cpu: $target_cpu")
  }

  # Environment.
  if (target_environment == "simulator") {
    triplet_environment = "-simulator"
  } 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_flags = [
    "-target",
    "$triplet_cpu-$triplet_os$ios_deployment_target$triplet_environment",
  ]

  # This is here so that all files get recompiled after an Xcode update.
  # (defines are passed via the command line, and build system rebuild things
  # when their commandline changes). Nothing should ever read this define.
  defines = [ "CR_XCODE_VERSION=$xcode_version" ]

  asmflags = common_flags
  cflags = common_flags
  swiftflags = common_flags

  swiftflags += [
    "-swift-version",
    "5",
  ]

  # Without this, the constructors and destructors of a C++ object inside
  # an Objective C struct won't be called, which is very bad.
  cflags_objcc = [ "-fobjc-call-cxx-cdtors" ]

  ldflags = common_flags
}

# This is included by reference in the //build/config/compiler:runtime_library
# config that is applied to all targets. It is here to separate out the logic
# that is iOS-only. Please see that target for advice on what should go in
# :runtime_library vs. :compiler.
config("runtime_library") {
  # The variable ios_sdk_path is relative to root_build_dir when using Goma RBE
  # and system Xcode (since Goma RBE only supports paths relative to source).
  # Rebase the value in that case since gn does not convert paths in compiler
  # flags (since it is not aware they are paths).
  _sdk_root = ios_sdk_path
  if (use_system_xcode && use_goma) {
    _sdk_root = rebase_path(ios_sdk_path, root_build_dir)
  }

  common_flags = [
    "-isysroot",
    _sdk_root,
  ]
  swiftflags = [
    "-sdk",
    _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) {
    if (is_debug) {
      common_flags += [ "-fembed-bitcode-marker" ]
    } else {
      common_flags += [ "-fembed-bitcode" ]
    }
  }

  asmflags = common_flags
  cflags = common_flags
  ldflags = common_flags
}

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 = [
    # Always load Objective-C categories and class.
    "-Wl,-ObjC",
  ]

  # The path to the Swift compatibility libraries (required to run code built
  # with version N of the SDK on older version of the OS) is relative to the
  # toolchains directory and changes with the environment.
  _swift_compatibility_libs_dir_prefix = "$ios_toolchains_path/usr/lib/swift"
  if (target_environment == "simulator") {
    _swift_compatibility_libs_dir =
        "$_swift_compatibility_libs_dir_prefix/iphonesimulator"
  } else if (target_environment == "device") {
    _swift_compatibility_libs_dir =
        "$_swift_compatibility_libs_dir_prefix/iphoneos"
  } else if (target_environment == "catalyst") {
    _swift_compatibility_libs_dir =
        "$_swift_compatibility_libs_dir_prefix/maccatalyst"
  }

  lib_dirs = [
    "$ios_sdk_path/usr/lib/swift",
    _swift_compatibility_libs_dir,
  ]
}

config("ios_shared_library_flags") {
  ldflags = [
    "-Wl,-rpath,@executable_path/Frameworks",
    "-Wl,-rpath,@loader_path/Frameworks",
  ]
}

config("disable_implicit_retain_self_warning") {
  cflags_objc = [ "-Wno-implicit-retain-self" ]
  cflags_objcc = cflags_objc
}

config("xctest_config") {
  # Use -iframework for XCTest.framework so that the compiler will treat it as a
  # system framework and ignore warnings in XCTest framework headers.
  common_flags = [
    "-iframework",
    rebase_path("$ios_sdk_platform_path/Developer/Library/Frameworks",
                root_build_dir),
  ]
  cflags = common_flags
  ldflags = common_flags

  frameworks = [
    "Foundation.framework",
    "XCTest.framework",
  ]
}

group("xctest") {
  public_configs = [ ":xctest_config" ]
}

_xctrunner_path =
    "$ios_sdk_platform_path/Developer/Library/Xcode/Agents/XCTRunner.app"

# When building with Goma RBE, $ios_sdk_platform_path corresponds to a symlink
# below $root_build_dir that points to the real SDK to use. Because the files
# are below $root_build_dir, it is not possible to list them as a target input
# without gn complaining (as it can't find a target creating those files).
#
# The symlinks are created by //build/config/apple/sdk_info.py script invoked
# via exec_script() from //build/config/{ios/ios_sdk.gni,mac/mac_sdk.gni}.
# As the invocation is done by exec_script, there is no target that can list
# those files as output.
#
# To workaround this, add a target that pretends to create those files
# (but does nothing). See https://crbug.com/1061487 for why this is needed.
if (use_system_xcode && use_goma) {
  action("copy_xctrunner_app") {
    testonly = true
    script = "//build/noop.py"
    outputs = [
      "$_xctrunner_path/Info.plist",
      "$_xctrunner_path/PkgInfo",
      "$_xctrunner_path/XCTRunner",
    ]
  }
}

# When creating the test runner for an XCUITest, the arm64e slice of the binary
# must be removed (at least until the app ships with arm64e slice which is not
# yet supported by Apple).
action("xctest_runner_without_arm64e") {
  testonly = true
  script = "//build/config/ios/strip_arm64e.py"
  sources = [ "$_xctrunner_path/XCTRunner" ]
  outputs = [ "$target_out_dir/XCTRunner" ]
  args = [
    "--output",
    rebase_path(outputs[0], root_build_dir),
    "--input",
    rebase_path(sources[0], root_build_dir),
    "--xcode-version",
    xcode_version,
  ]

  if (use_system_xcode && use_goma) {
    deps = [ ":copy_xctrunner_app" ]
  }
}