blob: 5049827303d7268489c9a6b7f524c432c6747102 [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("perfetto.gni")
Primiano Tucci4c5efa42018-10-23 13:15:13 +010016import("proto_library.gni")
Primiano Tucci7e05fc12019-08-27 17:29:47 +020017
18if (perfetto_root_path == "//") {
Andres Medina2cf423c2019-03-29 10:27:49 -070019 import("//gn/standalone/sanitizers/vars.gni")
20} else {
21 import("//build/config/sanitizers/sanitizers.gni")
22}
23
Primiano Tucci8e627442019-08-28 07:58:38 +020024# Genereates a header files that contains a macro definition for each build flag
25# that is required by the codebase. This is to avoid sprinkling cflags all over
26# the places, which is very fragile especially for our codebase that needs to
27# deal with several build systems.
28# The way this works is the following:
29# - This rule generates a header that contains a bunch of lines like:
Primiano Tucci02c11762019-08-30 00:57:59 +020030# #define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_ANDROID_BUILD()
Primiano Tucci8e627442019-08-28 07:58:38 +020031# - The generated header is included by base/build_config.h
32# - Source files in the codebase #include base/build_config and use the
33# pattern #if PERFETTO_BUILDFLAG(PERFETTO_ANDROID_BUILD)
34buildflag_gen_dir_ = "$root_gen_dir/$perfetto_root_path/build_config"
35action("gen_buildflags") {
36 script = "write_buildflag_header.py"
37 gen_header_path = "$buildflag_gen_dir_/perfetto_build_flags.h"
38
39 perfetto_component_build = false
40 if (defined(is_component_build) && is_component_build) {
41 perfetto_component_build = true
42 }
43 perfetto_force_dlog_on = perfetto_force_dlog == "on"
44 perfetto_force_dlog_off = perfetto_force_dlog == "off"
45
Primiano Tucci18c0cff2019-09-09 17:09:03 -070046 # We can't just use (is_linux || is_android) in perfetto.gni because that
47 # doesn't work in Android Mac host builds. We lose the GN notion of OS once
48 # we run the tools/gen_xxx generators.
49 if (enable_perfetto_watchdog) {
50 perfetto_watchdog = "PERFETTO_BUILDFLAG_DEFINE_PERFETTO_OS_ANDROID() || " +
51 "PERFETTO_BUILDFLAG_DEFINE_PERFETTO_OS_LINUX()"
52 } else {
53 perfetto_watchdog = "0"
54 }
Primiano Tucci41af34f2019-10-01 13:09:22 +010055 if (enable_perfetto_tools) {
Florian Mayer4c955702020-06-10 20:37:38 +020056 perfetto_local_symbolizer =
57 "PERFETTO_BUILDFLAG_DEFINE_PERFETTO_OS_LINUX() || " +
58 "PERFETTO_BUILDFLAG_DEFINE_PERFETTO_OS_MACOSX()"
Primiano Tucci41af34f2019-10-01 13:09:22 +010059 } else {
60 perfetto_local_symbolizer = "0"
61 }
Primiano Tuccia36cccc2019-10-27 13:15:04 +010062 if (enable_perfetto_trace_processor_httpd) {
63 perfetto_tp_httpd = "PERFETTO_BUILDFLAG_DEFINE_PERFETTO_OS_ANDROID() || " +
64 "PERFETTO_BUILDFLAG_DEFINE_PERFETTO_OS_LINUX() || " +
65 "PERFETTO_BUILDFLAG_DEFINE_PERFETTO_OS_MACOSX()"
66 } else {
67 perfetto_tp_httpd = "0"
68 }
Primiano Tucci41af34f2019-10-01 13:09:22 +010069
Primiano Tucci8e627442019-08-28 07:58:38 +020070 response_file_contents = [
71 "--flags", # Keep this marker first.
72 "PERFETTO_ANDROID_BUILD=$perfetto_build_with_android",
Primiano Tucci8e627442019-08-28 07:58:38 +020073 "PERFETTO_CHROMIUM_BUILD=$build_with_chromium",
74 "PERFETTO_STANDALONE_BUILD=$perfetto_build_standalone",
75 "PERFETTO_START_DAEMONS=$start_daemons_for_testing",
Primiano Tucci02c11762019-08-30 00:57:59 +020076 "PERFETTO_IPC=$enable_perfetto_ipc",
Primiano Tucci18c0cff2019-09-09 17:09:03 -070077 "PERFETTO_WATCHDOG=$perfetto_watchdog",
Primiano Tucci8e627442019-08-28 07:58:38 +020078 "PERFETTO_COMPONENT_BUILD=$perfetto_component_build",
79 "PERFETTO_FORCE_DLOG_ON=$perfetto_force_dlog_on",
80 "PERFETTO_FORCE_DLOG_OFF=$perfetto_force_dlog_off",
Eric Seckler08460482019-12-16 17:40:21 +000081 "PERFETTO_VERBOSE_LOGS=$perfetto_verbose_logs_enabled",
Primiano Tucci02c11762019-08-30 00:57:59 +020082 "PERFETTO_VERSION_GEN=$enable_perfetto_version_gen",
Primiano Tucci02c11762019-08-30 00:57:59 +020083 "PERFETTO_TP_PERCENTILE=$enable_perfetto_trace_processor_percentile",
Eric Secklerde589952019-10-17 12:46:07 +010084 "PERFETTO_TP_LINENOISE=$enable_perfetto_trace_processor_linenoise",
Primiano Tuccia36cccc2019-10-27 13:15:04 +010085 "PERFETTO_TP_HTTPD=$perfetto_tp_httpd",
Eric Secklerde589952019-10-17 12:46:07 +010086 "PERFETTO_TP_JSON=$enable_perfetto_trace_processor_json",
Primiano Tucci41af34f2019-10-01 13:09:22 +010087 "PERFETTO_LOCAL_SYMBOLIZER=$perfetto_local_symbolizer",
Primiano Tucci1b5fdae2020-01-16 09:28:05 +000088 "PERFETTO_ZLIB=$enable_perfetto_zlib",
Primiano Tucci8e627442019-08-28 07:58:38 +020089 ]
90
91 rel_out_path = rebase_path(gen_header_path, "$root_build_dir")
92 args = [
93 "--out",
94 rel_out_path,
95 "--rsp",
96 "{{response_file_name}}",
97 ]
98
Primiano Tucci2925e9d2020-01-27 10:15:58 +000099 outputs = [ gen_header_path ]
Primiano Tucci8e627442019-08-28 07:58:38 +0200100}
101
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100102# All targets should depend on this target to inherit the right flags and
103# include directories.
104group("default_deps") {
105 public_configs = [ ":default_config" ]
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000106 deps = [ ":gen_buildflags" ]
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200107 if (perfetto_build_standalone) {
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100108 public_deps = [
Primiano Tucci69132a12020-02-07 22:33:06 +0000109 "//gn/standalone:check_build_deps",
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100110 "//gn/standalone/libc++:deps",
111 "//gn/standalone/sanitizers:deps",
112 ]
Primiano Tucci69132a12020-02-07 22:33:06 +0000113 if (is_android) {
114 public_deps += [ "//gn/standalone:check_build_deps_android" ]
115 }
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100116 }
117}
118
119# The config that all targets in the perfetto codebase inherit by virtue of
120# having explicit deps on //gn:default_deps. This config is NOT propagated up to
121# embedders that depend on perfetto (e.g. chrome). :public_config (see below) is
122# used for that.
123config("default_config") {
124 configs = [ ":public_config" ]
125 defines = [ "PERFETTO_IMPLEMENTATION" ]
126 include_dirs = [ ".." ]
127
128 if (build_with_chromium && is_android) {
129 # Included for __android_log_print
130 libs = [ "log" ]
131 }
132}
133
134# This config is propagated to embedders via libperfetto. It's also included in
135# the default_config above.
136config("public_config") {
137 include_dirs = [
138 "../include",
139
Primiano Tucci8e627442019-08-28 07:58:38 +0200140 # For perfetto_build_flags.h
141 buildflag_gen_dir_,
Eric Secklerd7fd6c22020-01-22 18:46:35 +0000142
143 # For generated files (proto libraries etc). We add the directory here
144 # because we stop propagation of the configs for individual proto libraries
145 # to avoid duplicate include directory command line flags in compiler
146 # invocations, see proto_library.gni, crbug.com/1043279, crbug.com/gn/142.
147 "$root_gen_dir/$perfetto_root_path",
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100148 ]
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100149}
150
Andres Medina2cf423c2019-03-29 10:27:49 -0700151config("asan_instrumentation") {
152 if (use_sanitizer_configs_without_instrumentation) {
153 defines = [ "ADDRESS_SANITIZER_WITHOUT_INSTRUMENTATION" ]
154 }
155}
Oystein Eftevaagdd727e42017-12-05 08:49:55 -0800156
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200157if (perfetto_root_path != "//") {
158 config("gtest_and_gmock_embedder_config") {
159 include_dirs = [
160 "//testing/gtest/include",
161 "//testing/gmock/include",
162 ]
Eric Seckler57c89d92018-10-26 15:11:55 +0100163 }
164}
165
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100166group("gtest_and_gmock") {
Oystein Eftevaagdd727e42017-12-05 08:49:55 -0800167 testonly = true
168
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200169 if (perfetto_root_path == "//") {
Oystein Eftevaagdd727e42017-12-05 08:49:55 -0800170 public_deps = [
171 "//buildtools:gmock",
172 "//buildtools:gtest",
Oystein Eftevaagdd727e42017-12-05 08:49:55 -0800173 ]
174 } else {
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200175 public_configs = [ ":gtest_and_gmock_embedder_config" ]
Oystein Eftevaagdd727e42017-12-05 08:49:55 -0800176 public_deps = [
177 "//testing/gmock",
178 "//testing/gtest",
Florian Mayerd8bd81b2018-01-25 12:49:15 +0000179 ]
180 }
181}
182
183group("gtest_main") {
184 testonly = true
185
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200186 if (perfetto_root_path == "//") {
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000187 public_deps = [ "//buildtools:gtest_main" ]
Eric Secklera6ba1792019-01-02 12:51:00 +0000188 } else if (build_with_chromium) {
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000189 public_deps = [ "//base/test:run_all_unittests" ]
Florian Mayerd8bd81b2018-01-25 12:49:15 +0000190 } else {
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000191 public_deps = [ "//testing/gtest:gtest_main" ]
Oystein Eftevaagdd727e42017-12-05 08:49:55 -0800192 }
193}
194
Primiano Tuccid0001c32019-09-08 22:45:58 -0700195# Full protobuf is just for host tools .No binary shipped on device should
196# depend on this.
197whitelisted_protobuf_full_deps = [
Primiano Tuccid0001c32019-09-08 22:45:58 -0700198 "../src/ipc/protoc_plugin:*",
199 "../src/protozero/protoc_plugin:*",
200 "../src/trace_processor:trace_processor_shell",
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000201 "../tools/*",
Primiano Tuccid0001c32019-09-08 22:45:58 -0700202]
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100203
Primiano Tuccib7ebffd2019-09-09 07:42:35 -0700204group("protoc") {
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000205 public_deps = [ "${perfetto_protobuf_target_prefix}:protoc($host_toolchain)" ]
Primiano Tuccib7ebffd2019-09-09 07:42:35 -0700206}
Primiano Tuccid0001c32019-09-08 22:45:58 -0700207
Joel Fernandes80fc3cd2020-04-01 18:02:57 -0400208config("system_protoc") {
209 libs = [ "protoc" ] # This will link against libprotoc.so
210}
211
212config("system_protobuf") {
213 libs = [ "protobuf" ] # This will link against libprotobuf.so
214}
215
Primiano Tuccid0001c32019-09-08 22:45:58 -0700216# protoc compiler library, it's used for building protoc plugins and by
217# trace_processor_shell to dynamically load .proto files for metrics.
218group("protoc_lib") {
219 visibility = whitelisted_protobuf_full_deps
Primiano Tuccib7ebffd2019-09-09 07:42:35 -0700220 if (current_toolchain == host_toolchain) {
Joel Fernandes80fc3cd2020-04-01 18:02:57 -0400221 if (perfetto_use_system_protobuf) {
Primiano Tucci5cbeadf2020-04-03 22:28:40 +0100222 public_configs = [
223 ":system_protobuf",
224 ":system_protoc",
Primiano Tuccie95bb962020-04-06 09:05:02 +0100225 ":protobuf_gen_config",
Primiano Tucci5cbeadf2020-04-03 22:28:40 +0100226 ]
Joel Fernandes80fc3cd2020-04-01 18:02:57 -0400227 } else {
228 public_deps = [ "${perfetto_protobuf_target_prefix}:protoc_lib" ]
229 }
Primiano Tuccib7ebffd2019-09-09 07:42:35 -0700230 }
Oystein Eftevaagdd727e42017-12-05 08:49:55 -0800231}
232
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100233group("protobuf_full") {
Primiano Tuccid0001c32019-09-08 22:45:58 -0700234 visibility = whitelisted_protobuf_full_deps
Primiano Tuccib7ebffd2019-09-09 07:42:35 -0700235 if (current_toolchain == host_toolchain) {
Joel Fernandes80fc3cd2020-04-01 18:02:57 -0400236 if (perfetto_use_system_protobuf) {
237 public_configs = [ ":system_protobuf" ]
238 } else {
239 public_deps = [ "${perfetto_protobuf_target_prefix}:protobuf_full" ]
240 }
Primiano Tuccib7ebffd2019-09-09 07:42:35 -0700241 }
Oystein Eftevaagdd727e42017-12-05 08:49:55 -0800242}
243
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100244group("protobuf_lite") {
Joel Fernandes80fc3cd2020-04-01 18:02:57 -0400245 if (perfetto_use_system_protobuf) {
246 public_configs = [ ":system_protobuf" ]
247 } else {
248 public_deps = [ "${perfetto_protobuf_target_prefix}:protobuf_lite" ]
249 }
Oystein Eftevaag5e8a4eb2018-01-09 11:41:58 -0800250}
Florian Mayer3a3974e2018-01-24 11:37:29 +0000251
Primiano Tuccie95bb962020-04-06 09:05:02 +0100252# This config is applied to the .pb.{cc,h} generated by proto_library(). This
253# config is propagated up to the source sets that depend on generated proto
254# headers and proto libraries. Therefore this should stay as lean and clean as
255# possible in terms of -W-no* suppressions. Thankfully the autogenerated .pb.h
256# headers violate less warnings than the libprotobuf_* library itself.
257# This config is defined here (as opposed to //buildtools/BUILD.gn) so that when
258# perfetto_use_system_protobuf=true, the right compiler flags are passed.
259config("protobuf_gen_config") {
260 visibility = [ "*" ] # This is injected by standalone/proto_library.gni
261 defines = [
262 "GOOGLE_PROTOBUF_NO_RTTI",
263 "GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER",
264 ]
265 cflags = [
266 "-Wno-unknown-warning-option",
267 "-Wno-deprecated",
268 "-Wno-undef",
269 "-Wno-zero-as-null-pointer-constant",
270 ]
271
272 if (!perfetto_use_system_protobuf) {
273 cflags += [
274 # Using -isystem instead of include_dirs (-I), so we don't need to
275 # suppress warnings coming from libprotobuf headers. Doing so would mask
276 # warnings in our own code.
277 "-isystem",
278 rebase_path("../buildtools/protobuf/src", root_build_dir),
279 ]
280 }
281}
282
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100283# The Google C++ Benchmark library.
Hector Dearman5145e502019-09-18 16:52:24 +0100284# Only available in standalone builds.
Primiano Tucci02c11762019-08-30 00:57:59 +0200285if (enable_perfetto_benchmarks) {
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200286 group("benchmark") {
287 testonly = true
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000288 public_deps = [ "//buildtools:benchmark" ]
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100289 }
290}
291
292# Libbacktrace, used for printing stack traces from crash handler, only in
293# standalone debug builds.
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200294if (perfetto_build_standalone && (is_linux || is_android)) {
295 group("libbacktrace") {
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000296 public_deps = [ "//buildtools:libbacktrace" ]
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100297 }
298}
299
Mikhail Khokhlov0f7e68d2020-01-16 15:39:27 +0000300if (enable_perfetto_trace_processor_sqlite) {
301 group("sqlite") {
302 if (perfetto_root_path == "//") {
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000303 public_deps = [ "//buildtools:sqlite" ]
Mikhail Khokhlov0f7e68d2020-01-16 15:39:27 +0000304 } else {
Mikhail Khokhlov302f1f62020-03-12 12:08:29 +0000305 if (build_with_chromium) {
306 public_deps = [ "//third_party/sqlite:sqlite_dev" ]
307 } else {
308 public_deps = [ "//third_party/sqlite:sqlite" ]
309 }
Mikhail Khokhlov0f7e68d2020-01-16 15:39:27 +0000310 public_configs = [ ":sqlite_third_party_include_path" ]
311 }
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100312 }
Mikhail Khokhlov2bcfb352019-12-20 10:19:58 +0000313}
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100314
Mikhail Khokhlov2bcfb352019-12-20 10:19:58 +0000315config("sqlite_third_party_include_path") {
Mikhail Khokhlov302f1f62020-03-12 12:08:29 +0000316 if (build_with_chromium) {
317 include_dirs = [ "//third_party/sqlite/dev" ]
318 } else {
319 include_dirs = [ "//third_party/sqlite" ]
320 }
Mikhail Khokhlov2bcfb352019-12-20 10:19:58 +0000321}
Primiano Tucci02c11762019-08-30 00:57:59 +0200322
323if (enable_perfetto_trace_processor_json) {
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200324 group("jsoncpp") {
325 if (perfetto_root_path == "//") {
326 public_configs = [ "//buildtools:jsoncpp_config" ]
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000327 public_deps = [ "//buildtools:jsoncpp" ]
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200328 } else {
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000329 public_deps = [ "//third_party/jsoncpp:jsoncpp" ]
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200330 }
331 }
Primiano Tucci02c11762019-08-30 00:57:59 +0200332}
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200333
Primiano Tucci02c11762019-08-30 00:57:59 +0200334if (enable_perfetto_trace_processor_linenoise) {
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200335 # Used by the trace_processor_shell for REPL history.
Hector Dearman5145e502019-09-18 16:52:24 +0100336 # Only available in standalone builds.
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200337 group("linenoise") {
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000338 public_deps = [ "//buildtools:linenoise" ]
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200339 }
Primiano Tucci02c11762019-08-30 00:57:59 +0200340} # if (enable_perfetto_trace_processor_linenoise)
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200341
342# Only used by src/profiling in standalone and android builds.
Ryan Savitski56bc0c62020-01-27 13:50:02 +0000343if (enable_perfetto_heapprofd || enable_perfetto_traced_perf) {
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200344 group("libunwindstack") {
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100345 public_configs = [ "//buildtools:libunwindstack_config" ]
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000346 public_deps = [ "//buildtools:libunwindstack" ]
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100347 }
348}
Ryan Savitski154bfab2019-06-07 15:12:27 +0100349
Ryan Savitski56bc0c62020-01-27 13:50:02 +0000350# Used by src/profiling/perf for perf_regs.h.
351if (enable_perfetto_traced_perf) {
352 group("bionic_kernel_uapi_headers") {
353 public_configs = [ "//buildtools:bionic_kernel_uapi_headers" ]
354 }
355}
356
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200357# Zlib is used both by trace_processor and by perfetto_cmd.
Primiano Tucci1b5fdae2020-01-16 09:28:05 +0000358if (enable_perfetto_zlib) {
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200359 group("zlib") {
360 if (perfetto_root_path == "//") {
361 public_configs = [ "//buildtools:zlib_config" ]
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000362 public_deps = [ "//buildtools:zlib" ]
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200363 } else {
364 public_configs = [ "//third_party/zlib:zlib_config" ]
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000365 public_deps = [ "//third_party/zlib" ]
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200366 }
367 }
368}
369
Ryan Savitski154bfab2019-06-07 15:12:27 +0100370# Used by fuzzers.
Florian Mayer0bea7972019-09-02 15:28:13 +0100371if (enable_perfetto_fuzzers && use_libfuzzer) {
Ryan Savitski154bfab2019-06-07 15:12:27 +0100372 group("libfuzzer") {
Primiano Tucci02c11762019-08-30 00:57:59 +0200373 assert(perfetto_root_path == "//")
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000374 public_deps = [ "//buildtools:libfuzzer" ]
Ryan Savitski154bfab2019-06-07 15:12:27 +0100375 }
376}