-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWORKSPACE.bazel
226 lines (185 loc) · 7.67 KB
/
WORKSPACE.bazel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
workspace(name = "starflate")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
COMMON_CXX_FLAGS = [
"-march=native",
"-std=c++23",
]
COMMON_CXX_WARNINGS = [
"-Werror",
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wconversion",
"-Wnon-virtual-dtor",
"-Wold-style-cast",
"-Wcast-align",
"-Wunused",
"-Woverloaded-virtual",
"-Wmisleading-indentation",
"-Wnull-dereference",
"-Wdouble-promotion",
"-Wformat=2",
"-Wimplicit-fallthrough",
]
# Bazel sends stdout/stderr to file so we cannot use `-fdiagnostics-color=auto`
# https://github.com/bazelbuild/bazel/issues/6046#issuecomment-626941725
#
# Clang will also require libtinfo.so.5 with `-fdiagnostics-color=always`
# https://github.com/mun-lang/mun/issues/191#issuecomment-753402659
# https://reviews.llvm.org/D42274
load("//tools:host_system_libraries.bzl", "host_system_libraries")
host_system_libraries(
name = "host_system_libraries",
find = ["libtinfo.so.5"],
)
load("@host_system_libraries//:defs.bzl", "HOST_SYSTEM_LIBRARIES")
# Pull in rules_cc and patch it to inject options to the `copts` attribute of
# `cc_{binary,library,test}`. This is used to disable UBSan null pointer checks
# with GCC as enabling these features will reject valid code:
#
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67762#c2
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71962
#
# Note that we cannot set these options in toolchain registration
# (bootlin_toolchain below) as the sanitize feature disable flags will precede
# `-fsanitize=undefined` from `--features=ubsan` and thus be ignored.
#
# https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#id3
#
# The patched cc_* rules adds the sanitize feature disable flags in `copts` only
# for GCC + UBSan builds. As these are set in `user_compile_flags`, these
# options follow `-fsanitize=undefined` when present.
#
# https://bazel.build/rules/lib/toplevel/cc_common#parameters_5
#
http_archive(
name = "rules_cc",
patch_args = ["-p1"],
patches = ["//toolchain:rules_cc-gcc-ubsan-no-sanitize-null.patch"],
sha256 = "2037875b9a4456dce4a79d112a8ae885bbc4aad968e6587dca6e64f3a0900cdf",
strip_prefix = "rules_cc-0.0.9",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.9/rules_cc-0.0.9.tar.gz"],
)
# Note: not correct on MacOS.
LLVM_COLOR_FLAGS = ["-fdiagnostics-color=always" if "libinfo.so.5" in HOST_SYSTEM_LIBRARIES else ""]
BAZEL_BOOTLIN_COMMIT = "d15e4b4c3a984668d1d6bd5f3ca032efecae5cb1"
http_archive(
name = "bazel_bootlin",
sha256 = "9019568dc57601719b964a82371835fdbb3673a60bacb1ea2e049bc2c01c0a5f",
strip_prefix = "bazel_bootlin-%s" % BAZEL_BOOTLIN_COMMIT,
url = "https://github.com/oliverlee/bazel_bootlin/archive/%s.tar.gz" % BAZEL_BOOTLIN_COMMIT,
)
load("@bazel_bootlin//:defs.bzl", "bootlin_toolchain")
bootlin_toolchain(
name = "gcc_toolchain",
# x86-64-v3 should cover CPUs released after ~2015.
# see https://www.phoronix.com/news/GCC-11-x86-64-Feature-Levels.
architecture = "x86-64-v3",
# see https://toolchains.bootlin.com/releases_x86-64-v3.html
buildroot_version = "bleeding-edge-2023.08-1",
extra_cxx_flags = [
"-fdiagnostics-color=always",
"-Wduplicated-cond",
"-Wduplicated-branches",
"-Wlogical-op",
"-Wuseless-cast",
"-Wshadow=compatible-local", # Equivalent to -Wshadow on llvm. GCC default is stupid.
] + COMMON_CXX_FLAGS + COMMON_CXX_WARNINGS,
libc_impl = "glibc",
)
TOOLCHAINS_LLVM_VERSION = "bba94f8138ab454d70afcd263788b34e2801e2ba"
http_archive(
name = "toolchains_llvm",
integrity = "sha256-IyBbm0rakJat7jSGvZ65xVGS2xQQhbXvmx8Q5EA5wlA=",
strip_prefix = "toolchains_llvm-%s" % TOOLCHAINS_LLVM_VERSION,
url = "https://github.com/bazel-contrib/toolchains_llvm/archive/%s.tar.gz" % TOOLCHAINS_LLVM_VERSION,
)
load("//tools:llvm_toolchain_dependencies.bzl", "llvm_toolchain_dependencies")
llvm_toolchain_dependencies()
load("//tools:llvm_toolchain.bzl", "llvm_toolchain")
llvm_toolchain(
name = "llvm_toolchain",
cxx_flags = {
"": [
"-stdlib=libc++",
"-Wshadow",
] + COMMON_CXX_FLAGS + COMMON_CXX_WARNINGS + LLVM_COLOR_FLAGS,
},
# Link UBSan C++ runtime libraries if the `ubsan` feature is enabled
# https://github.com/bazelbuild/bazel/issues/12797#issuecomment-980641064
# use `link_libs` to prevent overriding default `link_flags`
# https://github.com/grailbio/bazel-toolchain/blob/ceeedcc4464322e05fe5b8df3749cc02273ee083/toolchain/cc_toolchain_config.bzl#L148-L150
link_libs = {
"": ["-fsanitize-link-c++-runtime"],
},
linux_x86_64_sysroot = "@gcc_toolchain_files//x86_64-buildroot-linux-gnu/sysroot",
llvm_version = "17.0.2",
)
# register llvm first, it has better error messages
load("@llvm_toolchain//:toolchains.bzl", "llvm_register_toolchains")
llvm_register_toolchains()
register_toolchains(
"@gcc_toolchain//:toolchain",
)
BOOST_UT_VERSION = "20f2c3f811e25b8c398c6e98545dbf07d72eb4e8"
http_archive(
name = "boost_ut",
build_file_content = """
load("@rules_cc//cc:defs.bzl", "cc_library")
cc_library(
name = "boost_ut",
hdrs = ["include/boost/ut.hpp"],
includes = ["."],
visibility = ["//visibility:public"],
)
""",
sha256 = "b5a4f3f1f88f3fb375370a734ab7b6b6c7b4f23e82f949544e61f64ebdb1f8dd",
strip_prefix = "ut-%s" % BOOST_UT_VERSION,
url = "https://github.com/boost-ext/ut/archive/%s.tar.gz" % BOOST_UT_VERSION,
)
GOOGLE_BENCHMARK_VERSION = "1.8.0"
http_archive(
name = "google_benchmark",
patch_args = ["-p1"],
patches = ["//:third_party/google_benchmark.patch"],
sha256 = "ea2e94c24ddf6594d15c711c06ccd4486434d9cf3eca954e2af8a20c88f9f172",
strip_prefix = "benchmark-%s" % GOOGLE_BENCHMARK_VERSION,
url = "https://github.com/google/benchmark/archive/refs/tags/v%s.tar.gz" % GOOGLE_BENCHMARK_VERSION,
)
BAZEL_CLANG_FORMAT_VERSION = "f4198b68887699a4d1862e44458e4969ad69fc8a"
http_archive(
name = "bazel_clang_format",
sha256 = "bd75df6dae8d290a716e1812c463ef4ab36869b5557d8a6dd6abb8315acfc6ac",
strip_prefix = "bazel_clang_format-%s" % BAZEL_CLANG_FORMAT_VERSION,
url = "https://github.com/oliverlee/bazel_clang_format/archive/%s.tar.gz" % BAZEL_CLANG_FORMAT_VERSION,
)
BAZEL_CLANG_TIDY_VERSION = "aae87699cca19d8f6e84538576ab47587043d1d2"
http_archive(
name = "bazel_clang_tidy",
sha256 = "ee7d89375b5c6554b40ea1b1132a8cf7e3e269f7c2f6b2f595e4c7181d44b736",
strip_prefix = "bazel_clang_tidy-%s" % BAZEL_CLANG_TIDY_VERSION,
url = "https://github.com/oliverlee/bazel_clang_tidy/archive/%s.tar.gz" % BAZEL_CLANG_TIDY_VERSION,
)
http_archive(
name = "buildifier_prebuilt",
sha256 = "e46c16180bc49487bfd0f1ffa7345364718c57334fa0b5b67cb5f27eba10f309",
strip_prefix = "buildifier-prebuilt-6.1.0",
urls = [
"https://github.com/keith/buildifier-prebuilt/archive/6.1.0.tar.gz",
],
)
load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps")
buildifier_prebuilt_deps()
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
bazel_skylib_workspace()
load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains")
buildifier_prebuilt_register_toolchains()
COMPILE_COMMANDS_VERSION = "3dddf205a1f5cde20faf2444c1757abe0564ff4c"
http_archive(
name = "hedron_compile_commands",
sha256 = "3cd0e49f0f4a6d406c1d74b53b7616f5e24f5fd319eafc1bf8eee6e14124d115",
strip_prefix = "bazel-compile-commands-extractor-%s" % COMPILE_COMMANDS_VERSION,
url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/%s.tar.gz" % COMPILE_COMMANDS_VERSION,
)
load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup")
hedron_compile_commands_setup()