summaryrefslogtreecommitdiff
path: root/chromium/components/cronet/ios/BUILD.gn
blob: 117b236c72c9b2dad301625da87962e6bb4aedeb (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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# Copyright 2015 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/c++/c++.gni")
import("//build/config/ios/rules.gni")
import("//build/config/mac/symbols.gni")
import("//build/mac/tweak_info_plist.gni")
import("//build/util/lastchange.gni")
import("//components/cronet/native/include/headers.gni")
import("//components/grpc_support/include/headers.gni")
import("//testing/test.gni")
import("//url/features.gni")

assert(!is_component_build, "Cronet requires static library build.")

group("cronet_consumer_group") {
  deps = [ "//components/cronet/ios/cronet_consumer" ]
}

config("cronet_include_config") {
  include_dirs = [ "//components/grpc_support/include" ]
}

config("cronet_static_config") {
  frameworks = [
    "Cronet.framework",
    "UIKit.framework",
    "CFNetwork.framework",
    "MobileCoreServices.framework",
    "Security.framework",
    "SystemConfiguration.framework",
  ]
  libs = [ "resolv" ]
  configs = [ ":cronet_include_config" ]
}

_cronet_deps = [
  ":generate_accept_languages",
  "//base:base",
  "//components/cronet:cronet_buildflags",
  "//components/cronet:cronet_common",
  "//components/cronet:cronet_version_header",
  "//components/cronet/native:cronet_native_impl",
  "//components/grpc_support",
  "//components/prefs:prefs",
  "//ios/net",
  "//ios/net:network_protocol",
  "//ios/web/common:user_agent",
  "//ios/web/init:global_state",
  "//ios/web/public/init:global_state",
  "//net",
  "//url",
]

_cronet_sources = [
  "Cronet.h",
  "Cronet.mm",
  "cronet_environment.h",
  "cronet_environment.mm",
  "cronet_global_state_ios.mm",
  "cronet_metrics.h",
  "cronet_metrics.mm",
]

_cronet_public_headers = [ "Cronet.h" ]
_cronet_public_headers += grpc_public_headers
_cronet_public_headers += cronet_native_public_headers

source_set("cronet_sources") {
  deps = _cronet_deps

  sources = _cronet_sources

  include_dirs = [ "//components/grpc_support/include" ]

  if (!use_platform_icu_alternatives) {
    deps += [ "//base:i18n" ]
  }

  configs += [ "//build/config/compiler:enable_arc" ]
}

source_set("cronet_sources_with_global_state") {
  deps = [
    "//base",
    "//ios/web/init:global_state",
    "//ios/web/public/init:global_state",
  ]

  public_deps = [ ":cronet_sources" ]

  sources = [ "ios_global_state_configuration.cc" ]
}

# Tweak |info_plist| with current version and revision.
tweak_info_plist("tweak_cronet_plist") {
  info_plist = "Info.plist"
}

ios_framework_bundle("cronet_framework") {
  output_name = "Cronet"
  info_plist_target = ":tweak_cronet_plist"

  deps = [
    ":cronet_sources_with_global_state",
    "//base",
    "//net:net",
  ]

  frameworks = [ "UIKit.framework" ]

  public_deps = [ "//components/grpc_support:headers" ]

  public_headers = _cronet_public_headers

  sources = [ "Cronet.h" ]

  configs -= [ "//build/config/compiler:default_symbols" ]
  configs += [ "//build/config/compiler:symbols" ]

  public_configs = [ ":cronet_include_config" ]
}

test("cronet_unittests_ios") {
  testonly = true

  sources = [ "../run_all_unittests.cc" ]

  deps = [
    ":cronet_sources_with_global_state",
    "//base",
    "//base/test:test_support",
    "//components/cronet:cronet_common_unittests",
    "//components/cronet/native:cronet_native_unittests",
    "//net",
    "//testing/gtest",
  ]

  bundle_deps = [ "//components/cronet/ios/test:cronet_test" ]
}

action("generate_accept_languages") {
  script = "//components/cronet/tools/generate_accept_languages.py"
  args = [
    rebase_path("$target_gen_dir"),
    rebase_path("//"),
  ]
  outputs = [ "$target_gen_dir/accept_languages_table.h" ]
}

# A static library which contains just _cronet_sources.
static_library("cronet_static") {
  visibility = [ ":*" ]
  deps = _cronet_deps
  sources = _cronet_sources + [ "ios_global_state_configuration.cc" ]
  public_configs = [ ":cronet_include_config" ]
  public_deps = [ "//components/grpc_support" ]

  configs += [ "//build/config/compiler:enable_arc" ]
}

# A static library which contains all dependencies of :cronet_static.
static_library("cronet_deps_complete") {
  visibility = [ ":*" ]
  complete_static_lib = true
  configs -= [ "//build/config/compiler:thin_archive" ]
  deps = [ ":cronet_static" ]

  if (use_custom_libcxx) {
    deps += [
      # Add shared_library_deps to include custom libc++ into dependencies.
      # They are by default only added to executable(), loadable_module(), and
      # shared_library() targets, but cronet_static_complete library needs it as well to
      # avoid linking with different versions of libc++.
      "//build/config:shared_library_deps",
    ]
  }
}

# A static library which contains cronet and all dependendencies hidden inside.
action("cronet_static_complete") {
  visibility = [ ":*" ]
  script = "//components/cronet/tools/hide_symbols.py"
  deps = [
    ":cronet_deps_complete",
    ":cronet_static",
  ]
  outputs = [ "$target_out_dir/$current_cpu/cronet_static_complete.a" ]
  args = [
    "--input_libs",
    rebase_path("$target_out_dir/libcronet_static.a", root_build_dir),
    "--deps_lib",
    rebase_path("$target_out_dir/libcronet_deps_complete.a", root_build_dir),
    "--output_obj",
    rebase_path("$target_out_dir/$current_cpu/cronet_static_complete.o",
                root_build_dir),
    "--output_lib",
    rebase_path("$target_out_dir/$current_cpu/cronet_static_complete.a",
                root_build_dir),
    "--current_cpu",
    current_cpu,
  ]
  if (use_custom_libcxx) {
    args += [ "--use_custom_libcxx" ]
  }

  public_configs = [ ":cronet_static_config" ]
}

# A fat static library which exports cronet public symbols and hides all dependendencies.
lipo_binary("libcronet") {
  arch_binary_target = ":cronet_static_complete"
  arch_binary_output = "cronet_static_complete.a"
  output_name = "libcronet.a"
  enable_stripping = false
  enable_dsyms = false
}

template("ios_static_framework") {
  _target_name = target_name
  _output_name = target_name
  if (defined(invoker.output_name)) {
    _output_name = invoker.output_name
  }
  _framework_name = target_name
  if (defined(invoker.framework_name)) {
    _framework_name = invoker.framework_name
  }

  _framework_headers_target = _target_name + "_framework_headers"
  bundle_data(_framework_headers_target) {
    visibility = [ ":$_target_name" ]
    sources = invoker.public_headers
    outputs = [ "{{bundle_contents_dir}}/Headers/{{source_file_part}}" ]
  }

  _framework_binary_target = _target_name + "_framework_binary"
  _static_library_target = invoker.static_library_target

  bundle_data(_framework_binary_target) {
    visibility = [ ":$_target_name" ]
    sources = get_target_outputs(_static_library_target)
    outputs = [ "{{bundle_executable_dir}}/$_framework_name" ]
    public_deps = [ _static_library_target ]
  }

  create_bundle(_target_name) {
    product_type = "com.apple.product-type.framework"
    bundle_root_dir = "$root_out_dir/Static/${_output_name}"
    bundle_contents_dir = bundle_root_dir
    bundle_executable_dir = bundle_contents_dir
    bundle_resources_dir = bundle_contents_dir
    deps = [
      ":$_framework_binary_target",
      ":$_framework_headers_target",
    ]
    public_configs = invoker.public_configs
  }
}

ios_static_framework("cronet_static_framework") {
  output_name = "Cronet.framework"
  framework_name = "Cronet"
  public_headers = _cronet_public_headers
  static_library_target = ":libcronet"
  public_configs = [ ":cronet_static_config" ]
}

if (additional_toolchains == [] || current_toolchain == default_toolchain) {
  _package_dir = "$root_out_dir/cronet"

  action("generate_license") {
    _license_path = "$_package_dir/LICENSE"

    script = "//tools/licenses.py"
    inputs = [ lastchange_file ]
    outputs = [ _license_path ]
    args = [
      "license_file",
      rebase_path(_license_path, root_build_dir),
      "--gn-target",
      "//components/cronet/ios:cronet_framework",
      "--gn-out-dir",
      ".",
      "--target-os",
      "ios",
    ]
  }

  copy("cronet_static_copy") {
    sources = [ "$root_out_dir/Static/Cronet.framework" ]
    outputs = [ "$_package_dir/Static/Cronet.framework" ]

    deps = [ ":cronet_static_framework" ]
  }

  copy("cronet_package_copy") {
    sources = [
      "$root_out_dir/Cronet.framework",
      "//AUTHORS",
      "//chrome/VERSION",
    ]
    outputs = [ "$_package_dir/{{source_file_part}}" ]

    deps = [
      ":cronet_framework",
      ":cronet_static_copy",
    ]
  }

  if (enable_dsyms) {
    action("cronet_dsym_archive") {
      script = "//chrome/tools/build/mac/archive_symbols.py"

      # These are the dSYMs that will be archived. The sources list must be
      # the target outputs that correspond to the dSYMs (since a dSYM is a
      # directory it cannot be listed as a source file). The targets that
      # generate both the dSYM and binary image are listed in deps.
      _dsyms = [ "$root_out_dir/Cronet.dSYM" ]

      sources = [ "$root_out_dir/Cronet.framework" ]

      _output = "$_package_dir/Cronet.dSYM.tar.bz2"

      outputs = [ _output ]

      args = [ rebase_path(_output, root_out_dir) ] +
             rebase_path(_dsyms, root_out_dir)

      deps = [ ":cronet_framework" ]
    }
  } else {
    group("cronet_dsym_archive") {
    }
  }

  group("cronet_package_ios") {
    deps = [
      ":cronet_dsym_archive",
      ":cronet_package_copy",
      ":generate_license",
    ]
  }
}