• 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
73if (!defined(is_gcc)) {
74  is_gcc = !is_clang && !is_win
75}
76
77if (!defined(is_qnx)) {
78  is_qnx = false
79}
80
81declare_args() {
82  # The Android blueprint file generator set this to true (as well as
83  # is_perfetto_build_generator). This is just about being built in the
84  # Android tree (AOSP and internal) and is NOT related with the target OS.
85  # In standalone Android builds and Chromium Android builds, this is false.
86  perfetto_build_with_android = false
87
88  # All the tools/gen_* scripts set this to true. This is mainly used to locate
89  # .gni files from //gn rather than //build.
90  is_perfetto_build_generator = false
91
92  # This is for override via `gn args` (e.g. for tools/gen_xxx). Embedders
93  # based on GN (e.g. v8) should NOT set this and instead directly sets
94  # perfetto_build_with_embedder=true in their GN files.
95  is_perfetto_embedder = false
96}
97
98# This can be overridden by embedders (e.g. v8) in their .gn(i) files. This must
99# be different from the GN args flag (is_perfetto_embedder) because of the way
100# GN works.
101if (!defined(perfetto_build_with_embedder)) {
102  perfetto_build_with_embedder = build_with_chromium || is_perfetto_embedder
103}
104
105perfetto_build_standalone =
106    !perfetto_build_with_android && !build_with_chromium &&
107    !perfetto_build_with_embedder
108
109# Only relevant for GN builds. Sets the path where perfetto lives. This is //
110# for standalone builds and //third_party/perfetto/ in embedders. The embedder
111# can override it in its GN files.
112if (perfetto_build_standalone || is_perfetto_build_generator) {
113  perfetto_root_path = "//"
114  import("//gn/standalone/android.gni")  # For android_api_level
115  import("//gn/standalone/libc++/libc++.gni")  # For use_custom_libcxx
116  import("//gn/standalone/sanitizers/vars.gni")  # For is_fuzzer
117} else if (!defined(perfetto_root_path)) {
118  perfetto_root_path = "//third_party/perfetto/"
119  import("//build/config/android/config.gni")  # For android_api_level
120}
121
122# Whether the ftrace producer and the service should be started
123# by the integration test or assumed to be running.
124# If we're building in the Android tree, we expect that the testing infra
125# will start the binaries in the system image before the tests are run.
126# In all other cases (i.e. when true), a temporary in-process instance will be
127# brought up by our own integrationtest harness.
128start_daemons_for_testing = !perfetto_build_with_android
129
130# +----------------------------------------------------------------------------+
131# | Tunable build variables for embedders                                      |
132# +----------------------------------------------------------------------------+
133# The variables in this section allow embedders to enable/disable features
134# at the build-system level. This allows to opt-in into the various services
135# and tools.
136
137perfetto_force_dlog_default = ""
138if (build_with_chromium) {
139  perfetto_force_dlog_default = "off"
140}
141
142declare_args() {
143  # Enables build of platform-wide tracing services (traced, traced_probes)
144  # and executables (perfetto_cmd, trigger_perfetto).
145  # When disabled, only the client library and other auxiliary tools can be
146  # built (for Chromium and other GN embedders).
147  # Note that traced_probes is further conditioned by the GN variable
148  # enable_perfetto_traced_probes, in the declare_args() section below.
149  enable_perfetto_platform_services =
150      perfetto_build_standalone || perfetto_build_with_android
151
152  # Allow the embedder to use the IPC layer. In turn this allows to use the
153  # system backend in the client library.
154  # This includes building things that rely on POSIX sockets, this places
155  # limitations on the supported operating systems.
156  # For now the IPC layer is conservatively not enabled on Chromium+Windows
157  # builds.
158  enable_perfetto_ipc =
159      !is_nacl && (perfetto_build_standalone || perfetto_build_with_android ||
160                   (build_with_chromium && !is_win) || is_fuchsia)
161
162  # Makes the heap profiling daemon target reachable. It works only on Android,
163  # but is built on Linux as well for test/compiler coverage.
164  # On Android, it requires API level 26 due to libunwindstack.
165  enable_perfetto_heapprofd =
166      perfetto_build_with_android ||
167      (perfetto_build_standalone && is_clang &&
168       (is_linux || (is_android && android_api_level >= 26)))
169
170  # Build the perf event profiler (traced_perf).
171  # TODO(rsavitski): figure out how to make the android-core dependencies build
172  # under gcc (_Atomic and other issues).
173  enable_perfetto_traced_perf =
174      perfetto_build_with_android ||
175      (perfetto_build_standalone && is_clang &&
176       (is_linux || (is_android && android_api_level >= 29)))
177
178  # The Trace Processor: offline analytical engine to process traces and compute
179  # metrics using a SQL engine.
180  if (!defined(enable_perfetto_trace_processor)) {
181    enable_perfetto_trace_processor =
182        perfetto_build_standalone || build_with_chromium ||
183        is_perfetto_build_generator
184  }
185
186  # Enables base::Watchdog. Is supported only on Linux-based platforms in
187  # standalone GN builds (NOT in bazel/blaze).
188  # gn/BUILD.gn further restricts this to OS_LINUX || OS_ANDROID when generating
189  # the perfetto_build_flags.h header.
190  enable_perfetto_watchdog =
191      perfetto_build_with_android ||
192      (perfetto_build_standalone && !is_perfetto_build_generator)
193
194  # Misc host executable under tools/.
195  enable_perfetto_tools =
196      perfetto_build_standalone || perfetto_build_with_android
197
198  enable_perfetto_unittests = perfetto_build_standalone ||
199                              build_with_chromium || perfetto_build_with_android
200
201  enable_perfetto_integration_tests =
202      perfetto_build_standalone || perfetto_build_with_android
203
204  enable_perfetto_android_java_sdk =
205      perfetto_build_with_android || (is_android && perfetto_build_standalone)
206
207  enable_perfetto_benchmarks = perfetto_build_standalone && !is_win && !is_qnx
208
209  enable_perfetto_fuzzers =
210      perfetto_build_standalone && defined(is_fuzzer) && is_fuzzer
211
212  # Enables the write_version_header.py tool that generates a .h that contains a
213  # macro with the current git revision and latest release version from
214  # CHANGELOG. If false base/version.h will return "unknown".
215  enable_perfetto_version_gen =
216      perfetto_build_standalone || is_perfetto_build_generator ||
217      perfetto_build_with_android
218
219  # Only for local development. When true the binaries (perfetto, traced, ...)
220  # are monolithic and don't use a common shared library. This is mainly to
221  # avoid LD_LIBRARY_PATH dances when testing locally.
222  # On Windows we default to monolithic executables, because pairing
223  # dllexport/import adds extra complexity for little benefit. Te only reason
224  # for monolithic_binaries=false is saving binary size, which matters mainly on
225  # Android. See also comments on PERFETTO_EXPORT_ENTRYPOINT in compiler.h.
226  monolithic_binaries = !perfetto_build_with_android && (is_win || is_mac)
227
228  # Whether DLOG should be enabled on debug builds (""), all builds ("on"), or
229  # none ("off"). We disable it by default for embedders to avoid spamming their
230  # console.
231  perfetto_force_dlog = perfetto_force_dlog_default
232
233  # Whether DCHECKs should be enabled or not. Values: "on" | "off" | "".
234  # By default ("") DCHECKs are enabled only:
235  # - If DCHECK_ALWAYS_ON is defined (which is mainly a Chromium-ism).
236  # - On debug builds (i.e. if NDEBUG is NOT defined) but only in Chromium,
237  #   Android and standalone builds.
238  # - On all other builds (e.g., SDK) it's off regardless of NDEBUG (unless
239  #   DCHECK_ALWAYS_ON is defined).
240  # See base/logging.h for the implementation of all this.
241  perfetto_force_dcheck = ""
242
243  # Installs a signal handler for the most common crash signals which unwinds
244  # the stack and prints the stack trace on stderr. Requires a dependency on
245  # libbacktrace when enabled.
246  enable_perfetto_stderr_crash_dump =
247      is_debug && perfetto_build_standalone && !is_wasm && !is_win && !is_qnx
248
249  # Enables more aggressive compiler flags that assume recent Intel CPUs.
250  # Runtime checks during initialization will print an error message and exit
251  # if the CPU doesn't support those flags.
252  # Don't enable by default for MacOS. Old Intel Macs as used in CIs
253  # etc don't have the fancy CPU instructions (i.e. AVX2) this implies.
254  enable_perfetto_x64_cpu_opt =
255      current_cpu == "x64" && is_linux && !is_wasm &&
256      perfetto_build_standalone && !is_perfetto_build_generator
257
258  # Enables complie-time thread safety analysis.
259  perfetto_thread_safety_annotations =
260      perfetto_build_standalone && !is_perfetto_build_generator &&
261      defined(use_custom_libcxx) && use_custom_libcxx
262}
263
264declare_args() {
265  # When false, it disables system backend consumer support in the Perfetto SDK.
266  # Saves ~300KB binary size.
267  if (!defined(enable_perfetto_system_consumer)) {
268    enable_perfetto_system_consumer = enable_perfetto_ipc
269  }
270}
271
272declare_args() {
273  perfetto_enable_git_rev_version_header =
274      enable_perfetto_version_gen && perfetto_build_standalone &&
275      !is_perfetto_build_generator
276
277  # The traced_probes daemon is very Linux-specific, as it depends on ftrace and
278  # various /proc interfaces. There is no point making its code platform-neutral
279  # as it won't do anything useful on Windows or QNX.
280  # The only reason why we still build it on Mac OS is to be able to run the
281  # unittests there and making dev on mac less cumbersome. The traced_probes
282  # code happens to build cleanly and for now the mainteinance cost on Mac is
283  # extremely low.
284  enable_perfetto_traced_probes =
285      enable_perfetto_platform_services && !is_win && !is_qnx
286
287  # The relay service is enabled when platform services are enabled.
288  # TODO(chinglinyu) check if we can enable on Windows.
289  enable_perfetto_traced_relay = enable_perfetto_platform_services && !is_win
290
291  # Whether info-level logging is enabled.
292  perfetto_verbose_logs_enabled =
293      !build_with_chromium || perfetto_force_dlog == "on"
294
295  # Enables the SQL query layer of trace processor.
296  enable_perfetto_trace_processor_sqlite =
297      enable_perfetto_trace_processor &&
298      (build_with_chromium || !perfetto_build_with_embedder)
299
300  # Enables the optional SQLite percentile module.
301  enable_perfetto_trace_processor_percentile =
302      enable_perfetto_trace_processor &&
303      (perfetto_build_standalone || perfetto_build_with_android)
304
305  # Enables the REPL interactive prompt in the trace processor.
306  enable_perfetto_trace_processor_linenoise =
307      perfetto_build_standalone && enable_perfetto_trace_processor &&
308      (is_linux || is_android || is_mac)
309
310  # Enables JSON support in the trace processor. Required for JSON trace import
311  # and export.
312  enable_perfetto_trace_processor_json =
313      enable_perfetto_trace_processor && !perfetto_build_with_android
314
315  # Enables the support for importing profiles from the MacOS Instruments app.
316  # Requires a dependency on libexpat for XML parsing.
317  # Disabled in chromium due to some fuzzer related build failure (b/363347029).
318  enable_perfetto_trace_processor_mac_instruments =
319      enable_perfetto_trace_processor &&
320      (perfetto_build_standalone || perfetto_build_with_android ||
321       is_perfetto_build_generator)
322
323  # Enables httpd RPC support in the trace processor.
324  # Further per-OS conditionals are applied in gn/BUILD.gn.
325  # Chromium+Win: httpd support depends on enable_perfetto_ipc, which is not
326  # enabled on Chromium+Win for now (see a comment there).
327  enable_perfetto_trace_processor_httpd =
328      enable_perfetto_trace_processor &&
329      (perfetto_build_standalone || perfetto_build_with_android ||
330       (build_with_chromium && !is_win))
331
332  # Enables Zlib support. This is used to compress traces (by the tracing
333  # service and by the "perfetto" cmdline client) and to decompress traces (by
334  # trace_processor).
335  enable_perfetto_zlib =
336      enable_perfetto_trace_processor || enable_perfetto_platform_services
337
338  # Enables function name demangling using sources from llvm. Otherwise
339  # trace_processor falls back onto using the c++ runtime demangler, which
340  # typically handles only itanium mangling.
341  # llvm-demangle is incompatible with GCC and can be used only when building
342  # with clang.
343  enable_perfetto_llvm_demangle =
344      is_clang && enable_perfetto_trace_processor && perfetto_build_standalone
345
346  # Enables gRPC in the Perfetto codebase. gRPC significantly increases build
347  # times and the general footprint of Perfetto. As it only required for
348  # BigTrace and even then only to build the final ready-to-ship binary, don't
349  # enable this by default.
350  enable_perfetto_grpc = false
351
352  # Enables the ETM importer in trace_processor. This feature is experimental at
353  # this point and it requires extra libraries so we only enable it in selected
354  # builds.
355  enable_perfetto_etm_importer =
356      is_linux && enable_perfetto_trace_processor && perfetto_build_standalone
357}
358
359declare_args() {
360  # Enables the traceconv tool.
361  enable_perfetto_traceconv =
362      enable_perfetto_tools && enable_perfetto_trace_processor_sqlite
363
364  # Allows to build the UI (TypeScript/ HTML / WASM)
365  enable_perfetto_ui =
366      perfetto_build_standalone && enable_perfetto_trace_processor_sqlite &&
367      host_os != "win"
368
369  # Allows to build the perfetto.dev website.
370  # WARNING: if this flag is enabled, the build performs globbing at generation
371  # time. Incremental builds that add/remove files will not be supported without
372  # rerunning gn.
373  enable_perfetto_site = false
374
375  # Check that the merged perfetto_trace.proto can be translated to a C++ lite
376  # proto and compiled. This is disabled by default because it's expensive (it
377  # can take a couple of minutes).
378  enable_perfetto_merged_protos_check = false
379
380  # Skip buildtools dependency checks (needed for ChromeOS).
381  skip_buildtools_check = false
382
383  # Used by CrOS builds. Uses pkg-config to determine the appropriate flags
384  # for including and linking system libraries.
385  #   set `host_pkg_config` to the `BUILD_PKG_CONFIG` and
386  #   set `pkg_config` to the target `PKG_CONFIG`.
387  # Note: that if this is enabled `perfetto_use_system_protobuf` should be also.
388  perfetto_use_pkgconfig = false
389
390  # Used by CrOS system builds. Uses the system version of protobuf
391  # from /usr/include instead of the hermetic one.
392  perfetto_use_system_protobuf = false
393
394  # Used by CrOS system builds. Uses the system version of sqlite
395  # from /usr/include instead of the hermetic one.
396  perfetto_use_system_sqlite = false
397
398  perfetto_use_system_zlib = false
399}
400
401if (is_win) {
402  # clang-cl
403  perfetto_isystem_cflag = "/I"
404} else {
405  perfetto_isystem_cflag = "-isystem"
406}
407
408# +---------------------------------------------------------------------------+
409# | Cross-checks                                                              |
410# +---------------------------------------------------------------------------+
411
412# Exactly one between build_with_android, build_standalone and
413# build_with_embedder must be true.
414assert(perfetto_build_standalone || perfetto_build_with_android ||
415       perfetto_build_with_embedder)
416assert(!(perfetto_build_with_android && perfetto_build_standalone))
417assert(!(perfetto_build_with_embedder && perfetto_build_standalone))
418assert(!(perfetto_build_with_android && perfetto_build_with_embedder))
419
420# If |build_with_chromium| is true then also |perfetto_build_with_embedder|
421# must be true
422assert(!build_with_chromium || perfetto_build_with_embedder)
423
424# If |perfetto_build_with_android| is true then also
425# |is_perfetto_build_generator| must be true.
426assert(!perfetto_build_with_android || is_perfetto_build_generator)
427
428# We should never end up in a state where is_perfetto_embedder=true but
429# perfetto_build_with_embedder=false.
430assert(!is_perfetto_embedder || perfetto_build_with_embedder)
431
432# The monolithic binaries is not supported when building in the Android tree.
433assert(!monolithic_binaries || !perfetto_build_with_android)
434
435# Watchdog must be on in Android builds.
436assert(enable_perfetto_watchdog || !perfetto_build_with_android)
437
438assert(perfetto_force_dlog == "" || perfetto_force_dlog == "on" ||
439       perfetto_force_dlog == "off")
440
441# If enable_perfetto_traced_probes is set, enable_perfetto_platform_services
442# must be set as well. Doesn't make sense to build traced_probes without the
443# rest. traced_probes integration tests depend on traced.
444assert(!enable_perfetto_traced_probes || enable_perfetto_platform_services)
445
446# |perfetto_use_pkgconfig| changes the behavior of
447# |perfetto_use_system_protobuf|, so if perfetto_use_pkgconfig is set,
448# |perfetto_use_system_protobuf| must be set.
449assert(!perfetto_use_pkgconfig || perfetto_use_system_protobuf,
450       "perfetto_use_pkgconfig requires perfetto_use_system_protobuf")
451