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 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 "//build/config/compiler:prevent_unsafe_narrowing", 29 "//third_party/abseil-cpp:absl_default_cflags_cc", 30 "//third_party/abseil-cpp:absl_define_config", 31 ] 32 33 if (is_component_build) { 34 defines = [ "ABSL_BUILD_DLL" ] 35 if (!is_win && (current_os != "aix")) { 36 configs -= [ "//build/config/gcc:symbol_visibility_hidden" ] 37 configs += [ "//build/config/gcc:symbol_visibility_default" ] 38 } 39 } 40 41 if (!defined(public_configs)) { 42 public_configs = [] 43 } 44 public_configs += [ "//third_party/abseil-cpp:absl_include_config" ] 45 46 if (!defined(visibility)) { 47 # Within Chromium builds, restrict direct visibility of Abseil sources, so 48 # users must depend on //third_party/abseil-cpp:absl. This prevents use of 49 # banned targets like absl/types:any. A few targets require exceptions. 50 # TODO(crbug.com/1096380): Consider replacing build_with_chromium with 51 # is_component_build for a narrower, more accurate condition. 52 if (build_with_chromium) { 53 visibility = [ 54 # Abseil itself. 55 "//third_party/abseil-cpp/*", 56 57 # GTest. It unconditionally #includes any.h if pretty-print support 58 # for absl types is enabled. 59 "//third_party/googletest/*", 60 61 # Centipede, a fuzz test runner 62 "//third_party/fuzztest/*", 63 64 # WebRTC binary to run PSNR and SSIM video quality analysis. It 65 # statically links absl and it is used by "browser_tests" when 66 # is_component_build=false but it cannot depend on the absl 67 # component because it uses absl/flags. 68 "//third_party/webrtc/rtc_tools:frame_analyzer", 69 70 # WebRTC binaries used by //:chromium_builder_asan. They both 71 # statically link absl (because they depend on absl/flags) and are 72 # used by Chromium only when is_component_build=false. 73 "//third_party/webrtc/rtc_tools:rtp_generator", 74 "//third_party/webrtc/rtc_tools:video_replay", 75 76 # Not used by Chromium directly. 77 "//chromecast/internal/*", 78 "//libassistant/*", 79 80 # Not built into Chrome. 81 "//components/optimization_guide/internal/*", 82 ] 83 } else { 84 visibility = [ "*" ] 85 } 86 } 87 } 88} 89 90template("absl_test") { 91 source_set(target_name) { 92 forward_variables_from(invoker, "*") 93 testonly = true 94 configs -= [ "//build/config/compiler:chromium_code" ] 95 configs += [ 96 "//build/config/compiler:no_chromium_code", 97 "//third_party/abseil-cpp:absl_default_cflags_cc", 98 "//third_party/abseil-cpp:absl_define_config", 99 "//third_party/abseil-cpp:absl_test_config", 100 ] 101 102 if (!defined(public_configs)) { 103 public_configs = [] 104 } 105 public_configs += [ "//third_party/abseil-cpp:absl_include_config" ] 106 107 visibility = [ "//third_party/abseil-cpp/:*" ] 108 deps += [ 109 "//third_party/googletest:gmock", 110 "//third_party/googletest:gtest", 111 ] 112 } 113} 114