Skip to content

Commit

Permalink
[nfc] Refactor bazel dependencies
Browse files Browse the repository at this point in the history
This allows us to avoid superfluous linker includes, for example the rust-deps library no longer need to be parsed for most api tests.
  • Loading branch information
fhanau committed Sep 12, 2023
1 parent e6644c6 commit d4eba72
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 11 deletions.
6 changes: 3 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ bazel_skylib_workspace()

http_archive(
name = "capnp-cpp",
sha256 = "19c489573aed8fe130f66e868e312d2cadfcdcb7b7640349b3b0f1cebfefe212",
strip_prefix = "capnproto-capnproto-99115bd/c++",
sha256 = "bb42e918b521aa8619225876b538e20f934510818809f0d99cb56eab0420561e",
strip_prefix = "capnproto-capnproto-ccc604e/c++",
type = "tgz",
urls = ["https://github.com/capnproto/capnproto/tarball/99115bdd4b3b3227dfd363921c6399d8785017aa"],
urls = ["https://github.com/capnproto/capnproto/tarball/ccc604e0b2a07e60fdc1345c7667c689ad4117ca"],
)

http_archive(
Expand Down
56 changes: 55 additions & 1 deletion src/workerd/api/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("//:build/kj_test.bzl", "kj_test")
load("//:build/wd_cc_capnp_library.bzl", "wd_cc_capnp_library")
load("//:build/wd_cc_library.bzl", "wd_cc_library")
load("//:build/wd_test.bzl", "wd_test")

filegroup(
Expand All @@ -8,12 +9,16 @@ filegroup(
"//src/workerd/io:set_enable_experimental_webgpu": glob(
["**/*.c++"],
exclude = [
"html-rewriter.c++",
"rtti.c++",
"**/*test*.c++",
],
),
"//conditions:default": glob(
["**/*.c++"],
exclude = [
"html-rewriter.c++",
"rtti.c++",
"**/*test*.c++",
"gpu/*.c++",
],
Expand All @@ -28,12 +33,18 @@ filegroup(
"//src/workerd/io:set_enable_experimental_webgpu": glob(
["**/*.h"],
exclude = [
"html-rewriter.h",
"modules.h",
"rtti.h",
"**/*test*.h",
],
),
"//conditions:default": glob(
["**/*.h"],
exclude = [
"html-rewriter.h",
"modules.h",
"rtti.h",
"**/*test*.h",
"gpu/*.h",
],
Expand All @@ -42,6 +53,31 @@ filegroup(
visibility = ["//visibility:public"],
)

wd_cc_library(
name = "rtti",
srcs = ["rtti.c++"],
hdrs = [
"rtti.h",
"modules.h",
],
visibility = ["//visibility:public"],
deps = [
":html-rewriter",
"//src/workerd/io:io",
],
)

wd_cc_library(
name = "html-rewriter",
srcs = ["html-rewriter.c++"],
hdrs = ["html-rewriter.h"],
visibility = ["//visibility:public"],
deps = [
"//src/workerd/io:io",
"@com_cloudflare_lol_html//:lolhtml",
],
)

wd_cc_capnp_library(
name = "r2-api_capnp",
srcs = ["r2-api.capnp"],
Expand All @@ -58,12 +94,13 @@ wd_cc_capnp_library(
src = f,
deps = [
"//src/workerd/io",
"//src/workerd/jsg:rtti",
],
) for f in glob(
["**/*-test.c++"],
exclude = [
"api-rtti-test.c++",
"cf-property-test.c++",
"actor-state-test.c++",
"node/*-test.c++",
],
)]
Expand All @@ -73,6 +110,23 @@ kj_test(
deps = ["//src/workerd/tests:test-fixture"],
)

kj_test(
src = "actor-state-test.c++",
deps = [
"//src/workerd/io",
"@capnp-cpp//src/capnp:capnp-rpc",
],
)

kj_test(
src = "api-rtti-test.c++",
deps = [
":html-rewriter",
"//src/workerd/io",
"//src/workerd/jsg:rtti",
],
)

kj_test(
src = "cf-property-test.c++",
deps = ["//src/workerd/tests:test-fixture"],
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/api/html-rewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#pragma once

#include "workerd/api/http.h"
#include <workerd/jsg/jsg.h>
#include <v8.h>
#include "http.h"

struct lol_html_HtmlRewriterBuilder;
struct lol_html_HtmlRewriter;
Expand Down
2 changes: 0 additions & 2 deletions src/workerd/io/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,10 @@ wd_cc_library(
"//src/workerd/jsg",
"//src/workerd/jsg:rtti",
"//src/workerd/util:sqlite",
"@capnp-cpp//src/capnp:capnp-rpc",
"@capnp-cpp//src/capnp/compat:http-over-capnp",
"@capnp-cpp//src/kj:kj-async",
"@capnp-cpp//src/kj/compat:kj-brotli",
"@capnp-cpp//src/kj/compat:kj-gzip",
"@com_cloudflare_lol_html//:lolhtml",
] + select({
":set_enable_experimental_webgpu": ["@dawn"],
"//conditions:default": [],
Expand Down
21 changes: 19 additions & 2 deletions src/workerd/jsg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,15 @@ wd_cc_library(
deps = [
":rtti_capnp",
":jsg",
# todo: move text encoding out
"@capnp-cpp//src/capnp:capnpc",
],
)

wd_cc_library(
name = "macro-meta",
hdrs = ["macro-meta.h"],
visibility = ["//visibility:public"],
)

wd_cc_capnp_library(
name = "modules_capnp",
srcs = ["modules.capnp"],
Expand All @@ -106,17 +110,30 @@ wd_cc_library(
["*-test.c++"],
exclude = [
# defined below
"macro-meta-test.c++",
"resource-test.c++",
"rtti-test.c++",
],
)]

# Moved out as macro-meta-test does not depend on V8 or JSG proper, this makes the test much
# smaller.
kj_test(
src = "macro-meta-test.c++",
tags = ["no-arm64"],
deps = [
":macro-meta",
],
)

kj_test(
src = "rtti-test.c++",
tags = ["no-arm64"],
deps = [
":rtti",
":rtti_test_capnp",
# todo: move text encoding out
"@capnp-cpp//src/capnp:capnpc",
],
)

Expand Down
4 changes: 3 additions & 1 deletion src/workerd/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ wd_cc_binary(
":server",
":workerd-meta_capnp",
":workerd_capnp",
"@capnp-cpp//src/capnp:capnpc",
] + select({
"@platforms//os:windows": [],
"//conditions:default": ["@workerd//src/workerd/util:symbolizer"],
Expand Down Expand Up @@ -93,9 +94,10 @@ wd_cc_library(
deps = [
":alarm-scheduler",
":workerd_capnp",
"//src/workerd/api:html-rewriter",
"//src/workerd/api:rtti",
"//src/workerd/io",
"//src/workerd/jsg",
"@capnp-cpp//src/capnp:capnpc",
],
)

Expand Down
3 changes: 2 additions & 1 deletion src/workerd/tools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ load("//:build/wd_cc_library.bzl", "wd_cc_library")
wd_cc_library(
name = "api_encoder_lib",
deps = [
"//src/workerd/api:html-rewriter",
"//src/workerd/io",
"//src/workerd/jsg",
"//src/workerd/jsg:rtti",
"@capnp-cpp//src/capnp:capnpc",
"@capnp-cpp//src/capnp",
],
)

Expand Down

0 comments on commit d4eba72

Please sign in to comment.