-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathBUILD.bazel
More file actions
137 lines (130 loc) · 4.63 KB
/
BUILD.bazel
File metadata and controls
137 lines (130 loc) · 4.63 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
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.
# * cityhash / lz4 / zstd / abseil come from BCR modules instead of
# contrib/; the contrib/ trees are only used by the CMake build.
# 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",
],
)
config_setting(
name = "tls_boringssl",
flag_values = {":tls": "boringssl"},
)
config_setting(
name = "tls_openssl",
flag_values = {":tls": "openssl"},
)
config_setting(
name = "tls_no",
flag_values = {":tls": "no"},
)
# 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"],
) + select({
":tls_no": [],
"//conditions:default": ["clickhouse/base/sslsocket.cpp"],
}),
hdrs = glob([
"clickhouse/*.h",
"clickhouse/base/*.h",
"clickhouse/columns/*.h",
"clickhouse/types/*.h",
]),
defines = 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",
],
"//conditions:default": [],
}),
# 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 = [
"@abseil-cpp//absl/numeric:int128",
"@cityhash//:cityhash",
"@lz4//:lz4",
"@zstd//:zstd",
] + select({
":tls_boringssl": [
"@boringssl//:crypto",
"@boringssl//:ssl",
],
":tls_openssl": [
"@openssl//:crypto",
"@openssl//:ssl",
],
":tls_no": [],
}),
)