• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 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
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
22template("absl_source_set") {
23  source_set(target_name) {
24    forward_variables_from(invoker, "*")
25    configs -= [ "//build/config/compiler:chromium_code" ]
26    configs += [
27      "//build/config/compiler:no_chromium_code",
28      "//third_party/abseil-cpp:absl_default_cflags_cc",
29      "//third_party/abseil-cpp:absl_define_config",
30    ]
31
32    if (is_component_build) {
33      defines = [ "ABSL_BUILD_DLL" ]
34      if (!is_win) {
35        configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
36        configs += [ "//build/config/gcc:symbol_visibility_default" ]
37      }
38    }
39
40    if (!defined(public_configs)) {
41      public_configs = []
42    }
43    public_configs += [ "//third_party/abseil-cpp:absl_include_config" ]
44
45    if (!defined(visibility)) {
46      # Within Chromium builds, restrict direct visibility of Abseil sources, so
47      # users must depend on //third_party/abseil-cpp:absl. This prevents use of
48      # banned targets like absl/types:any. A few targets require exceptions.
49      # TODO(crbug.com/1096380): Consider replacing build_with_chromium with
50      # is_component_build for a narrower, more accurate condition.
51      if (build_with_chromium) {
52        visibility = [
53          # Abseil itself.
54          "//third_party/abseil-cpp/*",
55
56          # GTest.  It unconditionally #includes any.h if pretty-print support
57          # for absl types is enabled.
58          "//third_party/googletest/*",
59
60          # WebRTC binary to run PSNR and SSIM video quality analysis. It
61          # statically links absl and it is used by "browser_tests" when
62          # is_component_build=false but it cannot depend on the absl
63          # component because it uses absl/flags.
64          "//third_party/webrtc/rtc_tools:frame_analyzer",
65
66          # WebRTC binaries used by //:chromium_builder_asan. They both
67          # statically link absl (because they depend on absl/flags) and are
68          # used by Chromium only when is_component_build=false.
69          "//third_party/webrtc/rtc_tools:rtp_generator",
70          "//third_party/webrtc/rtc_tools:video_replay",
71
72          # Not used by Chromium directly.
73          "//chromecast/internal/*",
74          "//libassistant/*",
75        ]
76      } else {
77        visibility = [ "*" ]
78      }
79    }
80  }
81}
82