-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathBUILD.bazel
More file actions
173 lines (166 loc) · 6.55 KB
/
Copy pathBUILD.bazel
File metadata and controls
173 lines (166 loc) · 6.55 KB
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
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@rules_cc//cc:cc_library.bzl", "cc_library")
# Bazel build for clickhouse-cpp. The canonical build is CMake
# (top-level CMakeLists.txt); this file mirrors the same library as
# a bzlmod target so downstream Bazel projects can depend on it via
# the Bazel Central Registry without standing up CMake.
#
# Differences from the CMake build that callers should be aware of:
# * TLS links against BoringSSL (`@boringssl`) by default; pass
# `--@clickhouse-cpp//:tls=openssl` to use the BCR OpenSSL module
# instead, or `--@clickhouse-cpp//:tls=no` to disable TLS
# entirely. `USE_BORINGSSL` ifdef-guards the two OpenSSL-only
# surfaces (`SSL_CONF_*` command API and `SSL_read_ex`) that
# BoringSSL doesn't provide; see clickhouse/base/sslsocket.cpp.
# * lz4 / zstd come from BCR modules instead of contrib/. cityhash is
# Selects the TLS implementation: `--@clickhouse-cpp//:tls=boringssl`
# (default), `--@clickhouse-cpp//:tls=openssl`, or
# `--@clickhouse-cpp//:tls=no` to disable TLS entirely (matching
# CMake's `WITH_OPENSSL=OFF` default). The two TLS libraries come from
# BCR modules and are linked statically, keeping the build hermetic.
string_flag(
name = "tls",
build_setting_default = "boringssl",
values = [
"boringssl",
"openssl",
"no",
],
)
# Public visibility so the config_setting can be referenced from other
# packages (e.g. ut/BUILD.bazel's `select()` on `//:tls_no`); Bazel's
# config-setting visibility enforcement rejects the private default
# across packages.
config_setting(
name = "tls_boringssl",
flag_values = {":tls": "boringssl"},
visibility = ["//visibility:public"],
)
config_setting(
name = "tls_openssl",
flag_values = {":tls": "openssl"},
visibility = ["//visibility:public"],
)
config_setting(
name = "tls_no",
flag_values = {":tls": "no"},
visibility = ["//visibility:public"],
)
# OpenSSL on Windows pulls in Win32 system libraries (the cert store via
# crypt32, plus user32) that BoringSSL bundles itself. Used to gate the
# extra linkopts below.
selects.config_setting_group(
name = "tls_openssl_on_windows",
match_all = [
":tls_openssl",
"@platforms//os:windows",
],
)
# The main clickhouse-cpp library. Downstream callers use
# `#include <clickhouse/client.h>` and link `@clickhouse-cpp//:clickhouse`.
cc_library(
name = "clickhouse",
srcs = glob(
[
"clickhouse/*.cpp",
"clickhouse/base/*.cpp",
"clickhouse/columns/*.cpp",
"clickhouse/types/*.cpp",
],
# Only compiled when TLS is enabled, mirroring CMake's
# `IF (WITH_OPENSSL)` source-list append.
exclude = ["clickhouse/base/sslsocket.cpp"],
) + [
# Vendored CityHash, NOT the BCR `@cityhash` module. ClickHouse's
# wire protocol checksums compressed blocks with a specific frozen
# CityHash128 variant (see clickhouse/base/compressed.cpp)
# See clickhouse/cityhash/city.h for details
"clickhouse/cityhash/city.cc",
"clickhouse/cityhash/city_config.h",
] + select({
":tls_no": [],
"//conditions:default": ["clickhouse/base/sslsocket.cpp"],
}),
hdrs = glob([
"clickhouse/*.h",
"clickhouse/base/*.h",
"clickhouse/columns/*.h",
"clickhouse/types/*.h",
]) + [
"clickhouse/cityhash/city.h",
"clickhouse/cityhash/citycrc.h",
],
# city_config.h gates __builtin_expect off with `#if WIN32 || WIN64`, but
# MSVC only predefines `_WIN32`/`_WIN64` — under CMake it's CMake that
# defines WIN32, which Bazel's MSVC toolchain doesn't. Define it here
# so the GCC/Clang-only builtin isn't used on MSVC.
copts = select({
"@platforms//os:windows": ["/DWIN32"],
"//conditions:default": [],
}),
defines = [
# Abseil fallback is not enabled in the Bazel build. This fallback will be removed in the
# near future. The Bazel build always uses the self-contained fallback for wide (128-bit)
# integers and never depends on Abseil. This mirrors CMake's
# `CH_USE_ABSEIL_FOR_BIGNUM=OFF` option and keeps the build free of any Abseil dependency.
# Users are free to include Abseil in their own projects and convert values produced by this
# library to the corresponding Abseil types.
"CH_USE_ABSEIL_FOR_BIGNUM=0",
] + select({
# `WITH_OPENSSL` enables the TLS code paths in client.cpp /
# sslsocket.cpp (same macro as the CMake option). `USE_BORINGSSL`
# takes the BoringSSL-compatible branches in sslsocket.cpp.
":tls_boringssl": [
"WITH_OPENSSL",
"USE_BORINGSSL",
],
":tls_openssl": ["WITH_OPENSSL"],
":tls_no": [],
}),
# Winsock, required by base/socket.cpp et al. Mirrors CMake's
# `IF (WIN32 OR MINGW)` link block. (The BoringSSL backend already
# propagates ws2_32 itself; declare it explicitly so the openssl
# and no-TLS configurations link too.)
linkopts = select({
"@platforms//os:windows": [
"-DEFAULTLIB:ws2_32.lib",
],
"//conditions:default": [],
}) + select({
# OpenSSL references the Win32 cert store and user32; declare
# them so downstream executables link without each consumer
# having to repeat it. Mirrors CMake's MSVC `Crypt32` link.
":tls_openssl_on_windows": [
"-DEFAULTLIB:crypt32.lib",
"-DEFAULTLIB:user32.lib",
"-DEFAULTLIB:advapi32.lib",
],
"//conditions:default": [],
}),
# Expose the vendored CityHash headers on the include path so the
# `#include <city.h>` form used by compressed.cpp / lowcardinality.cpp /
# types.cpp resolves (mirrors the old :cityhash target's
# `strip_include_prefix = "clickhouse/cityhash"`).
includes = ["clickhouse/cityhash"],
# Expose headers at their workspace path so both internal
# (`#include "client.h"` from clickhouse/*.cpp via quote-form
# source-dir search) and external (`#include <clickhouse/client.h>`)
# include forms resolve.
strip_include_prefix = "/",
visibility = ["//visibility:public"],
deps = [
"@lz4//:lz4",
"@zstd//:zstd",
] + select({
":tls_boringssl": [
"@boringssl//:crypto",
"@boringssl//:ssl",
],
":tls_openssl": [
"@openssl//:crypto",
"@openssl//:ssl",
],
":tls_no": [],
}),
)