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
required: true
default: 'false'
static:
description: Whether Clio is to be statically linked
required: true
default: 'false'
runs:
using: composite
steps:
@@ -28,9 +32,10 @@ runs:
env:
BUILD_OPTION: "${{ inputs.conan_cache_hit == 'true' && 'missing' || '' }}"
CODE_COVERAGE: "${{ inputs.code_coverage == 'true' && 'True' || 'False' }}"
STATIC_OPTION: "${{ inputs.static == 'true' && 'True' || 'False' }}"
run: |
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
shell: bash

View File

@@ -52,27 +52,32 @@ jobs:
build_type: Release
conan_profile: gcc
code_coverage: false
static: true
- os: heavy
container:
image: rippleci/clio_ci:latest
build_type: Debug
conan_profile: gcc
code_coverage: true
static: true
- os: heavy
container:
image: rippleci/clio_ci:latest
build_type: Release
conan_profile: clang
code_coverage: false
static: true
- os: heavy
container:
image: rippleci/clio_ci:latest
build_type: Debug
conan_profile: clang
code_coverage: false
static: true
- os: macos14
build_type: Release
code_coverage: false
static: false
runs-on: [self-hosted, "${{ matrix.os }}"]
container: ${{ matrix.container }}
@@ -122,6 +127,7 @@ jobs:
conan_cache_hit: ${{ steps.restore_cache.outputs.conan_cache_hit }}
build_type: ${{ matrix.build_type }}
code_coverage: ${{ matrix.code_coverage }}
static: ${{ matrix.static }}
- name: 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(packaging "Create distribution packages" FALSE)
option(lint "Run clang-tidy checks during compilation" FALSE)
option(static "Statically linked Clio" FALSE)
# ========================================================================== #
set(san "" CACHE STRING "Add sanitizer instrumentation")
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)

View File

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

View File

@@ -9,10 +9,20 @@ target_compile_features(clio PUBLIC cxx_std_23)
add_executable(clio_server)
target_sources(clio_server PRIVATE Main.cpp)
target_link_libraries(clio_server PRIVATE clio)
target_link_options(
# For now let's assume that we only using libstdc++ under gcc.
#
# 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 (static)
target_link_options(clio_server PRIVATE -static)
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})