feat: Use mold linker on Linux (#2304)

Fix: https://github.com/XRPLF/clio/issues/1242

Depends on: https://github.com/XRPLF/clio/pull/2329
This commit is contained in:
Ayaz Salikhov
2025-07-30 17:10:31 +01:00
committed by GitHub
parent 46b86a5d61
commit bc8a2c19aa
5 changed files with 22 additions and 1 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

8
cmake/Linker.cmake Normal file
View File

@@ -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 ()

View File

@@ -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,