Skip to content
File

Blob: BUILD.bazel

4.0 KB
1load("@aspect_rules_js//js:defs.bzl", "js_library")
2load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
3load("@bazel_skylib//lib:selects.bzl", "selects")
4load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
5load("@npm//:capnp-es/package_json.bzl", capnp_es_bins = "bin")
6load("@npm//:defs.bzl", "npm_link_all_packages")
7load("//:build/wd_cc_embed.bzl", "wd_cc_embed")
8 
9# This is used to embed the ICU data file which libicu needs at runtime to do its thing.
10# We bake this file into the binary to avoid shipping it separately. (V8's normal GN build can
11# actually do this for us, but we use the Bazel build which doesn't have this option.) Using #embed
12# makes this very fast and convenient.
13wd_cc_embed(
14 name = "icudata-embed",
15 src = "@com_googlesource_chromium_icu//:common/icudtl.dat",
16 base_name = "icu-data-file",
17 strip_include_prefix = "",
18 visibility = ["//visibility:public"],
19)
20 
21# Also re-export the v8 ICU library for @workerd-v8
22alias(
23 name = "v8_icu",
24 actual = "@v8//:v8_icu",
25 tags = ["manual"],
26 visibility = ["//visibility:public"],
27)
28 
29npm_link_all_packages(name = "node_modules")
30 
31npm_link_package(
32 name = "node_modules/@workerd/jsg",
33 src = "//src/workerd/jsg:jsg_js",
34 package = "@workerd/jsg",
35)
36 
37# Plugin to generate .js files
38capnp_es_bins.capnpc_js_binary(
39 name = "capnpc_js_plugin",
40 visibility = ["//visibility:public"],
41)
42 
43# Plugin to generate .ts files
44capnp_es_bins.capnpc_ts_binary(
45 name = "capnpc_ts_plugin",
46 visibility = ["//visibility:public"],
47)
48 
49js_library(
50 name = "prettierrc",
51 srcs = [":.prettierrc.json"],
52 visibility = ["//build/deps/formatters:__pkg__"],
53)
54 
55# Platform definition for using clang-cl on Windows
56platform(
57 name = "x64_windows-clang-cl",
58 constraint_values = [
59 "@platforms//cpu:x86_64",
60 "@platforms//os:windows",
61 "@bazel_tools//tools/cpp:clang-cl",
62 ],
63)
64 
65# Used for cross-compilation
66platform(
67 name = "macOS_x86",
68 constraint_values = [
69 "@platforms//os:macos",
70 "@platforms//cpu:x86_64",
71 ],
72)
73 
74# Detect whether we use Linux/macOS/either, used to configure whether tcmalloc/perfetto should be
75# used.
76config_setting(
77 name = "is_linux",
78 constraint_values = ["@platforms//os:linux"],
79 visibility = ["//visibility:public"],
80)
81 
82config_setting(
83 name = "is_macos",
84 constraint_values = ["@platforms//os:macos"],
85 visibility = ["//visibility:public"],
86)
87 
88selects.config_setting_group(
89 name = "is_unix",
90 match_any = [
91 ":is_linux",
92 ":is_macos",
93 ],
94 visibility = ["//visibility:public"],
95)
96 
97# bazel enables the --ffunction-sections, --gc-sections flags used to remove dead code by default
98# on Linux opt builds. Enable the equivalent macOS flag -Wl,-dead_strip here to work around bazel
99# idiosyncrasies.
100# Note that the flag is defined for all non-debug builds of kj_test() and wd_cc_binary() on mac as
101# it surprisingly appears to be faster, perhaps because the linker generates and writes binaries
102# with much fewer symbols. This also helps reduce local and CI disk usage. If needed, dead code
103# stripping can be limited to optimized builds.
104config_setting(
105 name = "fast_build",
106 values = {"compilation_mode": "fastbuild"},
107)
108 
109config_setting(
110 name = "opt_build",
111 values = {"compilation_mode": "opt"},
112)
113 
114bool_flag(
115 name = "dead_strip",
116 build_setting_default = True,
117)
118 
119config_setting(
120 name = "set_dead_strip",
121 flag_values = {"dead_strip": "True"},
122)
123 
124# Workaround for bazel not supporting negated conditions (https://github.com/bazelbuild/bazel-skylib/issues/272)
125selects.config_setting_group(
126 name = "not_dbg_build",
127 match_any = [
128 ":fast_build",
129 ":opt_build",
130 ],
131)
132 
133selects.config_setting_group(
134 name = "use_dead_strip",
135 match_all = [
136 "@platforms//os:macos",
137 ":set_dead_strip",
138 ":not_dbg_build",
139 ],
140)
141 
142# Clang-tidy config to use
143label_flag(
144 name = "clang_tidy_config",
145 build_setting_default = ":.clang-tidy",
146 visibility = ["//visibility:public"],
147)