1# Copyright (C) 2017 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15import("//build_overrides/build.gni") 16import("wasm_vars.gni") 17 18# Summary of our typical build configurations: 19 20# 1. Standalone builds 21# build_with_chromium = false 22# is_perfetto_build_generator = false 23# perfetto_build_standalone = true 24# perfetto_build_with_android = false 25# perfetto_build_with_embedder = false 26 27# 2. Android tree builds 28# build_with_chromium = false 29# is_perfetto_build_generator = true 30# perfetto_build_standalone = false 31# perfetto_build_with_android = true 32# perfetto_build_with_embedder = false 33 34# 3. Chromium tree builds 35# build_with_chromium = true 36# is_perfetto_build_generator = false 37# perfetto_build_standalone = false 38# perfetto_build_with_android = false 39# perfetto_build_with_embedder = true 40 41# 4. Builds in other embedder trees (e.g. V8 standalone) 42# build_with_chromium = false 43# is_perfetto_build_generator = false 44# perfetto_build_standalone = false 45# perfetto_build_with_android = false 46# perfetto_build_with_embedder = true 47 48# 5. Amalgamated sources (Client library) 49# build_with_chromium = false 50# is_perfetto_build_generator = true 51# perfetto_build_standalone = false 52# perfetto_build_with_android = false 53# perfetto_build_with_embedder = true 54 55# +----------------------------------------------------------------------------+ 56# | Toolchain / environment related configuration | 57# +----------------------------------------------------------------------------+ 58# This section contains a bunch of variables that are related with the toolchain 59# and the build environment. Only tools/gen_xxx should customize them. 60 61# Note that |build_with_chromium| is a global convention used by several 62# projects, set outside of our control. 63 64# Chromium sets this to true in its //build_overrides/build.gni. 65if (!defined(build_with_chromium)) { 66 build_with_chromium = false 67} 68 69if (!defined(is_nacl)) { 70 is_nacl = false 71} 72 73declare_args() { 74 # The Android blueprint file generator set this to true (as well as 75 # is_perfetto_build_generator). This is just about being built in the 76 # Android tree (AOSP and internal) and is NOT related with the target OS. 77 # In standalone Android builds and Chromium Android builds, this is false. 78 perfetto_build_with_android = false 79 80 # All the tools/gen_* scripts set this to true. This is mainly used to locate 81 # .gni files from //gn rather than //build. 82 is_perfetto_build_generator = false 83 84 # This is for override via `gn args` (e.g. for tools/gen_xxx). Embedders 85 # based on GN (e.g. v8) should NOT set this and instead directly sets 86 # perfetto_build_with_embedder=true in their GN files. 87 is_perfetto_embedder = false 88} 89 90# This can be overridden by embedders (e.g. v8) in their .gn(i) files. This must 91# be different from the GN args flag (is_perfetto_embedder) because of the way 92# GN works. 93if (!defined(perfetto_build_with_embedder)) { 94 perfetto_build_with_embedder = build_with_chromium || is_perfetto_embedder 95} 96 97perfetto_build_standalone = 98 !perfetto_build_with_android && !build_with_chromium && 99 !perfetto_build_with_embedder 100 101# Only relevant for GN builds. Sets the path where perfetto lives. This is // 102# for standalone builds and //third_party/perfetto/ in embedders. The embedder 103# can ovverride it in its GN files. 104if (perfetto_build_standalone || is_perfetto_build_generator) { 105 perfetto_root_path = "//" 106 import("//gn/standalone/android.gni") # For android_api_level 107 import("//gn/standalone/sanitizers/vars.gni") # For is_fuzzer 108} else if (!defined(perfetto_root_path)) { 109 perfetto_root_path = "//third_party/perfetto/" 110 import("//build/config/android/config.gni") # For android_api_level 111} 112 113# Whether the ftrace producer and the service should be started 114# by the integration test or assumed to be running. 115# If we're building in the Android tree, we expect that the testing infra 116# will start the binaries in the system image before the tests are run. 117# In all other cases (i.e. when true), a temporary in-process instance will be 118# brought up by our own integrationtest harness. 119start_daemons_for_testing = !perfetto_build_with_android 120 121# +----------------------------------------------------------------------------+ 122# | Tunable build variables for embedders | 123# +----------------------------------------------------------------------------+ 124# The variables in this section allow embedders to enable/disable features 125# at the build-system level. This allows to opt-in into the various services 126# and tools. 127 128perfetto_force_dlog_default = "" 129if (build_with_chromium) { 130 perfetto_force_dlog_default = "off" 131} 132 133declare_args() { 134 # Platform-wide tracing executables (traced, traced_probes, perfetto_cmd). 135 enable_perfetto_platform_services = 136 perfetto_build_standalone || perfetto_build_with_android 137 138 # Allow the embedder to use the IPC layer. In turn this allows to use the 139 # system backend in the client library. 140 # This includes building things that rely on POSIX sockets, this places 141 # limitations on the supported operating systems. 142 enable_perfetto_ipc = !is_win && !is_fuchsia && !is_nacl && 143 (perfetto_build_standalone || 144 perfetto_build_with_android || build_with_chromium) 145 146 # Makes the heap profiling daemon target reachable. It works only on Android, 147 # but is built on Linux as well for test/compiler coverage. 148 # On Android, it requires API level 26 due to libunwindstack. 149 enable_perfetto_heapprofd = 150 perfetto_build_with_android || 151 (perfetto_build_standalone && is_clang && 152 (is_linux || (is_android && android_api_level >= 26))) 153 154 # Build the perf event profiler (traced_perf). 155 # TODO(b/144281346): under development. 156 # TODO(rsavitski): figure out how to make the android-core dependencies build 157 # under gcc (_Atomic and other issues). 158 enable_perfetto_traced_perf = 159 perfetto_build_with_android || 160 (perfetto_build_standalone && is_clang && is_linux) 161 162 # The Trace Processor: offline analytical engine to process traces and compute 163 # metrics using a SQL engine. 164 if (!defined(enable_perfetto_trace_processor)) { 165 enable_perfetto_trace_processor = 166 perfetto_build_standalone || build_with_chromium || 167 is_perfetto_build_generator 168 } 169 170 # Enables base::Watchdog. Is supported only on Linux-based platforms. 171 # gn/BUILD.gn further restricts this to OS_LINUX || OS_ANDROID when generating 172 # the perfetto_build_flags.h header. 173 enable_perfetto_watchdog = 174 perfetto_build_with_android || perfetto_build_standalone 175 176 # Misc host executable under tools/. 177 enable_perfetto_tools = 178 perfetto_build_standalone || perfetto_build_with_android 179 180 enable_perfetto_unittests = perfetto_build_standalone || 181 build_with_chromium || perfetto_build_with_android 182 183 enable_perfetto_integration_tests = 184 perfetto_build_standalone || perfetto_build_with_android 185 186 enable_perfetto_benchmarks = perfetto_build_standalone 187 188 enable_perfetto_fuzzers = 189 perfetto_build_standalone && defined(is_fuzzer) && is_fuzzer 190 191 # Enables the gen_git_revision tool that generates a .h that contains a macro 192 # with the current git revision. Works only in standalone GN checkouts. 193 # If disabled, the version string will be "unknown". 194 enable_perfetto_version_gen = 195 perfetto_build_standalone && !is_perfetto_build_generator 196 197 # Only for local development. When true the binaries (perfetto, traced, ...) 198 # are monolithic and don't use a common shared library. This is mainly to 199 # avoid LD_LIBRARY_PATH dances when testing locally. 200 monolithic_binaries = false 201 202 # Whether DLOG should be enabled on debug builds (""), all builds ("on"), or 203 # none ("off"). We disable it by default for embedders to avoid spamming their 204 # console. 205 perfetto_force_dlog = perfetto_force_dlog_default 206} 207 208declare_args() { 209 # Whether info-level logging is enabled. 210 perfetto_verbose_logs_enabled = 211 !build_with_chromium || perfetto_force_dlog == "on" 212 213 # Enables the SQL query layer of trace processor. 214 enable_perfetto_trace_processor_sqlite = 215 enable_perfetto_trace_processor && 216 (build_with_chromium || !perfetto_build_with_embedder) 217 218 # Enables the optional SQLite percentile module. 219 enable_perfetto_trace_processor_percentile = 220 enable_perfetto_trace_processor && perfetto_build_standalone 221 222 # Enables the REPL interactive prompt in the trace processor. 223 enable_perfetto_trace_processor_linenoise = 224 perfetto_build_standalone && enable_perfetto_trace_processor && 225 (is_linux || is_android || is_mac) 226 227 # Enables JSON support in the trace processor. Required for JSON trace import 228 # and export. 229 enable_perfetto_trace_processor_json = 230 enable_perfetto_trace_processor && !perfetto_build_with_android 231 232 # Enables httpd RPC support in the trace processor. 233 # Further per-OS conditionals are applied in gn/BUILD.gn. 234 enable_perfetto_trace_processor_httpd = 235 enable_perfetto_trace_processor && perfetto_build_standalone 236 237 # Enables Zlib support. This is used both by the "perfetto" cmdline client 238 # (for compressing traces) and by trace processor (for compressed traces). 239 enable_perfetto_zlib = 240 enable_perfetto_trace_processor || enable_perfetto_platform_services 241} 242 243declare_args() { 244 # Enables the trace_to_text tool. 245 enable_perfetto_tools_trace_to_text = 246 enable_perfetto_tools && enable_perfetto_trace_processor_sqlite 247 248 # Allows to build the UI (TypeScript/ HTML / WASM) 249 enable_perfetto_ui = 250 perfetto_build_standalone && enable_perfetto_trace_processor_sqlite 251 252 # Skip buildtools dependency checks (needed for ChromeOS). 253 skip_buildtools_check = false 254 255 # Used by CrOS system builds. Uses the system version of protobuf 256 # from /usr/include instead of the hermetic one. 257 perfetto_use_system_protobuf = false 258} 259 260# +---------------------------------------------------------------------------+ 261# | Cross-checks | 262# +---------------------------------------------------------------------------+ 263 264# Exactly one between build_with_android, build_standalone and 265# build_with_embedder must be true. 266assert(perfetto_build_standalone || perfetto_build_with_android || 267 perfetto_build_with_embedder) 268assert(!(perfetto_build_with_android && perfetto_build_standalone)) 269assert(!(perfetto_build_with_embedder && perfetto_build_standalone)) 270assert(!(perfetto_build_with_android && perfetto_build_with_embedder)) 271 272# If |build_with_chromium| is true then also |perfetto_build_with_embedder| 273# must be true 274assert(!build_with_chromium || perfetto_build_with_embedder) 275 276# If |perfetto_build_with_android| is true then also 277# |is_perfetto_build_generator| must be true. 278assert(!perfetto_build_with_android || is_perfetto_build_generator) 279 280# The IPC layer based on UNIX sockets can't be built on Win. 281assert(!enable_perfetto_ipc || !is_win) 282 283# We should never end up in a state where is_perfetto_embedder=true but 284# perfetto_build_with_embedder=false. 285assert(!is_perfetto_embedder || perfetto_build_with_embedder) 286 287# The monolithic binaries is not supported when building in the Android tree. 288assert(!monolithic_binaries || !perfetto_build_with_android) 289 290# Watchdog must be on in Android builds. 291assert(enable_perfetto_watchdog || !perfetto_build_with_android) 292 293assert(perfetto_force_dlog == "" || perfetto_force_dlog == "on" || 294 perfetto_force_dlog == "off") 295