diff --git a/.github/actions/generate/action.yml b/.github/actions/generate/action.yml index 7fead90e..2f6c9269 100644 --- a/.github/actions/generate/action.yml +++ b/.github/actions/generate/action.yml @@ -29,6 +29,10 @@ inputs: description: Whether to enable compiler trace reports required: true default: "false" + use_mold: + description: Whether to use mold linker + required: true + default: "false" runs: using: composite @@ -45,6 +49,7 @@ runs: STATIC_OPTION: "${{ inputs.static == 'true' && 'True' || 'False' }}" INTEGRATION_TESTS_OPTION: "${{ inputs.build_integration_tests == 'true' && 'True' || 'False' }}" TIME_TRACE: "${{ inputs.time_trace == 'true' && 'True' || 'False' }}" + USE_MOLD: "${{ inputs.use_mold == 'true' && 'True' || 'False' }}" run: | cd build conan \ @@ -58,6 +63,7 @@ runs: -o "&:lint=False" \ -o "&:coverage=${CODE_COVERAGE}" \ -o "&:time_trace=${TIME_TRACE}" \ + -o "&:use_mold=${USE_MOLD}" \ --profile:all "${{ inputs.conan_profile }}" - name: Run cmake @@ -69,11 +75,13 @@ runs: endsWith(inputs.conan_profile, '.tsan') && '-Dsan=thread' || endsWith(inputs.conan_profile, '.ubsan') && '-Dsan=undefined' || '' }} + USE_MOLD_OPTION: "${{ inputs.use_mold == 'true' && '-DUSE_MOLD=ON' || '' }}" run: | cd build cmake \ -DCMAKE_TOOLCHAIN_FILE:FILEPATH=build/generators/conan_toolchain.cmake \ -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \ + "${USE_MOLD_OPTION}" \ "${SANITIZER_OPTION}" \ .. \ -G Ninja diff --git a/.github/workflows/build_impl.yml b/.github/workflows/build_impl.yml index da881bfb..e16c37ae 100644 --- a/.github/workflows/build_impl.yml +++ b/.github/workflows/build_impl.yml @@ -110,6 +110,7 @@ jobs: code_coverage: ${{ inputs.code_coverage }} static: ${{ inputs.static }} time_trace: ${{ inputs.analyze_build_time }} + use_mold: ${{ runner.os != 'macOS' }} - name: Build Clio uses: ./.github/actions/build_clio diff --git a/CMakeLists.txt b/CMakeLists.txt index ce7d3cec..410aba7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,7 @@ option(lint "Run clang-tidy checks during compilation" FALSE) option(static "Statically linked Clio" FALSE) option(snapshot "Build snapshot tool" FALSE) option(time_trace "Build using -ftime-trace to create compiler trace reports" FALSE) +option(use_mold "Use mold linker" FALSE) # ========================================================================== # set(san "" CACHE STRING "Add sanitizer instrumentation") @@ -29,6 +30,7 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) include(Ccache) include(CheckCXXCompilerFlag) include(ClangTidy) +include(Linker) add_library(clio_options INTERFACE) target_compile_features(clio_options INTERFACE cxx_std_23) # Clio needs c++23 but deps can remain c++20 for now diff --git a/cmake/Linker.cmake b/cmake/Linker.cmake new file mode 100644 index 00000000..5ac0a844 --- /dev/null +++ b/cmake/Linker.cmake @@ -0,0 +1,8 @@ +if (use_mold) + if (CMAKE_SYSTEM_NAME STREQUAL "Linux") + message(STATUS "Using Mold linker") + set(CMAKE_LINKER_TYPE MOLD) + else () + message(FATAL_ERROR "Mold linker is only supported on Linux.") + endif () +endif () diff --git a/conanfile.py b/conanfile.py index 3f7b0c6b..f42f2a9c 100644 --- a/conanfile.py +++ b/conanfile.py @@ -20,7 +20,8 @@ class ClioConan(ConanFile): 'coverage': [True, False], # build for test coverage report; create custom target `clio_tests-ccov` 'lint': [True, False], # run clang-tidy checks during compilation 'snapshot': [True, False], # build export/import snapshot tool - 'time_trace': [True, False] # build using -ftime-trace to create compiler trace reports + 'time_trace': [True, False], # build using -ftime-trace to create compiler trace reports + 'use_mold': [True, False], # use mold linker for faster linking } requires = [ @@ -47,6 +48,7 @@ class ClioConan(ConanFile): 'docs': False, 'snapshot': False, 'time_trace': False, + 'use_mold': False, 'xrpl/*:tests': False, 'xrpl/*:rocksdb': False,