File
Blob: src/workerd/io/BUILD.bazel
| 1 | load("//:build/kj_test.bzl", "kj_test") |
| 2 | load("//:build/wd_capnp_library.bzl", "wd_capnp_library") |
| 3 | load("//:build/wd_cc_embed.bzl", "wd_cc_embed") |
| 4 | load("//:build/wd_cc_library.bzl", "wd_cc_library") |
| 5 | load("//:build/wd_test.bzl", "wd_test") |
| 6 | |
| 7 | # TODO(cleanup): Split up into smaller targets, although this target is already relatively small and |
| 8 | # not encumbered with many dependencies. |
| 9 | wd_cc_library( |
| 10 | name = "io-helpers", |
| 11 | srcs = [ |
| 12 | "io-thread-context.c++", |
| 13 | "io-timers.c++", |
| 14 | "request-tracker.c++", |
| 15 | ], |
| 16 | hdrs = [ |
| 17 | "io-thread-context.h", |
| 18 | "io-timers.h", |
| 19 | "request-tracker.h", |
| 20 | ], |
| 21 | visibility = ["//visibility:public"], |
| 22 | deps = [ |
| 23 | "//src/workerd/jsg", |
| 24 | "@capnp-cpp//src/capnp/compat:http-over-capnp", |
| 25 | ], |
| 26 | ) |
| 27 | |
| 28 | wd_cc_library( |
| 29 | name = "io", |
| 30 | # HACK: Currently, the `io` and `api` packages are interdependent. We fold all the sources |
| 31 | # from `api` into `io`. In principle, it should be possible to pull them apart so `api` |
| 32 | # depends on `io` but not vice versa. In practice, this appears very difficult due to the |
| 33 | # IoContext -> Worker -> ServiceWorkerGlobalScope -> (various api targets) dependency chain. |
| 34 | # TODO(cleanup): Fix this. |
| 35 | srcs = [ |
| 36 | "compatibility-date.c++", |
| 37 | "external-pusher.c++", |
| 38 | "features.c++", |
| 39 | "hibernation-manager.c++", |
| 40 | "io-channels.c++", |
| 41 | "io-context.c++", |
| 42 | "io-own.c++", |
| 43 | "io-util.c++", |
| 44 | "trace-stream.c++", |
| 45 | "tracer.c++", |
| 46 | "worker.c++", |
| 47 | "worker-fs.c++", |
| 48 | ] + ["//src/workerd/api:srcs"], |
| 49 | hdrs = [ |
| 50 | "compatibility-date.h", |
| 51 | "external-pusher.h", |
| 52 | "hibernation-manager.h", |
| 53 | "io-channels.h", |
| 54 | "io-context.h", |
| 55 | "io-own.h", |
| 56 | "io-util.h", |
| 57 | "trace-stream.h", |
| 58 | "tracer.h", |
| 59 | "worker.h", |
| 60 | "worker-fs.h", |
| 61 | ] + ["//src/workerd/api:hdrs"], |
| 62 | implementation_deps = [ |
| 63 | "//src/rust/jsg", |
| 64 | "//src/workerd/api:crypto-crc-impl", |
| 65 | "//src/workerd/api:data-url", |
| 66 | "//src/workerd/api/node:exceptions", |
| 67 | "//src/workerd/util:completion-membrane", |
| 68 | "//src/workerd/util:entropy", |
| 69 | "//src/workerd/util:perfetto", |
| 70 | "//src/workerd/util:string-buffer", |
| 71 | "//src/workerd/util:strings", |
| 72 | "//src/workerd/util:uuid", |
| 73 | "@capnp-cpp//src/kj/compat:kj-brotli", |
| 74 | "@capnp-cpp//src/kj/compat:kj-gzip", |
| 75 | "@nbytes", |
| 76 | "@simdutf", |
| 77 | ], |
| 78 | visibility = ["//visibility:public"], |
| 79 | deps = [ |
| 80 | ":actor", |
| 81 | ":actor-id", |
| 82 | ":actor-storage_capnp", |
| 83 | ":cdp_capnp", |
| 84 | ":container_capnp", |
| 85 | ":features", |
| 86 | ":frankenvalue", |
| 87 | ":io-gate", |
| 88 | ":io-helpers", |
| 89 | ":limit-enforcer", |
| 90 | ":maximum-compatibility-date", |
| 91 | ":observer", |
| 92 | ":release-version", |
| 93 | ":trace", |
| 94 | ":wasm-instantiate-shim", |
| 95 | ":worker-interface", |
| 96 | ":worker-source", |
| 97 | "//src/rust/cxx-integration", |
| 98 | "//src/workerd/api:analytics-engine_capnp", |
| 99 | "//src/workerd/api:deferred-proxy", |
| 100 | "//src/workerd/api:encoding", |
| 101 | "//src/workerd/api:fuzzilli", |
| 102 | "//src/workerd/api:hibernation-event-params", |
| 103 | "//src/workerd/api:url", |
| 104 | "//src/workerd/jsg", |
| 105 | "//src/workerd/jsg:inspector", |
| 106 | "//src/workerd/jsg:script", |
| 107 | "//src/workerd/util:checked-queue", |
| 108 | "//src/workerd/util:exception", |
| 109 | "//src/workerd/util:header-validation", |
| 110 | "//src/workerd/util:immediate-crash", |
| 111 | "//src/workerd/util:ring-buffer", |
| 112 | "//src/workerd/util:small-set", |
| 113 | "//src/workerd/util:sqlite", |
| 114 | "//src/workerd/util:state-machine", |
| 115 | "//src/workerd/util:strong-bool", |
| 116 | "@capnp-cpp//src/capnp:capnp-rpc", |
| 117 | "@capnp-cpp//src/capnp/compat:http-over-capnp", |
| 118 | "@capnp-cpp//src/kj:kj-async", |
| 119 | "@ncrypto", |
| 120 | "@ssl", |
| 121 | ], |
| 122 | ) |
| 123 | |
| 124 | # Headers only target to avoid having circular dependencies. |
| 125 | wd_cc_library( |
| 126 | name = "features", |
| 127 | hdrs = ["features.h"], |
| 128 | implementation_deps = [ |
| 129 | "//src/workerd/jsg", |
| 130 | ], |
| 131 | visibility = ["//visibility:public"], |
| 132 | deps = [ |
| 133 | ":compatibility-date_capnp", |
| 134 | ], |
| 135 | ) |
| 136 | |
| 137 | wd_cc_library( |
| 138 | name = "worker-modules", |
| 139 | srcs = ["worker-modules.c++"], |
| 140 | hdrs = ["worker-modules.h"], |
| 141 | implementation_deps = [ |
| 142 | "//src/pyodide:pyodide_static", |
| 143 | "//src/workerd/api:pyodide", |
| 144 | "//src/workerd/api/node", |
| 145 | ], |
| 146 | visibility = ["//visibility:public"], |
| 147 | deps = [ |
| 148 | ":io", |
| 149 | "//src/pyodide:python-entrypoint", |
| 150 | "//src/workerd/api:commonjs", |
| 151 | "//src/workerd/api:rtti", |
| 152 | "//src/workerd/jsg", |
| 153 | "//src/workerd/util:strong-bool", |
| 154 | ], |
| 155 | ) |
| 156 | |
| 157 | wd_cc_library( |
| 158 | name = "bundle-fs", |
| 159 | srcs = ["bundle-fs.c++"], |
| 160 | hdrs = ["bundle-fs.h"], |
| 161 | visibility = ["//visibility:public"], |
| 162 | deps = [ |
| 163 | ":io", |
| 164 | ], |
| 165 | ) |
| 166 | |
| 167 | wd_cc_library( |
| 168 | name = "promise-wrapper", |
| 169 | hdrs = ["promise-wrapper.h"], |
| 170 | visibility = ["//visibility:public"], |
| 171 | deps = [ |
| 172 | ":io", |
| 173 | "//src/workerd/jsg", |
| 174 | ], |
| 175 | ) |
| 176 | |
| 177 | wd_cc_library( |
| 178 | name = "worker-source", |
| 179 | hdrs = ["worker-source.h"], |
| 180 | visibility = ["//visibility:public"], |
| 181 | deps = [ |
| 182 | "//src/rust/cxx-integration", |
| 183 | "@capnp-cpp//src/capnp", |
| 184 | ], |
| 185 | ) |
| 186 | |
| 187 | # TODO(cleanup): Split this up further. |
| 188 | wd_cc_library( |
| 189 | name = "actor", |
| 190 | srcs = [ |
| 191 | "actor-cache.c++", |
| 192 | "actor-sqlite.c++", |
| 193 | "actor-storage.c++", |
| 194 | ], |
| 195 | hdrs = [ |
| 196 | "actor-cache.h", |
| 197 | "actor-sqlite.h", |
| 198 | "actor-storage.h", |
| 199 | ], |
| 200 | visibility = ["//visibility:public"], |
| 201 | deps = [ |
| 202 | ":actor-storage_capnp", |
| 203 | ":io-gate", |
| 204 | ":trace", |
| 205 | "//src/workerd/jsg:exception", |
| 206 | "//src/workerd/util:duration-exceeded-logger", |
| 207 | "//src/workerd/util:exception", |
| 208 | "//src/workerd/util:sqlite", |
| 209 | "//src/workerd/util:strong-bool", |
| 210 | "@capnp-cpp//src/capnp:capnp-rpc", |
| 211 | "@capnp-cpp//src/kj:kj-async", |
| 212 | ], |
| 213 | ) |
| 214 | |
| 215 | wd_cc_library( |
| 216 | name = "frankenvalue", |
| 217 | srcs = ["frankenvalue.c++"], |
| 218 | hdrs = ["frankenvalue.h"], |
| 219 | visibility = ["//visibility:public"], |
| 220 | deps = [ |
| 221 | ":frankenvalue_capnp", |
| 222 | "//src/workerd/jsg", |
| 223 | "@capnp-cpp//src/capnp:capnpc", |
| 224 | ], |
| 225 | ) |
| 226 | |
| 227 | wd_cc_library( |
| 228 | name = "trace", |
| 229 | srcs = ["trace.c++"], |
| 230 | hdrs = ["trace.h"], |
| 231 | implementation_deps = [ |
| 232 | "//src/workerd/util:entropy", |
| 233 | "//src/workerd/util:thread-scopes", |
| 234 | ], |
| 235 | visibility = ["//visibility:public"], |
| 236 | deps = [ |
| 237 | ":trace_capnp", |
| 238 | ":worker-interface_capnp", |
| 239 | "//src/workerd/jsg:memory-tracker", |
| 240 | "//src/workerd/util:own-util", |
| 241 | "@capnp-cpp//src/capnp:capnp-rpc", |
| 242 | "@capnp-cpp//src/capnp:capnpc", |
| 243 | "@capnp-cpp//src/kj/compat:kj-http", |
| 244 | "@ssl", |
| 245 | ], |
| 246 | ) |
| 247 | |
| 248 | wd_cc_library( |
| 249 | name = "observer", |
| 250 | srcs = ["observer.c++"], |
| 251 | hdrs = ["observer.h"], |
| 252 | implementation_deps = [ |
| 253 | ":worker-interface", |
| 254 | "//src/workerd/util:exception", |
| 255 | ], |
| 256 | visibility = ["//visibility:public"], |
| 257 | deps = [ |
| 258 | ":features_capnp", |
| 259 | ":trace", |
| 260 | "//src/workerd/jsg:observer", |
| 261 | "//src/workerd/util:sqlite", |
| 262 | ], |
| 263 | ) |
| 264 | |
| 265 | wd_cc_library( |
| 266 | name = "io-gate", |
| 267 | srcs = ["io-gate.c++"], |
| 268 | hdrs = ["io-gate.h"], |
| 269 | visibility = ["//visibility:public"], |
| 270 | deps = [ |
| 271 | ":trace", |
| 272 | "@capnp-cpp//src/kj", |
| 273 | "@capnp-cpp//src/kj:kj-async", |
| 274 | ], |
| 275 | ) |
| 276 | |
| 277 | wd_cc_library( |
| 278 | name = "limit-enforcer", |
| 279 | srcs = ["tracked-wasm-instance.c++"], |
| 280 | hdrs = [ |
| 281 | "limit-enforcer.h", |
| 282 | "tracked-wasm-instance.h", |
| 283 | ], |
| 284 | visibility = ["//visibility:public"], |
| 285 | deps = [ |
| 286 | ":outcome_capnp", |
| 287 | "//src/workerd/jsg", |
| 288 | ], |
| 289 | ) |
| 290 | |
| 291 | wd_cc_library( |
| 292 | name = "worker-entrypoint", |
| 293 | srcs = ["worker-entrypoint.c++"], |
| 294 | hdrs = ["worker-entrypoint.h"], |
| 295 | implementation_deps = [ |
| 296 | "//src/workerd/util:perfetto", |
| 297 | "//src/workerd/util:strings", |
| 298 | ], |
| 299 | visibility = ["//visibility:public"], |
| 300 | deps = [ |
| 301 | ":io", |
| 302 | ], |
| 303 | ) |
| 304 | |
| 305 | wd_cc_library( |
| 306 | name = "worker-interface", |
| 307 | srcs = ["worker-interface.c++"], |
| 308 | hdrs = ["worker-interface.h"], |
| 309 | visibility = ["//visibility:public"], |
| 310 | deps = [ |
| 311 | ":frankenvalue_capnp", |
| 312 | ":trace", |
| 313 | ":worker-interface_capnp", |
| 314 | "//src/workerd/util", |
| 315 | "@capnp-cpp//src/capnp:capnp-rpc", |
| 316 | "@capnp-cpp//src/capnp:capnpc", |
| 317 | "@capnp-cpp//src/capnp/compat:http-over-capnp", |
| 318 | ], |
| 319 | ) |
| 320 | |
| 321 | wd_cc_library( |
| 322 | name = "actor-id", |
| 323 | hdrs = ["actor-id.h"], |
| 324 | visibility = ["//visibility:public"], |
| 325 | deps = ["@capnp-cpp//src/kj"], |
| 326 | ) |
| 327 | |
| 328 | genrule( |
| 329 | name = "trimmed-release-version-gen", |
| 330 | srcs = ["release-version.txt"], |
| 331 | outs = ["trimmed-release-version.txt"], |
| 332 | cmd = "tr -d '\n' < $(location release-version.txt) > $(location trimmed-release-version.txt)", |
| 333 | cmd_ps = "(Get-Content $(location release-version.txt) -Raw -Encoding Ascii).TrimEnd() | Set-Content $(location trimmed-release-version.txt) -NoNewLine -Encoding Ascii", |
| 334 | visibility = ["//visibility:public"], |
| 335 | ) |
| 336 | |
| 337 | genrule( |
| 338 | name = "trimmed-maximum-compatibility-date-gen", |
| 339 | srcs = ["maximum-compatibility-date.txt"], |
| 340 | outs = ["trimmed-maximum-compatibility-date.txt"], |
| 341 | cmd = "tr -d '\n' < $(location maximum-compatibility-date.txt) > $(location trimmed-maximum-compatibility-date.txt)", |
| 342 | cmd_ps = "(Get-Content $(location maximum-compatibility-date.txt) -Raw -Encoding Ascii).TrimEnd() | Set-Content $(location trimmed-maximum-compatibility-date.txt) -NoNewLine -Encoding Ascii", |
| 343 | visibility = ["//visibility:public"], |
| 344 | ) |
| 345 | |
| 346 | # The date of this release. Used for the version string and the npm compatibilityDate export. |
| 347 | wd_cc_embed( |
| 348 | name = "release-version", |
| 349 | src = ":trimmed-release-version.txt", |
| 350 | base_name = "release-version", |
| 351 | ) |
| 352 | |
| 353 | # Maximum compatibility date that can safely be set using code compiled from this repo. Set to |
| 354 | # 7 days beyond the release date so that users can set their compat date to today even if |
| 355 | # they're running a workerd release from a few days ago. |
| 356 | # |
| 357 | # Note that the production Cloudflare Workers upload API always accepts any date up to the current |
| 358 | # date regardless of this constant, on the assumption that Cloudflare is always running the latest |
| 359 | # version of the code. This constant is more to protect users who are self-hosting the runtime and |
| 360 | # could be running an older version. |
| 361 | wd_cc_embed( |
| 362 | name = "maximum-compatibility-date", |
| 363 | src = ":trimmed-maximum-compatibility-date.txt", |
| 364 | base_name = "maximum-compatibility-date", |
| 365 | ) |
| 366 | |
| 367 | wd_cc_embed( |
| 368 | name = "wasm-instantiate-shim", |
| 369 | src = "wasm-instantiate-shim.js", |
| 370 | base_name = "wasm-instantiate-shim", |
| 371 | ) |
| 372 | |
| 373 | wd_capnp_library(src = "cdp.capnp") |
| 374 | |
| 375 | wd_capnp_library( |
| 376 | src = "worker-interface.capnp", |
| 377 | deps = [ |
| 378 | ":frankenvalue_capnp", |
| 379 | ":outcome_capnp", |
| 380 | ":script-version_capnp", |
| 381 | ":trace_capnp", |
| 382 | "@capnp-cpp//src/capnp/compat:http-over-capnp_capnp", |
| 383 | ], |
| 384 | ) |
| 385 | |
| 386 | wd_capnp_library(src = "actor-storage.capnp") |
| 387 | |
| 388 | wd_capnp_library(src = "outcome.capnp") |
| 389 | |
| 390 | wd_capnp_library(src = "script-version.capnp") |
| 391 | |
| 392 | wd_capnp_library(src = "trace.capnp") |
| 393 | |
| 394 | wd_capnp_library(src = "compatibility-date.capnp") |
| 395 | |
| 396 | wd_capnp_library(src = "features.capnp") |
| 397 | |
| 398 | wd_capnp_library(src = "frankenvalue.capnp") |
| 399 | |
| 400 | wd_capnp_library( |
| 401 | src = "container.capnp", |
| 402 | deps = [ |
| 403 | ":compatibility-date_capnp", |
| 404 | "@capnp-cpp//src/capnp/compat:byte-stream_capnp", |
| 405 | ], |
| 406 | ) |
| 407 | |
| 408 | kj_test( |
| 409 | src = "io-gate-test.c++", |
| 410 | deps = [ |
| 411 | ":io-gate", |
| 412 | ], |
| 413 | ) |
| 414 | |
| 415 | kj_test( |
| 416 | src = "actor-cache-test.c++", |
| 417 | deps = [ |
| 418 | ":actor", |
| 419 | ":io-gate", |
| 420 | "//src/workerd/util:test", |
| 421 | "//src/workerd/util:test-util", |
| 422 | ], |
| 423 | ) |
| 424 | |
| 425 | kj_test( |
| 426 | src = "actor-sqlite-test.c++", |
| 427 | deps = [ |
| 428 | ":actor", |
| 429 | ":io-gate", |
| 430 | "//src/workerd/util:test", |
| 431 | "//src/workerd/util:test-util", |
| 432 | "@sqlite3", |
| 433 | ], |
| 434 | ) |
| 435 | |
| 436 | kj_test( |
| 437 | src = "promise-wrapper-test.c++", |
| 438 | # Omitting coverage because it takes a really long time executing it. |
| 439 | tags = ["no-coverage"], |
| 440 | deps = [ |
| 441 | ":io", |
| 442 | ":promise-wrapper", |
| 443 | ], |
| 444 | ) |
| 445 | |
| 446 | kj_test( |
| 447 | src = "compatibility-date-test.c++", |
| 448 | deps = [ |
| 449 | ":io", |
| 450 | "@capnp-cpp//src/capnp:capnpc", |
| 451 | ], |
| 452 | ) |
| 453 | |
| 454 | kj_test( |
| 455 | src = "observer-test.c++", |
| 456 | deps = [ |
| 457 | ":observer", |
| 458 | "//src/workerd/io:worker-interface", |
| 459 | "//src/workerd/util:strings", |
| 460 | "@capnp-cpp//src/capnp:capnpc", |
| 461 | ], |
| 462 | ) |
| 463 | |
| 464 | kj_test( |
| 465 | src = "trace-test.c++", |
| 466 | deps = [ |
| 467 | ":trace", |
| 468 | "//src/workerd/util:thread-scopes", |
| 469 | ], |
| 470 | ) |
| 471 | |
| 472 | kj_test( |
| 473 | src = "frankenvalue-test.c++", |
| 474 | deps = [ |
| 475 | ":frankenvalue", |
| 476 | ], |
| 477 | ) |
| 478 | |
| 479 | kj_test( |
| 480 | src = "worker-fs-test.c++", |
| 481 | deps = [ |
| 482 | ":io", |
| 483 | ], |
| 484 | ) |
| 485 | |
| 486 | wd_test( |
| 487 | src = "io-context-test.wd-test", |
| 488 | args = ["--experimental"], |
| 489 | data = ["io-context-test.js"], |
| 490 | ) |
| 491 | |
| 492 | kj_test( |
| 493 | src = "tracked-wasm-instance-test.c++", |
| 494 | deps = [ |
| 495 | ":limit-enforcer", |
| 496 | ], |
| 497 | ) |
| 498 | |
| 499 | wd_test( |
| 500 | src = "tracked-wasm-instance-js-test.wd-test", |
| 501 | args = ["--experimental"], |
| 502 | data = [ |
| 503 | "tracked-wasm-instance-test.js", |
| 504 | "//src/workerd/io/wasm:signal-basic.wasm", |
| 505 | "//src/workerd/io/wasm:signal-bounds-check-edge.wasm", |
| 506 | "//src/workerd/io/wasm:signal-bounds-check-overflow.wasm", |
| 507 | "//src/workerd/io/wasm:signal-bounds-check-valid.wasm", |
| 508 | "//src/workerd/io/wasm:signal-decoy-memory.wasm", |
| 509 | "//src/workerd/io/wasm:signal-externref-memory.wasm", |
| 510 | "//src/workerd/io/wasm:signal-imported-memory.wasm", |
| 511 | "//src/workerd/io/wasm:signal-memory-reclaim.wasm", |
| 512 | "//src/workerd/io/wasm:signal-no-globals.wasm", |
| 513 | "//src/workerd/io/wasm:signal-partial-exports.wasm", |
| 514 | "//src/workerd/io/wasm:signal-preinit.wasm", |
| 515 | "//src/workerd/io/wasm:signal-terminated-only.wasm", |
| 516 | ], |
| 517 | # The WebAssembly.instantiate shim is behind the WASM_SHUTDOWN_SIGNAL_SHIM autogate, |
| 518 | # so this test only works when all autogates are enabled. |
| 519 | generate_all_compat_flags_variant = False, |
| 520 | generate_default_variant = False, |
| 521 | ) |
| 522 | |
| 523 | kj_test( |
| 524 | src = "bundle-fs-test.c++", |
| 525 | deps = [ |
| 526 | ":bundle-fs", |
| 527 | ":io", |
| 528 | "//src/workerd/tests:test-fixture", |
| 529 | ], |
| 530 | ) |
| 531 | |
| 532 | kj_test( |
| 533 | src = "worker-getexportedhandler-test.c++", |
| 534 | deps = [ |
| 535 | ":io", |
| 536 | "//src/workerd/tests:test-fixture", |
| 537 | ], |
| 538 | ) |