From 45867a9a9d3db5e5190a32101f834624b2c4c428 Mon Sep 17 00:00:00 2001 From: Laurynas Biveinis Date: Wed, 19 Oct 2022 21:15:04 +0300 Subject: [PATCH] WIP link jemalloc statically [skip ci] --- .circleci/config.yml | 2 +- .github/workflows/build.yml | 4 ++-- .github/workflows/experimental-build.yml | 2 +- .github/workflows/msvc-build.yml | 8 +++++++- .github/workflows/old-compilers.yml | 2 +- .github/workflows/sonarcloud.yml | 2 +- CMakeLists.txt | 22 ++++++++++++++++++++++ 7 files changed, 35 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7e1cd462..473d9c41 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -29,7 +29,7 @@ jobs: - run: name: Installing dependencies (common) command: | - sudo apt-get install -y libboost-dev + sudo apt-get install -y libboost-dev libjemalloc-dev - when: condition: equal: [ "gcc", << parameters.compiler >> ] diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d91e3c12..4865dadb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -225,7 +225,7 @@ jobs: - name: Setup common dependencies for Linux run: | - sudo apt-get install -y libboost-dev libc6-dev-i386 + sudo apt-get install -y libboost-dev libc6-dev-i386 libjemalloc-dev sudo apt-get remove clang-tidy-11 if: runner.os == 'Linux' @@ -268,7 +268,7 @@ jobs: - name: Set up dependencies for macOS (common) run: | - brew install boost + brew install boost jemalloc if: runner.os == 'macOS' - name: Set up dependencies for macOS (coverage) diff --git a/.github/workflows/experimental-build.yml b/.github/workflows/experimental-build.yml index 78746c5d..4e6f5679 100644 --- a/.github/workflows/experimental-build.yml +++ b/.github/workflows/experimental-build.yml @@ -28,7 +28,7 @@ jobs: - name: Set up dependencies for macOS run: | brew update - brew install boost cppcheck iwyu + brew install boost cppcheck iwyu jemalloc - name: Create build environment run: mkdir ${{github.workspace}}/build diff --git a/.github/workflows/msvc-build.yml b/.github/workflows/msvc-build.yml index 35c5dac2..4d484de0 100644 --- a/.github/workflows/msvc-build.yml +++ b/.github/workflows/msvc-build.yml @@ -53,11 +53,17 @@ jobs: platform_version: 2019 toolset: msvc + - name: Install jemalloc + run: | + vcpkg install jemalloc + - name: Setup command line tools uses: ilammy/msvc-dev-cmd@v1 - name: Configure CMake - run: cmake --preset "${{ matrix.preset }}" + run: | + $env:PKG_CONFIG_PATH += ";C:\vcpkg\packages\jemalloc_x86-windows\lib\pkgconfig" + cmake --preset "${{ matrix.preset }}" env: BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }} diff --git a/.github/workflows/old-compilers.yml b/.github/workflows/old-compilers.yml index 361bfc6c..9fc8dad7 100644 --- a/.github/workflows/old-compilers.yml +++ b/.github/workflows/old-compilers.yml @@ -355,7 +355,7 @@ jobs: - name: Setup common dependencies for Linux run: | - sudo apt-get install -y libboost-dev libc6-dev-i386 + sudo apt-get install -y libboost-dev libc6-dev-i386 libjemalloc-dev if: runner.os == 'Linux' - name: Setup dependencies for Linux LLVM 11 & 12 diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 532af081..073cc560 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -37,7 +37,7 @@ jobs: - name: Setup dependencies run: | sudo add-apt-repository -y 'ppa:mhier/libboost-latest' - sudo apt-get install -y boost1.74 + sudo apt-get install -y boost1.74 libjemalloc-dev - name: Produce Compilation Database shell: bash diff --git a/CMakeLists.txt b/CMakeLists.txt index daec2b8c..eb2d49af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -256,6 +256,22 @@ find_package(Threads REQUIRED) find_package(Boost REQUIRED) +# Enable statically-linked jemalloc for Apple Silicon once +# https://github.com/jemalloc/jemalloc/issues/2051 is fixed +if(NOT("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin" + AND "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64")) + set(USE_JEMALLOC ON) +else() + set(USE_JEMALLOC OFF) +endif() + +if(USE_JEMALLOC) + find_package(PkgConfig REQUIRED) + + pkg_check_modules(JEMALLOC jemalloc) + pkg_search_module(JEMALLOC REQUIRED jemalloc) +endif() + string(REPLACE ";" " " CXX_FLAGS_FOR_SUBDIR_STR "${SANITIZER_CXX_FLAGS}") if(MSVC) string(REPLACE ";" " " MSVC_WARNING_FLAGS_FOR_SUBDIR_STR_TMP "${MSVC_CXX_WARNING_FLAGS}") @@ -395,6 +411,7 @@ set(is_clang_ge_13_not_windows "$") set(is_clang_ge_14_not_windows "$") set(is_gxx_ge_11 "$") set(is_gxx_ge_12 "$") +set(has_jemalloc "$") set(has_avx2 "$") set(fatal_warnings_on "$") set(coverage_on "$") @@ -496,6 +513,9 @@ function(COMMON_TARGET_PROPERTIES TARGET) set_target_properties(${TARGET} PROPERTIES CXX_EXTENSIONS OFF) target_compile_definitions(${TARGET} PRIVATE "$<${is_standalone}:UNODB_DETAIL_STANDALONE>") + target_compile_definitions(${TARGET} PRIVATE + # FIXME(laurynas): UNODB_DETAIL_USE_SIZED_FREE + "$<${has_jemalloc}:UNODB_DETAIL_USE_JEMALLOC>") target_compile_options(${TARGET} PRIVATE "${CXX_FLAGS}" "${SANITIZER_CXX_FLAGS}" "$<${is_msvc}:${MSVC_CXX_FLAGS}>" @@ -520,6 +540,8 @@ function(COMMON_TARGET_PROPERTIES TARGET) "$<$:$>" # Misc "$<${coverage_on}:--coverage>") + target_link_libraries(${TARGET} PRIVATE + "$<${has_jemalloc}:${JEMALLOC_LDFLAGS}>") # Change to target_link_options on 3.13 minimum CMake version target_link_libraries(${TARGET} INTERFACE "$<${coverage_on}:--coverage>") target_link_libraries(${TARGET} PRIVATE