# Copyright Materialize, Inc. and contributors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License in the LICENSE file at the # root of this repository, or online at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Additive BUILD file for the librdkafka-sys Rust crate.""" load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") filegroup( name = "all_srcs", srcs = glob(["librdkafka/**"]), ) cmake( name = "librdkafka", build_args = ["-j8"], build_data = ["@openssl//:openssl_root"], env = { # Note: casing here is important. "OpenSSL_ROOT": "$(execpath @openssl//:openssl_root)", }, copts = ["-UNDEBUG"], generate_args = [ # Features enabled by the Rust `rdkafka-sys` crate. "-DRDKAFKA_BUILD_STATIC=1", "-DRDKAFKA_BUILD_TESTS=0", "-DRDKAFKA_BUILD_EXAMPLES=0", "-DCMAKE_INSTALL_LIBDIR=lib", "-DWITH_ZLIB=1", "-DWITH_ZSTD=1", "-DWITH_SSL=1", "-DWITH_SASL_SCRAM=1", "-DWITH_SASL_OAUTHBEARER=1", # Additional features of librdkafka that we disable. "-DWITH_CURL=0", "-DWITH_SASL=0", "-DENABLE_LZ4_EXT=0", # `cmake` tries _very_ hard to find libraries to link against, and it # generally prefers dynamic libraries in the sysroot, which is exactly # what we don't want because it breaks hermeticity. # # We set a number of options here to limit what `cmake` will search for # so we link against our static libraries. "-DCMAKE_POLICY_DEFAULT_CMP0074=NEW", "-DCMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH=0", "-DCMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH=0", "-DCMAKE_FIND_USE_CMAKE_SYSTEM_PATH=0", # When builing with `CMAKE_BUILD_TYPE=Release`, cmake automatically # sets `-DNDEBUG` flags. This breaks librdkafka, which uses asserts for # runtime error checking (confluentinc/librdkafka#5099). We unset # `NDEBUG` by manually overwriting the cmake's `C_FLAGS` variables. "-DCMAKE_C_FLAGS_RELEASE=-O3", "-DCMAKE_CXX_FLAGS_RELEASE=-O3", # Uncomment this if you ever need to debug what library cmake is resolving. # "-DCMAKE_FIND_DEBUG_MODE=TRUE", ] + select({ "@platforms//os:macos": ["-DCMAKE_OSX_DEPLOYMENT_TARGET=14.0"], "//conditions:default": [], }), lib_source = ":all_srcs", out_static_libs = ["librdkafka.a"], deps = [ "@openssl", "@zlib", "@zstd", ], )