File
Blob: src/workerd/server/BUILD.bazel
| 1 | load("@bazel_skylib//lib:selects.bzl", "selects") |
| 2 | load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") |
| 3 | load("@bazel_skylib//rules:copy_file.bzl", "copy_file") |
| 4 | load("//:build/kj_test.bzl", "kj_test") |
| 5 | load("//:build/wd_capnp_library.bzl", "wd_capnp_library") |
| 6 | load("//:build/wd_cc_binary.bzl", "wd_cc_binary") |
| 7 | load("//:build/wd_cc_embed.bzl", "wd_cc_embed") |
| 8 | load("//:build/wd_cc_library.bzl", "wd_cc_library") |
| 9 | |
| 10 | # Flag that can be used to force-disable tcmalloc. Mainly used for ASAN builds. |
| 11 | # TODO(cleanup): This feels ugly but I've exceeded my timebox for fighting Bazel for now. |
| 12 | bool_flag( |
| 13 | name = "use_tcmalloc", |
| 14 | build_setting_default = True, |
| 15 | ) |
| 16 | |
| 17 | config_setting( |
| 18 | name = "set_use_tcmalloc", |
| 19 | flag_values = {"use_tcmalloc": "True"}, |
| 20 | ) |
| 21 | |
| 22 | bool_flag( |
| 23 | name = "use_transpiler", |
| 24 | build_setting_default = True, |
| 25 | ) |
| 26 | |
| 27 | config_setting( |
| 28 | name = "set_use_transpiler", |
| 29 | flag_values = {"use_transpiler": "True"}, |
| 30 | ) |
| 31 | |
| 32 | selects.config_setting_group( |
| 33 | name = "really_use_tcmalloc", |
| 34 | match_all = [ |
| 35 | ":set_use_tcmalloc", |
| 36 | "//:is_linux", |
| 37 | ], |
| 38 | ) |
| 39 | |
| 40 | # current malloc in use |
| 41 | wd_cc_library( |
| 42 | name = "malloc", |
| 43 | visibility = ["//visibility:public"], |
| 44 | deps = select({ |
| 45 | ":really_use_tcmalloc": ["@tcmalloc//tcmalloc"], |
| 46 | "//conditions:default": ["@bazel_tools//tools/cpp:malloc"], |
| 47 | }), |
| 48 | ) |
| 49 | |
| 50 | wd_cc_embed( |
| 51 | name = "workerd-capnp-schema", |
| 52 | src = "workerd.capnp", |
| 53 | base_name = "workerd-capnp-schema", |
| 54 | is_text = True, |
| 55 | ) |
| 56 | |
| 57 | wd_cc_embed( |
| 58 | name = "cpp-capnp-schema", |
| 59 | src = "@capnp-cpp//src/capnp:c++.capnp", |
| 60 | base_name = "cpp-capnp-schema", |
| 61 | is_text = True, |
| 62 | ) |
| 63 | |
| 64 | wd_cc_binary( |
| 65 | name = "workerd", |
| 66 | srcs = ["workerd.c++"], |
| 67 | malloc = ":malloc", |
| 68 | visibility = ["//visibility:public"], |
| 69 | deps = [ |
| 70 | ":cpp-capnp-schema", |
| 71 | ":json-logger", |
| 72 | ":server", |
| 73 | ":v8-platform-impl", |
| 74 | ":workerd-capnp-schema", |
| 75 | ":workerd_capnp", |
| 76 | "//src/pyodide:pyodide_extra_capnp", |
| 77 | "//src/rust/cxx-integration", |
| 78 | "//src/workerd/util:autogate", |
| 79 | "//src/workerd/util:perfetto", |
| 80 | "@capnp-cpp//src/capnp:capnpc", |
| 81 | ], |
| 82 | ) |
| 83 | |
| 84 | wd_cc_library( |
| 85 | name = "alarm-scheduler", |
| 86 | srcs = [ |
| 87 | "alarm-scheduler.c++", |
| 88 | ], |
| 89 | hdrs = [ |
| 90 | "alarm-scheduler.h", |
| 91 | ], |
| 92 | visibility = ["//visibility:public"], |
| 93 | deps = [ |
| 94 | "//src/workerd/io", |
| 95 | "//src/workerd/util:sqlite", |
| 96 | "@capnp-cpp//src/kj", |
| 97 | "@capnp-cpp//src/kj:kj-async", |
| 98 | ], |
| 99 | ) |
| 100 | |
| 101 | wd_cc_library( |
| 102 | name = "actor-id-impl", |
| 103 | srcs = [ |
| 104 | "actor-id-impl.c++", |
| 105 | ], |
| 106 | hdrs = [ |
| 107 | "actor-id-impl.h", |
| 108 | ], |
| 109 | visibility = ["//visibility:public"], |
| 110 | deps = [ |
| 111 | "//src/workerd/io:actor-id", |
| 112 | "//src/workerd/jsg:exception", |
| 113 | "//src/workerd/util:entropy", |
| 114 | "//src/workerd/util:own-util", |
| 115 | "//src/workerd/util:thread-scopes", |
| 116 | "@capnp-cpp//src/kj", |
| 117 | "@ssl", |
| 118 | ], |
| 119 | ) |
| 120 | |
| 121 | wd_cc_library( |
| 122 | name = "pyodide", |
| 123 | srcs = [ |
| 124 | "pyodide.c++", |
| 125 | ], |
| 126 | hdrs = [ |
| 127 | "pyodide.h", |
| 128 | ], |
| 129 | visibility = ["//visibility:public"], |
| 130 | deps = [ |
| 131 | "//src/workerd/api:pyodide", |
| 132 | "//src/workerd/io:compatibility-date_capnp", |
| 133 | "//src/workerd/jsg", |
| 134 | "@capnp-cpp//src/kj", |
| 135 | "@capnp-cpp//src/kj:kj-async", |
| 136 | "@capnp-cpp//src/kj/compat:kj-gzip", |
| 137 | "@capnp-cpp//src/kj/compat:kj-tls", |
| 138 | ], |
| 139 | ) |
| 140 | |
| 141 | wd_cc_library( |
| 142 | name = "workerd-debug-port-client", |
| 143 | srcs = [ |
| 144 | "workerd-debug-port-client.c++", |
| 145 | ], |
| 146 | hdrs = [ |
| 147 | "workerd-debug-port-client.h", |
| 148 | ], |
| 149 | visibility = ["//visibility:public"], |
| 150 | deps = [ |
| 151 | "//src/workerd/io", |
| 152 | ], |
| 153 | ) |
| 154 | |
| 155 | wd_cc_library( |
| 156 | name = "workerd-api", |
| 157 | srcs = [ |
| 158 | "workerd-api.c++", |
| 159 | ], |
| 160 | hdrs = [ |
| 161 | "workerd-api.h", |
| 162 | ], |
| 163 | implementation_deps = [ |
| 164 | "//src/workerd/api:analytics-engine", |
| 165 | "//src/workerd/api:capnp", |
| 166 | "//src/workerd/api:kv", |
| 167 | "//src/workerd/api:streams", |
| 168 | "//src/workerd/api:urlpattern", |
| 169 | "//src/workerd/api:urlpattern-standard", |
| 170 | "//src/workerd/api:worker-loader", |
| 171 | "//src/workerd/io:promise-wrapper", |
| 172 | ], |
| 173 | local_defines = select({ |
| 174 | ":set_use_transpiler": ["WORKERD_USE_TRANSPILER"], |
| 175 | "//conditions:default": [], |
| 176 | }), |
| 177 | visibility = ["//visibility:public"], |
| 178 | deps = [ |
| 179 | ":actor-id-impl", |
| 180 | ":fallback-service", |
| 181 | ":pyodide", |
| 182 | ":workerd-debug-port-client", |
| 183 | ":workerd_capnp", |
| 184 | "//src/cloudflare", |
| 185 | "//src/node", |
| 186 | "//src/pyodide:pyodide_static", |
| 187 | "//src/pyodide:python-entrypoint", |
| 188 | "//src/workerd/api:html-rewriter", |
| 189 | "//src/workerd/api:hyperdrive", |
| 190 | "//src/workerd/api:memory-cache", |
| 191 | "//src/workerd/api:pyodide", |
| 192 | "//src/workerd/api:r2", |
| 193 | "//src/workerd/api:rtti", |
| 194 | "//src/workerd/api/node", |
| 195 | "//src/workerd/io", |
| 196 | "//src/workerd/io:worker-modules", |
| 197 | "//src/workerd/jsg", |
| 198 | "//src/workerd/util:perfetto", |
| 199 | "@capnp-cpp//src/kj/compat:kj-gzip", |
| 200 | "@capnp-cpp//src/kj/compat:kj-tls", |
| 201 | ] + select({ |
| 202 | ":set_use_transpiler": ["//src/rust/transpiler"], |
| 203 | "//conditions:default": [], |
| 204 | }), |
| 205 | ) |
| 206 | |
| 207 | wd_cc_library( |
| 208 | name = "channel-token", |
| 209 | srcs = ["channel-token.c++"], |
| 210 | hdrs = ["channel-token.h"], |
| 211 | deps = [ |
| 212 | ":channel-token_capnp", |
| 213 | "//src/workerd/io", |
| 214 | "//src/workerd/util:entropy", |
| 215 | ], |
| 216 | ) |
| 217 | |
| 218 | wd_cc_library( |
| 219 | name = "server", |
| 220 | srcs = [ |
| 221 | "server.c++", |
| 222 | ], |
| 223 | hdrs = [ |
| 224 | "server.h", |
| 225 | ], |
| 226 | deps = [ |
| 227 | ":actor-id-impl", |
| 228 | ":alarm-scheduler", |
| 229 | ":channel-token", |
| 230 | ":channel-token_capnp", |
| 231 | ":container-client", |
| 232 | ":facet-tree-index", |
| 233 | ":fallback-service", |
| 234 | ":workerd-api", |
| 235 | ":workerd_capnp", |
| 236 | "//src/cloudflare", |
| 237 | "//src/node", |
| 238 | "//src/pyodide:pyodide_static", |
| 239 | "//src/workerd/api:memory-cache", |
| 240 | "//src/workerd/api:pyodide", |
| 241 | "//src/workerd/io", |
| 242 | "//src/workerd/io:bundle-fs", |
| 243 | "//src/workerd/io:worker-entrypoint", |
| 244 | "//src/workerd/jsg", |
| 245 | "//src/workerd/util:perfetto", |
| 246 | "//src/workerd/util:websocket-error-handler", |
| 247 | "@capnp-cpp//src/kj/compat:kj-gzip", |
| 248 | "@capnp-cpp//src/kj/compat:kj-tls", |
| 249 | ], |
| 250 | ) |
| 251 | |
| 252 | wd_capnp_library(src = "docker-api.capnp") |
| 253 | |
| 254 | wd_capnp_library(src = "log-schema.capnp") |
| 255 | |
| 256 | wd_capnp_library( |
| 257 | src = "channel-token.capnp", |
| 258 | deps = [ |
| 259 | "//src/workerd/io:frankenvalue_capnp", |
| 260 | ], |
| 261 | ) |
| 262 | |
| 263 | wd_cc_library( |
| 264 | name = "json-logger", |
| 265 | srcs = ["json-logger.c++"], |
| 266 | hdrs = ["json-logger.h"], |
| 267 | visibility = ["//visibility:public"], |
| 268 | deps = [ |
| 269 | ":log-schema_capnp", |
| 270 | "@capnp-cpp//src/capnp/compat:json", |
| 271 | "@capnp-cpp//src/kj", |
| 272 | ], |
| 273 | ) |
| 274 | |
| 275 | wd_cc_library( |
| 276 | name = "container-client", |
| 277 | srcs = ["container-client.c++"], |
| 278 | hdrs = ["container-client.h"], |
| 279 | visibility = ["//visibility:public"], |
| 280 | deps = [ |
| 281 | ":channel-token", |
| 282 | ":docker-api_capnp", |
| 283 | "//src/workerd/io", |
| 284 | "//src/workerd/io:container_capnp", |
| 285 | "//src/workerd/jsg", |
| 286 | "//src/workerd/util:strings", |
| 287 | "//src/workerd/util:uuid", |
| 288 | "@ada-url", |
| 289 | "@capnp-cpp//src/capnp/compat:http-over-capnp", |
| 290 | "@capnp-cpp//src/kj", |
| 291 | "@capnp-cpp//src/kj:kj-async", |
| 292 | "@capnp-cpp//src/kj/compat:kj-http", |
| 293 | ], |
| 294 | ) |
| 295 | |
| 296 | wd_cc_library( |
| 297 | name = "fallback-service", |
| 298 | srcs = [ |
| 299 | "fallback-service.c++", |
| 300 | ], |
| 301 | hdrs = [ |
| 302 | "fallback-service.h", |
| 303 | ], |
| 304 | visibility = ["//visibility:public"], |
| 305 | deps = [ |
| 306 | ":workerd_capnp", |
| 307 | "@capnp-cpp//src/kj", |
| 308 | "@capnp-cpp//src/kj:kj-async", |
| 309 | "@capnp-cpp//src/kj/compat:kj-http", |
| 310 | ], |
| 311 | ) |
| 312 | |
| 313 | wd_cc_library( |
| 314 | name = "v8-platform-impl", |
| 315 | srcs = [ |
| 316 | "v8-platform-impl.c++", |
| 317 | ], |
| 318 | hdrs = [ |
| 319 | "v8-platform-impl.h", |
| 320 | ], |
| 321 | deps = [ |
| 322 | "//src/workerd/jsg", |
| 323 | "@capnp-cpp//src/kj", |
| 324 | ], |
| 325 | ) |
| 326 | |
| 327 | wd_cc_library( |
| 328 | name = "facet-tree-index", |
| 329 | srcs = [ |
| 330 | "facet-tree-index.c++", |
| 331 | ], |
| 332 | hdrs = [ |
| 333 | "facet-tree-index.h", |
| 334 | ], |
| 335 | visibility = ["//visibility:public"], |
| 336 | deps = [ |
| 337 | "@capnp-cpp//src/kj", |
| 338 | ], |
| 339 | ) |
| 340 | |
| 341 | wd_capnp_library( |
| 342 | src = "workerd.capnp", |
| 343 | # Limit visibility to avoid accidental usage – there should be no need to use this outside of |
| 344 | # test-fixture and the workerd binary. |
| 345 | visibility = [ |
| 346 | ":__pkg__", |
| 347 | "//src/workerd/api:__pkg__", |
| 348 | "//src/workerd/tests:__pkg__", |
| 349 | ], |
| 350 | ) |
| 351 | |
| 352 | kj_test( |
| 353 | size = "large", |
| 354 | src = "server-test.c++", |
| 355 | deps = [ |
| 356 | ":server", |
| 357 | "//src/workerd/util:test-util", |
| 358 | ], |
| 359 | ) |
| 360 | |
| 361 | kj_test( |
| 362 | src = "channel-token-test.c++", |
| 363 | deps = [ |
| 364 | ":server", |
| 365 | ], |
| 366 | ) |
| 367 | |
| 368 | kj_test( |
| 369 | src = "actor-id-impl-test.c++", |
| 370 | deps = [ |
| 371 | ":actor-id-impl", |
| 372 | "//src/workerd/jsg:exception", |
| 373 | "//src/workerd/util:thread-scopes", |
| 374 | "@capnp-cpp//src/kj", |
| 375 | "@ssl", |
| 376 | ], |
| 377 | ) |
| 378 | |
| 379 | copy_file( |
| 380 | name = "pyodide.capnp.bin@rule", |
| 381 | src = "//src/pyodide:pyodide.capnp.bin_cross", |
| 382 | out = "pyodide.capnp.bin", |
| 383 | ) |
| 384 | |
| 385 | kj_test( |
| 386 | src = "container-client-test.c++", |
| 387 | deps = [ |
| 388 | ":container-client", |
| 389 | "@capnp-cpp//src/kj", |
| 390 | ], |
| 391 | ) |
| 392 | |
| 393 | kj_test( |
| 394 | src = "facet-tree-index-test.c++", |
| 395 | deps = [ |
| 396 | ":facet-tree-index", |
| 397 | "@capnp-cpp//src/kj", |
| 398 | ], |
| 399 | ) |
| 400 | |
| 401 | kj_test( |
| 402 | src = "json-logger-test.c++", |
| 403 | deps = [ |
| 404 | ":json-logger", |
| 405 | "@capnp-cpp//src/capnp/compat:json", |
| 406 | ], |
| 407 | ) |