BUILD.librdkafka.bazel 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License in the LICENSE file at the
  6. # root of this repository, or online at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. """Additive BUILD file for the librdkafka-sys Rust crate."""
  16. load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
  17. filegroup(
  18. name = "all_srcs",
  19. srcs = glob(["librdkafka/**"]),
  20. )
  21. cmake(
  22. name = "librdkafka",
  23. build_args = ["-j8"],
  24. build_data = ["@openssl//:openssl_root"],
  25. env = {
  26. # Note: casing here is important.
  27. "OpenSSL_ROOT": "$(execpath @openssl//:openssl_root)",
  28. },
  29. copts = ["-UNDEBUG"],
  30. generate_args = [
  31. # Features enabled by the Rust `rdkafka-sys` crate.
  32. "-DRDKAFKA_BUILD_STATIC=1",
  33. "-DRDKAFKA_BUILD_TESTS=0",
  34. "-DRDKAFKA_BUILD_EXAMPLES=0",
  35. "-DCMAKE_INSTALL_LIBDIR=lib",
  36. "-DWITH_ZLIB=1",
  37. "-DWITH_ZSTD=1",
  38. "-DWITH_SSL=1",
  39. "-DWITH_SASL_SCRAM=1",
  40. "-DWITH_SASL_OAUTHBEARER=1",
  41. # Additional features of librdkafka that we disable.
  42. "-DWITH_CURL=0",
  43. "-DWITH_SASL=0",
  44. "-DENABLE_LZ4_EXT=0",
  45. # `cmake` tries _very_ hard to find libraries to link against, and it
  46. # generally prefers dynamic libraries in the sysroot, which is exactly
  47. # what we don't want because it breaks hermeticity.
  48. #
  49. # We set a number of options here to limit what `cmake` will search for
  50. # so we link against our static libraries.
  51. "-DCMAKE_POLICY_DEFAULT_CMP0074=NEW",
  52. "-DCMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH=0",
  53. "-DCMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH=0",
  54. "-DCMAKE_FIND_USE_CMAKE_SYSTEM_PATH=0",
  55. # When builing with `CMAKE_BUILD_TYPE=Release`, cmake automatically
  56. # sets `-DNDEBUG` flags. This breaks librdkafka, which uses asserts for
  57. # runtime error checking (confluentinc/librdkafka#5099). We unset
  58. # `NDEBUG` by manually overwriting the cmake's `C_FLAGS` variables.
  59. "-DCMAKE_C_FLAGS_RELEASE=-O3",
  60. "-DCMAKE_CXX_FLAGS_RELEASE=-O3",
  61. # Uncomment this if you ever need to debug what library cmake is resolving.
  62. # "-DCMAKE_FIND_DEBUG_MODE=TRUE",
  63. ] + select({
  64. "@platforms//os:macos": ["-DCMAKE_OSX_DEPLOYMENT_TARGET=14.0"],
  65. "//conditions:default": [],
  66. }),
  67. lib_source = ":all_srcs",
  68. out_static_libs = ["librdkafka.a"],
  69. deps = [
  70. "@openssl",
  71. "@zlib",
  72. "@zstd",
  73. ],
  74. )