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 # Enables build of platform-wide tracing services (traced, traced_probes) 135 # and executables (perfetto_cmd, trigger_perfetto). 136 # When disabled, only the client library and other auxiliary tools can be 137 # built (for Chromium and other GN embedders). 138 # Note that traced_probes is further conditioned by the GN variable 139 # enable_perfetto_traced_probes, in the declare_args() section below. 140 enable_perfetto_platform_services = 141 perfetto_build_standalone || perfetto_build_with_android 142 143 # Allow the embedder to use the IPC layer. In turn this allows to use the 144 # system backend in the client library. 145 # This includes building things that rely on POSIX sockets, this places 146 # limitations on the supported operating systems. 147 enable_perfetto_ipc = !is_win && !is_fuchsia && !is_nacl && 148 (perfetto_build_standalone || 149 perfetto_build_with_android || build_with_chromium) 150 151 # Makes the heap profiling daemon target reachable. It works only on Android, 152 # but is built on Linux as well for test/compiler coverage. 153 # On Android, it requires API level 26 due to libunwindstack. 154 enable_perfetto_heapprofd = 155 perfetto_build_with_android || 156 (perfetto_build_standalone && is_clang && 157 (is_linux || (is_android && android_api_level >= 26))) 158 159 # Build the perf event profiler (traced_perf). 160 # TODO(b/144281346): under development. 161 # TODO(rsavitski): figure out how to make the android-core dependencies build 162 # under gcc (_Atomic and other issues). 163 enable_perfetto_traced_perf = 164 perfetto_build_with_android || 165 (perfetto_build_standalone && is_clang && is_linux) 166 167 # The Trace Processor: offline analytical engine to process traces and compute 168 # metrics using a SQL engine. 169 if (!defined(enable_perfetto_trace_processor)) { 170 enable_perfetto_trace_processor = 171 perfetto_build_standalone || build_with_chromium || 172 is_perfetto_build_generator 173 } 174 175 # Enables base::Watchdog. Is supported only on Linux-based platforms. 176 # gn/BUILD.gn further restricts this to OS_LINUX || OS_ANDROID when generating 177 # the perfetto_build_flags.h header. 178 enable_perfetto_watchdog = 179 perfetto_build_with_android || perfetto_build_standalone 180 181 # Misc host executable under tools/. 182 enable_perfetto_tools = 183 perfetto_build_standalone || perfetto_build_with_android 184 185 enable_perfetto_unittests = perfetto_build_standalone || 186 build_with_chromium || perfetto_build_with_android 187 188 enable_perfetto_integration_tests = 189 (perfetto_build_standalone && !is_win) || perfetto_build_with_android 190 191 enable_perfetto_benchmarks = perfetto_build_standalone && !is_win 192 193 enable_perfetto_fuzzers = 194 perfetto_build_standalone && defined(is_fuzzer) && is_fuzzer 195 196 # Enables the write_version_header.py tool that generates a .h that contains a 197 # macro with the current git revision and latest release version from 198 # CHANGELOG. If false base/version.h will return "unknown". 199 enable_perfetto_version_gen = 200 perfetto_build_standalone || is_perfetto_build_generator || 201 perfetto_build_with_android 202 203 # Only for local development. When true the binaries (perfetto, traced, ...) 204 # are monolithic and don't use a common shared library. This is mainly to 205 # avoid LD_LIBRARY_PATH dances when testing locally. 206 # On Windows we default to monolithic executables, because pairing 207 # dllexport/import adds extra complexity for little benefit. Te only reason 208 # for monolithic_binaries=false is saving binary size, which matters mainly on 209 # Android. See also comments on PERFETTO_EXPORTED_ENTRYPOINT in compiler.h. 210 monolithic_binaries = is_win 211 212 # Whether DLOG should be enabled on debug builds (""), all builds ("on"), or 213 # none ("off"). We disable it by default for embedders to avoid spamming their 214 # console. 215 perfetto_force_dlog = perfetto_force_dlog_default 216 217 # Installs a signal handler for the most common crash signals which unwinds 218 # the stack and prints the stack trace on stderr. Requires a dependency on 219 # libbacktrace when enabled. 220 enable_perfetto_stderr_crash_dump = 221 is_debug && perfetto_build_standalone && !is_wasm && !is_win 222} 223 224declare_args() { 225 perfetto_enable_git_rev_version_header = enable_perfetto_version_gen 226 227 # The traced_probes daemon is very Linux-specific, as it depends on ftrace and 228 # various /proc interfaces. There is no point making its code platform-neutral 229 # as it won't do anything useful on Windows. 230 # The only reason why we still build it on Mac OS is to be able to run the 231 # unittests there and making dev on mac less cumbersome. The traced_probes 232 # code happens to build cleanly and for now the mainteinance cost on Mac is 233 # extremely low. 234 enable_perfetto_traced_probes = enable_perfetto_platform_services && !is_win 235 236 # Whether info-level logging is enabled. 237 perfetto_verbose_logs_enabled = 238 !build_with_chromium || perfetto_force_dlog == "on" 239 240 # Enables the SQL query layer of trace processor. 241 enable_perfetto_trace_processor_sqlite = 242 enable_perfetto_trace_processor && 243 (build_with_chromium || !perfetto_build_with_embedder) 244 245 # Enables the optional SQLite percentile module. 246 enable_perfetto_trace_processor_percentile = 247 enable_perfetto_trace_processor && perfetto_build_standalone 248 249 # Enables the REPL interactive prompt in the trace processor. 250 enable_perfetto_trace_processor_linenoise = 251 perfetto_build_standalone && enable_perfetto_trace_processor && 252 (is_linux || is_android || is_mac) 253 254 # Enables JSON support in the trace processor. Required for JSON trace import 255 # and export. 256 enable_perfetto_trace_processor_json = 257 enable_perfetto_trace_processor && !perfetto_build_with_android 258 259 # Enables httpd RPC support in the trace processor. 260 # Further per-OS conditionals are applied in gn/BUILD.gn. 261 enable_perfetto_trace_processor_httpd = 262 enable_perfetto_trace_processor && perfetto_build_standalone 263 264 # Enables Zlib support. This is used both by the "perfetto" cmdline client 265 # (for compressing traces) and by trace processor (for compressed traces). 266 enable_perfetto_zlib = 267 enable_perfetto_trace_processor || enable_perfetto_platform_services 268} 269 270declare_args() { 271 # Enables the trace_to_text tool. 272 enable_perfetto_tools_trace_to_text = 273 enable_perfetto_tools && enable_perfetto_trace_processor_sqlite 274 275 # Allows to build the UI (TypeScript/ HTML / WASM) 276 enable_perfetto_ui = 277 perfetto_build_standalone && enable_perfetto_trace_processor_sqlite && 278 host_os != "win" 279 280 # Skip buildtools dependency checks (needed for ChromeOS). 281 skip_buildtools_check = false 282 283 # Used by CrOS system builds. Uses the system version of protobuf 284 # from /usr/include instead of the hermetic one. 285 perfetto_use_system_protobuf = false 286 287 perfetto_use_system_zlib = false 288} 289 290if (is_win) { 291 # clang-cl 292 perfetto_isystem_cflag = "/I" 293} else { 294 perfetto_isystem_cflag = "-isystem" 295} 296 297# +---------------------------------------------------------------------------+ 298# | Cross-checks | 299# +---------------------------------------------------------------------------+ 300 301# Exactly one between build_with_android, build_standalone and 302# build_with_embedder must be true. 303assert(perfetto_build_standalone || perfetto_build_with_android || 304 perfetto_build_with_embedder) 305assert(!(perfetto_build_with_android && perfetto_build_standalone)) 306assert(!(perfetto_build_with_embedder && perfetto_build_standalone)) 307assert(!(perfetto_build_with_android && perfetto_build_with_embedder)) 308 309# If |build_with_chromium| is true then also |perfetto_build_with_embedder| 310# must be true 311assert(!build_with_chromium || perfetto_build_with_embedder) 312 313# If |perfetto_build_with_android| is true then also 314# |is_perfetto_build_generator| must be true. 315assert(!perfetto_build_with_android || is_perfetto_build_generator) 316 317# The IPC layer based on UNIX sockets can't be built on Win. 318assert(!enable_perfetto_ipc || !is_win) 319 320# We should never end up in a state where is_perfetto_embedder=true but 321# perfetto_build_with_embedder=false. 322assert(!is_perfetto_embedder || perfetto_build_with_embedder) 323 324# The monolithic binaries is not supported when building in the Android tree. 325assert(!monolithic_binaries || !perfetto_build_with_android) 326 327# Watchdog must be on in Android builds. 328assert(enable_perfetto_watchdog || !perfetto_build_with_android) 329 330assert(perfetto_force_dlog == "" || perfetto_force_dlog == "on" || 331 perfetto_force_dlog == "off") 332 333# If enable_perfetto_traced_probes is set, enable_perfetto_platform_services 334# must be set as well. Doesn't make sense to build traced_probes without the 335# rest. traced_probes integration tests depend on traced. 336assert(!enable_perfetto_traced_probes || enable_perfetto_platform_services) 337