Static linkage (#1377)

Fixes #1300
This commit is contained in:
Alex Kremer
2024-04-25 16:51:16 +01:00
committed by GitHub
parent c00342c792
commit 0dcbbf9afa
5 changed files with 33 additions and 8 deletions

View File

@@ -16,6 +16,10 @@ inputs:
description: Whether conan's coverage option should be on or not description: Whether conan's coverage option should be on or not
required: true required: true
default: 'false' default: 'false'
static:
description: Whether Clio is to be statically linked
required: true
default: 'false'
runs: runs:
using: composite using: composite
steps: steps:
@@ -28,9 +32,10 @@ runs:
env: env:
BUILD_OPTION: "${{ inputs.conan_cache_hit == 'true' && 'missing' || '' }}" BUILD_OPTION: "${{ inputs.conan_cache_hit == 'true' && 'missing' || '' }}"
CODE_COVERAGE: "${{ inputs.code_coverage == 'true' && 'True' || 'False' }}" CODE_COVERAGE: "${{ inputs.code_coverage == 'true' && 'True' || 'False' }}"
STATIC_OPTION: "${{ inputs.static == 'true' && 'True' || 'False' }}"
run: | run: |
cd build cd build
conan install .. -of . -b $BUILD_OPTION -s build_type=${{ inputs.build_type }} -o clio:tests=True -o clio:lint=False -o clio:coverage="${CODE_COVERAGE}" --profile ${{ inputs.conan_profile }} conan install .. -of . -b $BUILD_OPTION -s build_type=${{ inputs.build_type }} -o clio:static="${STATIC_OPTION}" -o clio:tests=True -o clio:lint=False -o clio:coverage="${CODE_COVERAGE}" --profile ${{ inputs.conan_profile }}
- name: Run cmake - name: Run cmake
shell: bash shell: bash

View File

@@ -52,27 +52,32 @@ jobs:
build_type: Release build_type: Release
conan_profile: gcc conan_profile: gcc
code_coverage: false code_coverage: false
static: true
- os: heavy - os: heavy
container: container:
image: rippleci/clio_ci:latest image: rippleci/clio_ci:latest
build_type: Debug build_type: Debug
conan_profile: gcc conan_profile: gcc
code_coverage: true code_coverage: true
static: true
- os: heavy - os: heavy
container: container:
image: rippleci/clio_ci:latest image: rippleci/clio_ci:latest
build_type: Release build_type: Release
conan_profile: clang conan_profile: clang
code_coverage: false code_coverage: false
static: true
- os: heavy - os: heavy
container: container:
image: rippleci/clio_ci:latest image: rippleci/clio_ci:latest
build_type: Debug build_type: Debug
conan_profile: clang conan_profile: clang
code_coverage: false code_coverage: false
static: true
- os: macos14 - os: macos14
build_type: Release build_type: Release
code_coverage: false code_coverage: false
static: false
runs-on: [self-hosted, "${{ matrix.os }}"] runs-on: [self-hosted, "${{ matrix.os }}"]
container: ${{ matrix.container }} container: ${{ matrix.container }}
@@ -122,6 +127,7 @@ jobs:
conan_cache_hit: ${{ steps.restore_cache.outputs.conan_cache_hit }} conan_cache_hit: ${{ steps.restore_cache.outputs.conan_cache_hit }}
build_type: ${{ matrix.build_type }} build_type: ${{ matrix.build_type }}
code_coverage: ${{ matrix.code_coverage }} code_coverage: ${{ matrix.code_coverage }}
static: ${{ matrix.static }}
- name: Build Clio - name: Build Clio
uses: ./.github/actions/build_clio uses: ./.github/actions/build_clio

View File

@@ -14,6 +14,7 @@ option(docs "Generate doxygen docs" FALSE)
option(coverage "Build test coverage report" FALSE) option(coverage "Build test coverage report" FALSE)
option(packaging "Create distribution packages" FALSE) option(packaging "Create distribution packages" FALSE)
option(lint "Run clang-tidy checks during compilation" FALSE) option(lint "Run clang-tidy checks during compilation" FALSE)
option(static "Statically linked Clio" FALSE)
# ========================================================================== # # ========================================================================== #
set(san "" CACHE STRING "Add sanitizer instrumentation") set(san "" CACHE STRING "Add sanitizer instrumentation")
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)

View File

@@ -9,7 +9,8 @@ class Clio(ConanFile):
description = 'Clio RPC server' description = 'Clio RPC server'
settings = 'os', 'compiler', 'build_type', 'arch' settings = 'os', 'compiler', 'build_type', 'arch'
options = { options = {
'fPIC': [True, False], 'static': [True, False], # static linkage
'fPIC': [True, False], # unused?
'verbose': [True, False], 'verbose': [True, False],
'tests': [True, False], # build unit tests; create `clio_tests` binary 'tests': [True, False], # build unit tests; create `clio_tests` binary
'benchmark': [True, False], # build benchmarks; create `clio_benchmarks` binary 'benchmark': [True, False], # build benchmarks; create `clio_benchmarks` binary
@@ -31,6 +32,7 @@ class Clio(ConanFile):
] ]
default_options = { default_options = {
'static': False,
'fPIC': True, 'fPIC': True,
'verbose': False, 'verbose': False,
'tests': False, 'tests': False,
@@ -79,6 +81,7 @@ class Clio(ConanFile):
def generate(self): def generate(self):
tc = CMakeToolchain(self) tc = CMakeToolchain(self)
tc.variables['verbose'] = self.options.verbose tc.variables['verbose'] = self.options.verbose
tc.variables['static'] = self.options.static
tc.variables['tests'] = self.options.tests tc.variables['tests'] = self.options.tests
tc.variables['coverage'] = self.options.coverage tc.variables['coverage'] = self.options.coverage
tc.variables['lint'] = self.options.lint tc.variables['lint'] = self.options.lint

View File

@@ -9,10 +9,20 @@ target_compile_features(clio PUBLIC cxx_std_23)
add_executable(clio_server) add_executable(clio_server)
target_sources(clio_server PRIVATE Main.cpp) target_sources(clio_server PRIVATE Main.cpp)
target_link_libraries(clio_server PRIVATE clio) target_link_libraries(clio_server PRIVATE clio)
target_link_options(
# For now let's assume that we only using libstdc++ under gcc. if (static)
# target_link_options(clio_server PRIVATE -static)
# TODO: libc++ static linkage in https://github.com/XRPLF/clio/issues/1300
clio_server PRIVATE $<$<AND:$<BOOL:${is_gcc}>,$<NOT:$<BOOL:${san}>>>:-static-libstdc++ -static-libgcc> if (is_gcc AND NOT san)
) target_link_options(
# For now let's assume that we only using libstdc++ under gcc.
clio_server PRIVATE -static-libstdc++ -static-libgcc
)
endif ()
if (is_appleclang)
message(FATAL_ERROR "Static linkage not supported on AppleClang")
endif ()
endif ()
set_target_properties(clio_server PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set_target_properties(clio_server PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})