• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 override 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  # For now the IPC layer is conservatively not enabled on Chromium+Windows
148  # builds.
149  enable_perfetto_ipc =
150      !is_nacl && (perfetto_build_standalone || perfetto_build_with_android ||
151                   (build_with_chromium && !is_win) || is_fuchsia)
152
153  # Makes the heap profiling daemon target reachable. It works only on Android,
154  # but is built on Linux as well for test/compiler coverage.
155  # On Android, it requires API level 26 due to libunwindstack.
156  enable_perfetto_heapprofd =
157      perfetto_build_with_android ||
158      (perfetto_build_standalone && is_clang &&
159       (is_linux || (is_android && android_api_level >= 26)))
160
161  # Build the perf event profiler (traced_perf).
162  # TODO(rsavitski): figure out how to make the android-core dependencies build
163  # under gcc (_Atomic and other issues).
164  enable_perfetto_traced_perf =
165      perfetto_build_with_android ||
166      (perfetto_build_standalone && is_clang &&
167       (is_linux || (is_android && android_api_level >= 29)))
168
169  # The Trace Processor: offline analytical engine to process traces and compute
170  # metrics using a SQL engine.
171  if (!defined(enable_perfetto_trace_processor)) {
172    enable_perfetto_trace_processor =
173        perfetto_build_standalone || build_with_chromium ||
174        is_perfetto_build_generator
175  }
176
177  # Enables base::Watchdog. Is supported only on Linux-based platforms in
178  # standalone GN builds (NOT in bazel/blaze).
179  # gn/BUILD.gn further restricts this to OS_LINUX || OS_ANDROID when generating
180  # the perfetto_build_flags.h header.
181  enable_perfetto_watchdog =
182      perfetto_build_with_android ||
183      (perfetto_build_standalone && !is_perfetto_build_generator)
184
185  # Misc host executable under tools/.
186  enable_perfetto_tools =
187      perfetto_build_standalone || perfetto_build_with_android
188
189  enable_perfetto_unittests = perfetto_build_standalone ||
190                              build_with_chromium || perfetto_build_with_android
191
192  enable_perfetto_integration_tests =
193      perfetto_build_standalone || perfetto_build_with_android
194
195  enable_perfetto_benchmarks = perfetto_build_standalone && !is_win
196
197  enable_perfetto_fuzzers =
198      perfetto_build_standalone && defined(is_fuzzer) && is_fuzzer
199
200  # Enables the write_version_header.py tool that generates a .h that contains a
201  # macro with the current git revision and latest release version from
202  # CHANGELOG. If false base/version.h will return "unknown".
203  enable_perfetto_version_gen =
204      perfetto_build_standalone || is_perfetto_build_generator ||
205      perfetto_build_with_android
206
207  # Only for local development. When true the binaries (perfetto, traced, ...)
208  # are monolithic and don't use a common shared library. This is mainly to
209  # avoid LD_LIBRARY_PATH dances when testing locally.
210  # On Windows we default to monolithic executables, because pairing
211  # dllexport/import adds extra complexity for little benefit. Te only reason
212  # for monolithic_binaries=false is saving binary size, which matters mainly on
213  # Android. See also comments on PERFETTO_EXPORT_ENTRYPOINT in compiler.h.
214  monolithic_binaries = !perfetto_build_with_android && (is_win || is_mac)
215
216  # Whether DLOG should be enabled on debug builds (""), all builds ("on"), or
217  # none ("off"). We disable it by default for embedders to avoid spamming their
218  # console.
219  perfetto_force_dlog = perfetto_force_dlog_default
220
221  # Whether DCHECKs should be enabled or not. Values: "on" | "off" | "".
222  # By default ("") DCHECKs are enabled only:
223  # - If DCHECK_ALWAYS_ON is defined (which is mainly a Chromium-ism).
224  # - On debug builds (i.e. if NDEBUG is NOT defined) but only in Chromium,
225  #   Android and standalone builds.
226  # - On all other builds (e.g., SDK) it's off regardless of NDEBUG (unless
227  #   DCHECK_ALWAYS_ON is defined).
228  # See base/logging.h for the implementation of all this.
229  perfetto_force_dcheck = ""
230
231  # Installs a signal handler for the most common crash signals which unwinds
232  # the stack and prints the stack trace on stderr. Requires a dependency on
233  # libbacktrace when enabled.
234  enable_perfetto_stderr_crash_dump =
235      is_debug && perfetto_build_standalone && !is_wasm && !is_win
236
237  # Enables more aggressive compiler flags that assume recent Intel CPUs.
238  # Runtime checks during initialization will print an error message and exit
239  # if the CPU doesn't support those flags.
240  # Don't enable by default for MacOS. Old Intel Macs as used in CIs
241  # etc don't have the fancy CPU instructions (i.e. AVX2) this implies.
242  enable_perfetto_x64_cpu_opt =
243      current_cpu == "x64" && is_linux && !is_wasm &&
244      perfetto_build_standalone && !is_perfetto_build_generator
245}
246
247declare_args() {
248  # When false, it disables system backend consumer support in the Perfetto SDK.
249  # Saves ~300KB binary size.
250  if (!defined(enable_perfetto_system_consumer)) {
251    enable_perfetto_system_consumer = enable_perfetto_ipc
252  }
253}
254
255declare_args() {
256  perfetto_enable_git_rev_version_header =
257      enable_perfetto_version_gen && perfetto_build_standalone &&
258      !is_perfetto_build_generator
259
260  # The traced_probes daemon is very Linux-specific, as it depends on ftrace and
261  # various /proc interfaces. There is no point making its code platform-neutral
262  # as it won't do anything useful on Windows.
263  # The only reason why we still build it on Mac OS is to be able to run the
264  # unittests there and making dev on mac less cumbersome. The traced_probes
265  # code happens to build cleanly and for now the mainteinance cost on Mac is
266  # extremely low.
267  enable_perfetto_traced_probes = enable_perfetto_platform_services && !is_win
268
269  # The relay service is enabled when platform services are enabled.
270  # TODO(chinglinyu) check if we can enable on Windows.
271  enable_perfetto_traced_relay = enable_perfetto_platform_services && !is_win
272
273  # Whether info-level logging is enabled.
274  perfetto_verbose_logs_enabled =
275      !build_with_chromium || perfetto_force_dlog == "on"
276
277  # Enables the SQL query layer of trace processor.
278  enable_perfetto_trace_processor_sqlite =
279      enable_perfetto_trace_processor &&
280      (build_with_chromium || !perfetto_build_with_embedder)
281
282  # Enables the optional SQLite percentile module.
283  enable_perfetto_trace_processor_percentile =
284      enable_perfetto_trace_processor &&
285      (perfetto_build_standalone || perfetto_build_with_android)
286
287  # Enables the REPL interactive prompt in the trace processor.
288  enable_perfetto_trace_processor_linenoise =
289      perfetto_build_standalone && enable_perfetto_trace_processor &&
290      (is_linux || is_android || is_mac)
291
292  # Enables JSON support in the trace processor. Required for JSON trace import
293  # and export.
294  enable_perfetto_trace_processor_json =
295      enable_perfetto_trace_processor && !perfetto_build_with_android
296
297  # Enables httpd RPC support in the trace processor.
298  # Further per-OS conditionals are applied in gn/BUILD.gn.
299  # Chromium+Win: httpd support depends on enable_perfetto_ipc, which is not
300  # enabled on Chromium+Win for now (see a comment there).
301  enable_perfetto_trace_processor_httpd =
302      enable_perfetto_trace_processor &&
303      (perfetto_build_standalone || perfetto_build_with_android ||
304       (build_with_chromium && !is_win))
305
306  # Enables Zlib support. This is used to compress traces (by the tracing
307  # service and by the "perfetto" cmdline client) and to decompress traces (by
308  # trace_processor).
309  enable_perfetto_zlib =
310      enable_perfetto_trace_processor || enable_perfetto_platform_services
311
312  # Enables function name demangling using sources from llvm. Otherwise
313  # trace_processor falls back onto using the c++ runtime demangler, which
314  # typically handles only itanium mangling.
315  # llvm-demangle is incompatible with GCC and can be used only when building
316  # with clang.
317  enable_perfetto_llvm_demangle =
318      is_clang && enable_perfetto_trace_processor && perfetto_build_standalone
319
320  # Enables gRPC in the Perfetto codebase. gRPC significantly increases build
321  # times and the general footprint of Perfetto. As it only required for
322  # BigTrace and even then only to build the final ready-to-ship binary, don't
323  # enable this by default.
324  enable_perfetto_grpc = false
325}
326
327declare_args() {
328  # Enables the traceconv tool.
329  enable_perfetto_traceconv =
330      enable_perfetto_tools && enable_perfetto_trace_processor_sqlite
331
332  # Allows to build the UI (TypeScript/ HTML / WASM)
333  enable_perfetto_ui =
334      perfetto_build_standalone && enable_perfetto_trace_processor_sqlite &&
335      host_os != "win"
336
337  # Allows to build the perfetto.dev website.
338  # WARNING: if this flag is enabled, the build performs globbing at generation
339  # time. Incremental builds that add/remove files will not be supported without
340  # rerunning gn.
341  enable_perfetto_site = false
342
343  # Check that the merged perfetto_trace.proto can be translated to a C++ lite
344  # proto and compiled. This is disabled by default because it's expensive (it
345  # can take a couple of minutes).
346  enable_perfetto_merged_protos_check = false
347
348  # Skip buildtools dependency checks (needed for ChromeOS).
349  skip_buildtools_check = false
350
351  # Used by CrOS builds. Uses pkg-config to determine the appropriate flags
352  # for including and linking system libraries.
353  #   set `host_pkg_config` to the `BUILD_PKG_CONFIG` and
354  #   set `pkg_config` to the target `PKG_CONFIG`.
355  # Note: that if this is enabled `perfetto_use_system_protobuf` should be also.
356  perfetto_use_pkgconfig = false
357
358  # Used by CrOS system builds. Uses the system version of protobuf
359  # from /usr/include instead of the hermetic one.
360  perfetto_use_system_protobuf = false
361
362  # Used by CrOS system builds. Uses the system version of sqlite
363  # from /usr/include instead of the hermetic one.
364  perfetto_use_system_sqlite = false
365
366  perfetto_use_system_zlib = false
367}
368
369if (is_win) {
370  # clang-cl
371  perfetto_isystem_cflag = "/I"
372} else {
373  perfetto_isystem_cflag = "-isystem"
374}
375
376# +---------------------------------------------------------------------------+
377# | Cross-checks                                                              |
378# +---------------------------------------------------------------------------+
379
380# Exactly one between build_with_android, build_standalone and
381# build_with_embedder must be true.
382assert(perfetto_build_standalone || perfetto_build_with_android ||
383       perfetto_build_with_embedder)
384assert(!(perfetto_build_with_android && perfetto_build_standalone))
385assert(!(perfetto_build_with_embedder && perfetto_build_standalone))
386assert(!(perfetto_build_with_android && perfetto_build_with_embedder))
387
388# If |build_with_chromium| is true then also |perfetto_build_with_embedder|
389# must be true
390assert(!build_with_chromium || perfetto_build_with_embedder)
391
392# If |perfetto_build_with_android| is true then also
393# |is_perfetto_build_generator| must be true.
394assert(!perfetto_build_with_android || is_perfetto_build_generator)
395
396# We should never end up in a state where is_perfetto_embedder=true but
397# perfetto_build_with_embedder=false.
398assert(!is_perfetto_embedder || perfetto_build_with_embedder)
399
400# The monolithic binaries is not supported when building in the Android tree.
401assert(!monolithic_binaries || !perfetto_build_with_android)
402
403# Watchdog must be on in Android builds.
404assert(enable_perfetto_watchdog || !perfetto_build_with_android)
405
406assert(perfetto_force_dlog == "" || perfetto_force_dlog == "on" ||
407       perfetto_force_dlog == "off")
408
409# If enable_perfetto_traced_probes is set, enable_perfetto_platform_services
410# must be set as well. Doesn't make sense to build traced_probes without the
411# rest. traced_probes integration tests depend on traced.
412assert(!enable_perfetto_traced_probes || enable_perfetto_platform_services)
413
414# |perfetto_use_pkgconfig| changes the behavior of
415# |perfetto_use_system_protobuf|, so if perfetto_use_pkgconfig is set,
416# |perfetto_use_system_protobuf| must be set.
417assert(!perfetto_use_pkgconfig || perfetto_use_system_protobuf,
418       "perfetto_use_pkgconfig requires perfetto_use_system_protobuf")
419