Files
cpp/BUILD.bazel
zeekay 286f257aae De-brand the client: clickhouse-cpp -> datastore-cpp
Pure rename applied on top of upstream tag v2.6.2 (8d2415d6), not HEAD.
The fork was cut at 737145d = v2.6.2-57, which still declared version 2.6.2
in version.h; renaming there would have shipped 57 unreleased commits wearing
a 2.6.2 label. Reset to the tag first so this commit changes names only.

  clickhouse/            -> datastore/            (public include root)
  namespace clickhouse   -> namespace datastore
  CLICKHOUSE_CPP_VERSION -> DATASTORE_CPP_VERSION
  clickhouse-cpp-lib/-ut -> datastore-cpp-lib/-ut (CMake, Bazel)
  CH_MAP_BOOL_TO_UINT8   -> DS_MAP_BOOL_TO_UINT8
  CLICKHOUSE_*           -> DATASTORE_*           (test env vars)
  doc links              -> docs.hanzo.ai/datastore

This client speaks the NATIVE binary protocol only - there is no HTTP path
and no X-ClickHouse-* header anywhere in it, so the header rename that the
HTTP clients required does not apply and nothing here was broken.

The one string that reaches the wire is CLIENT_NAME, sent by both SendHello
and SendQuery's ClientInfo from a single macro, and it lands in
system.query_log.client_name. Both sites still read the one macro, so they
stay consistent and the server's Hello/Query consistency check is satisfied.
Old rows keep the old name; that is a reporting discontinuity, not a
migration, since nothing keys on it.

CI is repointed at our own server: ghcr.io/hanzoai/datastore:26.2.3.2, the
image production runs. Its entrypoint honours DATASTORE_SKIP_USER_SETUP, not
the CLICKHOUSE_ spelling the compose file used, and its config lives in
/etc/hanzo-datastore-server. ci/docker-compose/config.xml is now layered in
as a config.d drop-in so the image keeps its own white-labelling. That file
and users.xml deliberately keep a <clickhouse> root: it must match the roots
of the drop-ins the image ships, and a mismatch fails silently - the server
logs "Merging bypassed" and starts with every drop-in discarded.

The remote-TLS suites used to default to the third-party host
play.clickhouse.com. They now read DATASTORE_SECURE*_HOST and skip when it is
unset rather than point at a host we do not run.

Dropped as upstream infrastructure with no meaning here: AI_POLICY.md
(upstream's policy about their codebase), .travis.yml (dead CI referencing a
third-party apt repo), cross-repo-bug-relay.yml (relays our issues into an
upstream triage repo). LICENSE keeps its copyright notice, as Apache-2.0
requires.

Verified: cmake configure + 115-target build clean; the full suite is green
against ghcr.io/hanzoai/datastore:26.2.3.2 (894 passed, 0 failed); the
pristine v2.6.2 build run against that same server passes the identical set,
and both logged the same 3914 queries under their respective client names.
2026-07-26 11:44:39 -07:00

168 lines
5.9 KiB
Python

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 datastore-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
# `--@datastore-cpp-client//:tls=openssl` to use the BCR OpenSSL module
# instead, or `--@datastore-cpp-client//: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 datastore/base/sslsocket.cpp.
# * lz4 / zstd / abseil come from BCR modules instead of contrib/.
# cityhash is the exception: it is built from contrib/ because the
# wire protocol needs Datastore's frozen CityHash variant, which
# differs from the stock BCR module (see the :cityhash target).
# Selects the TLS implementation: `--@datastore-cpp-client//:tls=boringssl`
# (default), `--@datastore-cpp-client//:tls=openssl`, or
# `--@datastore-cpp-client//: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",
],
)
# Vendored CityHash from contrib/, NOT the BCR `@cityhash` module.
# Datastore's wire protocol checksums compressed blocks with a specific
# frozen CityHash128 variant (see datastore/base/compressed.cpp); the
# stock Google CityHash 1.0.2 that BCR packages produces *different*
# hashes, so a server rejects compressed blocks with "Checksum doesn't
# match: corrupted data". This is the exact copy the CMake build uses,
# guaranteeing byte-identical hashing and wire compatibility.
cc_library(
name = "cityhash",
srcs = [
"contrib/cityhash/cityhash/city.cc",
"contrib/cityhash/cityhash/config.h",
],
hdrs = [
"contrib/cityhash/cityhash/city.h",
"contrib/cityhash/cityhash/citycrc.h",
],
# 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": [],
}),
strip_include_prefix = "contrib/cityhash/cityhash",
)
# The main datastore-cpp library. Downstream callers use
# `#include <datastore/client.h>` and link `@datastore-cpp-client//:datastore`.
cc_library(
name = "datastore",
srcs = glob(
[
"datastore/*.cpp",
"datastore/base/*.cpp",
"datastore/columns/*.cpp",
"datastore/types/*.cpp",
],
# Only compiled when TLS is enabled, mirroring CMake's
# `IF (WITH_OPENSSL)` source-list append.
exclude = ["datastore/base/sslsocket.cpp"],
) + select({
":tls_no": [],
"//conditions:default": ["datastore/base/sslsocket.cpp"],
}),
hdrs = glob([
"datastore/*.h",
"datastore/base/*.h",
"datastore/columns/*.h",
"datastore/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 datastore/*.cpp via quote-form
# source-dir search) and external (`#include <datastore/client.h>`)
# include forms resolve.
strip_include_prefix = "/",
visibility = ["//visibility:public"],
deps = [
"@abseil-cpp//absl/numeric:int128",
":cityhash",
"@lz4//:lz4",
"@zstd//:zstd",
] + select({
":tls_boringssl": [
"@boringssl//:crypto",
"@boringssl//:ssl",
],
":tls_openssl": [
"@openssl//:crypto",
"@openssl//:ssl",
],
":tls_no": [],
}),
)