1# Copyright 2015 The Chromium Authors. All rights reserved.
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/apple/tweak_info_plist.gni")
6import("//build/config/c++/c++.gni")
7import("//build/config/ios/rules.gni")
8import("//build/config/mac/symbols.gni")
9import("//build/util/lastchange.gni")
10import("//components/cronet/native/include/headers.gni")
11import("//components/grpc_support/include/headers.gni")
12import("//testing/test.gni")
13import("//url/features.gni")
14
15assert(!is_component_build, "Cronet requires static library build.")
16
17group("cronet_consumer_group") {
18  deps = [ "//components/cronet/ios/cronet_consumer" ]
19}
20
21config("cronet_include_config") {
22  include_dirs = [ "//components/grpc_support/include" ]
23}
24
25config("cronet_static_config") {
26  frameworks = [
27    "Cronet.framework",
28    "CoreTelephony.framework",
29    "UIKit.framework",
30    "CFNetwork.framework",
31    "MobileCoreServices.framework",
32    "Security.framework",
33    "SystemConfiguration.framework",
34  ]
35  libs = [ "resolv" ]
36  configs = [ ":cronet_include_config" ]
37}
38
39_cronet_deps = [
40  ":generate_accept_languages",
41  "//base:base",
42  "//components/cronet:cronet_buildflags",
43  "//components/cronet:cronet_common",
44  "//components/cronet:cronet_version_header",
45  "//components/cronet/native:cronet_native_impl",
46  "//components/grpc_support",
47  "//components/prefs:prefs",
48  "//ios/net",
49  "//ios/net:network_protocol",
50  "//ios/web/common:user_agent",
51  "//ios/web/init:global_state",
52  "//ios/web/public/init:global_state",
53  "//net",
54  "//url",
55]
56
57_cronet_sources = [
58  "Cronet.h",
59  "Cronet.mm",
60  "cronet_environment.h",
61  "cronet_environment.mm",
62  "cronet_global_state_ios.mm",
63  "cronet_metrics.h",
64  "cronet_metrics.mm",
65]
66
67_cronet_public_headers = [ "Cronet.h" ]
68_cronet_public_headers += grpc_public_headers
69_cronet_public_headers += cronet_native_public_headers
70
71source_set("cronet_sources") {
72  deps = _cronet_deps
73
74  sources = _cronet_sources
75
76  include_dirs = [ "//components/grpc_support/include" ]
77
78  if (!use_platform_icu_alternatives) {
79    deps += [ "//base:i18n" ]
80  }
81
82  configs += [ "//build/config/compiler:enable_arc" ]
83}
84
85source_set("cronet_sources_with_global_state") {
86  deps = [
87    "//base",
88    "//ios/web/init:global_state",
89    "//ios/web/public/init:global_state",
90  ]
91
92  public_deps = [ ":cronet_sources" ]
93
94  sources = [ "ios_global_state_configuration.cc" ]
95}
96
97# Tweak |info_plist| with current version and revision.
98tweak_info_plist("tweak_cronet_plist") {
99  info_plist = "Info.plist"
100}
101
102ios_framework_bundle("cronet_framework") {
103  output_name = "Cronet"
104  info_plist_target = ":tweak_cronet_plist"
105
106  deps = [
107    ":cronet_sources_with_global_state",
108    "//base",
109    "//net:net",
110  ]
111
112  frameworks = [ "UIKit.framework" ]
113
114  public_deps = [ "//components/grpc_support:headers" ]
115
116  public_headers = _cronet_public_headers
117
118  sources = [ "Cronet.h" ]
119
120  configs -= [ "//build/config/compiler:default_symbols" ]
121  configs += [ "//build/config/compiler:symbols" ]
122
123  public_configs = [ ":cronet_include_config" ]
124}
125
126test("cronet_unittests_ios") {
127  testonly = true
128
129  sources = [ "../run_all_unittests.cc" ]
130
131  deps = [
132    ":cronet_sources_with_global_state",
133    "//base",
134    "//base/test:test_support",
135    "//components/cronet:cronet_common_unittests",
136    "//components/cronet/native:cronet_native_unittests",
137    "//net",
138    "//testing/gtest",
139  ]
140
141  bundle_deps = [ "//components/cronet/ios/test:cronet_test" ]
142}
143
144action("generate_accept_languages") {
145  script = "//components/cronet/tools/generate_accept_languages.py"
146  args = [
147    rebase_path("$target_gen_dir"),
148    rebase_path("//"),
149  ]
150  outputs = [ "$target_gen_dir/accept_languages_table.h" ]
151}
152
153# A static library which contains just _cronet_sources.
154static_library("cronet_static") {
155  visibility = [ ":*" ]
156  deps = _cronet_deps
157  sources = _cronet_sources + [ "ios_global_state_configuration.cc" ]
158  public_configs = [ ":cronet_include_config" ]
159  public_deps = [ "//components/grpc_support" ]
160
161  configs += [ "//build/config/compiler:enable_arc" ]
162}
163
164# A static library which contains all dependencies of :cronet_static.
165static_library("cronet_deps_complete") {
166  visibility = [ ":*" ]
167  complete_static_lib = true
168  configs -= [ "//build/config/compiler:thin_archive" ]
169  deps = [ ":cronet_static" ]
170
171  if (use_custom_libcxx) {
172    deps += [
173      # Add shared_library_deps to include custom libc++ into dependencies.
174      # They are by default only added to executable(), loadable_module(), and
175      # shared_library() targets, but cronet_static_complete library needs it as well to
176      # avoid linking with different versions of libc++.
177      "//build/config:shared_library_deps",
178    ]
179  }
180}
181
182# A static library which contains cronet and all dependendencies hidden inside.
183action("cronet_static_complete") {
184  visibility = [ ":*" ]
185  script = "//components/cronet/tools/hide_symbols.py"
186  deps = [
187    ":cronet_deps_complete",
188    ":cronet_static",
189  ]
190  outputs = [ "$target_out_dir/$current_cpu/cronet_static_complete.a" ]
191  args = [
192    "--input_libs",
193    rebase_path("$target_out_dir/libcronet_static.a", root_build_dir),
194    "--deps_lib",
195    rebase_path("$target_out_dir/libcronet_deps_complete.a", root_build_dir),
196    "--output_obj",
197    rebase_path("$target_out_dir/$current_cpu/cronet_static_complete.o",
198                root_build_dir),
199    "--output_lib",
200    rebase_path("$target_out_dir/$current_cpu/cronet_static_complete.a",
201                root_build_dir),
202    "--current_cpu",
203    current_cpu,
204  ]
205  if (use_custom_libcxx) {
206    args += [ "--use_custom_libcxx" ]
207  }
208
209  public_configs = [ ":cronet_static_config" ]
210}
211
212# A fat static library which exports cronet public symbols and hides all dependendencies.
213lipo_binary("libcronet") {
214  arch_binary_target = ":cronet_static_complete"
215  arch_binary_output = "cronet_static_complete.a"
216  output_name = "libcronet.a"
217  enable_stripping = false
218  enable_dsyms = false
219}
220
221template("ios_static_framework") {
222  _target_name = target_name
223  _output_name = target_name
224  if (defined(invoker.output_name)) {
225    _output_name = invoker.output_name
226  }
227  _framework_name = target_name
228  if (defined(invoker.framework_name)) {
229    _framework_name = invoker.framework_name
230  }
231
232  _framework_headers_target = _target_name + "_framework_headers"
233  bundle_data(_framework_headers_target) {
234    visibility = [ ":$_target_name" ]
235    sources = invoker.public_headers
236    outputs = [ "{{bundle_contents_dir}}/Headers/{{source_file_part}}" ]
237  }
238
239  _framework_binary_target = _target_name + "_framework_binary"
240  _static_library_target = invoker.static_library_target
241
242  bundle_data(_framework_binary_target) {
243    visibility = [ ":$_target_name" ]
244    sources = get_target_outputs(_static_library_target)
245    outputs = [ "{{bundle_executable_dir}}/$_framework_name" ]
246    public_deps = [ _static_library_target ]
247  }
248
249  create_bundle(_target_name) {
250    product_type = "com.apple.product-type.framework"
251    bundle_root_dir = "$root_out_dir/Static/${_output_name}"
252    bundle_contents_dir = bundle_root_dir
253    bundle_executable_dir = bundle_contents_dir
254    bundle_resources_dir = bundle_contents_dir
255    deps = [
256      ":$_framework_binary_target",
257      ":$_framework_headers_target",
258    ]
259    public_configs = invoker.public_configs
260  }
261}
262
263ios_static_framework("cronet_static_framework") {
264  output_name = "Cronet.framework"
265  framework_name = "Cronet"
266  public_headers = _cronet_public_headers
267  static_library_target = ":libcronet"
268  public_configs = [ ":cronet_static_config" ]
269}
270
271if (additional_toolchains == [] || current_toolchain == default_toolchain) {
272  _package_dir = "$root_out_dir/cronet"
273
274  action("generate_license") {
275    _license_path = "$_package_dir/LICENSE"
276
277    script = "//tools/licenses.py"
278    inputs = [ lastchange_file ]
279    outputs = [ _license_path ]
280    args = [
281      "license_file",
282      rebase_path(_license_path, root_build_dir),
283      "--gn-target",
284      "//components/cronet/ios:cronet_framework",
285      "--gn-out-dir",
286      ".",
287      "--target-os",
288      "ios",
289    ]
290  }
291
292  copy("cronet_static_copy") {
293    sources = [ "$root_out_dir/Static/Cronet.framework" ]
294    outputs = [ "$_package_dir/Static/Cronet.framework" ]
295
296    deps = [ ":cronet_static_framework" ]
297  }
298
299  copy("cronet_package_copy") {
300    sources = [
301      "$root_out_dir/Cronet.framework",
302      "//AUTHORS",
303      "//chrome/VERSION",
304    ]
305    outputs = [ "$_package_dir/{{source_file_part}}" ]
306
307    deps = [
308      ":cronet_framework",
309      ":cronet_static_copy",
310    ]
311  }
312
313  if (enable_dsyms) {
314    action("cronet_dsym_archive") {
315      script = "//chrome/tools/build/mac/archive_symbols.py"
316
317      # These are the dSYMs that will be archived. The sources list must be
318      # the target outputs that correspond to the dSYMs (since a dSYM is a
319      # directory it cannot be listed as a source file). The targets that
320      # generate both the dSYM and binary image are listed in deps.
321      _dsyms = [ "$root_out_dir/Cronet.dSYM" ]
322
323      sources = [ "$root_out_dir/Cronet.framework" ]
324
325      _output = "$_package_dir/Cronet.dSYM.tar.bz2"
326
327      outputs = [ _output ]
328
329      args = [ rebase_path(_output, root_out_dir) ] +
330             rebase_path(_dsyms, root_out_dir)
331
332      deps = [ ":cronet_framework" ]
333    }
334  } else {
335    group("cronet_dsym_archive") {
336    }
337  }
338
339  group("cronet_package_ios") {
340    deps = [
341      ":cronet_dsym_archive",
342      ":cronet_package_copy",
343      ":generate_license",
344    ]
345  }
346}
347