absl.gni (5510B)
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 20 import("//build_overrides/build.gni") 21 22 declare_args() { 23 absl_build_tests = build_with_chromium 24 moz_webrtc_build = true 25 } 26 27 template("absl_source_set") { 28 source_set(target_name) { 29 if (defined(invoker.testonly) && invoker.testonly && !absl_build_tests) { 30 not_needed(invoker, "*") 31 } else { 32 forward_variables_from(invoker, "*") 33 configs -= [ "//chromium/build/config/compiler:chromium_code" ] 34 configs += [ 35 "//chromium/build/config/compiler:no_chromium_code", 36 "//chromium/build/config/compiler:prevent_unsafe_narrowing", 37 "//abseil-cpp:absl_default_cflags_cc", 38 "//abseil-cpp:absl_define_config", 39 ] 40 41 if (moz_webrtc_build) { 42 configs -= [ "//chromium/build/config/compiler:prevent_unsafe_narrowing" ] 43 } 44 45 if (!defined(defines)) { 46 defines = [] 47 } 48 if (is_component_build) { 49 defines += [ "ABSL_BUILD_DLL" ] 50 if (!is_win && current_os != "aix") { 51 configs -= [ "//chromium/build/config/gcc:symbol_visibility_hidden" ] 52 configs += [ "//chromium/build/config/gcc:symbol_visibility_default" ] 53 } 54 } 55 56 if (!defined(public_configs)) { 57 public_configs = [] 58 } 59 public_configs += [ "//abseil-cpp:absl_include_config" ] 60 61 if (!defined(visibility)) { 62 # Within Chromium builds, restrict direct visibility of Abseil sources, so 63 # users must depend on //third_party/abseil-cpp:absl. This prevents use of 64 # banned targets like absl/types:any. A few targets require exceptions. 65 if (build_with_chromium) { 66 visibility = [ 67 # Abseil itself. 68 "//third_party/abseil-cpp/*", 69 70 # GTest. It unconditionally #includes any.h if pretty-print support 71 # for absl types is enabled. 72 "//third_party/googletest/*", 73 ] 74 75 if (!is_component_build) { 76 visibility += [ 77 # Not used by Chromium directly. 78 "//chromecast/internal/*", 79 "//libassistant/*", 80 ] 81 } 82 } else { 83 visibility = [ "*" ] 84 } 85 } 86 visibility += [ "//abseil-cpp/*" ] 87 88 # Now that abseil-cpp lives under Mozilla's third_party instead 89 # of under libwebrtc's third_party and is built as a stand-alone 90 # library, we need to "re-root" the dependency paths. We can 91 # modify the dependencies here to avoid modifying most, if not 92 # all, of the BUILD.gn files. 93 if (defined(deps)) { 94 modified_deps = [] 95 foreach (dep, deps) { 96 newdep = string_replace(dep, "//third_party/abseil-cpp/", "//") 97 newdep = string_replace(newdep, "//build", "//chromium/build") 98 modified_deps += [ newdep ] 99 } 100 deps = [] 101 deps = modified_deps 102 } 103 104 # Same for public_deps 105 if (defined(public_deps)) { 106 modified_deps = [] 107 foreach (dep, public_deps) { 108 newdep = string_replace(dep, "//third_party/abseil-cpp/", "//") 109 modified_deps += [ newdep ] 110 } 111 public_deps = [] 112 public_deps = modified_deps 113 } 114 115 # Same for visibility 116 if (defined(visibility)) { 117 modified_deps = [] 118 foreach (dep, visibility) { 119 newdep = string_replace(dep, "//third_party/abseil-cpp/", "//") 120 modified_deps += [ newdep ] 121 } 122 visibility = [] 123 visibility = modified_deps 124 } 125 } 126 } 127 } 128 129 template("absl_test") { 130 source_set(target_name) { 131 if (!absl_build_tests) { 132 not_needed(invoker, "*") 133 } else { 134 forward_variables_from(invoker, "*") 135 testonly = true 136 configs -= [ "//chromium/build/config/compiler:chromium_code" ] 137 configs += [ 138 "//chromium/build/config/compiler:no_chromium_code", 139 "//abseil-cpp:absl_default_cflags_cc", 140 "//abseil-cpp:absl_define_config", 141 "//abseil-cpp:absl_test_config", 142 ] 143 144 if (!defined(public_configs)) { 145 public_configs = [] 146 } 147 public_configs += [ "//abseil-cpp:absl_include_config" ] 148 149 visibility = [ "//third_party/abseil-cpp/:*" ] 150 deps += [ 151 "//third_party/googletest:gmock", 152 "//third_party/googletest:gtest", 153 ] 154 } 155 156 # Now that abseil-cpp lives under Mozilla's third_party instead 157 # of under libwebrtc's third_party and is built as a stand-alone 158 # library, we need to "re-root" the dependency paths. We can 159 # modify the dependencies here to avoid modifying most, if not 160 # all, of the BUILD.gn files. 161 if (defined(deps)) { 162 modified_deps = [] 163 foreach (dep, deps) { 164 newdep = string_replace(dep, "//third_party/abseil-cpp/", "//") 165 modified_deps += [ newdep ] 166 } 167 deps = [] 168 deps = modified_deps 169 } 170 } 171 }