Skip to content

Commit

Permalink
Build jemalloc with bazel
Browse files Browse the repository at this point in the history
We can provide this bazel-built library to the tikv-jemallocator build script,
so that we don't need to depend on a Cargo build script to build a dependency.

Fixed: 335517665
Change-Id: I920a6bcf75cf80c53a121927e7de60179d350b34
  • Loading branch information
jblebrun committed May 17, 2024
1 parent 609a78d commit 93bc167
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
25 changes: 22 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ android_sdk_repository(

http_archive(
name = "rules_foreign_cc",
sha256 = "2a4d07cd64b0719b39a7c12218a3e507672b82a97b98c6a89d38565894cf7c51",
strip_prefix = "rules_foreign_cc-0.9.0",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/refs/tags/0.9.0.tar.gz",
sha256 = "5816f4198184a1e0e682d7e6b817331219929401e2f18358fac7f7b172737976",
strip_prefix = "rules_foreign_cc-0.10.0",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/refs/tags/0.10.0.tar.gz",
)

load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
Expand Down Expand Up @@ -351,6 +351,25 @@ crate_universe_dependencies(bootstrap = True)

load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_repository")

# Build jemalloc with bazel, so that we can provide it to the tikv-jemallocator build script.
git_repository(
name = "jemalloc",
build_file = "//bazel:jemalloc.BUILD",
# jemalloc pointer for tikv-jemalloc-sys submodule pointer at 0.5.3
commit = "e13ca993e8ccb9ba9847cc330696e02839f328f7",

# Fix an issue when building jemalloc with gcc 10.3 (which is the version we
# currently use due to the aspect_gcc target)
# There's a target in the Makefile that uses the -MM flag, and
# when it does that, it doesn't include the $(CFLAGS).
# This results in __GNUC_PREREQ not being defined, which causes compiler
# failures.
# As a workaround, we patch that line in the Makefile.in to include the CFLAGS.
# TODO: b/341166977 Remove this when we can.
patch_cmds = ["sed -i '481s/-MM/$(CFLAGS) -MM/' Makefile.in"],
remote = "https://github.com/tikv/jemalloc",
)

# Default crate repository - some crates may require std.
crates_repository(
name = "oak_crates_index",
Expand Down
34 changes: 34 additions & 0 deletions bazel/jemalloc.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make")

filegroup(
name = "all_srcs",
srcs = glob(["**"]),
)

# Check here for options used when jemalloc-sys builds it
# https://github.com/tikv/jemallocator/blob/8b886be1677d1693834b158e76780a793eb3b8db/jemalloc-sys/build.rs
configure_make(
name = "jemalloc",
autogen = True,
configure_in_place = True,
configure_options = [
"--disable-cxx",
"--enable-doc=no",
"--enable-shared=no",
"--with-jemalloc-prefix=_rjem_",
"--with-private-namespace=_rjem_",
],
lib_name = "libjemalloc",
lib_source = ":all_srcs",
targets = [
"install_lib_static",
],
visibility = ["//visibility:public"],
)

filegroup(
name = "gen_dir",
srcs = [":jemalloc"],
output_group = "gen_dir",
visibility = ["//visibility:public"],
)
3 changes: 3 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@
export GRADLE_OPTS="-Dorg.gradle.project.android.aapt2FromMavenOverride=${androidSdk}/libexec/android-sdk/build-tools/28.0.3/aapt2";
'';
packages = [
autoconf
autogen
automake
jdk11_headless
bazel
androidSdk
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ clang-tidy:
bare_metal_crates := "//oak_linux_boot_params //oak_channel //oak_core //oak_virtio //third_party/rust-hypervisor-firmware-virtio"

bazel-ci:
bazel build --config=unsafe-fast-presubmit -- //...:all
bazel build --config=unsafe-fast-presubmit -- @jemalloc //...:all
bazel test --config=unsafe-fast-presubmit -- //...:all

# Some crates also need to be built for x86_64-unknown-none.
Expand Down

0 comments on commit 93bc167

Please sign in to comment.