# 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. load("@rules_foreign_cc//foreign_cc:configure.bzl", "configure_make") """Builds jemalloc.""" filegroup( name = "all_srcs", srcs = glob( include = ["**"], exclude = ["*.bazel"], ), ) # Copied from `jemalloc-sys` # # See https://github.com/tikv/jemallocator/blob/714705e15f6d38424c6645abe2eef877ec828967/jemalloc-sys/build.rs CONFIGURE_OPTIONS = [ "--enable-doc=no", "--enable-shared=no", "--disable-cxx", "--with-private-namespace=_rjem_", # Features we enable for jemalloc-sys. "--enable-prof", "--enable-stats", "--with-malloc-conf=background_thread:true", ] configure_make( name = "jemalloc", # TODO(parkmycar): Dynamically configure the number of jobs make uses. args = ["-j8"], # Our llvm_toolchain specifies libtool as the static linker, but it doesn't # support the arguments generated by jemalloc's configure script, so for # macOS we use llvm-ar instead. build_data = select({ "@platforms//os:macos": ["@llvm_toolchain_llvm//:ar"], "//conditions:default": [], }), configure_in_place = True, # TODO(parkmycar): Do we want to customize page sizes? configure_options = CONFIGURE_OPTIONS + select({ "@//misc/bazel/platforms:linux_arm": ["--host=aarch64-unknown-linux-gnu"], "@//misc/bazel/platforms:linux_x86_64": ["--host=x86_64-unknown-linux-gnu"], "@//misc/bazel/platforms:macos_arm": ["--host=aarch64-apple-darwin"], "@//misc/bazel/platforms:macos_x86_64": ["--host=x86_64-apple-darwin"], "//conditions:default": [], }) + select({ "@platforms//os:macos": ["--with-jemalloc-prefix=_rjem_"], "//conditions:default": [], }), copts = ["-lpthread"], env = select({ "@platforms//os:macos": {"AR": "$(execpath @llvm_toolchain_llvm//:ar)"}, "//conditions:default": {}, }), lib_name = "jemalloc", lib_source = ":all_srcs", out_static_libs = ["libjemalloc.a"], targets = [ "build_lib_static", "install_lib_static", "install_include", ], visibility = ["//visibility:public"], )