BUILD.jemalloc.bazel 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. load("@rules_foreign_cc//foreign_cc:configure.bzl", "configure_make")
  16. """Builds jemalloc."""
  17. filegroup(
  18. name = "all_srcs",
  19. srcs = glob(
  20. include = ["**"],
  21. exclude = ["*.bazel"],
  22. ),
  23. )
  24. # Copied from `jemalloc-sys`
  25. #
  26. # See https://github.com/tikv/jemallocator/blob/714705e15f6d38424c6645abe2eef877ec828967/jemalloc-sys/build.rs
  27. CONFIGURE_OPTIONS = [
  28. "--enable-doc=no",
  29. "--enable-shared=no",
  30. "--disable-cxx",
  31. "--with-private-namespace=_rjem_",
  32. # Features we enable for jemalloc-sys.
  33. "--enable-prof",
  34. "--enable-stats",
  35. "--with-malloc-conf=background_thread:true",
  36. ]
  37. configure_make(
  38. name = "jemalloc",
  39. # TODO(parkmycar): Dynamically configure the number of jobs make uses.
  40. args = ["-j8"],
  41. # Our llvm_toolchain specifies libtool as the static linker, but it doesn't
  42. # support the arguments generated by jemalloc's configure script, so for
  43. # macOS we use llvm-ar instead.
  44. build_data = select({
  45. "@platforms//os:macos": ["@llvm_toolchain_llvm//:ar"],
  46. "//conditions:default": [],
  47. }),
  48. configure_in_place = True,
  49. # TODO(parkmycar): Do we want to customize page sizes?
  50. configure_options = CONFIGURE_OPTIONS + select({
  51. "@//misc/bazel/platforms:linux_arm": ["--host=aarch64-unknown-linux-gnu"],
  52. "@//misc/bazel/platforms:linux_x86_64": ["--host=x86_64-unknown-linux-gnu"],
  53. "@//misc/bazel/platforms:macos_arm": ["--host=aarch64-apple-darwin"],
  54. "@//misc/bazel/platforms:macos_x86_64": ["--host=x86_64-apple-darwin"],
  55. "//conditions:default": [],
  56. }) + select({
  57. "@platforms//os:macos": ["--with-jemalloc-prefix=_rjem_"],
  58. "//conditions:default": [],
  59. }),
  60. copts = ["-lpthread"],
  61. env = select({
  62. "@platforms//os:macos": {"AR": "$(execpath @llvm_toolchain_llvm//:ar)"},
  63. "//conditions:default": {},
  64. }),
  65. lib_name = "jemalloc",
  66. lib_source = ":all_srcs",
  67. out_static_libs = ["libjemalloc.a"],
  68. targets = [
  69. "build_lib_static",
  70. "install_lib_static",
  71. "install_include",
  72. ],
  73. visibility = ["//visibility:public"],
  74. )