Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Dockerfile — Option A with DTO-provided cachelib.patch applied to CacheLib
FROM ubuntu:24.04
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

ARG DEBIAN_FRONTEND=noninteractive
ARG DTO_REPO=https://github.com/intel/DTO.git
ARG DTO_BRANCH=cachelib
# If your patch path inside DTO is different, override at build:
# --build-arg DTO_PATCH_PATH=patches/cachelib.patch
ARG DTO_PATCH_PATH=
# Accept patch via CLI
ARG GETDEPS_PATCH_B64=""
ARG GETDEPS_PATCH_URL=""
ARG JOBS=16

RUN apt-get update && apt-get install -y software-properties-common \
&& add-apt-repository -y universe && apt-get update
RUN apt-get install -y libboost-all-dev

# 1) Base toolchain + libs
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates curl git python3 build-essential cmake ninja-build pkg-config \
autoconf automake libtool patch \
accel-config uuid-dev linux-libc-dev libaccel-config-dev \
sudo python3-pip \
libssl-dev zlib1g-dev libunwind-dev libevent-dev libnuma-dev libaio-dev \
vim less libbz2-dev

# Make sure /usr/local is searched for headers/libs and pkg-config
ENV LD_LIBRARY_PATH=/usr/local/lib
ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
ENV CMAKE_PREFIX_PATH=/usr/local

# 2) Bring in your CacheLib sources
WORKDIR /src/CacheLib
COPY . .

# 3) Clone DTO (cachelib branch), locate the patch, apply to CacheLib
WORKDIR /opt/dto
RUN git clone --depth=1 --branch "${DTO_BRANCH}" "${DTO_REPO}" . && \
set -eux; \
# Determine patch file path:
if [ -n "${DTO_PATCH_PATH}" ] && [ -f "${DTO_PATCH_PATH}" ]; then \
PATCH_FILE="${DTO_PATCH_PATH}"; \
else \
# Try common locations, otherwise auto-discover the first match
if [ -f /opt/dto/cachelib.patch ]; then PATCH_FILE=/opt/dto/cachelib.patch; \
elif [ -f /opt/dto/patches/cachelib.patch ]; then PATCH_FILE=/opt/dto/patches/cachelib.patch; \
else PATCH_FILE="$(find /opt/dto -maxdepth 4 -type f -iname '*cachelib*.patch' -print -quit)"; fi; \
fi; \
test -n "${PATCH_FILE}" && test -f "${PATCH_FILE}" || { echo 'cachelib patch not found in DTO repo'; exit 1; }; \
echo "Using DTO patch: ${PATCH_FILE}"; \
# Apply patch to CacheLib tree
git -C /src/CacheLib apply "${PATCH_FILE}" || (cd /src/CacheLib && patch -p1 < "${PATCH_FILE}")

# 4) Install system deps via getdeps (after patch is applied)

# Apply getdeps patch if provided
WORKDIR /src/CacheLib
RUN set -euo pipefail \
&& if [[ -n "${GETDEPS_PATCH_B64:-}" ]]; then \
echo "${GETDEPS_PATCH_B64}" | base64 -d > /tmp/getdeps.patch; \
elif [[ -n "${GETDEPS_PATCH_URL:-}" ]]; then \
apt-get update && apt-get install -y --no-install-recommends ca-certificates curl; \
curl -fsSL "${GETDEPS_PATCH_URL}" -o /tmp/getdeps.patch; \
fi \
&& if [[ -s /tmp/getdeps.patch ]]; then \
echo "Checking getdeps patch applicability..."; \
if patch -p1 -N --dry-run < /tmp/getdeps.patch >/dev/null 2>&1; then \
echo "Applying getdeps patch"; \
patch -p1 -N < /tmp/getdeps.patch; \
else \
echo "Skipping getdeps patch (already applied or not applicable)"; \
fi; \
else \
echo "No getdeps patch provided; skipping."; \
fi

WORKDIR /src/CacheLib
RUN python3 build/fbcode_builder/getdeps.py \
--allow-system-packages install-system-deps --recursive cachelib

# 5) Build & install DTO (so CacheLib can link against it)
WORKDIR /opt/dto
RUN cmake -S . -B build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_INSTALL_PREFIX=/usr/local && \
cmake --build build -j"${JOBS}" && \
cmake --install build && \
ldconfig

# 6) Build CacheLib (no tests), then fix up runtime deps into /usr/local
WORKDIR /src/CacheLib
RUN python3 build/fbcode_builder/getdeps.py \
--allow-system-packages build --src-dir=. cachelib --project-install-prefix cachelib:/usr/local

RUN python3 build/fbcode_builder/getdeps.py \
--allow-system-packages fixup-dyn-deps --strip --src-dir=. \
cachelib /opt/cachelib-runtime \
--project-install-prefix cachelib:/usr/local \
--final-install-prefix /opt/cachelib-runtime

