xref: /aosp_15_r20/external/cronet/third_party/abseil-cpp/absl.gni (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1# Copyright 2020 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# This file contains the definition of the template absl_source_set which
6# should be the only type of target needed in abseil's BUILD.gn files.
7# This template will correctly set "configs" and "public_configs" in order
8# to correctly compile abseil in Chromium.
9#
10# Usage:
11# Most of the times its usage will be similar to the example below but all
12# the arguments avilable in source_set are also available for absl_source_set.
13#
14#  absl_source_set("foo") {
15#    sources = [ "foo.cc" ]
16#    public = [ "foo.h" ]
17#    deps = [ ":bar" ]
18#  }
19
20import("//build_overrides/build.gni")
21
22declare_args() {
23  absl_build_tests = build_with_chromium
24}
25
26template("absl_source_set") {
27  source_set(target_name) {
28    if (defined(invoker.testonly) && invoker.testonly && !absl_build_tests) {
29      not_needed(invoker, "*")
30    } else {
31      forward_variables_from(invoker, "*")
32      configs -= [ "//build/config/compiler:chromium_code" ]
33      configs += [
34        "//build/config/compiler:no_chromium_code",
35        "//build/config/compiler:prevent_unsafe_narrowing",
36        "//third_party/abseil-cpp:absl_default_cflags_cc",
37        "//third_party/abseil-cpp:absl_define_config",
38      ]
39
40      if (is_component_build) {
41        defines = [ "ABSL_BUILD_DLL" ]
42        if (!is_win && current_os != "aix") {
43          configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
44          configs += [ "//build/config/gcc:symbol_visibility_default" ]
45        }
46      }
47
48      if (!defined(public_configs)) {
49        public_configs = []
50      }
51      public_configs += [
52        "//third_party/abseil-cpp:absl_include_config",
53        "//third_party/abseil-cpp:absl_public_cflags_cc",
54      ]
55
56      if (!defined(visibility)) {
57        # Within Chromium builds, restrict direct visibility of Abseil sources, so
58        # users must depend on //third_party/abseil-cpp:absl. This prevents use of
59        # banned targets like absl/types:any. A few targets require exceptions.
60        # TODO(crbug.com/1096380): Consider replacing build_with_chromium with
61        # is_component_build for a narrower, more accurate condition.
62        if (build_with_chromium) {
63          visibility = [
64            # Abseil itself.
65            "//third_party/abseil-cpp/*",
66
67            # GTest.  It unconditionally #includes any.h if pretty-print support
68            # for absl types is enabled.
69            "//third_party/googletest/*",
70
71            # WebRTC binary to run PSNR and SSIM video quality analysis. It
72            # statically links absl and it is used by "browser_tests" when
73            # is_component_build=false but it cannot depend on the absl
74            # component because it uses absl/flags.
75            "//third_party/webrtc/rtc_tools:frame_analyzer",
76
77            # WebRTC binaries used by //:chromium_builder_asan. They both
78            # statically link absl (because they depend on absl/flags) and are
79            # used by Chromium only when is_component_build=false.
80            "//third_party/webrtc/rtc_tools:rtp_generator",
81            "//third_party/webrtc/rtc_tools:video_replay",
82
83            # Not used by Chromium directly.
84            "//chromecast/internal/*",
85            "//libassistant/*",
86
87            # Not built into Chrome.
88            "//components/optimization_guide/internal/*",
89          ]
90        } else {
91          visibility = [ "*" ]
92        }
93      }
94    }
95  }
96}
97
98template("absl_test") {
99  source_set(target_name) {
100    if (!absl_build_tests) {
101      not_needed(invoker, "*")
102    } else {
103      forward_variables_from(invoker, "*")
104      testonly = true
105      configs -= [ "//build/config/compiler:chromium_code" ]
106      configs += [
107        "//build/config/compiler:no_chromium_code",
108        "//third_party/abseil-cpp:absl_default_cflags_cc",
109        "//third_party/abseil-cpp:absl_define_config",
110        "//third_party/abseil-cpp:absl_test_config",
111      ]
112
113      if (!defined(public_configs)) {
114        public_configs = []
115      }
116      public_configs += [
117        "//third_party/abseil-cpp:absl_include_config",
118        "//third_party/abseil-cpp:absl_public_cflags_cc",
119      ]
120
121      visibility = [ "//third_party/abseil-cpp/:*" ]
122      deps += [
123        "//third_party/googletest:gmock",
124        "//third_party/googletest:gtest",
125      ]
126    }
127  }
128}
129