diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6a623981..7961e2aa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,14 +41,11 @@ jobs: steps: - uses: actions/checkout@v6 - with: - submodules: recursive # actions/checkout writes its own safe.directory, but later steps # invoke git from a fresh shell (`sh -e {0}`) where that scoped # config is not always picked up. Set it once globally so every - # `git ...` call in this job — checkout's submodule walk, the - # bootstrap-key step, etc. — sees the workspace as safe. + # `git ...` call in this job sees the workspace as safe. - name: Mark workspace as safe for git run: git config --global --add safe.directory "$GITHUB_WORKSPACE" @@ -68,37 +65,6 @@ jobs: ccache --max-size=400M ccache --zero-stats - # Cache key invalidates when any submodule SHA or bootstrap script changes. - - name: Compute bootstrap cache key - id: bootstrap-key - run: | - git submodule status > .submodule-state - echo "hash=$(sha256sum .submodule-state build_tools/bootstrap*.sh | sha256sum | cut -c1-16)" >> "$GITHUB_OUTPUT" - - - name: Restore third_party build cache - id: tp-cache - uses: actions/cache@v4 - with: - path: | - third_party/masstree/lib*.a - third_party/masstree/config.h - third_party/masstree/config.status - third_party/mimalloc/out - third_party/googletest/build - key: tp-${{ runner.os }}-${{ steps.bootstrap-key.outputs.hash }} - - - name: Build third-party (masstree) - if: steps.tp-cache.outputs.cache-hit != 'true' - run: ./build_tools/bootstrap.sh - - - name: Build third-party (mimalloc) - if: steps.tp-cache.outputs.cache-hit != 'true' - run: ./build_tools/bootstrap_mimalloc.sh - - - name: Build third-party (googletest) - if: steps.tp-cache.outputs.cache-hit != 'true' - run: ./build_tools/bootstrap_googletest.sh - - name: Configure (top-level cmake) # Sanitizer adds significant link-time memory/cpu cost and CI does # not run binaries, so it adds no value here. Use Release for the diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index b7505bba..00000000 --- a/.gitmodules +++ /dev/null @@ -1,9 +0,0 @@ -[submodule "third_party/masstree"] - path = third_party/masstree - url = https://github.com/thawk105/masstree-beta.git -[submodule "third_party/googletest"] - path = third_party/googletest - url = https://github.com/google/googletest.git -[submodule "third_party/mimalloc"] - path = third_party/mimalloc - url = https://github.com/microsoft/mimalloc.git diff --git a/CMakeLists.txt b/CMakeLists.txt index b15f5d43..41dc9cc0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,8 +8,6 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") # protocol binary via ccbench_add_protocol() (see cmake/CompileOptions.cmake). include(CompileOptions) -set(THIRD_PARTY_DIR "${PROJECT_SOURCE_DIR}/third_party/") - option(ENABLE_SANITIZER "enable sanitizer on debug build" ON) option(ENABLE_UB_SANITIZER "enable undefined behavior sanitizer on debug build" OFF) option(ENABLE_COVERAGE "enable coverage on debug build" OFF) @@ -32,17 +30,12 @@ find_package(glog REQUIRED) find_package(Boost COMPONENTS filesystem) # --------------------------------------------------------------------------- -# Imported targets for the bootstrap-built third-party static libraries. -# Replaces the raw ${THIRD_PARTY_DIR}/.../*.a paths previously copy-pasted -# into every protocol's target_link_libraries(...). +# Third-party dependencies (masstree / mimalloc / googletest) are pulled in +# via FetchContent — see cmake/ThirdParty.cmake. Exposes ccbench::masstree +# / ccbench::mimalloc / GTest::gtest{,_main}, which replace the static +# IMPORTED targets and raw third_party/*.a paths used previously. # --------------------------------------------------------------------------- -add_library(ccbench::masstree STATIC IMPORTED GLOBAL) -set_target_properties(ccbench::masstree PROPERTIES - IMPORTED_LOCATION "${THIRD_PARTY_DIR}/masstree/libkohler_masstree_json.a") - -add_library(ccbench::mimalloc STATIC IMPORTED GLOBAL) -set_target_properties(ccbench::mimalloc PROPERTIES - IMPORTED_LOCATION "${THIRD_PARTY_DIR}/mimalloc/out/release/libmimalloc.a") +include(ThirdParty) # --------------------------------------------------------------------------- # common/ as a real shared static library — replaces the per-binary diff --git a/build_tools/bootstrap.sh b/build_tools/bootstrap.sh deleted file mode 100755 index a954f223..00000000 --- a/build_tools/bootstrap.sh +++ /dev/null @@ -1,9 +0,0 @@ -# prepare for masstree -cd third_party/masstree -./bootstrap.sh -./configure --disable-assertions -make clean -make -j CXXFLAGS='-g -W -Wall -O3 -fPIC' -ar cr libkohler_masstree_json.a json.o string.o straccum.o str.o msgpack.o clp.o kvrandom.o compiler.o memdebug.o kvthread.o misc.o -ranlib libkohler_masstree_json.a - diff --git a/build_tools/bootstrap_googletest.sh b/build_tools/bootstrap_googletest.sh deleted file mode 100755 index 6156930f..00000000 --- a/build_tools/bootstrap_googletest.sh +++ /dev/null @@ -1,5 +0,0 @@ -cd third_party/googletest -mkdir -p build -cd build -cmake .. -make -j diff --git a/build_tools/bootstrap_mimalloc.sh b/build_tools/bootstrap_mimalloc.sh deleted file mode 100755 index ca856408..00000000 --- a/build_tools/bootstrap_mimalloc.sh +++ /dev/null @@ -1,24 +0,0 @@ -# prepare for mimalloc -cd third_party/mimalloc -mkdir -p out/release -cd out/release -cmake -DCMAKE_BUILD_TYPE=Release ../.. -make clean all -j - -cd ../ -mkdir debug -cd debug -cmake -DCMAKE_BUILD_TYPE=Debug ../.. -make clean all -j - -cd ../ -mkdir secure -cd secure -cmake -DMI_SECURE=ON ../.. -make clean all -j - -# prepare for tbb -cd ../../../tbb -make clean all -j - -cd ../../ diff --git a/cc/ss2pl/test/CMakeLists.txt b/cc/ss2pl/test/CMakeLists.txt index 12bbff80..176ebde3 100644 --- a/cc/ss2pl/test/CMakeLists.txt +++ b/cc/ss2pl/test/CMakeLists.txt @@ -28,19 +28,18 @@ foreach(src IN LISTS TEST_SOURCES) KEY_SORT=${CCBENCH_KEY_SORT} ) - target_include_directories(${test_name} - PRIVATE ${PROJECT_SOURCE_DIR}/../third_party/googletest/googletest/include - ) - + # All three deps now come from FetchContent (cmake/ThirdParty.cmake) — + # GTest::gtest{,_main} carry their own INTERFACE_INCLUDE_DIRECTORIES so + # we no longer need the manual include path override. target_link_libraries(${test_name} Boost::filesystem gflags::gflags glog::glog - ${PROJECT_SOURCE_DIR}/../third_party/mimalloc/out/release/libmimalloc.a - ${PROJECT_SOURCE_DIR}/../third_party/masstree/libkohler_masstree_json.a + ccbench::mimalloc + ccbench::masstree Threads::Threads - ${PROJECT_SOURCE_DIR}/../third_party/googletest/build/lib/libgtest.a - ${PROJECT_SOURCE_DIR}/../third_party/googletest/build/lib/libgtest_main.a + GTest::gtest + GTest::gtest_main ) set_compile_options(${test_name}) add_test( diff --git a/cmake/ThirdParty.cmake b/cmake/ThirdParty.cmake new file mode 100644 index 00000000..06c449d1 --- /dev/null +++ b/cmake/ThirdParty.cmake @@ -0,0 +1,136 @@ +# cmake/ThirdParty.cmake +# +# Centralised FetchContent declarations for ccbench's third-party +# dependencies. Replaces tracked submodules under third_party/ + +# the per-library build_tools/bootstrap_*.sh scripts. +# +# Targets exposed to the rest of the build: +# ccbench::masstree — static archive built from upstream sources +# (libkohler_masstree_json.a; same 11 objects the +# old build_tools/bootstrap.sh produced) +# ccbench::mimalloc — alias for the upstream mimalloc-static target +# GTest::gtest / +# GTest::gtest_main — provided directly by upstream googletest +# +# All revisions are pinned to commit SHAs / tags so the build is +# reproducible and FetchContent never silently follows a moving branch. + +include(FetchContent) +include(ExternalProject) + +# --- masstree -------------------------------------------------------------- +# +# Upstream masstree-beta is not a CMake project (autotools + hand-rolled +# Makefile). We mirror the old build_tools/bootstrap.sh exactly: +# ./bootstrap.sh && ./configure --disable-assertions +# make CXXFLAGS='-g -W -Wall -O3 -fPIC' +# ar cr libkohler_masstree_json.a <11 objects> && ranlib … +# done at configure time via ExternalProject_Add, then exposed as a +# STATIC IMPORTED target so the rest of the CMake graph treats it the +# same way as before. +# +# The fork URL + commit SHA come from the previous .gitmodules / +# `git submodule status` (see issue #97). + +set(CCBENCH_MASSTREE_REPO "https://github.com/thawk105/masstree-beta.git") +set(CCBENCH_MASSTREE_TAG "b3c5d054b66b08374d7a6ff5a0faeaf28b041a38") +set(CCBENCH_MIMALLOC_REPO "https://github.com/microsoft/mimalloc.git") +set(CCBENCH_MIMALLOC_TAG "v2.3.2") # commit 02a2f5d, matches old submodule +set(CCBENCH_GOOGLETEST_REPO "https://github.com/google/googletest.git") +set(CCBENCH_GOOGLETEST_TAG "f8d7d77c06936315286eb55f8de22cd23c188571") + +FetchContent_Declare( + masstree + GIT_REPOSITORY "${CCBENCH_MASSTREE_REPO}" + GIT_TAG "${CCBENCH_MASSTREE_TAG}" + GIT_SHALLOW FALSE # SHA pin needs the full object, not a tag-only fetch +) + +# Populate() leaves us with masstree_SOURCE_DIR / masstree_BINARY_DIR but +# does NOT add it to the build graph (the upstream tree has no +# CMakeLists.txt). We then drive its autotools build out-of-tree. +FetchContent_GetProperties(masstree) +if(NOT masstree_POPULATED) + FetchContent_Populate(masstree) +endif() + +set(_masstree_archive "${masstree_SOURCE_DIR}/libkohler_masstree_json.a") +set(_masstree_config_h "${masstree_SOURCE_DIR}/config.h") + +# Mirror the historical bootstrap.sh object set verbatim — these are the +# exact 11 translation units the old script packed into the archive. +set(_masstree_objs + json.o string.o straccum.o str.o msgpack.o clp.o + kvrandom.o compiler.o memdebug.o kvthread.o misc.o) + +add_custom_command( + OUTPUT "${_masstree_archive}" "${_masstree_config_h}" + COMMAND ${CMAKE_COMMAND} -E echo "Building masstree (libkohler_masstree_json.a)" + COMMAND ./bootstrap.sh + COMMAND ./configure --disable-assertions + COMMAND make -j CXXFLAGS=-g\ -W\ -Wall\ -O3\ -fPIC + COMMAND ar cr libkohler_masstree_json.a ${_masstree_objs} + COMMAND ranlib libkohler_masstree_json.a + WORKING_DIRECTORY "${masstree_SOURCE_DIR}" + COMMENT "masstree: bootstrap + configure + make + ar" + VERBATIM +) +add_custom_target(masstree_build DEPENDS "${_masstree_archive}" "${_masstree_config_h}") + +# Expose masstree as an INTERFACE library (rather than STATIC IMPORTED) so +# we can use add_dependencies() to wire the upstream-build custom target +# into every consumer — IMPORTED targets don't propagate build-order deps +# reliably across all CMake versions we care about. +add_library(ccbench_masstree INTERFACE) +target_include_directories(ccbench_masstree INTERFACE "${masstree_SOURCE_DIR}") +target_link_libraries(ccbench_masstree INTERFACE "${_masstree_archive}") +add_dependencies(ccbench_masstree masstree_build) +add_library(ccbench::masstree ALIAS ccbench_masstree) + +# --- mimalloc -------------------------------------------------------------- +# +# mimalloc is a regular CMake project; FetchContent_MakeAvailable drops it +# straight into the build graph and gives us the upstream +# `mimalloc-static` target. We alias it so the rest of the tree keeps +# linking against ccbench::mimalloc unchanged. +# +# Note: we keep the same commit (v2.3.2) the old submodule was pinned to — +# bumping the allocator version is out of scope for issue #98. + +set(MI_BUILD_STATIC ON CACHE BOOL "" FORCE) +set(MI_BUILD_SHARED OFF CACHE BOOL "" FORCE) +set(MI_BUILD_OBJECT OFF CACHE BOOL "" FORCE) +set(MI_BUILD_TESTS OFF CACHE BOOL "" FORCE) +set(MI_OVERRIDE OFF CACHE BOOL "" FORCE) + +FetchContent_Declare( + mimalloc + GIT_REPOSITORY "${CCBENCH_MIMALLOC_REPO}" + GIT_TAG "${CCBENCH_MIMALLOC_TAG}" + GIT_SHALLOW TRUE +) +FetchContent_MakeAvailable(mimalloc) + +# Upstream exports `mimalloc-static`; expose it under ccbench:: so callers +# don't have to know which upstream name to use. +add_library(ccbench::mimalloc ALIAS mimalloc-static) + +# --- googletest ------------------------------------------------------------ +# +# Standard FetchContent + MakeAvailable. The googletest CMake project +# exports `GTest::gtest` / `GTest::gtest_main` targets that the test +# subdirectories (currently only cc/ss2pl/test) link against directly. + +set(BUILD_GMOCK OFF CACHE BOOL "" FORCE) +set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) +# Match MSVC's runtime to the rest of the build — no-op on Linux but +# keeps the project portable if anyone ever builds tests on Windows. +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + +FetchContent_Declare( + googletest + GIT_REPOSITORY "${CCBENCH_GOOGLETEST_REPO}" + GIT_TAG "${CCBENCH_GOOGLETEST_TAG}" + GIT_SHALLOW FALSE # SHA pin +) +FetchContent_MakeAvailable(googletest) diff --git a/include/masstree_wrapper.hh b/include/masstree_wrapper.hh index 50b9ab8c..9913db1f 100644 --- a/include/masstree_wrapper.hh +++ b/include/masstree_wrapper.hh @@ -13,19 +13,23 @@ // フォーマッターを利用すると,辞書順のために下記2行が入れ替わる. // しかし,依存関係があるため,config -> compiler の順にしなければ // 大量のエラーが出てしまう. そのため,改行を防ぐため空行を空けている -#include "../third_party/masstree/config.h" - -#include "../third_party/masstree/compiler.hh" - -#include "../third_party/masstree/kvthread.hh" -#include "../third_party/masstree/masstree.hh" -#include "../third_party/masstree/masstree_insert.hh" -#include "../third_party/masstree/masstree_print.hh" -#include "../third_party/masstree/masstree_remove.hh" -#include "../third_party/masstree/masstree_scan.hh" -#include "../third_party/masstree/masstree_stats.hh" -#include "../third_party/masstree/masstree_tcursor.hh" -#include "../third_party/masstree/string.hh" +// +// masstree のヘッダは ccbench::masstree (cmake/ThirdParty.cmake) の +// INTERFACE_INCLUDE_DIRECTORIES から angle-bracket 形式で引き当てる。 +// FetchContent によりソースは build/_deps/masstree-src/ に置かれる。 +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "atomic_wrapper.hh" #include "debug.hh" diff --git a/third_party/googletest b/third_party/googletest deleted file mode 160000 index f8d7d77c..00000000 --- a/third_party/googletest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f8d7d77c06936315286eb55f8de22cd23c188571 diff --git a/third_party/masstree b/third_party/masstree deleted file mode 160000 index b3c5d054..00000000 --- a/third_party/masstree +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b3c5d054b66b08374d7a6ff5a0faeaf28b041a38 diff --git a/third_party/mimalloc b/third_party/mimalloc deleted file mode 160000 index 02a2f5df..00000000 --- a/third_party/mimalloc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 02a2f5df9d7d46d30263b83832eebeeab62dc5fe