From f3bcc651c70e4e523595a458a638839ac1b87e8d Mon Sep 17 00:00:00 2001 From: John Freeman Date: Thu, 11 Jul 2024 17:04:30 -0500 Subject: [PATCH] Add xrpld build option and Conan package test (#5052) * Make xrpld target optional * Add job to test Conan recipe * [fold] address review comments * [fold] Enable tests in workflows * [fold] Rename with_xrpld option * [fold] Fix grep expression --- .github/actions/build/action.yml | 2 + .github/actions/dependencies/action.yml | 2 + .github/workflows/nix.yml | 50 +++++++++++++ cmake/RippledCore.cmake | 96 +++++++++++++------------ cmake/RippledInstall.cmake | 38 +++++----- cmake/RippledSettings.cmake | 2 + conanfile.py | 5 +- examples/example/CMakeLists.txt | 16 +++++ examples/example/conanfile.py | 59 +++++++++++++++ examples/example/src/example.cpp | 8 +++ 10 files changed, 211 insertions(+), 67 deletions(-) create mode 100644 examples/example/CMakeLists.txt create mode 100644 examples/example/conanfile.py create mode 100644 examples/example/src/example.cpp diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index 79bbe9af075..6714369155f 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -20,6 +20,8 @@ runs: ${{ inputs.generator && format('-G "{0}"', inputs.generator) || '' }} \ -DCMAKE_TOOLCHAIN_FILE:FILEPATH=build/generators/conan_toolchain.cmake \ -DCMAKE_BUILD_TYPE=${{ inputs.configuration }} \ + -Dtests=TRUE \ + -Dxrpld=TRUE \ ${{ inputs.cmake-args }} \ .. - name: build diff --git a/.github/actions/dependencies/action.yml b/.github/actions/dependencies/action.yml index d9687ff121e..50e2999018a 100644 --- a/.github/actions/dependencies/action.yml +++ b/.github/actions/dependencies/action.yml @@ -50,6 +50,8 @@ runs: conan install \ --output-folder . \ --build missing \ + --options tests=True \ + --options xrpld=True \ --settings build_type=${{ inputs.configuration }} \ .. - name: upload dependencies to remote diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index 77cd50d9d68..6b8261c5d69 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -232,3 +232,53 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} attempt_limit: 5 attempt_delay: 210000 # in milliseconds + + conan: + needs: dependencies + runs-on: [self-hosted, heavy] + container: rippleci/rippled-build-ubuntu:aaf5e3e + env: + build_dir: .build + configuration: Release + steps: + - name: download cache + uses: actions/download-artifact@v3 + with: + name: linux-gcc-${{ env.configuration }} + - name: extract cache + run: | + mkdir -p ~/.conan + tar -xzf conan.tar -C ~/.conan + - name: check environment + run: | + env | sort + echo ${PATH} | tr ':' '\n' + conan --version + cmake --version + - name: checkout + uses: actions/checkout@v4 + - name: dependencies + uses: ./.github/actions/dependencies + env: + CONAN_URL: http://18.143.149.228:8081/artifactory/api/conan/conan-non-prod + with: + configuration: ${{ env.configuration }} + - name: export + run: | + version=$(conan inspect --raw version .) + reference="xrpl/${version}@local/test" + conan remove -f ${reference} || true + conan export . local/test + echo "reference=${reference}" >> "${GITHUB_ENV}" + - name: build + run: | + cd examples/example + mkdir ${build_dir} + cd ${build_dir} + conan install .. --output-folder . \ + --require-override ${reference} --build missing + cmake .. \ + -DCMAKE_TOOLCHAIN_FILE:FILEPATH=./build/${configuration}/generators/conan_toolchain.cmake \ + -DCMAKE_BUILD_TYPE=${configuration} + cmake --build . + ./example | grep '^[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+' diff --git a/cmake/RippledCore.cmake b/cmake/RippledCore.cmake index cc483034714..6a0060f7b32 100644 --- a/cmake/RippledCore.cmake +++ b/cmake/RippledCore.cmake @@ -91,57 +91,59 @@ target_link_libraries(xrpl.libxrpl xxHash::xxhash ) -add_executable(rippled) -if(unity) - set_target_properties(rippled PROPERTIES UNITY_BUILD ON) -endif() -if(tests) - target_compile_definitions(rippled PUBLIC ENABLE_TESTS) -endif() -target_include_directories(rippled - PRIVATE - $ -) - -file(GLOB_RECURSE sources CONFIGURE_DEPENDS - "${CMAKE_CURRENT_SOURCE_DIR}/src/xrpld/*.cpp" -) -target_sources(rippled PRIVATE ${sources}) +if(xrpld) + add_executable(rippled) + if(unity) + set_target_properties(rippled PROPERTIES UNITY_BUILD ON) + endif() + if(tests) + target_compile_definitions(rippled PUBLIC ENABLE_TESTS) + endif() + target_include_directories(rippled + PRIVATE + $ + ) -if(tests) file(GLOB_RECURSE sources CONFIGURE_DEPENDS - "${CMAKE_CURRENT_SOURCE_DIR}/src/test/*.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/src/xrpld/*.cpp" ) target_sources(rippled PRIVATE ${sources}) -endif() -target_link_libraries(rippled - Ripple::boost - Ripple::opts - Ripple::libs - xrpl.libxrpl -) -exclude_if_included(rippled) -# define a macro for tests that might need to -# be exluded or run differently in CI environment -if(is_ci) - target_compile_definitions(rippled PRIVATE RIPPLED_RUNNING_IN_CI) -endif () - -if(reporting) - set(suffix -reporting) - set_target_properties(rippled PROPERTIES OUTPUT_NAME rippled-reporting) - get_target_property(BIN_NAME rippled OUTPUT_NAME) - message(STATUS "Reporting mode build: rippled renamed ${BIN_NAME}") - target_compile_definitions(rippled PRIVATE RIPPLED_REPORTING) -endif() + if(tests) + file(GLOB_RECURSE sources CONFIGURE_DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/src/test/*.cpp" + ) + target_sources(rippled PRIVATE ${sources}) + endif() -# any files that don't play well with unity should be added here -if(tests) - set_source_files_properties( - # these two seem to produce conflicts in beast teardown template methods - src/test/rpc/ValidatorRPC_test.cpp - src/test/rpc/ShardArchiveHandler_test.cpp - src/test/ledger/Invariants_test.cpp - PROPERTIES SKIP_UNITY_BUILD_INCLUSION TRUE) + target_link_libraries(rippled + Ripple::boost + Ripple::opts + Ripple::libs + xrpl.libxrpl + ) + exclude_if_included(rippled) + # define a macro for tests that might need to + # be exluded or run differently in CI environment + if(is_ci) + target_compile_definitions(rippled PRIVATE RIPPLED_RUNNING_IN_CI) + endif () + + if(reporting) + set(suffix -reporting) + set_target_properties(rippled PROPERTIES OUTPUT_NAME rippled-reporting) + get_target_property(BIN_NAME rippled OUTPUT_NAME) + message(STATUS "Reporting mode build: rippled renamed ${BIN_NAME}") + target_compile_definitions(rippled PRIVATE RIPPLED_REPORTING) + endif() + + # any files that don't play well with unity should be added here + if(tests) + set_source_files_properties( + # these two seem to produce conflicts in beast teardown template methods + src/test/rpc/ValidatorRPC_test.cpp + src/test/rpc/ShardArchiveHandler_test.cpp + src/test/ledger/Invariants_test.cpp + PROPERTIES SKIP_UNITY_BUILD_INCLUSION TRUE) + endif() endif() diff --git a/cmake/RippledInstall.cmake b/cmake/RippledInstall.cmake index d92cecc24eb..3199c9a19b8 100644 --- a/cmake/RippledInstall.cmake +++ b/cmake/RippledInstall.cmake @@ -21,6 +21,13 @@ install( DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) +if(NOT WIN32) + install( + CODE "file(CREATE_LINK xrpl \ + \${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/ripple SYMBOLIC)" + ) +endif() + install (EXPORT RippleExports FILE RippleTargets.cmake NAMESPACE Ripple:: @@ -31,14 +38,9 @@ write_basic_package_version_file ( VERSION ${rippled_version} COMPATIBILITY SameMajorVersion) -if (is_root_project) +if (is_root_project AND TARGET rippled) install (TARGETS rippled RUNTIME DESTINATION bin) set_target_properties(rippled PROPERTIES INSTALL_RPATH_USE_LINK_PATH ON) - install ( - FILES - ${CMAKE_CURRENT_SOURCE_DIR}/cmake/RippleConfig.cmake - ${CMAKE_CURRENT_BINARY_DIR}/RippleConfigVersion.cmake - DESTINATION lib/cmake/ripple) # sample configs should not overwrite existing files # install if-not-exists workaround as suggested by # https://cmake.org/Bug/view.php?id=12646 @@ -53,18 +55,16 @@ if (is_root_project) copy_if_not_exists(\"${CMAKE_CURRENT_SOURCE_DIR}/cfg/rippled-example.cfg\" etc rippled.cfg) copy_if_not_exists(\"${CMAKE_CURRENT_SOURCE_DIR}/cfg/validators-example.txt\" etc validators.txt) ") + if(NOT WIN32) + install( + CODE "file(CREATE_LINK rippled${suffix} \ + \${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/xrpld${suffix} SYMBOLIC)" + ) + endif() endif () -if(NOT WIN32) - install( - CODE "file(CREATE_LINK xrpl \ - \${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/ripple SYMBOLIC)" - ) -endif() - -if(NOT WIN32) - install( - CODE "file(CREATE_LINK rippled${suffix} \ - \${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/xrpld${suffix} SYMBOLIC)" - ) -endif() +install ( + FILES + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/RippleConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/RippleConfigVersion.cmake + DESTINATION lib/cmake/ripple) diff --git a/cmake/RippledSettings.cmake b/cmake/RippledSettings.cmake index fae09cc5d3f..a431bb61389 100644 --- a/cmake/RippledSettings.cmake +++ b/cmake/RippledSettings.cmake @@ -8,6 +8,8 @@ ProcessorCount(PROCESSOR_COUNT) option(assert "Enables asserts, even in release builds" OFF) +option(xrpld "Build xrpld" ON) + option(reporting "Build rippled with reporting mode enabled" OFF) option(tests "Build tests" ON) diff --git a/conanfile.py b/conanfile.py index 68b0a7cd405..425fee8b682 100644 --- a/conanfile.py +++ b/conanfile.py @@ -21,6 +21,7 @@ class Xrpl(ConanFile): 'static': [True, False], 'tests': [True, False], 'unity': [True, False], + 'xrpld': [True, False], } requires = [ @@ -47,8 +48,9 @@ class Xrpl(ConanFile): 'rocksdb': True, 'shared': False, 'static': True, - 'tests': True, + 'tests': False, 'unity': False, + 'xrpld': False, 'cassandra-cpp-driver/*:shared': False, 'cassandra-cpp-driver/*:use_atomic': None, @@ -142,6 +144,7 @@ def generate(self): tc.variables['BUILD_SHARED_LIBS'] = self.options.shared tc.variables['static'] = self.options.static tc.variables['unity'] = self.options.unity + tc.variables['xrpld'] = self.options.xrpld tc.generate() def build(self): diff --git a/examples/example/CMakeLists.txt b/examples/example/CMakeLists.txt new file mode 100644 index 00000000000..83aa24880d1 --- /dev/null +++ b/examples/example/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.21) + +set(name example) +set(version 0.1.0) + +project( + ${name} + VERSION ${version} + LANGUAGES CXX +) + +find_package(xrpl REQUIRED) + +add_executable(example) +target_sources(example PRIVATE src/example.cpp) +target_link_libraries(example PRIVATE xrpl::libxrpl) diff --git a/examples/example/conanfile.py b/examples/example/conanfile.py new file mode 100644 index 00000000000..be3750bf9e9 --- /dev/null +++ b/examples/example/conanfile.py @@ -0,0 +1,59 @@ +from conan import ConanFile, conan_version +from conan.tools.cmake import CMake, cmake_layout + +class Example(ConanFile): + + def set_name(self): + if self.name is None: + self.name = 'example' + + def set_version(self): + if self.version is None: + self.version = '0.1.0' + + license = 'ISC' + author = 'John Freeman ' + + settings = 'os', 'compiler', 'build_type', 'arch' + options = {'shared': [True, False], 'fPIC': [True, False]} + default_options = { + 'shared': False, + 'fPIC': True, + 'xrpl:xrpld': False, + } + + requires = ['xrpl/2.2.0-rc1@jfreeman/nodestore'] + generators = ['CMakeDeps', 'CMakeToolchain'] + + exports_sources = [ + 'CMakeLists.txt', + 'cmake/*', + 'external/*', + 'include/*', + 'src/*', + ] + + # For out-of-source build. + # https://docs.conan.io/en/latest/reference/build_helpers/cmake.html#configure + no_copy_source = True + + def layout(self): + cmake_layout(self) + + def config_options(self): + if self.settings.os == 'Windows': + del self.options.fPIC + + def build(self): + cmake = CMake(self) + cmake.configure(variables={'BUILD_TESTING': 'NO'}) + cmake.build() + + def package(self): + cmake = CMake(self) + cmake.install() + + def package_info(self): + path = f'{self.package_folder}/share/{self.name}/cpp_info.py' + with open(path, 'r') as file: + exec(file.read(), {}, {'self': self.cpp_info}) diff --git a/examples/example/src/example.cpp b/examples/example/src/example.cpp new file mode 100644 index 00000000000..7ff07f6ea4d --- /dev/null +++ b/examples/example/src/example.cpp @@ -0,0 +1,8 @@ +#include + +#include + +int main(int argc, char const** argv) { + std::printf("%s\n", ripple::BuildInfo::getVersionString().c_str()); + return 0; +}