blob: a755b8c047c57adf23bf73894154b8e4bf822970 [file] [log] [blame]
Oystein Eftevaagdd727e42017-12-05 08:49:55 -08001# 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")
Primiano Tucci02c11762019-08-30 00:57:59 +020016import("wasm_vars.gni")
Oystein Eftevaagdd727e42017-12-05 08:49:55 -080017
Primiano Tucci7e05fc12019-08-27 17:29:47 +020018# Summary of our typical build configurations:
Primiano Tucci4c5efa42018-10-23 13:15:13 +010019
20# 1. Standalone builds
Primiano Tucci4c5efa42018-10-23 13:15:13 +010021# build_with_chromium = false
Primiano Tucci7e05fc12019-08-27 17:29:47 +020022# is_perfetto_build_generator = false
23# perfetto_build_standalone = true
24# perfetto_build_with_android = false
25# perfetto_build_with_embedder = false
Primiano Tucci4c5efa42018-10-23 13:15:13 +010026
27# 2. Android tree builds
Primiano Tucci7e05fc12019-08-27 17:29:47 +020028# build_with_chromium = false
29# is_perfetto_build_generator = true
Primiano Tucci4c5efa42018-10-23 13:15:13 +010030# perfetto_build_standalone = false
31# perfetto_build_with_android = true
32# perfetto_build_with_embedder = false
Primiano Tucci4c5efa42018-10-23 13:15:13 +010033
34# 3. Chromium tree builds
Primiano Tucci4c5efa42018-10-23 13:15:13 +010035# build_with_chromium = true
Primiano Tucci7e05fc12019-08-27 17:29:47 +020036# is_perfetto_build_generator = false
Primiano Tucci4c5efa42018-10-23 13:15:13 +010037# perfetto_build_standalone = false
38# perfetto_build_with_android = false
39# perfetto_build_with_embedder = true
Primiano Tucci7e05fc12019-08-27 17:29:47 +020040
41# 4. Builds in other embedder trees (e.g. V8 standalone)
Primiano Tucci4c5efa42018-10-23 13:15:13 +010042# build_with_chromium = false
Primiano Tucci7e05fc12019-08-27 17:29:47 +020043# 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
Primiano Tucci4c5efa42018-10-23 13:15:13 +010054
Primiano Tucci02c11762019-08-30 00:57:59 +020055# +----------------------------------------------------------------------------+
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
Primiano Tucci4c5efa42018-10-23 13:15:13 +010061# Note that |build_with_chromium| is a global convention used by several
62# projects, set outside of our control.
63
Primiano Tucci7e05fc12019-08-27 17:29:47 +020064# Chromium sets this to true in its //build_overrides/build.gni.
Eric Seckler7faef112019-01-16 15:07:50 +000065if (!defined(build_with_chromium)) {
66 build_with_chromium = false
67}
68
Stephen Nusko036d1982020-01-22 13:10:37 +000069if (!defined(is_nacl)) {
70 is_nacl = false
71}
72
Eric Seckler357966a2019-01-15 13:45:37 +000073declare_args() {
Primiano Tucci7e05fc12019-08-27 17:29:47 +020074 # 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
Eric Seckler357966a2019-01-15 13:45:37 +000088}
89
Primiano Tucci7e05fc12019-08-27 17:29:47 +020090# 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
Primiano Tucci4c5efa42018-10-23 13:15:13 +010097perfetto_build_standalone =
98 !perfetto_build_with_android && !build_with_chromium &&
99 !perfetto_build_with_embedder
100
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200101# 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) {
Oystein Eftevaagdd727e42017-12-05 08:49:55 -0800105 perfetto_root_path = "//"
Primiano Tucci02c11762019-08-30 00:57:59 +0200106 import("//gn/standalone/android.gni") # For android_api_level
107 import("//gn/standalone/sanitizers/vars.gni") # For is_fuzzer
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100108} else if (!defined(perfetto_root_path)) {
Oystein Eftevaagdd727e42017-12-05 08:49:55 -0800109 perfetto_root_path = "//third_party/perfetto/"
Primiano Tucci02c11762019-08-30 00:57:59 +0200110 import("//build/config/android/config.gni") # For android_api_level
Oystein Eftevaagdd727e42017-12-05 08:49:55 -0800111}
Lalit Magantid0e76792018-02-12 14:25:01 +0000112
Primiano Tucci02c11762019-08-30 00:57:59 +0200113# Whether the ftrace producer and the service should be started
114# by the integration test or assumed to be running.
Lalit Magantid0e76792018-02-12 14:25:01 +0000115# 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.
Primiano Tucci02c11762019-08-30 00:57:59 +0200117# 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"
Lalit Magantid0e76792018-02-12 14:25:01 +0000131}
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100132
Primiano Tucci02c11762019-08-30 00:57:59 +0200133declare_args() {
Primiano Tuccia7f5a8e2021-01-02 17:10:50 +0100134 # 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.
Primiano Tucci02c11762019-08-30 00:57:59 +0200140 enable_perfetto_platform_services =
Primiano Tuccia7f5a8e2021-01-02 17:10:50 +0100141 perfetto_build_standalone || perfetto_build_with_android
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200142
Primiano Tucci02c11762019-08-30 00:57:59 +0200143 # 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.
Primiano Tucci5f3008e2021-05-19 21:34:45 +0100147 # For now the IPC layer is conservatively not enabled on Chromium+Windows
148 # builds.
149 enable_perfetto_ipc =
150 !is_fuchsia && !is_nacl &&
151 (perfetto_build_standalone || perfetto_build_with_android ||
152 (build_with_chromium && !is_win))
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200153
Primiano Tucci02c11762019-08-30 00:57:59 +0200154 # Makes the heap profiling daemon target reachable. It works only on Android,
155 # but is built on Linux as well for test/compiler coverage.
156 # On Android, it requires API level 26 due to libunwindstack.
157 enable_perfetto_heapprofd =
158 perfetto_build_with_android ||
159 (perfetto_build_standalone && is_clang &&
160 (is_linux || (is_android && android_api_level >= 26)))
161
Ryan Savitskia76b3cc2019-11-20 16:25:24 +0000162 # Build the perf event profiler (traced_perf).
163 # TODO(b/144281346): under development.
Ryan Savitski56bc0c62020-01-27 13:50:02 +0000164 # TODO(rsavitski): figure out how to make the android-core dependencies build
165 # under gcc (_Atomic and other issues).
166 enable_perfetto_traced_perf =
167 perfetto_build_with_android ||
168 (perfetto_build_standalone && is_clang && is_linux)
Ryan Savitskia76b3cc2019-11-20 16:25:24 +0000169
Primiano Tucci02c11762019-08-30 00:57:59 +0200170 # The Trace Processor: offline analytical engine to process traces and compute
171 # metrics using a SQL engine.
Sami Kyostila413b6432020-02-04 17:52:12 +0000172 if (!defined(enable_perfetto_trace_processor)) {
173 enable_perfetto_trace_processor =
174 perfetto_build_standalone || build_with_chromium ||
175 is_perfetto_build_generator
176 }
Primiano Tucci02c11762019-08-30 00:57:59 +0200177
Primiano Tucci44729e02021-10-25 11:28:19 +0100178 # Enables base::Watchdog. Is supported only on Linux-based platforms in
179 # standalone GN builds (NOT in bazel/blaze).
Primiano Tucci18c0cff2019-09-09 17:09:03 -0700180 # gn/BUILD.gn further restricts this to OS_LINUX || OS_ANDROID when generating
181 # the perfetto_build_flags.h header.
Primiano Tucci02c11762019-08-30 00:57:59 +0200182 enable_perfetto_watchdog =
Primiano Tucci44729e02021-10-25 11:28:19 +0100183 perfetto_build_with_android ||
184 (perfetto_build_standalone && !is_perfetto_build_generator)
Primiano Tucci02c11762019-08-30 00:57:59 +0200185
186 # Misc host executable under tools/.
187 enable_perfetto_tools =
Primiano Tuccif33540e2019-09-19 12:35:57 +0100188 perfetto_build_standalone || perfetto_build_with_android
Primiano Tucci02c11762019-08-30 00:57:59 +0200189
Primiano Tucci02c11762019-08-30 00:57:59 +0200190 enable_perfetto_unittests = perfetto_build_standalone ||
191 build_with_chromium || perfetto_build_with_android
192
193 enable_perfetto_integration_tests =
Primiano Tucci5f3008e2021-05-19 21:34:45 +0100194 perfetto_build_standalone || perfetto_build_with_android
Primiano Tucci02c11762019-08-30 00:57:59 +0200195
Primiano Tucci42433ab2020-11-30 18:42:01 +0100196 enable_perfetto_benchmarks = perfetto_build_standalone && !is_win
Primiano Tucci02c11762019-08-30 00:57:59 +0200197
198 enable_perfetto_fuzzers =
199 perfetto_build_standalone && defined(is_fuzzer) && is_fuzzer
200
Primiano Tucciec590132020-11-16 14:16:44 +0100201 # Enables the write_version_header.py tool that generates a .h that contains a
202 # macro with the current git revision and latest release version from
203 # CHANGELOG. If false base/version.h will return "unknown".
Primiano Tucci02c11762019-08-30 00:57:59 +0200204 enable_perfetto_version_gen =
Primiano Tucciec590132020-11-16 14:16:44 +0100205 perfetto_build_standalone || is_perfetto_build_generator ||
206 perfetto_build_with_android
Primiano Tucci02c11762019-08-30 00:57:59 +0200207
208 # Only for local development. When true the binaries (perfetto, traced, ...)
209 # are monolithic and don't use a common shared library. This is mainly to
210 # avoid LD_LIBRARY_PATH dances when testing locally.
Primiano Tucci59a00fe2021-01-02 12:58:02 +0100211 # On Windows we default to monolithic executables, because pairing
212 # dllexport/import adds extra complexity for little benefit. Te only reason
213 # for monolithic_binaries=false is saving binary size, which matters mainly on
214 # Android. See also comments on PERFETTO_EXPORTED_ENTRYPOINT in compiler.h.
215 monolithic_binaries = is_win
Primiano Tucci02c11762019-08-30 00:57:59 +0200216
217 # Whether DLOG should be enabled on debug builds (""), all builds ("on"), or
218 # none ("off"). We disable it by default for embedders to avoid spamming their
219 # console.
220 perfetto_force_dlog = perfetto_force_dlog_default
Primiano Tucci824be142020-07-08 16:15:44 +0100221
Primiano Tucci1a69d012021-09-07 14:52:27 +0100222 # Whether DCHECKs should be enabled or not. Values: "on" | "off" | "".
223 # By default ("") DCHECKs are enabled only:
224 # - If DCHECK_ALWAYS_ON is defined (which is mainly a Chromium-ism).
225 # - On debug builds (i.e. if NDEBUG is NOT defined) but only in Chromium,
226 # Android and standalone builds.
227 # - On all other builds (e.g., SDK) it's off regardless of NDEBUG (unless
228 # DCHECK_ALWAYS_ON is defined).
229 # See base/logging.h for the implementation of all this.
230 perfetto_force_dcheck = ""
231
Primiano Tucci824be142020-07-08 16:15:44 +0100232 # Installs a signal handler for the most common crash signals which unwinds
233 # the stack and prints the stack trace on stderr. Requires a dependency on
234 # libbacktrace when enabled.
235 enable_perfetto_stderr_crash_dump =
Primiano Tucci42433ab2020-11-30 18:42:01 +0100236 is_debug && perfetto_build_standalone && !is_wasm && !is_win
Primiano Tucci2277f062021-11-08 22:24:05 +0000237
238 # Enables more aggressive compiler flags that assume recent Intel CPUs.
239 # Runtime checks during initialization will print an error message and exit
240 # if the CPU doesn't support those flags.
241 enable_perfetto_x64_cpu_opt =
242 current_cpu == "x64" && (is_linux || is_mac) && !is_wasm &&
243 perfetto_build_standalone && !is_perfetto_build_generator
Primiano Tucci02c11762019-08-30 00:57:59 +0200244}
245
246declare_args() {
Primiano Tuccidc77d722021-10-15 13:17:52 +0100247 perfetto_enable_git_rev_version_header =
248 enable_perfetto_version_gen && perfetto_build_standalone &&
249 !is_perfetto_build_generator
Florian Mayer89516832021-04-21 16:37:00 +0100250
Primiano Tuccia7f5a8e2021-01-02 17:10:50 +0100251 # The traced_probes daemon is very Linux-specific, as it depends on ftrace and
252 # various /proc interfaces. There is no point making its code platform-neutral
253 # as it won't do anything useful on Windows.
254 # The only reason why we still build it on Mac OS is to be able to run the
255 # unittests there and making dev on mac less cumbersome. The traced_probes
256 # code happens to build cleanly and for now the mainteinance cost on Mac is
257 # extremely low.
258 enable_perfetto_traced_probes = enable_perfetto_platform_services && !is_win
259
Eric Seckler08460482019-12-16 17:40:21 +0000260 # Whether info-level logging is enabled.
261 perfetto_verbose_logs_enabled =
262 !build_with_chromium || perfetto_force_dlog == "on"
263
Mikhail Khokhlov0f7e68d2020-01-16 15:39:27 +0000264 # Enables the SQL query layer of trace processor.
265 enable_perfetto_trace_processor_sqlite =
266 enable_perfetto_trace_processor &&
267 (build_with_chromium || !perfetto_build_with_embedder)
268
Primiano Tucci02c11762019-08-30 00:57:59 +0200269 # Enables the optional SQLite percentile module.
270 enable_perfetto_trace_processor_percentile =
271 enable_perfetto_trace_processor && perfetto_build_standalone
272
Primiano Tucci02c11762019-08-30 00:57:59 +0200273 # Enables the REPL interactive prompt in the trace processor.
274 enable_perfetto_trace_processor_linenoise =
275 perfetto_build_standalone && enable_perfetto_trace_processor &&
276 (is_linux || is_android || is_mac)
Eric Secklerde589952019-10-17 12:46:07 +0100277
Eric Seckler510a3ee2019-11-01 13:23:24 +0000278 # Enables JSON support in the trace processor. Required for JSON trace import
Lalit Maganti6d1f7b52020-02-27 13:16:44 +0000279 # and export.
Eric Secklerde589952019-10-17 12:46:07 +0100280 enable_perfetto_trace_processor_json =
281 enable_perfetto_trace_processor && !perfetto_build_with_android
Eric Secklerac2ea612019-10-21 16:44:39 +0100282
Primiano Tuccia36cccc2019-10-27 13:15:04 +0100283 # Enables httpd RPC support in the trace processor.
284 # Further per-OS conditionals are applied in gn/BUILD.gn.
285 enable_perfetto_trace_processor_httpd =
Paul Thomson4a792952021-06-04 13:51:47 +0100286 enable_perfetto_trace_processor &&
287 (perfetto_build_standalone || perfetto_build_with_android)
Primiano Tucci1b5fdae2020-01-16 09:28:05 +0000288
289 # Enables Zlib support. This is used both by the "perfetto" cmdline client
290 # (for compressing traces) and by trace processor (for compressed traces).
291 enable_perfetto_zlib =
Mohit Saini98097092022-02-17 14:40:44 +0000292 (enable_perfetto_trace_processor && !build_with_chromium) ||
293 enable_perfetto_platform_services
Primiano Tucci02c11762019-08-30 00:57:59 +0200294}
295
Eric Secklera7870e62019-11-01 10:11:58 +0000296declare_args() {
297 # Enables the trace_to_text tool.
Mikhail Khokhlov0f7e68d2020-01-16 15:39:27 +0000298 enable_perfetto_tools_trace_to_text =
299 enable_perfetto_tools && enable_perfetto_trace_processor_sqlite
Eric Secklera7870e62019-11-01 10:11:58 +0000300
301 # Allows to build the UI (TypeScript/ HTML / WASM)
Mikhail Khokhlov0f7e68d2020-01-16 15:39:27 +0000302 enable_perfetto_ui =
Primiano Tucci42433ab2020-11-30 18:42:01 +0100303 perfetto_build_standalone && enable_perfetto_trace_processor_sqlite &&
304 host_os != "win"
Joel Fernandes090d2712020-02-24 13:53:27 -0500305
306 # Skip buildtools dependency checks (needed for ChromeOS).
307 skip_buildtools_check = false
Joel Fernandes80fc3cd2020-04-01 18:02:57 -0400308
309 # Used by CrOS system builds. Uses the system version of protobuf
310 # from /usr/include instead of the hermetic one.
311 perfetto_use_system_protobuf = false
Florian Mayer319ba562021-04-20 17:35:03 +0100312
313 perfetto_use_system_zlib = false
Eric Secklera7870e62019-11-01 10:11:58 +0000314}
315
Primiano Tucci2f811552020-12-07 16:48:22 +0100316if (is_win) {
317 # clang-cl
318 perfetto_isystem_cflag = "/I"
319} else {
320 perfetto_isystem_cflag = "-isystem"
321}
322
Primiano Tucci02c11762019-08-30 00:57:59 +0200323# +---------------------------------------------------------------------------+
324# | Cross-checks |
325# +---------------------------------------------------------------------------+
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100326
Primiano Tucci7c7f5f52019-01-15 21:47:04 +0000327# Exactly one between build_with_android, build_standalone and
328# build_with_embedder must be true.
329assert(perfetto_build_standalone || perfetto_build_with_android ||
330 perfetto_build_with_embedder)
331assert(!(perfetto_build_with_android && perfetto_build_standalone))
332assert(!(perfetto_build_with_embedder && perfetto_build_standalone))
333assert(!(perfetto_build_with_android && perfetto_build_with_embedder))
334
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100335# If |build_with_chromium| is true then also |perfetto_build_with_embedder|
336# must be true
337assert(!build_with_chromium || perfetto_build_with_embedder)
Stephen Nusko5da63f32019-04-25 17:06:26 +0100338
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200339# If |perfetto_build_with_android| is true then also
340# |is_perfetto_build_generator| must be true.
341assert(!perfetto_build_with_android || is_perfetto_build_generator)
Primiano Tucci2bf82842019-08-27 07:10:55 +0200342
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200343# We should never end up in a state where is_perfetto_embedder=true but
344# perfetto_build_with_embedder=false.
345assert(!is_perfetto_embedder || perfetto_build_with_embedder)
Primiano Tucci02c11762019-08-30 00:57:59 +0200346
347# The monolithic binaries is not supported when building in the Android tree.
348assert(!monolithic_binaries || !perfetto_build_with_android)
349
350# Watchdog must be on in Android builds.
351assert(enable_perfetto_watchdog || !perfetto_build_with_android)
352
353assert(perfetto_force_dlog == "" || perfetto_force_dlog == "on" ||
354 perfetto_force_dlog == "off")
Primiano Tuccia7f5a8e2021-01-02 17:10:50 +0100355
356# If enable_perfetto_traced_probes is set, enable_perfetto_platform_services
357# must be set as well. Doesn't make sense to build traced_probes without the
358# rest. traced_probes integration tests depend on traced.
359assert(!enable_perfetto_traced_probes || enable_perfetto_platform_services)