xref: /aosp_15_r20/external/cronet/third_party/abseil-cpp/BUILD.gn (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1# Copyright 2018 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
5# Flags specified here must not impact ABI. Code compiled with and without these
6# opts will be linked together, and in some cases headers compiled with and
7# without these options will be part of the same program.
8
9import("//build/config/c++/c++.gni")
10import("//build/config/nacl/config.gni")
11import("//build/config/sanitizers/sanitizers.gni")
12import("//build/toolchain/toolchain.gni")
13import("//build_overrides/build.gni")
14import("//third_party/abseil-cpp/absl.gni")
15
16config("absl_component_build") {
17  defines = [ "ABSL_CONSUME_DLL" ]
18}
19
20assert(!is_nacl || is_nacl_saigo,
21       "base must not be built in most nacl toolchains")
22
23component("absl") {
24  public_deps = [ ":absl_component_deps" ]
25  if (is_component_build) {
26    public_configs = [ ":absl_component_build" ]
27
28    if (is_win && is_clang) {
29      if (current_cpu == "x64") {
30        if (is_debug) {
31          sources = [ "symbols_x64_dbg.def" ]
32        } else {
33          if (is_asan) {
34            sources = [ "symbols_x64_rel_asan.def" ]
35          } else {
36            sources = [ "symbols_x64_rel.def" ]
37          }
38        }
39      }
40      if (current_cpu == "x86") {
41        if (is_debug) {
42          sources = [ "symbols_x86_dbg.def" ]
43        } else {
44          sources = [ "symbols_x86_rel.def" ]
45        }
46      }
47      if (current_cpu == "arm64") {
48        if (is_debug) {
49          sources = [ "symbols_arm64_dbg.def" ]
50        } else {
51          sources = [ "symbols_arm64_rel.def" ]
52        }
53      }
54    }
55  }
56}
57
58group("absl_component_deps") {
59  public_deps = [
60    "//third_party/abseil-cpp/absl/algorithm:container",
61    "//third_party/abseil-cpp/absl/base",
62    "//third_party/abseil-cpp/absl/base:config",
63    "//third_party/abseil-cpp/absl/base:core_headers",
64    "//third_party/abseil-cpp/absl/base:no_destructor",
65    "//third_party/abseil-cpp/absl/base:nullability",
66    "//third_party/abseil-cpp/absl/base:prefetch",
67    "//third_party/abseil-cpp/absl/cleanup",
68    "//third_party/abseil-cpp/absl/container:btree",
69    "//third_party/abseil-cpp/absl/container:fixed_array",
70    "//third_party/abseil-cpp/absl/container:flat_hash_map",
71    "//third_party/abseil-cpp/absl/container:flat_hash_set",
72    "//third_party/abseil-cpp/absl/container:inlined_vector",
73    "//third_party/abseil-cpp/absl/container:node_hash_map",
74    "//third_party/abseil-cpp/absl/container:node_hash_set",
75    "//third_party/abseil-cpp/absl/debugging:failure_signal_handler",
76    "//third_party/abseil-cpp/absl/debugging:stacktrace",
77    "//third_party/abseil-cpp/absl/debugging:symbolize",
78    "//third_party/abseil-cpp/absl/functional:any_invocable",
79    "//third_party/abseil-cpp/absl/functional:bind_front",
80    "//third_party/abseil-cpp/absl/functional:function_ref",
81    "//third_party/abseil-cpp/absl/functional:overload",
82    "//third_party/abseil-cpp/absl/hash",
83    "//third_party/abseil-cpp/absl/log:absl_check",
84    "//third_party/abseil-cpp/absl/log:absl_log",
85    "//third_party/abseil-cpp/absl/log:die_if_null",
86    "//third_party/abseil-cpp/absl/memory",
87    "//third_party/abseil-cpp/absl/meta:type_traits",
88    "//third_party/abseil-cpp/absl/numeric:bits",
89    "//third_party/abseil-cpp/absl/numeric:int128",
90    "//third_party/abseil-cpp/absl/random",
91    "//third_party/abseil-cpp/absl/random:distributions",
92    "//third_party/abseil-cpp/absl/status",
93    "//third_party/abseil-cpp/absl/status:statusor",
94    "//third_party/abseil-cpp/absl/strings",
95    "//third_party/abseil-cpp/absl/strings:cord",
96    "//third_party/abseil-cpp/absl/strings:has_ostream_operator",
97    "//third_party/abseil-cpp/absl/strings:str_format",
98    "//third_party/abseil-cpp/absl/strings:string_view",
99    "//third_party/abseil-cpp/absl/synchronization",
100    "//third_party/abseil-cpp/absl/time",
101    "//third_party/abseil-cpp/absl/types:optional",
102    "//third_party/abseil-cpp/absl/types:span",
103    "//third_party/abseil-cpp/absl/types:variant",
104    "//third_party/abseil-cpp/absl/utility",
105  ]
106
107  if (is_component_build) {
108    public_deps += [ ":absl_full_deps" ]
109  }
110
111  # The following dependencies currently don't build with NaCl.
112  # TODO(https://crbug.com/1114625): Fix build errors and remove this section.
113  if (is_nacl) {
114    public_deps -=
115        [ "//third_party/abseil-cpp/absl/debugging:failure_signal_handler" ]
116  }
117
118  visibility = [ ":absl" ]
119}
120
121# Some third-party libraries use additional parts of absl that are banned in
122# Chrome (e.g. flags generates static initializers that are undesirable in
123# non-test binaries). These third-party libraries can depend on `absl_full`
124# instead of `absl` to use those banned subsets of Abseil as well.
125source_set("absl_full") {
126  public_deps = [ ":absl" ]
127
128  # In component builds, `absl` itself depends on `absl_full_deps` directly so
129  # that all of absl is built as a single shared library. This is to prevent
130  # globals from being duplicated between both `absl` and `absl_full` (e.g.
131  # inline variables), and the subtle breakage that could cause.
132  #
133  # Deps violations will still be enforced by the non-component build.
134  if (!is_component_build) {
135    public_deps += [ ":absl_full_deps" ]
136  }
137
138  if (build_with_chromium) {
139    visibility = [
140      "//third_party/fuzztest:*",
141
142      # GoogleTest doesn't actually need absl_full, but this makes gn check
143      # happier.
144      "//third_party/googletest:*",
145    ]
146  }
147}
148
149group("absl_full_deps") {
150  public_deps = [
151    # Banned because each flag registration generates a static initializer, and
152    # the flag registration mechanism is problematic in component builds.
153    "//third_party/abseil-cpp/absl/flags:config",
154    "//third_party/abseil-cpp/absl/flags:flag",
155    "//third_party/abseil-cpp/absl/flags:parse",
156    "//third_party/abseil-cpp/absl/flags:reflection",
157    "//third_party/abseil-cpp/absl/flags:usage",
158
159    # Banned because the LOG and CHECK macros conflict with Chrome's version of
160    # those macros.
161    "//third_party/abseil-cpp/absl/log",
162    "//third_party/abseil-cpp/absl/log:check",
163
164    # TODO(danilchap): Investigate if these targets need to be banned in 3rd party library code.
165    "//third_party/abseil-cpp/absl/log:globals",
166    "//third_party/abseil-cpp/absl/log:initialize",
167    "//third_party/abseil-cpp/absl/random:bit_gen_ref",
168  ]
169
170  visibility = [
171    ":absl_component_deps",
172    ":absl_full",
173  ]
174
175  public_configs = [ "//third_party/abseil-cpp/absl/flags:absl_flags_config" ]
176}
177
178config("absl_include_config") {
179  include_dirs = [ "." ]
180}
181
182config("absl_define_config") {
183  defines = [ "ABSL_ALLOCATOR_NOTHROW=1" ]
184
185  if (is_win && !use_custom_libcxx) {
186    defines += [
187      # See crbug.com/1101367: Acknowledge extended alignment when using
188      # MSVC's standard library.
189      "_ENABLE_EXTENDED_ALIGNED_STORAGE",
190    ]
191  }
192}
193
194config("absl_default_cflags_cc") {
195  cflags_cc = []
196  if (is_clang) {
197    cflags_cc += [
198      # TODO(crbug.com/588506): Explicitly enable conversion warnings.
199      "-Wbool-conversion",
200      "-Wconstant-conversion",
201      "-Wenum-conversion",
202      "-Wint-conversion",
203      "-Wliteral-conversion",
204      "-Wnon-literal-null-conversion",
205      "-Wnull-conversion",
206      "-Wobjc-literal-conversion",
207      "-Wstring-conversion",
208    ]
209    if (!is_nacl) {
210      cflags_cc += [ "-Wbitfield-enum-conversion" ]
211    }
212  }
213}
214
215config("absl_public_cflags_cc") {
216  # Non-chromium users of abseil have more lax style guides and use additional features in
217  # abseil, Remove a few extra warnings for that use case.
218  if (!build_with_chromium && is_clang) {
219    cflags = [
220      # Allow the use of enable_if()
221      "-Wno-gcc-compat",
222      "-Wno-unreachable-code-break",
223    ]
224  }
225}
226
227config("absl_test_cflags_cc") {
228  cflags_cc = []
229  if (is_clang || !is_win) {
230    cflags_cc += [
231      "-Wno-conversion-null",
232      "-Wno-missing-declarations",
233      "-Wno-unused-function",
234      "-Wno-unused-parameter",
235      "-Wno-unused-private-field",
236    ]
237  }
238  if (is_win) {
239    cflags_cc += [
240      "/wd4101",  # unreferenced local variable
241    ]
242  }
243}
244
245config("absl_test_config") {
246  cflags_cc = []
247  if (is_win && !is_clang) {
248    cflags_cc += [ "/wd4996" ]
249  }
250  if (is_clang) {
251    cflags_cc += [
252      "-Wno-deprecated-declarations",
253      "-Wno-implicit-const-int-float-conversion",
254      "-Wno-unused-private-field",
255      "-Wno-unused-function",
256    ]
257  }
258}
259
260if (absl_build_tests) {
261  import("//testing/test.gni")
262
263  if (!is_component_build) {
264    test("absl_tests") {
265      testonly = true
266      deps = [
267        "absl/algorithm:algorithm_test",
268        "absl/algorithm:container_test",
269        "absl/base:config_test",
270        "absl/base:no_destructor_test",
271        "absl/base:nullability_test",
272        "absl/base:prefetch_test",
273        "absl/cleanup:cleanup_test",
274
275        # TODO(mbonadei): Fix issue with EXPECT_DEATH and uncomment.
276        # "absl/container:btree_test",
277        "absl/container:common_policy_traits_test",
278        "absl/container:fixed_array_test",
279        "absl/container:flat_hash_map_test",
280        "absl/container:flat_hash_set_test",
281        "absl/container:hash_function_defaults_test",
282        "absl/container:inlined_vector_test",
283        "absl/container:node_slot_policy_test",
284        "absl/container:raw_hash_set_allocator_test",
285        "absl/container:raw_hash_set_test",
286        "absl/container:sample_element_size_test",
287        "absl/crc:crc32c_test",
288        "absl/crc:crc_cord_state_test",
289        "absl/crc:crc_memcpy_test",
290        "absl/crc:non_temporal_memcpy_test",
291        "absl/debugging:stacktrace_test",
292        "absl/flags:flag_test",
293        "absl/functional:any_invocable_test",
294        "absl/functional:function_ref_test",
295        "absl/functional:overload_test",
296        "absl/hash:hash_instantiated_test",
297        "absl/hash:hash_test",
298        "absl/hash:low_level_hash_test",
299        "absl/log:absl_check_test",
300        "absl/log:absl_log_basic_test",
301        "absl/log:die_if_null_test",
302        "absl/log:flags_test",
303        "absl/log:globals_test",
304        "absl/log:log_entry_test",
305        "absl/log:log_format_test",
306        "absl/log:log_macro_hygiene_test",
307        "absl/log:log_modifier_methods_test",
308        "absl/log:log_sink_test",
309        "absl/log:log_streamer_test",
310        "absl/log:scoped_mock_log_test",
311        "absl/log:stripping_test",
312        "absl/log:vlog_is_on_test",
313        "absl/log/internal:fnmatch_test",
314        "absl/log/internal:stderr_log_sink_test",
315        "absl/memory:memory_test",
316        "absl/meta:type_traits_test",
317        "absl/numeric:int128_test",
318        "absl/profiling:exponential_biased_test",
319        "absl/profiling:periodic_sampler_test",
320        "absl/status:status_test",
321        "absl/status:statusor_test",
322        "absl/strings:ascii_test",
323        "absl/strings:char_formatting_test",
324        "absl/strings:charset_test",
325        "absl/strings:cord_buffer_test",
326        "absl/strings:cord_data_edge_test",
327        "absl/strings:cord_rep_btree_navigator_test",
328        "absl/strings:cord_rep_btree_reader_test",
329        "absl/strings:cord_rep_btree_test",
330        "absl/strings:cord_rep_crc_test",
331        "absl/strings:cordz_functions_test",
332        "absl/strings:cordz_info_statistics_test",
333        "absl/strings:cordz_info_test",
334        "absl/strings:cordz_test",
335        "absl/strings:cordz_update_scope_test",
336        "absl/strings:cordz_update_tracker_test",
337        "absl/strings:damerau_levenshtein_distance_test",
338        "absl/strings:has_absl_stringify_test",
339        "absl/strings:has_ostream_operator_test",
340        "absl/strings:match_test",
341        "absl/strings:str_format_arg_test",
342        "absl/strings:str_format_bind_test",
343        "absl/strings:str_format_checker_test",
344        "absl/strings:str_format_convert_test",
345        "absl/strings:str_format_extension_test",
346        "absl/strings:str_format_output_test",
347        "absl/strings:str_format_parser_test",
348        "absl/strings:str_format_test",
349        "absl/strings:str_replace_test",
350        "absl/strings:string_view_test",
351        "absl/synchronization:kernel_timeout_internal_test",
352        "absl/synchronization:waiter_test",
353        "absl/time:time_test",
354        "absl/types:optional_test",
355        "absl/types:span_test",
356        "absl/types:variant_test",
357        "absl/utility:if_constexpr_test",
358        "//third_party/googletest:gtest_main",
359      ]
360    }
361  }
362
363  test("absl_hardening_tests") {
364    testonly = true
365    sources = [ "absl_hardening_test.cc" ]
366    deps = [
367      ":absl",
368      "//base/test:run_all_unittests",
369      "//third_party/googletest:gtest",
370    ]
371  }
372}
373