File
Blob: src/workerd/jsg/BUILD.bazel
| 1 | load("@aspect_rules_js//npm:defs.bzl", "npm_package") |
| 2 | load("//:build/js_capnp_library.bzl", "js_capnp_library") |
| 3 | load("//:build/kj_test.bzl", "kj_test") |
| 4 | load("//:build/wd_cc_capnp_library.bzl", "wd_cc_capnp_library") |
| 5 | load("//:build/wd_cc_library.bzl", "wd_cc_library") |
| 6 | |
| 7 | exports_files(["modules.capnp"]) |
| 8 | |
| 9 | wd_cc_library( |
| 10 | name = "jsg", |
| 11 | srcs = [], |
| 12 | hdrs = [ |
| 13 | "jsg-test.h", |
| 14 | "type-wrapper.h", |
| 15 | ], |
| 16 | local_defines = ["JSG_IMPLEMENTATION"], |
| 17 | visibility = ["//visibility:public"], |
| 18 | deps = [ |
| 19 | ":exception", |
| 20 | ":iterator", |
| 21 | ":jsg-core", |
| 22 | ":memory-tracker", |
| 23 | ":url", |
| 24 | "//src/workerd/util", |
| 25 | "//src/workerd/util:sentry", |
| 26 | "//src/workerd/util:thread-scopes", |
| 27 | "@capnp-cpp//src/kj", |
| 28 | "@workerd-v8//:v8", |
| 29 | ], |
| 30 | ) |
| 31 | |
| 32 | wd_cc_library( |
| 33 | name = "iterator", |
| 34 | srcs = [ |
| 35 | "iterator.c++", |
| 36 | ], |
| 37 | hdrs = [ |
| 38 | "iterator.h", |
| 39 | "struct.h", |
| 40 | "value.h", |
| 41 | ], |
| 42 | local_defines = ["JSG_IMPLEMENTATION"], |
| 43 | deps = [ |
| 44 | ":exception", |
| 45 | ":jsg-core", |
| 46 | ":memory-tracker", |
| 47 | "//src/workerd/util", |
| 48 | "//src/workerd/util:sentry", |
| 49 | "//src/workerd/util:thread-scopes", |
| 50 | "@capnp-cpp//src/kj", |
| 51 | "@workerd-v8//:v8", |
| 52 | ], |
| 53 | ) |
| 54 | |
| 55 | wd_cc_library( |
| 56 | name = "script", |
| 57 | srcs = ["script.c++"], |
| 58 | hdrs = ["script.h"], |
| 59 | local_defines = ["JSG_IMPLEMENTATION"], |
| 60 | visibility = ["//visibility:public"], |
| 61 | deps = [ |
| 62 | ":jsg-core", |
| 63 | "@capnp-cpp//src/kj", |
| 64 | "@workerd-v8//:v8", |
| 65 | ], |
| 66 | ) |
| 67 | |
| 68 | # Subset of JSG that includes core JSG interfaces, but does not depend on type-wrapper API. |
| 69 | # Factoring this out reduces the need for circular includes and will make future refactoring of JSG |
| 70 | # much easier. |
| 71 | # This is only visible in this package for now – to avoid extensive include changes in code using |
| 72 | # the JSG type wrapper, the main JSG target should be used instead for now. |
| 73 | # Avoid adding dependencies or new files to this when possible. |
| 74 | wd_cc_library( |
| 75 | name = "jsg-core", |
| 76 | srcs = [ |
| 77 | "async-context.c++", |
| 78 | "buffersource.c++", |
| 79 | "dom-exception.c++", |
| 80 | "jsg.c++", |
| 81 | "jsvalue.c++", |
| 82 | "modules.c++", |
| 83 | "modules-new.c++", |
| 84 | "promise.c++", |
| 85 | "resource.c++", |
| 86 | "ser.c++", |
| 87 | "setup.c++", |
| 88 | "util.c++", |
| 89 | "v8-platform-wrapper.c++", |
| 90 | "wrappable.c++", |
| 91 | ], |
| 92 | hdrs = [ |
| 93 | "async-context.h", |
| 94 | "buffersource.h", |
| 95 | "dom-exception.h", |
| 96 | "fast-api.h", |
| 97 | "function.h", |
| 98 | "jsg.h", |
| 99 | "jsvalue.h", |
| 100 | "modules.h", |
| 101 | "modules-new.h", |
| 102 | "promise.h", |
| 103 | "resource.h", |
| 104 | "ser.h", |
| 105 | "setup.h", |
| 106 | "util.h", |
| 107 | "v8-platform-wrapper.h", |
| 108 | "web-idl.h", |
| 109 | "wrappable.h", |
| 110 | ], |
| 111 | # Some JSG headers can't be compiled on their own |
| 112 | features = ["-parse_headers"], |
| 113 | implementation_deps = [ |
| 114 | "//src/workerd/util:entropy", |
| 115 | "@simdutf", |
| 116 | "@ssl", |
| 117 | ], |
| 118 | local_defines = ["JSG_IMPLEMENTATION"], |
| 119 | tags = ["no-clang-tidy"], |
| 120 | visibility = [ |
| 121 | "//src/rust/jsg:__pkg__", |
| 122 | "//src/rust/jsg-test:__pkg__", |
| 123 | ], |
| 124 | deps = [ |
| 125 | ":exception", |
| 126 | ":exception_metadata_capnp", |
| 127 | ":macro-meta", |
| 128 | ":memory-tracker", |
| 129 | ":meta", |
| 130 | ":modules_capnp", |
| 131 | ":observer", |
| 132 | ":url", |
| 133 | "//src/workerd/util", # Required for util/batch-queue.h |
| 134 | "//src/workerd/util:autogate", |
| 135 | "//src/workerd/util:sentry", |
| 136 | "//src/workerd/util:thread-scopes", |
| 137 | "@capnp-cpp//src/kj", |
| 138 | "@workerd-v8//:v8", |
| 139 | ], |
| 140 | ) |
| 141 | |
| 142 | wd_cc_library( |
| 143 | name = "compile-cache", |
| 144 | srcs = [ |
| 145 | "compile-cache.c++", |
| 146 | ], |
| 147 | hdrs = [ |
| 148 | "compile-cache.h", |
| 149 | ], |
| 150 | local_defines = ["JSG_IMPLEMENTATION"], |
| 151 | visibility = ["//visibility:public"], |
| 152 | deps = [ |
| 153 | "@capnp-cpp//src/kj", |
| 154 | "@workerd-v8//:v8", |
| 155 | ], |
| 156 | ) |
| 157 | |
| 158 | wd_cc_library( |
| 159 | name = "inspector", |
| 160 | srcs = [ |
| 161 | "inspector.c++", |
| 162 | ], |
| 163 | hdrs = [ |
| 164 | "inspector.h", |
| 165 | ], |
| 166 | implementation_deps = [ |
| 167 | ":jsg-core", |
| 168 | "@capnp-cpp//src/kj", |
| 169 | "@simdutf", |
| 170 | "@workerd-v8//:v8", |
| 171 | ], |
| 172 | local_defines = ["JSG_IMPLEMENTATION"], |
| 173 | # Some JSG headers can't be compiled on their own |
| 174 | visibility = ["//visibility:public"], |
| 175 | ) |
| 176 | |
| 177 | wd_cc_library( |
| 178 | name = "memory-tracker", |
| 179 | srcs = ["memory.c++"], |
| 180 | hdrs = ["memory.h"], |
| 181 | visibility = ["//visibility:public"], |
| 182 | deps = [ |
| 183 | "@capnp-cpp//src/kj", |
| 184 | "@workerd-v8//:v8", |
| 185 | ], |
| 186 | ) |
| 187 | |
| 188 | wd_cc_library( |
| 189 | name = "meta", |
| 190 | hdrs = ["meta.h"], |
| 191 | visibility = ["//visibility:public"], |
| 192 | deps = [ |
| 193 | "@capnp-cpp//src/kj", |
| 194 | "@workerd-v8//:v8", |
| 195 | ], |
| 196 | ) |
| 197 | |
| 198 | wd_cc_library( |
| 199 | name = "url", |
| 200 | srcs = ["url.c++"], |
| 201 | hdrs = [ |
| 202 | "url.h", |
| 203 | ], |
| 204 | implementation_deps = [ |
| 205 | "//src/workerd/util:strings", |
| 206 | "@ada-url", |
| 207 | ], |
| 208 | visibility = ["//visibility:public"], |
| 209 | deps = [ |
| 210 | ":memory-tracker", |
| 211 | "@capnp-cpp//src/kj", |
| 212 | ], |
| 213 | ) |
| 214 | |
| 215 | wd_cc_library( |
| 216 | name = "exception", |
| 217 | srcs = ["exception.c++"], |
| 218 | hdrs = ["exception.h"], |
| 219 | visibility = ["//visibility:public"], |
| 220 | deps = [ |
| 221 | "@capnp-cpp//src/kj", |
| 222 | ], |
| 223 | ) |
| 224 | |
| 225 | wd_cc_capnp_library( |
| 226 | name = "rtti_capnp", |
| 227 | srcs = ["rtti.capnp"], |
| 228 | visibility = ["//visibility:public"], |
| 229 | ) |
| 230 | |
| 231 | wd_cc_capnp_library( |
| 232 | name = "exception_metadata_capnp", |
| 233 | srcs = ["exception-metadata.capnp"], |
| 234 | visibility = ["//visibility:public"], |
| 235 | ) |
| 236 | |
| 237 | js_capnp_library( |
| 238 | name = "rtti_capnp_js", |
| 239 | srcs = ["rtti.capnp"], |
| 240 | outs = [ |
| 241 | "rtti.js", |
| 242 | "rtti.ts", |
| 243 | ], |
| 244 | data = ["//:node_modules/capnp-es"], |
| 245 | target_compatible_with = select({ |
| 246 | "@platforms//os:windows": ["@platforms//:incompatible"], |
| 247 | "@//build/config:no_build": ["@platforms//:incompatible"], |
| 248 | "//conditions:default": [], |
| 249 | }), |
| 250 | visibility = ["//visibility:public"], |
| 251 | ) |
| 252 | |
| 253 | npm_package( |
| 254 | name = "jsg_js", |
| 255 | srcs = [":rtti_capnp_js"], |
| 256 | # Required to ensure source files are copied when running internal builds |
| 257 | # that depend on `workerd` as an external repository |
| 258 | include_external_repositories = ["workerd"], |
| 259 | publishable = False, |
| 260 | visibility = ["//visibility:public"], |
| 261 | ) |
| 262 | |
| 263 | wd_cc_library( |
| 264 | name = "rtti", |
| 265 | hdrs = ["rtti.h"], |
| 266 | visibility = ["//visibility:public"], |
| 267 | deps = [ |
| 268 | ":jsg", |
| 269 | ":rtti_capnp", |
| 270 | ], |
| 271 | ) |
| 272 | |
| 273 | wd_cc_library( |
| 274 | name = "macro-meta", |
| 275 | hdrs = ["macro-meta.h"], |
| 276 | visibility = ["//visibility:public"], |
| 277 | ) |
| 278 | |
| 279 | wd_cc_capnp_library( |
| 280 | name = "modules_capnp", |
| 281 | srcs = ["modules.capnp"], |
| 282 | visibility = ["//visibility:public"], |
| 283 | ) |
| 284 | |
| 285 | wd_cc_library( |
| 286 | name = "observer", |
| 287 | hdrs = ["observer.h"], |
| 288 | visibility = ["//visibility:public"], |
| 289 | deps = [ |
| 290 | "//src/workerd/util:strong-bool", |
| 291 | "@capnp-cpp//src/kj", |
| 292 | "@workerd-v8//:v8", |
| 293 | ], |
| 294 | ) |
| 295 | |
| 296 | [kj_test( |
| 297 | src = f, |
| 298 | local_defines = ["JSG_IMPLEMENTATION"], |
| 299 | deps = [":jsg"], |
| 300 | ) for f in glob( |
| 301 | ["*-test.c++"], |
| 302 | exclude = [ |
| 303 | # defined below |
| 304 | "macro-meta-test.c++", |
| 305 | "resource-test.c++", |
| 306 | "rtti-test.c++", |
| 307 | "url-test.c++", |
| 308 | "multiple-typewrappers-test.c++", |
| 309 | ], |
| 310 | )] |
| 311 | |
| 312 | # Moved out as macro-meta-test does not depend on V8 or JSG proper, this makes the test much |
| 313 | # smaller. |
| 314 | kj_test( |
| 315 | src = "macro-meta-test.c++", |
| 316 | deps = [ |
| 317 | ":macro-meta", |
| 318 | ], |
| 319 | ) |
| 320 | |
| 321 | kj_test( |
| 322 | src = "rtti-test.c++", |
| 323 | deps = [ |
| 324 | ":rtti", |
| 325 | ":rtti_test_capnp", |
| 326 | # TODO: move text encoding out |
| 327 | "@capnp-cpp//src/capnp:capnpc", |
| 328 | ], |
| 329 | ) |
| 330 | |
| 331 | kj_test( |
| 332 | src = "url-test.c++", |
| 333 | deps = [ |
| 334 | ":url", |
| 335 | "@ssl", |
| 336 | ], |
| 337 | ) |
| 338 | |
| 339 | wd_cc_capnp_library( |
| 340 | name = "resource_test_capnp", |
| 341 | srcs = ["resource-test.capnp"], |
| 342 | data = glob(["resource-test-*.js"]), |
| 343 | deps = [":modules_capnp"], |
| 344 | ) |
| 345 | |
| 346 | wd_cc_capnp_library( |
| 347 | name = "rtti_test_capnp", |
| 348 | srcs = ["rtti-test.capnp"], |
| 349 | deps = [":modules_capnp"], |
| 350 | ) |
| 351 | |
| 352 | kj_test( |
| 353 | src = "resource-test.c++", |
| 354 | deps = [ |
| 355 | ":jsg", |
| 356 | ":resource_test_capnp", |
| 357 | ], |
| 358 | ) |
| 359 | |
| 360 | kj_test( |
| 361 | src = "multiple-typewrappers-test.c++", |
| 362 | deps = [ |
| 363 | ":jsg", |
| 364 | "//src/workerd/io:compatibility-date_capnp", |
| 365 | ], |
| 366 | ) |