RUN if [ -d /opt/cachelib-runtime/usr/local ]; then \
mv /opt/cachelib-runtime/usr/local/* /opt/cachelib-runtime/; \
rmdir /opt/cachelib-runtime/usr/local || true; \
fi

#RUN mkdir -p /opt/artifacts && \
# python3 build/fbcode_builder/getdeps.py \
# --allow-system-packages fixup-dyn-deps --strip --src-dir=. cachelib /opt/artifacts \
# --project-install-prefix cachelib:/usr/local --final-install-prefix /usr/local && \
# cp -a /opt/artifacts/usr/local/. /usr/local/ && \
# ldconfig

# 7) Prove it runs (no tests). Override CMD with any cachebench args you want.
#ENTRYPOINT ["/usr/local/bin/cachebench"]
#CMD ["--help"]

2 changes: 1 addition & 1 deletion build/fbcode_builder/getdeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def run_project_cmd(self, args, loader, manifest):
]
+ packages
)
cmd_argss.append(["pip", "install", "pex"])
cmd_argss.append(["pip", "install","--break-system-packages", "pex"])
elif manager == "homebrew":
packages = sorted(set(all_packages["homebrew"]))
if packages:
Expand Down
1 change: 1 addition & 0 deletions build/fbcode_builder/manifests/cachelib
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ zstd
mvfst
numa
libaio
proxygen
# cachelib also depends on openssl but since the latter requires a platform-
# specific configuration we rely on the folly manifest to provide this
# dependency to avoid duplication.
Expand Down
5 changes: 4 additions & 1 deletion build/fbcode_builder/manifests/libiberty
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ name = libiberty
binutils-devel
binutils

[debs]
[debs.not(all(distro=ubuntu,distro_vers="24.04"))]
binutils-dev

[debs.all(distro=ubuntu,distro_vers="24.04")]
binutils-x86-64-linux-gnu

[download]
url = https://ftp.gnu.org/gnu/binutils/binutils-2.43.tar.xz
sha256 = b53606f443ac8f01d1d5fc9c39497f2af322d99e14cea5c0b4b124d630379365
Expand Down
1 change: 1 addition & 0 deletions build_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sudo -E docker build --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy -t cachelib:dto .
54 changes: 54 additions & 0 deletions examples/proxygen_cache/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# 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 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.

cmake_minimum_required (VERSION 3.12)

project(proxygen_cache VERSION 0.1)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")

find_package(cachelib CONFIG REQUIRED)


find_package(proxygen CONFIG REQUIRED)
find_package(GTest CONFIG REQUIRED) # GTest::gtest, GTest::gmock
find_package(NUMA REQUIRED) # NUMA::NUMA
find_package(glog REQUIRED) # Glog::glog

add_executable(proxygen_cache main.cpp)

if (TARGET cachelib)
get_target_property(_cachelib_inc cachelib INTERFACE_INCLUDE_DIRECTORIES)
# If it ends in /include/cachelib, step up one level
foreach(dir IN LISTS _cachelib_inc)
if(dir MATCHES ".*/include/cachelib$")
get_filename_component(PARENT_DIR "${dir}" DIRECTORY)
target_include_directories(proxygen_cache PRIVATE "${PARENT_DIR}")
else()
target_include_directories(proxygen_cache PRIVATE "${dir}")
endif()
endforeach()
endif()

target_link_libraries(proxygen_cache PUBLIC
cachelib
GTest::gmock
glog::glog
NUMA::NUMA
proxygen::proxygen
proxygen::proxygenhttpserver
)

get_target_property(_inc cachelib INTERFACE_INCLUDE_DIRECTORIES)
message(STATUS "cachelib include dirs: ${_inc}")
36 changes: 36 additions & 0 deletions examples/proxygen_cache/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# 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 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.

set -e

CLBASE="/tmp/fbcode_builder_getdeps-ZsrcZCacheLibZbuildZfbcode_builder-root/installed"

# Additional "FindXXX.cmake" files are here (e.g. FindSodium.cmake)
#CLCMAKE="$CLBASE/cachelib/cmake"

# After ensuring we are in the correct directory, set the installation prefix"
PREFIX="$CLBASE/cachelib/usr/local"
PREFIXB="$CLBASE/"
CMAKE_PREFIX_PATH="$PREFIX/lib/cmake:$PREFIX/lib64/cmake:$PREFIX/lib:$PREFIX/lib64:$PREFIX:$PREFIXB:${CMAKE_PREFIX_PATH:-}"
export CMAKE_PREFIX_PATH
PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig:$PREFIX/lib64/pkgconfig:${PKG_CONFIG_PATH:-}"
export PKG_CONFIG_PATH
LD_LIBRARY_PATH="$PREFIX/lib:$PREFIX/lib64:${LD_LIBRARY_PATH:-}"
export LD_LIBRARY_PATH

mkdir -p build
cd build
cmake $CMAKE_PARAMS ..
make
50 changes: 50 additions & 0 deletions examples/proxygen_cache/cmake/FindNUMA.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# 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 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.

# - Find NUMA
# Find the NUMA library and includes
#
# NUMA_INCLUDE_DIRS - where to find numa.h, etc.
# NUMA_LIBRARIES - List of libraries when using NUMA.
# NUMA_FOUND - True if NUMA found.

message(STATUS "looking numa in dir: : ${NUMA_INCLUDE_DIRS}")
message(STATUS "root: : ${NUMA_ROOT_DIR}")

find_path(NUMA_INCLUDE_DIRS
NAMES numa.h numaif.h
HINTS ${NUMA_ROOT_DIR}/include)

message(STATUS "root: : ${NUMA_ROOT_DIR}")

message(STATUS "looking numa in dir again : ${NUMA_INCLUDE_DIRS}")

find_library(NUMA_LIBRARIES
NAMES numa
HINTS ${NUMA_ROOT_DIR}/lib)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NUMA DEFAULT_MSG NUMA_LIBRARIES NUMA_INCLUDE_DIRS)

mark_as_advanced(
NUMA_LIBRARIES
NUMA_INCLUDE_DIRS)

if(NUMA_FOUND AND NOT (TARGET NUMA::NUMA))
add_library (NUMA::NUMA UNKNOWN IMPORTED)
set_target_properties(NUMA::NUMA
PROPERTIES
IMPORTED_LOCATION ${NUMA_LIBRARIES}
INTERFACE_INCLUDE_DIRECTORIES ${NUMA_INCLUDE_DIRS})
endif()
Loading
Loading