From 6daf4de664b8227710c28c1c8d6893a7dfbd08a2 Mon Sep 17 00:00:00 2001 From: Carbo Date: Fri, 5 Jun 2026 14:26:44 -0700 Subject: [PATCH 1/4] Add Bazel cc_test target for server-independent unit tests --- .github/workflows/bazel.yml | 3 +++ MODULE.bazel | 3 +++ ut/BUILD.bazel | 45 +++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 ut/BUILD.bazel diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml index a9265c6c..2a17ba1d 100644 --- a/.github/workflows/bazel.yml +++ b/.github/workflows/bazel.yml @@ -41,3 +41,6 @@ jobs: - name: Build project run: bazel build //... --@clickhouse_cpp//:tls=${{ matrix.tls }} + + - name: Run unit tests + run: bazel test //ut:unit_tests --@clickhouse_cpp//:tls=${{ matrix.tls }} --test_output=errors diff --git a/MODULE.bazel b/MODULE.bazel index db533874..0af35e0c 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -12,3 +12,6 @@ bazel_dep(name = "lz4", version = "1.10.0.bcr.1") bazel_dep(name = "openssl", version = "3.5.5.bcr.4") bazel_dep(name = "rules_cc", version = "0.2.19") bazel_dep(name = "zstd", version = "1.5.7.bcr.1") + +# Test-only dependencies; not pulled in by consumers of the library. +bazel_dep(name = "googletest", version = "1.17.0.bcr.2", dev_dependency = True) diff --git a/ut/BUILD.bazel b/ut/BUILD.bazel new file mode 100644 index 00000000..0317fb67 --- /dev/null +++ b/ut/BUILD.bazel @@ -0,0 +1,45 @@ +load("@rules_cc//cc:cc_test.bzl", "cc_test") + +# Hermetic subset of the googletest suite in this directory: only the +# tests that do not need a running ClickHouse server. The remaining +# files (client_ut.cpp, roundtrip_tests.cpp, Column_ut.cpp, ...) connect +# to $CLICKHOUSE_HOST and stay CMake-only for now, where CI provides a +# server via docker-compose (see .github/workflows/linux.yml). +# +# socket_ut.cpp is included: it spins up its own LocalTcpServer on +# localhost, which works inside the Bazel test sandbox. +cc_test( + name = "unit_tests", + size = "small", + srcs = [ + # Test cases. + "CreateColumnByType_ut.cpp", + "block_ut.cpp", + "column_array_ut.cpp", + "columns_ut.cpp", + "itemview_ut.cpp", + "socket_ut.cpp", + "stream_ut.cpp", + "type_parser_ut.cpp", + "types_ut.cpp", + "utils_ut.cpp", + # Test entry point and shared support code. + "main.cpp", + "tcp_server.cpp", + "tcp_server.h", + "utils.cpp", + "utils.h", + "utils_comparison.h", + "utils_meta.h", + "value_generators.cpp", + "value_generators.h", + ], + # Some tests include support headers via the angled + # `#include ` form; expose the repo root for those. + copts = ["-I."], + deps = [ + "//:clickhouse", + "@abseil-cpp//absl/numeric:int128", + "@googletest//:gtest", + ], +) From a9c9267291769adae92db64401b2075380b59550 Mon Sep 17 00:00:00 2001 From: Carbo Date: Fri, 5 Jun 2026 14:34:26 -0700 Subject: [PATCH 2/4] Add windows-latest to Bazel CI matrix --- .github/workflows/bazel.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml index 2a17ba1d..398e2990 100644 --- a/.github/workflows/bazel.yml +++ b/.github/workflows/bazel.yml @@ -21,7 +21,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-24.04, macos-latest] + os: [ubuntu-24.04, macos-latest, windows-latest] tls: [boringssl, openssl, 'no'] runs-on: ${{ matrix.os }} From ad9bd5dd2bffb35be2b158b08a44e41a33d0a4e5 Mon Sep 17 00:00:00 2001 From: Carbo Date: Fri, 5 Jun 2026 14:42:37 -0700 Subject: [PATCH 3/4] Link ws2_32 on Windows, mirroring the CMake build --- BUILD.bazel | 10 ++++++++++ MODULE.bazel | 1 + MODULE.bazel.lock | 5 ++++- ut/BUILD.bazel | 6 +++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 44a44807..53cfb2ef 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -81,6 +81,16 @@ cc_library( ":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": [], + }), # Expose headers at their workspace path so both internal # (`#include "client.h"` from clickhouse/*.cpp via quote-form # source-dir search) and external (`#include `) diff --git a/MODULE.bazel b/MODULE.bazel index 0af35e0c..7bef78a8 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -10,6 +10,7 @@ bazel_dep(name = "boringssl", version = "0.20260526.0") bazel_dep(name = "cityhash", version = "1.0.2") bazel_dep(name = "lz4", version = "1.10.0.bcr.1") bazel_dep(name = "openssl", version = "3.5.5.bcr.4") +bazel_dep(name = "platforms", version = "1.1.0") bazel_dep(name = "rules_cc", version = "0.2.19") bazel_dep(name = "zstd", version = "1.5.7.bcr.1") diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 5c2bd055..4fddc55e 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -85,6 +85,8 @@ "https://bcr.bazel.build/modules/nlohmann_json/3.6.1/source.json": "f448c6e8963fdfa7eb831457df83ad63d3d6355018f6574fb017e8169deb43a9", "https://bcr.bazel.build/modules/openssl/3.5.5.bcr.4/MODULE.bazel": "b3f35b53c6c73bd3a7c8efbf9b7e79e92566d189e64d313aede69f608ac6dd77", "https://bcr.bazel.build/modules/openssl/3.5.5.bcr.4/source.json": "662d68be9227e60ef65fed83c6820564bda4af0efe6a40dc62dd9aee288fe9cf", + "https://bcr.bazel.build/modules/package_metadata/0.0.3/MODULE.bazel": "77890552ecea9e284b5424c9de827a58099348763a4359e975c359a83d4faa83", + "https://bcr.bazel.build/modules/package_metadata/0.0.3/source.json": "742075a428ad12a3fa18a69014c2f57f01af910c6d9d18646c990200853e641a", "https://bcr.bazel.build/modules/platforms/0.0.10/MODULE.bazel": "8cb8efaf200bdeb2150d93e162c40f388529a25852b332cec879373771e48ed5", "https://bcr.bazel.build/modules/platforms/0.0.11/MODULE.bazel": "0daefc49732e227caa8bfa834d65dc52e8cc18a2faf80df25e8caea151a9413f", "https://bcr.bazel.build/modules/platforms/0.0.4/MODULE.bazel": "9b328e31ee156f53f3c416a64f8491f7eb731742655a47c9eec4703a71644aee", @@ -94,7 +96,8 @@ "https://bcr.bazel.build/modules/platforms/0.0.8/MODULE.bazel": "9f142c03e348f6d263719f5074b21ef3adf0b139ee4c5133e2aa35664da9eb2d", "https://bcr.bazel.build/modules/platforms/0.0.9/MODULE.bazel": "4a87a60c927b56ddd67db50c89acaa62f4ce2a1d2149ccb63ffd871d5ce29ebc", "https://bcr.bazel.build/modules/platforms/1.0.0/MODULE.bazel": "f05feb42b48f1b3c225e4ccf351f367be0371411a803198ec34a389fb22aa580", - "https://bcr.bazel.build/modules/platforms/1.0.0/source.json": "f4ff1fd412e0246fd38c82328eb209130ead81d62dcd5a9e40910f867f733d96", + "https://bcr.bazel.build/modules/platforms/1.1.0/MODULE.bazel": "1c0c09f5bdcf4b3f924720d2478a3711cb39f4977019ca5988685e5b7e18b3d2", + "https://bcr.bazel.build/modules/platforms/1.1.0/source.json": "fcf351c47596c939140ab0d333dfdd08ed1ea6ce33c2fe70c12493a301cf1344", "https://bcr.bazel.build/modules/protobuf/21.7/MODULE.bazel": "a5a29bb89544f9b97edce05642fac225a808b5b7be74038ea3640fae2f8e66a7", "https://bcr.bazel.build/modules/protobuf/23.1/MODULE.bazel": "88b393b3eb4101d18129e5db51847cd40a5517a53e81216144a8c32dfeeca52a", "https://bcr.bazel.build/modules/protobuf/24.4/MODULE.bazel": "7bc7ce5f2abf36b3b7b7c8218d3acdebb9426aeb35c2257c96445756f970eb12", diff --git a/ut/BUILD.bazel b/ut/BUILD.bazel index 0317fb67..65e6893f 100644 --- a/ut/BUILD.bazel +++ b/ut/BUILD.bazel @@ -36,7 +36,11 @@ cc_test( ], # Some tests include support headers via the angled # `#include ` form; expose the repo root for those. - copts = ["-I."], + # /bigobj mirrors CMake's MSVC handling for this test binary. + copts = ["-I."] + select({ + "@platforms//os:windows": ["/bigobj"], + "//conditions:default": [], + }), deps = [ "//:clickhouse", "@abseil-cpp//absl/numeric:int128", From a10011927f1f5c48b276c16a8c6b9ea604d1a66b Mon Sep 17 00:00:00 2001 From: Carbo Date: Mon, 8 Jun 2026 10:13:08 -0700 Subject: [PATCH 4/4] Add SSL link test and link crypt32/user32 for OpenSSL on Windows --- BUILD.bazel | 21 +++++++++++++++++++++ ut/BUILD.bazel | 7 ++++++- ut/ssl_link_ut.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 ut/ssl_link_ut.cpp diff --git a/BUILD.bazel b/BUILD.bazel index 53cfb2ef..4fcf37a5 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,3 +1,4 @@ +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") @@ -46,6 +47,17 @@ config_setting( 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 ` and link `@clickhouse_cpp//:clickhouse`. cc_library( @@ -90,6 +102,15 @@ cc_library( "-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 diff --git a/ut/BUILD.bazel b/ut/BUILD.bazel index 65e6893f..72b0b8e5 100644 --- a/ut/BUILD.bazel +++ b/ut/BUILD.bazel @@ -33,7 +33,12 @@ cc_test( "utils_meta.h", "value_generators.cpp", "value_generators.h", - ], + ] + select({ + # Link guard for the TLS code path; sslsocket.cpp (and the + # system libs it needs) only exist when TLS is enabled. + "//:tls_no": [], + "//conditions:default": ["ssl_link_ut.cpp"], + }), # Some tests include support headers via the angled # `#include ` form; expose the repo root for those. # /bigobj mirrors CMake's MSVC handling for this test binary. diff --git a/ut/ssl_link_ut.cpp b/ut/ssl_link_ut.cpp new file mode 100644 index 00000000..0797c20d --- /dev/null +++ b/ut/ssl_link_ut.cpp @@ -0,0 +1,26 @@ +#include + +#include + +// Link/compile guard for the TLS code path. +// +// A library-only `bazel build //:clickhouse` produces a static archive +// and never runs the linker, so missing system libraries (on Windows, +// the Win32 cert store `crypt32` and `user32` that OpenSSL needs) stay +// invisible until a *consumer* links an executable that actually pulls +// in sslsocket.obj. The hermetic unit_tests subset doesn't touch SSL, +// so it didn't surface them either. +// +// Constructing an SSLContext drags sslsocket.obj — and transitively the +// SSL_CTX_*/X509_* symbols and their system-lib dependencies — into the +// test binary's link step. Default-constructed params do no CA loading +// and open no socket, so this runs in the hermetic sandbox while still +// exercising the link that previously only broke for downstream users. +// +// Only compiled when TLS is enabled (excluded for tls=no, where +// sslsocket.cpp isn't part of the library); see ut/BUILD.bazel. +TEST(SSLLink, ConstructContext) { + clickhouse::SSLParams params{}; + clickhouse::SSLContext context(params); + SUCCEED(); +}