xref: /aosp_15_r20/external/perfetto/src/base/BUILD.gn (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
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("../../gn/gen_perfetto_version_header.gni")
16import("../../gn/perfetto.gni")
17import("../../gn/perfetto_component.gni")
18import("../../gn/test.gni")
19import("../../gn/wasm.gni")
20
21# On standalone builds this is all the OSes we support. On chromium builds,
22# though, this really means !is_fuchsia && !is_nacl.
23_subprocess_supported =
24    is_linux || is_chromeos || is_android || is_mac || is_win
25
26perfetto_component("base") {
27  deps = [
28    "../../gn:base_platform",
29    "../../gn:default_deps",
30  ]
31  public_deps = [
32    "../../include/perfetto/base",
33    "../../include/perfetto/ext/base",
34  ]
35  sources = [
36    "android_utils.cc",
37    "base64.cc",
38    "crash_keys.cc",
39    "ctrl_c_handler.cc",
40    "event_fd.cc",
41    "file_utils.cc",
42    "getopt_compat.cc",
43    "log_ring_buffer.h",
44    "logging.cc",
45    "metatrace.cc",
46    "paged_memory.cc",
47    "periodic_task.cc",
48    "pipe.cc",
49    "scoped_mmap.cc",
50    "status.cc",
51    "string_splitter.cc",
52    "string_utils.cc",
53    "string_view.cc",
54    "string_view_splitter.cc",
55    "temp_file.cc",
56    "thread_checker.cc",
57    "thread_utils.cc",
58    "time.cc",
59    "utils.cc",
60    "uuid.cc",
61    "virtual_destructors.cc",
62    "waitable_event.cc",
63    "watchdog_posix.cc",
64    "weak_runner.cc",
65  ]
66
67  if (!is_nacl) {
68    sources += [
69      "thread_task_runner.cc",
70      "unix_task_runner.cc",
71    ]
72  }
73
74  if (_subprocess_supported) {
75    sources += [
76      "subprocess.cc",
77      "subprocess_posix.cc",
78      "subprocess_windows.cc",
79    ]
80  }
81
82  if (enable_perfetto_stderr_crash_dump) {
83    deps += [ ":debug_crash_stack_trace" ]
84  }
85}
86
87perfetto_component("clock_snapshots") {
88  deps = [ "../../gn:default_deps" ]
89  public_deps = [
90    "../../include/perfetto/ext/base",
91    "../../protos/perfetto/common:zero",
92  ]
93  sources = [ "clock_snapshots.cc" ]
94}
95
96# This target needs to be named as such because it's exposed directly in Bazel
97# and Android.bp.
98perfetto_component("perfetto_base_default_platform") {
99  deps = [
100    "../../gn:default_deps",
101    "../../include/perfetto/ext/base",
102  ]
103  sources = [ "default_platform.cc" ]
104}
105
106perfetto_component("version") {
107  deps = [
108    ":base",
109    "../../gn:default_deps",
110  ]
111  public_deps = [ "../../include/perfetto/ext/base:version" ]
112  sources = [ "version.cc" ]
113
114  if (enable_perfetto_version_gen) {
115    deps += [ ":version_gen_h" ]
116  }
117}
118
119if (enable_perfetto_version_gen) {
120  config("version_gen_config") {
121    include_dirs = [ root_gen_dir ]
122  }
123
124  # Note: the build file translators (tools/gn_utils.py) depend on the hardcoded
125  # "//src/base:version_gen_h". If you rename this target, update build file
126  # translators accordingly.
127  gen_perfetto_version_header("version_gen_h") {
128    cpp_out = "${root_gen_dir}/perfetto_version.gen.h"
129  }
130}
131
132if (enable_perfetto_stderr_crash_dump) {
133  source_set("debug_crash_stack_trace") {
134    sources = [ "debug_crash_stack_trace.cc" ]
135    deps = [
136      "../../gn:default_deps",
137      "../../include/perfetto/ext/base",
138      "../../include/perfetto/ext/base",
139    ]
140    if (is_linux || is_android) {
141      deps += [ "../../gn:libbacktrace" ]
142    }
143    cflags = [ "-Wno-deprecated" ]
144  }
145}
146
147if (enable_perfetto_ipc) {
148  # This cannot be in :base as it does not build on WASM.
149  perfetto_component("unix_socket") {
150    deps = [
151      "../../gn:default_deps",
152      "../../include/perfetto/ext/base",
153    ]
154    sources = [
155      "unix_socket.cc",
156      "vm_sockets.h",
157    ]
158    if (is_win && perfetto_build_standalone) {
159      libs = [ "Ws2_32.lib" ]
160    }
161  }
162}
163
164source_set("test_support") {
165  testonly = true
166  deps = [
167    ":base",
168    "../../gn:default_deps",
169    "../../gn:gtest_and_gmock",
170  ]
171  sources = [
172    "test/status_matchers.h",
173    "test/tmp_dir_tree.cc",
174    "test/tmp_dir_tree.h",
175    "test/utils.cc",
176    "test/utils.h",
177    "test/vm_test_utils.cc",
178    "test/vm_test_utils.h",
179  ]
180
181  if (!is_nacl) {
182    # test_task_runner depends on unix_task_runner, which isn't available on
183    # NaCL.
184    sources += [
185      "test/test_task_runner.cc",
186      "test/test_task_runner.h",
187    ]
188  }
189}
190
191perfetto_unittest_source_set("unittests") {
192  testonly = true
193  deps = [
194    ":base",
195    ":test_support",
196    "../../gn:default_deps",
197    "../../gn:gtest_and_gmock",
198  ]
199
200  if (enable_perfetto_ipc) {
201    deps += [ "http:unittests" ]
202  }
203
204  sources = [
205    "base64_unittest.cc",
206    "circular_queue_unittest.cc",
207    "flat_hash_map_unittest.cc",
208    "flat_set_unittest.cc",
209    "getopt_compat_unittest.cc",
210    "hash_unittest.cc",
211    "logging_unittest.cc",
212    "no_destructor_unittest.cc",
213    "paged_memory_unittest.cc",
214    "periodic_task_unittest.cc",
215    "scoped_file_unittest.cc",
216    "scoped_mmap_unittest.cc",
217    "small_vector_unittest.cc",
218    "status_or_unittest.cc",
219    "status_unittest.cc",
220    "string_splitter_unittest.cc",
221    "string_utils_unittest.cc",
222    "string_view_splitter_unittest.cc",
223    "string_view_unittest.cc",
224    "string_writer_unittest.cc",
225    "task_runner_unittest.cc",
226    "temp_file_unittest.cc",
227    "thread_checker_unittest.cc",
228    "time_unittest.cc",
229    "utils_unittest.cc",
230    "uuid_unittest.cc",
231    "weak_ptr_unittest.cc",
232  ]
233  if (_subprocess_supported) {
234    # Don't run on Fuchsia, NaCL. They pretend to be POSIX but then give up on
235    # execve(2).
236    sources += [ "subprocess_unittest.cc" ]
237  }
238
239  # TODO: Enable these for Windows when possible.
240  if (!is_win) {
241    sources += [
242      "metatrace_unittest.cc",
243      "thread_task_runner_unittest.cc",
244      "watchdog_posix_unittest.cc",
245    ]
246  }
247  if (is_fuchsia) {
248    deps += [ "//third_party/fuchsia-sdk/sdk/pkg/fdio" ]  # nogncheck
249  }
250  if (perfetto_build_standalone || perfetto_build_with_android) {
251    sources += [ "unix_socket_unittest.cc" ]
252    deps += [ ":unix_socket" ]
253
254    # This causes some problems on the chromium waterfall.
255    if (is_linux || is_android) {
256      sources += [ "watchdog_unittest.cc" ]
257    }
258  }
259}
260
261if (enable_perfetto_benchmarks) {
262  declare_args() {
263    perfetto_benchmark_3p_libs_prefix = ""
264  }
265  source_set("benchmarks") {
266    # If you intend to reproduce the comparison with {Absl, Folly, Tessil}
267    # you need to manually install those libraries and then set the GN arg
268    # perfetto_benchmark_3p_libs_prefix = "/usr/local"
269    testonly = true
270    deps = [
271      ":base",
272      "../../gn:benchmark",
273      "../../gn:default_deps",
274    ]
275    if (perfetto_benchmark_3p_libs_prefix != "") {
276      defines = [ "PERFETTO_HASH_MAP_COMPARE_THIRD_PARTY_LIBS" ]
277      cflags = [ "-isystem${perfetto_benchmark_3p_libs_prefix}/include" ]
278      libs = [
279        "${perfetto_benchmark_3p_libs_prefix}/lib/libfolly.a",
280        "${perfetto_benchmark_3p_libs_prefix}/lib/libabsl_raw_hash_set.a",
281        "${perfetto_benchmark_3p_libs_prefix}/lib/libabsl_hash.a",
282      ]
283    }
284    sources = [
285      "flat_hash_map_benchmark.cc",
286      "flat_set_benchmark.cc",
287    ]
288  }
289}
290