File
Blob: src/workerd/util/BUILD.bazel
| 1 | load("@bazel_skylib//lib:selects.bzl", "selects") |
| 2 | load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") |
| 3 | load("//:build/kj_test.bzl", "kj_test") |
| 4 | load("//:build/wd_cc_library.bzl", "wd_cc_library") |
| 5 | |
| 6 | bool_flag( |
| 7 | name = "use_perfetto", |
| 8 | build_setting_default = True, |
| 9 | ) |
| 10 | |
| 11 | config_setting( |
| 12 | name = "set_use_perfetto", |
| 13 | flag_values = {"use_perfetto": "True"}, |
| 14 | ) |
| 15 | |
| 16 | selects.config_setting_group( |
| 17 | name = "really_use_perfetto", |
| 18 | match_all = [ |
| 19 | ":set_use_perfetto", |
| 20 | "//:is_unix", |
| 21 | ], |
| 22 | ) |
| 23 | |
| 24 | wd_cc_library( |
| 25 | name = "perfetto", |
| 26 | srcs = ["perfetto-tracing.c++"], |
| 27 | hdrs = [ |
| 28 | "perfetto-tracing.h", |
| 29 | "use-perfetto-categories.h", |
| 30 | ], |
| 31 | # HACK: We do not use the perfetto IPC system backend in any capacity. If perfetto-tracing.c++ |
| 32 | # is able to inline and optimize its perfetto::Tracing::Initialize() call properly, there are no |
| 33 | # references to it anywhere in workerd and the linker can optimize it away, reducing binary |
| 34 | # sizes. Enable optimization unconditionally here so that the backend goes away. |
| 35 | # See perfetto's include/perfetto/tracing/tracing.h for more context. |
| 36 | # Alternatively, we could create an override for perfetto_build_flags.h to disable the |
| 37 | # PERFETTO_IPC and PERFETTO_SYSTEM_CONSUMER defines which also exist to facilitate link-time |
| 38 | # code elimination, but doing so results in a smaller size improvement than enabling |
| 39 | # optimization here, or no additional improvement when doing combined with enabling |
| 40 | # optimization. |
| 41 | copts = select({ |
| 42 | "@platforms//os:windows": [ |
| 43 | "/O2", |
| 44 | "/clang:-O3", |
| 45 | ], |
| 46 | "//conditions:default": ["-O3"], |
| 47 | }), |
| 48 | defines = select({ |
| 49 | ":really_use_perfetto": ["WORKERD_USE_PERFETTO"], |
| 50 | "//conditions:default": [], |
| 51 | }), |
| 52 | visibility = ["//visibility:public"], |
| 53 | deps = [ |
| 54 | "@capnp-cpp//src/kj", |
| 55 | ] + select({ |
| 56 | ":really_use_perfetto": ["@perfetto//:libperfetto_client_experimental"], |
| 57 | "//conditions:default": [], |
| 58 | }), |
| 59 | ) |
| 60 | # TODO(later): Currently perfetto support is not enabled on Windows simply because the |
| 61 | # perfetto bazel build fails on windows for some reason and it's currently not worth |
| 62 | # the time to invest of figuring out why. If some intrepid soul wishes to figure out |
| 63 | # why the Windows build is failing, we could simplify things here a bit. |
| 64 | |
| 65 | wd_cc_library( |
| 66 | name = "util", |
| 67 | srcs = [ |
| 68 | "stream-utils.c++", |
| 69 | "wait-list.c++", |
| 70 | ], |
| 71 | # This is verbose, but allows us to be intentional about what we include here and e.g. avoid |
| 72 | # accidentally including test headers or having targets depend on more than they need to. |
| 73 | # TODO (cleanup): Break this up entirely. |
| 74 | hdrs = [ |
| 75 | "abortable.h", |
| 76 | "batch-queue.h", |
| 77 | "canceler.h", |
| 78 | "color-util.h", |
| 79 | "http-util.h", |
| 80 | "stream-utils.h", |
| 81 | "uncaught-exception-source.h", |
| 82 | "wait-list.h", |
| 83 | "weak-refs.h", |
| 84 | "xthreadnotifier.h", |
| 85 | ], |
| 86 | visibility = ["//visibility:public"], |
| 87 | deps = [ |
| 88 | ":duration-exceeded-logger", |
| 89 | "@capnp-cpp//src/kj", |
| 90 | "@capnp-cpp//src/kj:kj-async", |
| 91 | # TODO(cleanup): Only for abortable.h, factor out |
| 92 | "@capnp-cpp//src/kj/compat:kj-http", |
| 93 | ], |
| 94 | ) |
| 95 | |
| 96 | wd_cc_library( |
| 97 | name = "checked-queue", |
| 98 | hdrs = ["checked-queue.h"], |
| 99 | visibility = ["//visibility:public"], |
| 100 | deps = ["@capnp-cpp//src/kj"], |
| 101 | ) |
| 102 | |
| 103 | wd_cc_library( |
| 104 | name = "ring-buffer", |
| 105 | hdrs = ["ring-buffer.h"], |
| 106 | visibility = ["//visibility:public"], |
| 107 | deps = ["@capnp-cpp//src/kj"], |
| 108 | ) |
| 109 | |
| 110 | wd_cc_library( |
| 111 | name = "small-set", |
| 112 | hdrs = ["small-set.h"], |
| 113 | visibility = ["//visibility:public"], |
| 114 | deps = [ |
| 115 | "@capnp-cpp//src/kj", |
| 116 | ], |
| 117 | ) |
| 118 | |
| 119 | wd_cc_library( |
| 120 | name = "mimetype", |
| 121 | srcs = ["mimetype.c++"], |
| 122 | hdrs = ["mimetype.h"], |
| 123 | implementation_deps = [ |
| 124 | ":string-buffer", |
| 125 | ], |
| 126 | visibility = ["//visibility:public"], |
| 127 | deps = [ |
| 128 | ":strings", |
| 129 | "//src/workerd/jsg:memory-tracker", |
| 130 | "@capnp-cpp//src/kj", |
| 131 | "@capnp-cpp//src/kj:kj-async", |
| 132 | ], |
| 133 | ) |
| 134 | |
| 135 | wd_cc_library( |
| 136 | name = "strings", |
| 137 | srcs = ["strings.c++"], |
| 138 | hdrs = ["strings.h"], |
| 139 | visibility = ["//visibility:public"], |
| 140 | deps = [ |
| 141 | "@capnp-cpp//src/kj", |
| 142 | ], |
| 143 | ) |
| 144 | |
| 145 | wd_cc_library( |
| 146 | name = "string-buffer", |
| 147 | hdrs = ["string-buffer.h"], |
| 148 | visibility = ["//visibility:public"], |
| 149 | deps = [":strings"], |
| 150 | ) |
| 151 | |
| 152 | wd_cc_library( |
| 153 | name = "strong-bool", |
| 154 | hdrs = ["strong-bool.h"], |
| 155 | visibility = ["//visibility:public"], |
| 156 | deps = [ |
| 157 | "@capnp-cpp//src/kj", |
| 158 | ], |
| 159 | ) |
| 160 | |
| 161 | wd_cc_library( |
| 162 | name = "uuid", |
| 163 | srcs = ["uuid.c++"], |
| 164 | hdrs = ["uuid.h"], |
| 165 | implementation_deps = [ |
| 166 | ":entropy", |
| 167 | "@capnp-cpp//src/kj/compat:kj-http", |
| 168 | "@ssl", |
| 169 | ], |
| 170 | visibility = ["//visibility:public"], |
| 171 | deps = [ |
| 172 | "@capnp-cpp//src/kj", |
| 173 | ], |
| 174 | ) |
| 175 | |
| 176 | wd_cc_library( |
| 177 | name = "test", |
| 178 | hdrs = ["test.h"], |
| 179 | visibility = ["//visibility:public"], |
| 180 | deps = [ |
| 181 | "@capnp-cpp//src/kj:kj-test", |
| 182 | ], |
| 183 | ) |
| 184 | |
| 185 | wd_cc_library( |
| 186 | name = "account-limits", |
| 187 | hdrs = ["account-limits.h"], |
| 188 | visibility = ["//visibility:public"], |
| 189 | deps = [ |
| 190 | "@capnp-cpp//src/kj", |
| 191 | ], |
| 192 | ) |
| 193 | |
| 194 | wd_cc_library( |
| 195 | name = "sqlite", |
| 196 | srcs = [ |
| 197 | "sqlite.c++", |
| 198 | "sqlite-kv.c++", |
| 199 | "sqlite-metadata.c++", |
| 200 | ], |
| 201 | hdrs = [ |
| 202 | "sqlite.h", |
| 203 | "sqlite-kv.h", |
| 204 | "sqlite-metadata.h", |
| 205 | ], |
| 206 | implementation_deps = [ |
| 207 | ":autogate", |
| 208 | "//src/workerd/jsg:exception", |
| 209 | "@sqlite3", |
| 210 | ], |
| 211 | visibility = ["//visibility:public"], |
| 212 | deps = [ |
| 213 | ":account-limits", |
| 214 | ":sentry", |
| 215 | ":sqlite-metering", |
| 216 | "@capnp-cpp//src/kj:kj-async", |
| 217 | ], |
| 218 | ) |
| 219 | |
| 220 | wd_cc_library( |
| 221 | name = "sqlite-metering", |
| 222 | srcs = ["sqlite-metering.c++"], |
| 223 | hdrs = ["sqlite-metering.h"], |
| 224 | implementation_deps = [ |
| 225 | "@sqlite3", |
| 226 | ], |
| 227 | visibility = ["//visibility:public"], |
| 228 | deps = [ |
| 229 | "@capnp-cpp//src/kj", |
| 230 | ], |
| 231 | ) |
| 232 | |
| 233 | wd_cc_library( |
| 234 | name = "test-util", |
| 235 | testonly = True, |
| 236 | srcs = ["capnp-mock.c++"], |
| 237 | hdrs = ["capnp-mock.h"], |
| 238 | visibility = ["//visibility:public"], |
| 239 | deps = [ |
| 240 | "@capnp-cpp//src/capnp:capnpc", |
| 241 | ], |
| 242 | ) |
| 243 | |
| 244 | wd_cc_library( |
| 245 | name = "own-util", |
| 246 | hdrs = ["own-util.h"], |
| 247 | visibility = ["//visibility:public"], |
| 248 | deps = ["@capnp-cpp//src/kj"], |
| 249 | ) |
| 250 | |
| 251 | wd_cc_library( |
| 252 | name = "sentry", |
| 253 | hdrs = ["sentry.h"], |
| 254 | visibility = ["//visibility:public"], |
| 255 | deps = [ |
| 256 | "@capnp-cpp//src/kj", |
| 257 | ], |
| 258 | ) |
| 259 | |
| 260 | wd_cc_library( |
| 261 | name = "thread-scopes", |
| 262 | srcs = ["thread-scopes.c++"], |
| 263 | hdrs = ["thread-scopes.h"], |
| 264 | visibility = ["//visibility:public"], |
| 265 | deps = [ |
| 266 | "@capnp-cpp//src/kj/compat:kj-http", |
| 267 | ], |
| 268 | ) |
| 269 | |
| 270 | wd_cc_library( |
| 271 | name = "autogate", |
| 272 | srcs = ["autogate.c++"], |
| 273 | hdrs = ["autogate.h"], |
| 274 | # Make missing string repr for an autogate into a hard error |
| 275 | copts = ["-Werror=switch"], |
| 276 | visibility = ["//visibility:public"], |
| 277 | deps = [ |
| 278 | ":sentry", |
| 279 | ":strong-bool", |
| 280 | "@capnp-cpp//src/capnp", |
| 281 | "@capnp-cpp//src/kj", |
| 282 | ], |
| 283 | ) |
| 284 | |
| 285 | wd_cc_library( |
| 286 | name = "duration-exceeded-logger", |
| 287 | hdrs = ["duration-exceeded-logger.h"], |
| 288 | visibility = ["//visibility:public"], |
| 289 | deps = ["@capnp-cpp//src/kj"], |
| 290 | ) |
| 291 | |
| 292 | wd_cc_library( |
| 293 | name = "entropy", |
| 294 | srcs = ["entropy.c++"], |
| 295 | hdrs = ["entropy.h"], |
| 296 | implementation_deps = [ |
| 297 | "@ncrypto", |
| 298 | "@ssl", |
| 299 | ], |
| 300 | visibility = ["//visibility:public"], |
| 301 | deps = ["@capnp-cpp//src/kj"], |
| 302 | ) |
| 303 | |
| 304 | wd_cc_library( |
| 305 | name = "completion-membrane", |
| 306 | hdrs = ["completion-membrane.h"], |
| 307 | visibility = ["//visibility:public"], |
| 308 | deps = ["@capnp-cpp//src/capnp"], |
| 309 | ) |
| 310 | |
| 311 | wd_cc_library( |
| 312 | name = "exception", |
| 313 | hdrs = ["exception.h"], |
| 314 | visibility = ["//visibility:public"], |
| 315 | deps = ["@capnp-cpp//src/kj"], |
| 316 | ) |
| 317 | |
| 318 | wd_cc_library( |
| 319 | name = "immediate-crash", |
| 320 | hdrs = ["immediate-crash.h"], |
| 321 | visibility = ["//visibility:public"], |
| 322 | ) |
| 323 | |
| 324 | wd_cc_library( |
| 325 | name = "header-validation", |
| 326 | hdrs = ["header-validation.h"], |
| 327 | visibility = ["//visibility:public"], |
| 328 | deps = [ |
| 329 | "@capnp-cpp//src/kj", |
| 330 | ], |
| 331 | ) |
| 332 | |
| 333 | wd_cc_library( |
| 334 | name = "websocket-error-handler", |
| 335 | srcs = ["websocket-error-handler.c++"], |
| 336 | hdrs = ["websocket-error-handler.h"], |
| 337 | visibility = ["//visibility:public"], |
| 338 | deps = [ |
| 339 | "//src/workerd/jsg:exception", |
| 340 | "@capnp-cpp//src/kj/compat:kj-http", |
| 341 | ], |
| 342 | ) |
| 343 | |
| 344 | exports_files(["autogate.h"]) |
| 345 | |
| 346 | [ |
| 347 | kj_test( |
| 348 | src = f, |
| 349 | deps = [ |
| 350 | ":util", |
| 351 | ], |
| 352 | ) |
| 353 | for f in [ |
| 354 | "batch-queue-test.c++", |
| 355 | "wait-list-test.c++", |
| 356 | "duration-exceeded-logger-test.c++", |
| 357 | ] |
| 358 | ] |
| 359 | |
| 360 | kj_test( |
| 361 | src = "string-buffer-test.c++", |
| 362 | deps = [ |
| 363 | ":string-buffer", |
| 364 | ], |
| 365 | ) |
| 366 | |
| 367 | kj_test( |
| 368 | src = "strong-bool-test.c++", |
| 369 | deps = [ |
| 370 | ":strong-bool", |
| 371 | ], |
| 372 | ) |
| 373 | |
| 374 | kj_test( |
| 375 | src = "mimetype-test.c++", |
| 376 | deps = [ |
| 377 | ":mimetype", |
| 378 | ], |
| 379 | ) |
| 380 | |
| 381 | kj_test( |
| 382 | size = "large", |
| 383 | src = "sqlite-test.c++", |
| 384 | deps = [ |
| 385 | ":sqlite", |
| 386 | "//src/workerd/io:io-gate", |
| 387 | "@sqlite3", |
| 388 | ], |
| 389 | ) |
| 390 | |
| 391 | kj_test( |
| 392 | src = "sqlite-kv-test.c++", |
| 393 | deps = [ |
| 394 | ":sqlite", |
| 395 | ], |
| 396 | ) |
| 397 | |
| 398 | kj_test( |
| 399 | src = "sqlite-metadata-test.c++", |
| 400 | deps = [ |
| 401 | ":sqlite", |
| 402 | ], |
| 403 | ) |
| 404 | |
| 405 | kj_test( |
| 406 | src = "sqlite-metering-test.c++", |
| 407 | deps = [ |
| 408 | ":sqlite-metering", |
| 409 | "@capnp-cpp//src/kj", |
| 410 | ], |
| 411 | ) |
| 412 | |
| 413 | kj_test( |
| 414 | src = "test-test.c++", |
| 415 | deps = [ |
| 416 | ":test", |
| 417 | ], |
| 418 | ) |
| 419 | |
| 420 | kj_test( |
| 421 | src = "uuid-test.c++", |
| 422 | deps = [ |
| 423 | ":uuid", |
| 424 | ], |
| 425 | ) |
| 426 | |
| 427 | kj_test( |
| 428 | src = "checked-queue-test.c++", |
| 429 | deps = [":checked-queue"], |
| 430 | ) |
| 431 | |
| 432 | kj_test( |
| 433 | src = "ring-buffer-test.c++", |
| 434 | deps = [":ring-buffer"], |
| 435 | ) |
| 436 | |
| 437 | kj_test( |
| 438 | src = "small-set-test.c++", |
| 439 | deps = [ |
| 440 | ":small-set", |
| 441 | ":util", |
| 442 | ], |
| 443 | ) |
| 444 | |
| 445 | wd_cc_library( |
| 446 | name = "state-machine", |
| 447 | hdrs = ["state-machine.h"], |
| 448 | visibility = ["//visibility:public"], |
| 449 | deps = ["@capnp-cpp//src/kj"], |
| 450 | ) |
| 451 | |
| 452 | kj_test( |
| 453 | src = "state-machine-test.c++", |
| 454 | deps = [":state-machine"], |
| 455 | ) |