From 6337e7b1d0986cd9852c9e5188869e0db5afee1f Mon Sep 17 00:00:00 2001 From: snider Date: Mon, 6 Oct 2025 15:39:09 +0100 Subject: [PATCH 01/19] Add selective clean function for build directory --- cmake/CleanBuild.cmake | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 cmake/CleanBuild.cmake diff --git a/cmake/CleanBuild.cmake b/cmake/CleanBuild.cmake new file mode 100644 index 00000000..b0b2473b --- /dev/null +++ b/cmake/CleanBuild.cmake @@ -0,0 +1,57 @@ +# cmake/CleanBuild.cmake + +# Function to selectively clean the build directory. +# +# This function will remove most of the generated build files from the build +# directory, while preserving specific directories that contain downloaded +# tools or generated documentation. +# +# Golden Rules: +# - never delete build/ +# - never delete build/bin +# - never delete build/docs +# - never delete build/sdk (non cache) +# +# It will: +# - purge build files +# - clean up conan build files, cached sources can always remain. +function(selective_clean_build_dir) + if(EXISTS "${CMAKE_SOURCE_DIR}/build") + message(STATUS "Selectively cleaning build directory: ${CMAKE_SOURCE_DIR}/build") + + # List of top-level items in the build directory to keep. + set(golden_items + "${CMAKE_SOURCE_DIR}/build/bin" + "${CMAKE_SOURCE_DIR}/build/docs" + "${CMAKE_SOURCE_DIR}/build/sdk" + ) + + # Get all top-level items in the build directory. + file(GLOB top_level_items "${CMAKE_SOURCE_DIR}/build/*") + + foreach(item ${top_level_items}) + list(FIND golden_items "${item}" is_golden) + if(is_golden STREQUAL "-1") + string(FIND "${item}" "${CMAKE_SOURCE_DIR}/build" is_prefixed) + if(is_prefixed EQUAL 0) + message(STATUS "Removing: ${item}") + if(IS_DIRECTORY ${item}) + file(REMOVE_RECURSE "${item}") + else() + file(REMOVE "${item}") + endif() + else() + message(WARNING "Safety check failed: Will not remove '${item}' because it is not prefixed with CMAKE_SOURCE_DIR/build.") + endif() + else() + message(STATUS "Keeping golden item: ${item}") + endif() + endforeach() + + message(STATUS "Selective clean complete.") + else() + message(STATUS "Build directory not found, skipping clean.") + endif() +endfunction() + +selective_clean_build_dir() From d012f0744e62a57079fdceabd217fb9c051349ba Mon Sep 17 00:00:00 2001 From: snider Date: Mon, 6 Oct 2025 15:39:27 +0100 Subject: [PATCH 02/19] Add CMake module to download and install Conan --- cmake/GetConan.cmake | 90 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 cmake/GetConan.cmake diff --git a/cmake/GetConan.cmake b/cmake/GetConan.cmake new file mode 100644 index 00000000..ebbf2359 --- /dev/null +++ b/cmake/GetConan.cmake @@ -0,0 +1,90 @@ +# cmake/GetConan.cmake + +# This module downloads and installs Conan if it's not found. + +# Set the Conan version +set(CONAN_VERSION 2.21.0) + +# Set the download URLs +set(CONAN_URL_MACOS_ARM "https://github.com/conan-io/conan/releases/download/${CONAN_VERSION}/conan-${CONAN_VERSION}-macos-arm64.tgz") +set(CONAN_URL_MACOS_INTEL "https://github.com/conan-io/conan/releases/download/${CONAN_VERSION}/conan-${CONAN_VERSION}-macos-x86_64.tgz") +set(CONAN_URL_WINDOWS_X86_64 "https://github.com/conan-io/conan/releases/download/${CONAN_VERSION}/conan-${CONAN_VERSION}-windows-x86_64.zip") +set(CONAN_URL_WINDOWS_ARM64 "https://github.com/conan-io/conan/releases/download/${CONAN_VERSION}/conan-${CONAN_VERSION}-windows-arm64.zip") +set(CONAN_URL_LINUX_X86_64 "https://github.com/conan-io/conan/releases/download/${CONAN_VERSION}/conan-${CONAN_VERSION}-linux-x86_64.tgz") +set(CONAN_URL_LINUX_AARCH64 "https://github.com/conan-io/conan/releases/download/${CONAN_VERSION}/conan-${CONAN_VERSION}-linux-aarch64.tgz") +set(CONAN_INSTALL_DIR "${CMAKE_SOURCE_DIR}/build") +# Set the installation directory +if(NOT CMAKE_BINARY_DIR) + set(CMAKE_BINARY_DIR "${CONAN_INSTALL_DIR}") +endif() + +set(CONAN_EXECUTABLE "${CONAN_INSTALL_DIR}/bin/conan") + +# Check if Conan is already installed +if(NOT EXISTS "${CONAN_EXECUTABLE}") + message(STATUS "Conan not found. Downloading and installing...") + + file(MAKE_DIRECTORY "${CONAN_INSTALL_DIR}") + + # Detect the operating system and architecture + if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") + if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "arm64") + set(CONAN_URL ${CONAN_URL_MACOS_ARM}) + set(CONAN_ARCHIVE_TYPE "tgz") + else() + set(CONAN_URL ${CONAN_URL_MACOS_INTEL}) + set(CONAN_ARCHIVE_TYPE "tgz") + endif() + elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "ARM64") + set(CONAN_URL ${CONAN_URL_WINDOWS_ARM64}) + set(CONAN_ARCHIVE_TYPE "zip") + else() + set(CONAN_URL ${CONAN_URL_WINDOWS_X86_64}) + set(CONAN_ARCHIVE_TYPE "zip") + endif() + elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") + if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64") + set(CONAN_URL ${CONAN_URL_LINUX_AARCH64}) + set(CONAN_ARCHIVE_TYPE "tgz") + else() + set(CONAN_URL ${CONAN_URL_LINUX_X86_64}) + set(CONAN_ARCHIVE_TYPE "tgz") + endif() + else() + message(FATAL_ERROR "Unsupported operating system: ${CMAKE_HOST_SYSTEM_NAME}") + endif() + + # Download and extract Conan + set(CONAN_ARCHIVE "${CMAKE_BINARY_DIR}/conan.${CONAN_ARCHIVE_TYPE}") + + message(STATUS "Downloading ${CONAN_URL} to ${CONAN_ARCHIVE}") + file(DOWNLOAD "${CONAN_URL}" "${CONAN_ARCHIVE}" SHOW_PROGRESS) + + message(STATUS "Extracting ${CONAN_ARCHIVE} to ${CONAN_INSTALL_DIR}") + if(CONAN_ARCHIVE_TYPE STREQUAL "tgz") + execute_process( + COMMAND ${CMAKE_COMMAND} -E tar xzf "${CONAN_ARCHIVE}" + WORKING_DIRECTORY "${CONAN_INSTALL_DIR}" + RESULT_VARIABLE result + ) + elseif(CONAN_ARCHIVE_TYPE STREQUAL "zip") + # Cmake -E tar can handle zip files + execute_process( + COMMAND ${CMAKE_COMMAND} -E tar xf "${CONAN_ARCHIVE}" + WORKING_DIRECTORY "${CONAN_INSTALL_DIR}" + RESULT_VARIABLE result + ) + endif() + + if(NOT result EQUAL 0) + message(FATAL_ERROR "Failed to extract Conan archive.") + endif() + + # Clean up the archive + file(REMOVE "${CONAN_ARCHIVE}") + + message(STATUS "Conan installed successfully in ${CONAN_INSTALL_DIR}/conan") +else() + message(STATUS "Conan already installed in ${CONAN_INSTALL_DIR}/conan") +endif() From 893b3ed1ff99058978c319954ff7acb8f631611b Mon Sep 17 00:00:00 2001 From: snider Date: Mon, 6 Oct 2025 15:39:42 +0100 Subject: [PATCH 03/19] Remove Conan installation steps from CI configurations and update asset paths --- .github/workflows/build-docs.yml | 21 ++++-------- .github/workflows/build-linux-arm64.yml | 9 +---- .github/workflows/build-linux-intel.yml | 8 +---- .github/workflows/build-macos-arm64.yml | 8 +---- .github/workflows/build-macos-intel.yml | 9 +---- .github/workflows/build-windows-intel.yml | 8 +---- Makefile | 41 ++++++++++------------- cmake/CPackConfig.cmake | 2 +- cmake/conan_provider.cmake | 14 +++++++- utils/docker/images/lthn-chain/Dockerfile | 2 +- 10 files changed, 43 insertions(+), 79 deletions(-) diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index 336e75c3..ad99155f 100644 --- a/.github/workflows/build-docs.yml +++ b/.github/workflows/build-docs.yml @@ -17,12 +17,6 @@ jobs: with: python-version: 3.x - - name: Install Conan - uses: conan-io/setup-conan@v1 - with: - home: ${{ github.workspace }}/build/sdk - cache_packages: true - - uses: actions/cache@v4 with: key: ${{ github.ref }} @@ -34,13 +28,10 @@ jobs: - name: Build Offline Version run: make docs - - name: Zip Build - run: | - cd build/docs - zip -qq -r ../documentation.zip * - - - name: Upload Artifacts - uses: actions/upload-artifact@v4.6.2 + - name: CLI Artifacts + uses: ./.github/actions/upload-artifacts with: - name: Documentation - path: build/documentation.zip + chain-network: ${{ inputs.chain-network }} + assets: * + asset-type: 'docs' + asset-directory: ${{ github.workspace }}/build/docs diff --git a/.github/workflows/build-linux-arm64.yml b/.github/workflows/build-linux-arm64.yml index 73fa8155..e38c6fbe 100644 --- a/.github/workflows/build-linux-arm64.yml +++ b/.github/workflows/build-linux-arm64.yml @@ -36,13 +36,6 @@ jobs: - run: pip install mkdocs-material mkdocs-git-revision-date-localized-plugin mkdocs-git-committers-plugin-2 mkdocs-git-authors-plugin "mkdocs-material[imaging]" - - - name: Install Conan - uses: conan-io/setup-conan@v1 - with: - home: ${{ github.workspace }}/build/sdk - cache_packages: false - - name: Compile Release run: make release CPU_CORES=4 TESTNET=${{ inputs.chain-network == 'testnet' && '1' || '0' }} @@ -52,4 +45,4 @@ jobs: chain-network: ${{ inputs.chain-network }} assets: lethean-* asset-type: 'cli' - asset-directory: ${{ github.workspace }}/build/release/packages + asset-directory: ${{ github.workspace }}/build/packages diff --git a/.github/workflows/build-linux-intel.yml b/.github/workflows/build-linux-intel.yml index bb30c892..465e6c5e 100644 --- a/.github/workflows/build-linux-intel.yml +++ b/.github/workflows/build-linux-intel.yml @@ -35,12 +35,6 @@ jobs: python-version: 3.x - run: pip install mkdocs-material mkdocs-git-revision-date-localized-plugin mkdocs-git-committers-plugin-2 mkdocs-git-authors-plugin "mkdocs-material[imaging]" - - name: Install Conan - uses: conan-io/setup-conan@v1 - with: - home: ${{ github.workspace }}/build/sdk - cache_packages: false - - name: Compile Release run: make release CPU_CORES=4 TESTNET=${{ inputs.chain-network == 'testnet' && '1' || '0' }} @@ -50,4 +44,4 @@ jobs: chain-network: ${{ inputs.chain-network }} assets: lethean-* asset-type: 'cli' - asset-directory: ${{ github.workspace }}/build/release/packages + asset-directory: ${{ github.workspace }}/build/packages diff --git a/.github/workflows/build-macos-arm64.yml b/.github/workflows/build-macos-arm64.yml index 24c3249d..f5de4d66 100644 --- a/.github/workflows/build-macos-arm64.yml +++ b/.github/workflows/build-macos-arm64.yml @@ -35,12 +35,6 @@ jobs: - run: pip install mkdocs-material mkdocs-git-revision-date-localized-plugin mkdocs-git-committers-plugin-2 mkdocs-git-authors-plugin "mkdocs-material[imaging]" - - name: Install Conan - uses: conan-io/setup-conan@v1 - with: - home: ${{ github.workspace }}/build/sdk - cache_packages: false - # - name: Compile Release # run: make apple-clang-armv8 TESTNET=${{ inputs.chain-network == 'testnet' && '1' || '0' }} @@ -54,4 +48,4 @@ jobs: chain-network: ${{ inputs.chain-network }} assets: lethean-* asset-type: 'cli' - asset-directory: ${{ github.workspace }}/build/release/packages + asset-directory: ${{ github.workspace }}/build/packages diff --git a/.github/workflows/build-macos-intel.yml b/.github/workflows/build-macos-intel.yml index 15b50386..be0b02ff 100644 --- a/.github/workflows/build-macos-intel.yml +++ b/.github/workflows/build-macos-intel.yml @@ -21,7 +21,6 @@ jobs: fetch-depth: 0 submodules: recursive - - name: Cache SDK Folder uses: actions/cache@v4 with: @@ -33,12 +32,6 @@ jobs: python-version: 3.x - run: pip install mkdocs-material mkdocs-git-revision-date-localized-plugin mkdocs-git-committers-plugin-2 mkdocs-git-authors-plugin "mkdocs-material[imaging]" - - name: Install Conan - uses: conan-io/setup-conan@v1 - with: - home: ${{ github.workspace }}/build/sdk - cache_packages: false - - name: Compile Release run: make release CPU_CORES=4 TESTNET=${{ inputs.chain-network == 'testnet' && '1' || '0' }} @@ -48,4 +41,4 @@ jobs: chain-network: ${{ inputs.chain-network }} assets: lethean-* asset-type: 'cli' - asset-directory: ${{ github.workspace }}/build/release/packages + asset-directory: ${{ github.workspace }}/build/packages diff --git a/.github/workflows/build-windows-intel.yml b/.github/workflows/build-windows-intel.yml index 1d59e014..369b746f 100644 --- a/.github/workflows/build-windows-intel.yml +++ b/.github/workflows/build-windows-intel.yml @@ -32,12 +32,6 @@ jobs: python-version: 3.x - run: pip install mkdocs-material mkdocs-git-revision-date-localized-plugin mkdocs-git-committers-plugin-2 mkdocs-git-authors-plugin "mkdocs-material[imaging]" - - name: Install Conan - uses: conan-io/setup-conan@v1 - with: - home: ${{ github.workspace }}/build/sdk - cache_packages: false - - name: Compile Release run: make release CPU_CORES=4 TESTNET=${{ inputs.chain-network == 'testnet' && '1' || '0' }} @@ -47,4 +41,4 @@ jobs: chain-network: ${{ inputs.chain-network }} assets: lethean-* asset-type: 'cli' - asset-directory: ${{ github.workspace }}/build/release/packages + asset-directory: ${{ github.workspace }}/build/packages diff --git a/Makefile b/Makefile index e0b51891..7c87c19e 100644 --- a/Makefile +++ b/Makefile @@ -52,32 +52,19 @@ ifeq ($(OS),Windows_NT) endif endif -#testnet-genesis-new: -# $(eval command += $(cmake_release) $(testnet)) -# $(call CMAKE,$(dir_release),$(command) -DGENERATE_PREMINE_WALLET=1 -DPREMINE_WALLET_PASSWORD=12345678) && cmake --build ./src --target premine_wallet || true -# $(eval command += $(cmake_release) $(testnet)) -# $(call CMAKE,$(dir_release),$(command) -DGENERATE_FRESH_GENESIS=1) && cmake --build ./src --target genesis_generator -# $(eval command += $(cmake_release) $(testnet)) -# $(call CMAKE,$(dir_release),$(command)) && $(MAKE) -# -#genesis-new: -# $(eval command += $(cmake_release)) -# $(call CMAKE,$(dir_release),$(command) -DGENERATE_FRESH_GENESIS=1) && cmake --build ./src --target genesis_generator -# $(eval command += $(cmake_release)) -# $(call CMAKE,$(dir_release),$(command)) && $(MAKE) - # ----------------------------------------------------------------- # Safety net – ensure we always have a positive integer. # ----------------------------------------------------------------- CPU_CORES := $(or $(CPU_CORES),1) CPU_CORES := $(shell expr $(CPU_CORES) + 0 2>/dev/null || echo 1) -#CONAN_CPU_COUNT=$(CPU_CORES) +CONAN_CPU_COUNT=$(CPU_CORES) PROFILES := $(patsubst cmake/profiles/%,%,$(wildcard cmake/profiles/*)) SORTED_PROFILES := $(sort $(PROFILES)) CONAN_CACHE := $(CURDIR)/build/sdk DEFAULT_CONAN_PROFILE := $(CONAN_CACHE)/profiles/default +CONAN_EXECUTABLE := $(CURDIR)/build/bin/conan CC_DOCKER_FILE?=utils/docker/images/lthn-chain/Dockerfile # Detect if we are on Windows ifeq ($(OS), Windows_NT) @@ -91,37 +78,40 @@ all: help release: docs build (cd $(BUILD_FOLDER) && cpack) + @rm -rf $(CURDIR)/build/packages/_CPack_Packages build: configure cmake --build $(BUILD_FOLDER) --config=$(BUILD_TYPE) --parallel=$(CPU_CORES) debug: conan-profile-detect @echo "Building profile: debug" - $(FIX_ENV) CONAN_HOME=$(CONAN_CACHE) conan install . --output-folder=build/debug --build=missing -s build_type=Debug + $(FIX_ENV) CONAN_HOME=$(CONAN_CACHE) $(CONAN_EXECUTABLE) install . --output-folder=build/debug --build=missing -s build_type=Debug cmake -S . -B build/debug -DCMAKE_TOOLCHAIN_FILE=build/debug/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Debug -DTESTNET=$(TESTNET) cmake --build build/debug --config=Debug --parallel=$(CPU_CORES) build-deps: conan-profile-detect @echo "Build Dependencies: $(BUILD_TYPE) testnet=$(TESTNET)" - $(FIX_ENV) CONAN_HOME=$(CONAN_CACHE) conan install . --build=missing -s build_type=$(BUILD_TYPE) + $(FIX_ENV) CONAN_HOME=$(CONAN_CACHE) $(CONAN_EXECUTABLE) install . --build=missing -s build_type=$(BUILD_TYPE) configure: build-deps @echo "Running Configure: $(BUILD_TYPE) testnet=$(TESTNET)" cmake -S . -B $(BUILD_FOLDER) -DCMAKE_TOOLCHAIN_FILE=$(BUILD_FOLDER)/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DSTATIC=$(STATIC) -DTESTNET=$(TESTNET) -DBUILD_VERSION=$(BUILD_VERSION) +get-conan: + cmake -P cmake/GetConan.cmake -conan-profile-detect: +conan-profile-detect: get-conan @if [ ! -f "$(DEFAULT_CONAN_PROFILE)" ]; then \ echo "Default conan profile not found. Detecting a new one..."; \ - CONAN_HOME=$(CONAN_CACHE) conan profile detect --name=default --force; \ + CONAN_HOME=$(CONAN_CACHE) $(CONAN_EXECUTABLE) profile detect --name=default --force; \ fi # Rule for each profile $(PROFILES): conan-profile-detect @echo "Building profile: $@" - CFLAGS="" CXXFLAGS="" CONAN_HOME=$(CONAN_CACHE) conan install . -pr:h=cmake/profiles/$@ --build=missing -s build_type=$(BUILD_TYPE) + CFLAGS="" CXXFLAGS="" CONAN_HOME=$(CONAN_CACHE) $(CONAN_EXECUTABLE) install . -pr:h=cmake/profiles/$@ --build=missing -s build_type=$(BUILD_TYPE) cmake -S . -B $(BUILD_FOLDER) -DCMAKE_TOOLCHAIN_FILE=$(BUILD_FOLDER)/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DSTATIC=$(STATIC) -DTESTNET=$(TESTNET) -DBUILD_VERSION=$(BUILD_VERSION) cmake --build $(BUILD_FOLDER) --config=$(BUILD_TYPE) --parallel=$(CPU_CORES) (cd $(BUILD_FOLDER) && cpack) @@ -129,6 +119,7 @@ $(PROFILES): conan-profile-detect help: @echo "Available targets:" @printf " %-42s %s\n" "make clean" "Clean all build directories" + @printf " %-42s %s\n" "make get-conan" "Download and install conan locally" @printf " %-42s %s\n" "make release" "Build release" @printf " %-42s %s\n" "make static" "Build static release" @printf " %-42s %s\n" "make debug" "Build debug" @@ -147,14 +138,14 @@ help: test: test-release test-release: @echo "Building profile: test-release" - CONAN_HOME=$(CONAN_CACHE) conan install . --output-folder=build/test-release --build=missing -s build_type=$(BUILD_TYPE) + CONAN_HOME=$(CONAN_CACHE) $(CONAN_EXECUTABLE) install . --output-folder=build/test-release --build=missing -s build_type=$(BUILD_TYPE) cmake -S . -B build/test-release -DCMAKE_TOOLCHAIN_FILE=build/test-release/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release -D BUILD_TESTS=ON cmake --build build/test-release --config=Release --parallel=$(CPU_CORES) $(MAKE) test test-debug: @echo "Building profile: test-debug" - CONAN_HOME=$(CONAN_CACHE) conan install . --output-folder=build/test-debug --build=missing -s build_type=$(BUILD_TYPE) + CONAN_HOME=$(CONAN_CACHE) $(CONAN_EXECUTABLE) install . --output-folder=build/test-debug --build=missing -s build_type=$(BUILD_TYPE) cmake -S . -B build/test-debug -DCMAKE_TOOLCHAIN_FILE=build/test-debug/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Debug -D BUILD_TESTS=ON cmake --build build/test-debug --config=Debug --parallel=$(CPU_CORES) $(MAKE) test @@ -168,11 +159,13 @@ docs-dev: configure @echo "Building Documentation" cmake --build build/release --target=serve_docs --config=Release - clean: + @cmake -P cmake/CleanBuild.cmake + +clean-build: rm -rf build tags: ctags -R --sort=1 --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ src contrib tests/gtest -.PHONY: all release docker-chain-node debug docs docs-dev configure static static-release test test-release test-debug clean tags conan-profile-detect $(PROFILES) +.PHONY: all release docker-chain-node debug docs docs-dev configure static static-release test test-release test-debug clean tags conan-profile-detect get-conan $(PROFILES) diff --git a/cmake/CPackConfig.cmake b/cmake/CPackConfig.cmake index 47f03de9..c120a637 100644 --- a/cmake/CPackConfig.cmake +++ b/cmake/CPackConfig.cmake @@ -56,7 +56,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.txt") # set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md") - set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/packages") + set(CPACK_PACKAGE_DIRECTORY "${CMAKE_SOURCE_DIR}/build/packages") install(FILES README.md LICENSE.txt DESTINATION "share/doc/${PROJECT_NAME}" diff --git a/cmake/conan_provider.cmake b/cmake/conan_provider.cmake index d39187c6..cffc6751 100644 --- a/cmake/conan_provider.cmake +++ b/cmake/conan_provider.cmake @@ -565,7 +565,19 @@ macro(conan_provide_dependency method package_name) set_property(GLOBAL PROPERTY CONAN_PROVIDE_DEPENDENCY_INVOKED TRUE) get_property(_conan_install_success GLOBAL PROPERTY CONAN_INSTALL_SUCCESS) if(NOT _conan_install_success) - find_program(CONAN_COMMAND "conan" REQUIRED) + set(CONAN_COMMAND "${CMAKE_SOURCE_DIR}/build/bin/conan/bin/conan") + if(NOT EXISTS ${CONAN_COMMAND}) + message(STATUS "CMake-Conan: Local conan not found, attempting to download it.") + execute_process(COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_LIST_DIR}/GetConan.cmake + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) + if(NOT result EQUAL 0) + message(FATAL_ERROR "Failed to download conan.") + endif() + endif() + if(NOT EXISTS ${CONAN_COMMAND}) + message(FATAL_ERROR "Conan executable not found at ${CONAN_COMMAND} after trying to download it. Also, make sure it has execution permissions.") + endif() conan_get_version(${CONAN_COMMAND} CONAN_CURRENT_VERSION) conan_version_check(MINIMUM ${CONAN_MINIMUM_VERSION} CURRENT ${CONAN_CURRENT_VERSION}) message(STATUS "CMake-Conan: first find_package() found. Installing dependencies with Conan") diff --git a/utils/docker/images/lthn-chain/Dockerfile b/utils/docker/images/lthn-chain/Dockerfile index aecf275a..6b7d08a4 100644 --- a/utils/docker/images/lthn-chain/Dockerfile +++ b/utils/docker/images/lthn-chain/Dockerfile @@ -19,7 +19,7 @@ RUN apt install -y build-essential pkgconf \ g++ llvm clang lld cmake python-is-python3 \ git python3 python3-pip python3-dev xz-utils gperf -RUN pip3 install conan mkdocs-git-revision-date-localized-plugin mkdocs-git-committers-plugin-2 mkdocs-git-authors-plugin mkdocs-material[imaging] --break-system-packages +RUN pip3 install mkdocs-git-revision-date-localized-plugin mkdocs-git-committers-plugin-2 mkdocs-git-authors-plugin mkdocs-material[imaging] --break-system-packages WORKDIR / From 3fcee22c868c7fe6a5168722ce6ee97b7f169b08 Mon Sep 17 00:00:00 2001 From: snider Date: Mon, 6 Oct 2025 16:06:09 +0100 Subject: [PATCH 04/19] Fix asset glob pattern in build-docs.yml for artifact upload --- .github/workflows/build-docs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index ad99155f..93c910bb 100644 --- a/.github/workflows/build-docs.yml +++ b/.github/workflows/build-docs.yml @@ -32,6 +32,6 @@ jobs: uses: ./.github/actions/upload-artifacts with: chain-network: ${{ inputs.chain-network }} - assets: * + assets: "*" asset-type: 'docs' asset-directory: ${{ github.workspace }}/build/docs From 6c35d636b3bb6e83a1fa1de52a101891c3e9c158 Mon Sep 17 00:00:00 2001 From: snider Date: Mon, 6 Oct 2025 16:44:06 +0100 Subject: [PATCH 05/19] Add ccache support and update caching paths in build configurations --- .github/workflows/build-linux-arm64.yml | 5 ++++- .github/workflows/build-linux-intel.yml | 5 ++++- .github/workflows/build-macos-arm64.yml | 5 ++++- .github/workflows/build-macos-intel.yml | 5 ++++- .github/workflows/build-windows-intel.yml | 5 ++++- CMakeLists.txt | 7 +++++- cmake/CleanBuild.cmake | 1 + cmake/FindCcache.cmake | 26 +++++++++++++++++++++++ conanfile.py | 2 ++ 9 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 cmake/FindCcache.cmake diff --git a/.github/workflows/build-linux-arm64.yml b/.github/workflows/build-linux-arm64.yml index e38c6fbe..89005d1d 100644 --- a/.github/workflows/build-linux-arm64.yml +++ b/.github/workflows/build-linux-arm64.yml @@ -27,7 +27,10 @@ jobs: - name: Cache SDK Folder uses: actions/cache@v4 with: - path: ${{ github.workspace }}/build/sdk + path: | + ${{ github.workspace }}/build/.ccache + ${{ github.workspace }}/build/sdk + ${{ github.workspace }}/build/bin key: ${{ runner.os }}-${{ runner.arch }}-sdk - uses: actions/setup-python@v5 diff --git a/.github/workflows/build-linux-intel.yml b/.github/workflows/build-linux-intel.yml index 465e6c5e..1d530dc6 100644 --- a/.github/workflows/build-linux-intel.yml +++ b/.github/workflows/build-linux-intel.yml @@ -27,7 +27,10 @@ jobs: - name: Cache SDK Folder uses: actions/cache@v4 with: - path: ${{ github.workspace }}/build/sdk + path: | + ${{ github.workspace }}/build/.ccache + ${{ github.workspace }}/build/sdk + ${{ github.workspace }}/build/bin key: ${{ runner.os }}-${{ runner.arch }}-sdk - uses: actions/setup-python@v5 diff --git a/.github/workflows/build-macos-arm64.yml b/.github/workflows/build-macos-arm64.yml index f5de4d66..1b469ef3 100644 --- a/.github/workflows/build-macos-arm64.yml +++ b/.github/workflows/build-macos-arm64.yml @@ -26,7 +26,10 @@ jobs: - name: Cache SDK Folder uses: actions/cache@v4 with: - path: ${{ github.workspace }}/build/sdk + path: | + ${{ github.workspace }}/build/.ccache + ${{ github.workspace }}/build/sdk + ${{ github.workspace }}/build/bin key: ${{ runner.os }}-${{ runner.arch }}-sdk - uses: actions/setup-python@v5 diff --git a/.github/workflows/build-macos-intel.yml b/.github/workflows/build-macos-intel.yml index be0b02ff..a18f5803 100644 --- a/.github/workflows/build-macos-intel.yml +++ b/.github/workflows/build-macos-intel.yml @@ -24,7 +24,10 @@ jobs: - name: Cache SDK Folder uses: actions/cache@v4 with: - path: ${{ github.workspace }}/build/sdk + path: | + ${{ github.workspace }}/build/.ccache + ${{ github.workspace }}/build/sdk + ${{ github.workspace }}/build/bin key: ${{ runner.os }}-${{ runner.arch }}-sdk - uses: actions/setup-python@v5 diff --git a/.github/workflows/build-windows-intel.yml b/.github/workflows/build-windows-intel.yml index 369b746f..8b085681 100644 --- a/.github/workflows/build-windows-intel.yml +++ b/.github/workflows/build-windows-intel.yml @@ -24,7 +24,10 @@ jobs: - name: Cache SDK Folder uses: actions/cache@v4 with: - path: ${{ github.workspace }}/build/sdk + path: | + ${{ github.workspace }}/build/.ccache + ${{ github.workspace }}/build/sdk + ${{ github.workspace }}/build/bin key: ${{ runner.os }}-${{ runner.arch }}-sdk - uses: actions/setup-python@v5 diff --git a/CMakeLists.txt b/CMakeLists.txt index ecaf33c5..abc1cd54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,6 @@ PROJECT(Lethean) set(VERSION "1.0" CACHE STRING "Build version") - message("OPENSSL_INCLUDE_DIR: ${OPENSSL_INCLUDE_DIR}") message("OPENSSL_CRYPTO_LIBRARY: ${OPENSSL_CRYPTO_LIBRARY}") message("OPENSSL_SSL_LIBRARY: ${OPENSSL_SSL_LIBRARY}") @@ -15,6 +14,12 @@ message("OPENSSL_SSL_LIBRARY: ${OPENSSL_SSL_LIBRARY}") list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(DocBuilder) +option (USE_CCACHE "Use ccache if a usable instance is found" ON) +if (USE_CCACHE) + include(FindCcache) +else() + message(STATUS "ccache deselected") +endif() if(POLICY CMP0043) cmake_policy(SET CMP0043 NEW) diff --git a/cmake/CleanBuild.cmake b/cmake/CleanBuild.cmake index b0b2473b..2c6616b1 100644 --- a/cmake/CleanBuild.cmake +++ b/cmake/CleanBuild.cmake @@ -21,6 +21,7 @@ function(selective_clean_build_dir) # List of top-level items in the build directory to keep. set(golden_items + "${CMAKE_SOURCE_DIR}/build/.ccache" "${CMAKE_SOURCE_DIR}/build/bin" "${CMAKE_SOURCE_DIR}/build/docs" "${CMAKE_SOURCE_DIR}/build/sdk" diff --git a/cmake/FindCcache.cmake b/cmake/FindCcache.cmake new file mode 100644 index 00000000..47a23cfa --- /dev/null +++ b/cmake/FindCcache.cmake @@ -0,0 +1,26 @@ +find_program(CCACHE_FOUND ccache) +if (CCACHE_FOUND) + # Try to compile a test program with ccache, in order to verify if it really works. (needed on exotic setups) + set(TEST_PROJECT "${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CMakeTmp") + file(WRITE "${TEST_PROJECT}/CMakeLists.txt" [=[ +cmake_minimum_required(VERSION 3.10) +project(test) +option (CCACHE "") +file(WRITE "${CMAKE_SOURCE_DIR}/test.cpp" "int main() { return 0; }") +set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE} cache_dir=${CMAKE_SOURCE_DIR}/build/.ccache") +set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE} cache_dir=${CMAKE_SOURCE_DIR}/build/.ccache") +add_executable(main test.cpp) +]=]) + try_compile(RET "${TEST_PROJECT}/build" "${TEST_PROJECT}" "test" CMAKE_FLAGS -DCCACHE="${CCACHE_FOUND}") + unset(TEST_PROJECT) + if (${RET}) + # Success + message(STATUS "Found usable ccache: ${CCACHE_FOUND}") + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_FOUND} cache_dir=${CMAKE_SOURCE_DIR}/build/.ccache") + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_FOUND} cache_dir=${CMAKE_SOURCE_DIR}/build/.ccache") + else() + message(STATUS "Found ccache ${CCACHE_FOUND}, but is UNUSABLE! Return code: ${RET}") + endif() +else() + message(STATUS "ccache NOT found! Please install it for faster rebuilds.") +endif() \ No newline at end of file diff --git a/conanfile.py b/conanfile.py index efed9a7b..e8ae447c 100644 --- a/conanfile.py +++ b/conanfile.py @@ -18,6 +18,8 @@ class BlockchainConan(ConanFile): "testnet": False } + tool_requires = "ccache/4.11" + requires = [ "zlib/1.3.1", "boost/1.85.0", From 1e17cd41e61cbed5650df1046ba8f368795baf53 Mon Sep 17 00:00:00 2001 From: snider Date: Mon, 6 Oct 2025 17:04:54 +0100 Subject: [PATCH 06/19] Update permissions in build-docs.yml and adjust Conan installation paths in GetConan.cmake --- .github/workflows/build-docs.yml | 2 +- cmake/GetConan.cmake | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index 93c910bb..3fbcd9fb 100644 --- a/.github/workflows/build-docs.yml +++ b/.github/workflows/build-docs.yml @@ -1,6 +1,6 @@ name: docs permissions: - contents: read + contents: write on: workflow_call: diff --git a/cmake/GetConan.cmake b/cmake/GetConan.cmake index ebbf2359..a1796dab 100644 --- a/cmake/GetConan.cmake +++ b/cmake/GetConan.cmake @@ -12,14 +12,18 @@ set(CONAN_URL_WINDOWS_X86_64 "https://github.com/conan-io/conan/releases/downloa set(CONAN_URL_WINDOWS_ARM64 "https://github.com/conan-io/conan/releases/download/${CONAN_VERSION}/conan-${CONAN_VERSION}-windows-arm64.zip") set(CONAN_URL_LINUX_X86_64 "https://github.com/conan-io/conan/releases/download/${CONAN_VERSION}/conan-${CONAN_VERSION}-linux-x86_64.tgz") set(CONAN_URL_LINUX_AARCH64 "https://github.com/conan-io/conan/releases/download/${CONAN_VERSION}/conan-${CONAN_VERSION}-linux-aarch64.tgz") -set(CONAN_INSTALL_DIR "${CMAKE_SOURCE_DIR}/build") + # Set the installation directory if(NOT CMAKE_BINARY_DIR) set(CMAKE_BINARY_DIR "${CONAN_INSTALL_DIR}") endif() - -set(CONAN_EXECUTABLE "${CONAN_INSTALL_DIR}/bin/conan") - +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + set(CONAN_EXECUTABLE "${CONAN_INSTALL_DIR}/bin/conan.exe") + set(CONAN_INSTALL_DIR "${CMAKE_SOURCE_DIR}/build/bin") +else () + set(CONAN_EXECUTABLE "${CONAN_INSTALL_DIR}/bin/conan") + set(CONAN_INSTALL_DIR "${CMAKE_SOURCE_DIR}/build") +endif () # Check if Conan is already installed if(NOT EXISTS "${CONAN_EXECUTABLE}") message(STATUS "Conan not found. Downloading and installing...") @@ -44,7 +48,7 @@ if(NOT EXISTS "${CONAN_EXECUTABLE}") set(CONAN_ARCHIVE_TYPE "zip") endif() elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") - if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64") + if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64|arm64") set(CONAN_URL ${CONAN_URL_LINUX_AARCH64}) set(CONAN_ARCHIVE_TYPE "tgz") else() From 5efd4b0e6be7c30f8d0483ce0431b4281f989772 Mon Sep 17 00:00:00 2001 From: snider Date: Mon, 6 Oct 2025 17:11:47 +0100 Subject: [PATCH 07/19] Fix Conan command path for Windows and update ARM64 processor check in GetConan.cmake --- cmake/GetConan.cmake | 2 +- cmake/conan_provider.cmake | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cmake/GetConan.cmake b/cmake/GetConan.cmake index a1796dab..af32c546 100644 --- a/cmake/GetConan.cmake +++ b/cmake/GetConan.cmake @@ -48,7 +48,7 @@ if(NOT EXISTS "${CONAN_EXECUTABLE}") set(CONAN_ARCHIVE_TYPE "zip") endif() elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") - if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64|arm64") + if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM64") set(CONAN_URL ${CONAN_URL_LINUX_AARCH64}) set(CONAN_ARCHIVE_TYPE "tgz") else() diff --git a/cmake/conan_provider.cmake b/cmake/conan_provider.cmake index cffc6751..c5904c5d 100644 --- a/cmake/conan_provider.cmake +++ b/cmake/conan_provider.cmake @@ -565,7 +565,11 @@ macro(conan_provide_dependency method package_name) set_property(GLOBAL PROPERTY CONAN_PROVIDE_DEPENDENCY_INVOKED TRUE) get_property(_conan_install_success GLOBAL PROPERTY CONAN_INSTALL_SUCCESS) if(NOT _conan_install_success) - set(CONAN_COMMAND "${CMAKE_SOURCE_DIR}/build/bin/conan/bin/conan") + if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + set(CONAN_COMMAND "${CMAKE_SOURCE_DIR}/build/bin/conan.exe") + else () + set(CONAN_COMMAND "${CMAKE_SOURCE_DIR}/build/bin/conan") + endif () if(NOT EXISTS ${CONAN_COMMAND}) message(STATUS "CMake-Conan: Local conan not found, attempting to download it.") execute_process(COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_LIST_DIR}/GetConan.cmake From 5acd82799d4824f1dec77608f003b014b7305907 Mon Sep 17 00:00:00 2001 From: snider Date: Mon, 6 Oct 2025 17:17:56 +0100 Subject: [PATCH 08/19] Add status message for OS and architecture detection in GetConan.cmake --- cmake/GetConan.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/GetConan.cmake b/cmake/GetConan.cmake index af32c546..b219baec 100644 --- a/cmake/GetConan.cmake +++ b/cmake/GetConan.cmake @@ -31,6 +31,7 @@ if(NOT EXISTS "${CONAN_EXECUTABLE}") file(MAKE_DIRECTORY "${CONAN_INSTALL_DIR}") # Detect the operating system and architecture + message(STATUS "Detecting OS and architecture: ${CMAKE_HOST_SYSTEM_PROCESSOR} on ${CMAKE_HOST_SYSTEM_NAME}") if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "arm64") set(CONAN_URL ${CONAN_URL_MACOS_ARM}) From c5ebeeca065e824639f80095d1a6d1918de56589 Mon Sep 17 00:00:00 2001 From: snider Date: Mon, 6 Oct 2025 17:23:53 +0100 Subject: [PATCH 09/19] Add boost option to disable tests and set C++ standard to C++17 in conanfile.py --- conanfile.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/conanfile.py b/conanfile.py index e8ae447c..29d86224 100644 --- a/conanfile.py +++ b/conanfile.py @@ -15,7 +15,8 @@ class BlockchainConan(ConanFile): } default_options = { "static": False, - "testnet": False + "testnet": False, + "boost/*:without_test": True } tool_requires = "ccache/4.11" @@ -28,6 +29,10 @@ class BlockchainConan(ConanFile): "jwt-cpp/0.7.1" ] + def configure(self): + if self.settings.compiler.get_safe("cppstd"): + self.settings.compiler.cppstd = "17" + def generate(self): tc = CMakeToolchain(self) tc.user_presets_path = False From eacc0a9f1c732ada496030b0f706fd7b2ff4996c Mon Sep 17 00:00:00 2001 From: snider Date: Mon, 6 Oct 2025 17:34:55 +0100 Subject: [PATCH 10/19] Fix quoting issues in CMake scripts and enhance OS/architecture detection logic --- cmake/CleanBuild.cmake | 2 +- cmake/GetConan.cmake | 19 +++++++++++++------ cmake/conan_provider.cmake | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/cmake/CleanBuild.cmake b/cmake/CleanBuild.cmake index 2c6616b1..0a1146db 100644 --- a/cmake/CleanBuild.cmake +++ b/cmake/CleanBuild.cmake @@ -36,7 +36,7 @@ function(selective_clean_build_dir) string(FIND "${item}" "${CMAKE_SOURCE_DIR}/build" is_prefixed) if(is_prefixed EQUAL 0) message(STATUS "Removing: ${item}") - if(IS_DIRECTORY ${item}) + if(IS_DIRECTORY "${item}") file(REMOVE_RECURSE "${item}") else() file(REMOVE "${item}") diff --git a/cmake/GetConan.cmake b/cmake/GetConan.cmake index b219baec..37bf7d1d 100644 --- a/cmake/GetConan.cmake +++ b/cmake/GetConan.cmake @@ -18,11 +18,11 @@ if(NOT CMAKE_BINARY_DIR) set(CMAKE_BINARY_DIR "${CONAN_INSTALL_DIR}") endif() if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") - set(CONAN_EXECUTABLE "${CONAN_INSTALL_DIR}/bin/conan.exe") set(CONAN_INSTALL_DIR "${CMAKE_SOURCE_DIR}/build/bin") + set(CONAN_EXECUTABLE "${CONAN_INSTALL_DIR}/bin/conan.exe") else () - set(CONAN_EXECUTABLE "${CONAN_INSTALL_DIR}/bin/conan") set(CONAN_INSTALL_DIR "${CMAKE_SOURCE_DIR}/build") + set(CONAN_EXECUTABLE "${CONAN_INSTALL_DIR}/bin/conan") endif () # Check if Conan is already installed if(NOT EXISTS "${CONAN_EXECUTABLE}") @@ -30,10 +30,17 @@ if(NOT EXISTS "${CONAN_EXECUTABLE}") file(MAKE_DIRECTORY "${CONAN_INSTALL_DIR}") + # Determine the processor architecture, with a fallback + if(CMAKE_HOST_SYSTEM_PROCESSOR) + set(HOST_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}) + else() + set(HOST_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR}) + endif() + # Detect the operating system and architecture - message(STATUS "Detecting OS and architecture: ${CMAKE_HOST_SYSTEM_PROCESSOR} on ${CMAKE_HOST_SYSTEM_NAME}") + message(STATUS "Detecting OS and architecture: ${HOST_PROCESSOR} on ${CMAKE_HOST_SYSTEM_NAME}") if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") - if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "arm64") + if(HOST_PROCESSOR MATCHES "arm64") set(CONAN_URL ${CONAN_URL_MACOS_ARM}) set(CONAN_ARCHIVE_TYPE "tgz") else() @@ -41,7 +48,7 @@ if(NOT EXISTS "${CONAN_EXECUTABLE}") set(CONAN_ARCHIVE_TYPE "tgz") endif() elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") - if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "ARM64") + if(HOST_PROCESSOR MATCHES "ARM64") set(CONAN_URL ${CONAN_URL_WINDOWS_ARM64}) set(CONAN_ARCHIVE_TYPE "zip") else() @@ -49,7 +56,7 @@ if(NOT EXISTS "${CONAN_EXECUTABLE}") set(CONAN_ARCHIVE_TYPE "zip") endif() elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") - if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM64") + if(HOST_PROCESSOR MATCHES "aarch64|arm64|ARM64") set(CONAN_URL ${CONAN_URL_LINUX_AARCH64}) set(CONAN_ARCHIVE_TYPE "tgz") else() diff --git a/cmake/conan_provider.cmake b/cmake/conan_provider.cmake index c5904c5d..1a6d9ec6 100644 --- a/cmake/conan_provider.cmake +++ b/cmake/conan_provider.cmake @@ -572,9 +572,9 @@ macro(conan_provide_dependency method package_name) endif () if(NOT EXISTS ${CONAN_COMMAND}) message(STATUS "CMake-Conan: Local conan not found, attempting to download it.") - execute_process(COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_LIST_DIR}/GetConan.cmake + execute_process(COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_LIST_DIR}/GetConan.cmake" RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}") if(NOT result EQUAL 0) message(FATAL_ERROR "Failed to download conan.") endif() From 958580d91d359f048afb294bd290beaa04a5f2fc Mon Sep 17 00:00:00 2001 From: snider Date: Mon, 6 Oct 2025 18:22:26 +0100 Subject: [PATCH 11/19] Improve processor detection logic in GetConan.cmake by using cmake_host_system_information --- cmake/GetConan.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/GetConan.cmake b/cmake/GetConan.cmake index 37bf7d1d..fb6e8666 100644 --- a/cmake/GetConan.cmake +++ b/cmake/GetConan.cmake @@ -34,7 +34,7 @@ if(NOT EXISTS "${CONAN_EXECUTABLE}") if(CMAKE_HOST_SYSTEM_PROCESSOR) set(HOST_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}) else() - set(HOST_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR}) + cmake_host_system_information(RESULT HOST_PROCESSOR QUERY OS_PLATFORM) endif() # Detect the operating system and architecture From 1131a97c250b09262dbfc2dcb2ed5750e8997142 Mon Sep 17 00:00:00 2001 From: snider Date: Mon, 6 Oct 2025 18:34:44 +0100 Subject: [PATCH 12/19] Set C++ standard to C++17 in conanfile.py and update Makefile to specify compiler settings --- Makefile | 2 +- conanfile.py | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 7c87c19e..83f7fd6c 100644 --- a/Makefile +++ b/Makefile @@ -92,7 +92,7 @@ debug: conan-profile-detect build-deps: conan-profile-detect @echo "Build Dependencies: $(BUILD_TYPE) testnet=$(TESTNET)" - $(FIX_ENV) CONAN_HOME=$(CONAN_CACHE) $(CONAN_EXECUTABLE) install . --build=missing -s build_type=$(BUILD_TYPE) + $(FIX_ENV) CONAN_HOME=$(CONAN_CACHE) $(CONAN_EXECUTABLE) install . --build=missing -s compiler.cppstd=17 -s build_type=$(BUILD_TYPE) configure: build-deps @echo "Running Configure: $(BUILD_TYPE) testnet=$(TESTNET)" diff --git a/conanfile.py b/conanfile.py index 29d86224..0d10f9cd 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,7 +1,7 @@ import os from conan import ConanFile -from conan.tools.cmake import cmake_layout, CMakeDeps, CMakeToolchain, CMake +from conan.tools.cmake import CMakeDeps, CMakeToolchain, CMake class BlockchainConan(ConanFile): @@ -29,10 +29,6 @@ class BlockchainConan(ConanFile): "jwt-cpp/0.7.1" ] - def configure(self): - if self.settings.compiler.get_safe("cppstd"): - self.settings.compiler.cppstd = "17" - def generate(self): tc = CMakeToolchain(self) tc.user_presets_path = False From eca04f4332bde771856bb89b59fa651ef16f16c8 Mon Sep 17 00:00:00 2001 From: snider Date: Mon, 6 Oct 2025 18:50:42 +0100 Subject: [PATCH 13/19] Update Makefile to set C++ standard to C++17 and improve Conan options for static runtime --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 83f7fd6c..f4958f60 100644 --- a/Makefile +++ b/Makefile @@ -66,13 +66,13 @@ CONAN_CACHE := $(CURDIR)/build/sdk DEFAULT_CONAN_PROFILE := $(CONAN_CACHE)/profiles/default CONAN_EXECUTABLE := $(CURDIR)/build/bin/conan CC_DOCKER_FILE?=utils/docker/images/lthn-chain/Dockerfile +CONAN_OPTIONS:= -s compiler.cppstd=17 # Detect if we are on Windows ifeq ($(OS), Windows_NT) # If so, define a prefix to clear the problematic env vars - FIX_ENV := CFLAGS="" CXXFLAGS="" + CONAN_OPTIONS+= -s compiler.runtime=static else # Otherwise, the prefix is empty - FIX_ENV := endif all: help @@ -85,14 +85,14 @@ build: configure debug: conan-profile-detect @echo "Building profile: debug" - $(FIX_ENV) CONAN_HOME=$(CONAN_CACHE) $(CONAN_EXECUTABLE) install . --output-folder=build/debug --build=missing -s build_type=Debug + CONAN_HOME=$(CONAN_CACHE) $(CONAN_EXECUTABLE) install . --output-folder=build/debug --build=missing -s build_type=Debug cmake -S . -B build/debug -DCMAKE_TOOLCHAIN_FILE=build/debug/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Debug -DTESTNET=$(TESTNET) cmake --build build/debug --config=Debug --parallel=$(CPU_CORES) build-deps: conan-profile-detect @echo "Build Dependencies: $(BUILD_TYPE) testnet=$(TESTNET)" - $(FIX_ENV) CONAN_HOME=$(CONAN_CACHE) $(CONAN_EXECUTABLE) install . --build=missing -s compiler.cppstd=17 -s build_type=$(BUILD_TYPE) + CONAN_HOME=$(CONAN_CACHE) $(CONAN_EXECUTABLE) install . --build=missing -s build_type=$(BUILD_TYPE) $(CONAN_OPTIONS) configure: build-deps @echo "Running Configure: $(BUILD_TYPE) testnet=$(TESTNET)" @@ -111,7 +111,7 @@ conan-profile-detect: get-conan # Rule for each profile $(PROFILES): conan-profile-detect @echo "Building profile: $@" - CFLAGS="" CXXFLAGS="" CONAN_HOME=$(CONAN_CACHE) $(CONAN_EXECUTABLE) install . -pr:h=cmake/profiles/$@ --build=missing -s build_type=$(BUILD_TYPE) + CONAN_HOME=$(CONAN_CACHE) $(CONAN_EXECUTABLE) install . -pr:h=cmake/profiles/$@ --build=missing -s build_type=$(BUILD_TYPE) cmake -S . -B $(BUILD_FOLDER) -DCMAKE_TOOLCHAIN_FILE=$(BUILD_FOLDER)/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DSTATIC=$(STATIC) -DTESTNET=$(TESTNET) -DBUILD_VERSION=$(BUILD_VERSION) cmake --build $(BUILD_FOLDER) --config=$(BUILD_TYPE) --parallel=$(CPU_CORES) (cd $(BUILD_FOLDER) && cpack) From c1f3b2e773014bbf8ad0d706a6009158c87e60d2 Mon Sep 17 00:00:00 2001 From: snider Date: Mon, 6 Oct 2025 19:21:06 +0100 Subject: [PATCH 14/19] Add Conan profile setup script and update Makefile for profile detection --- Makefile | 6 +---- cmake/ConanProfileSetup.cmake | 42 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 cmake/ConanProfileSetup.cmake diff --git a/Makefile b/Makefile index f4958f60..8bd8fa9b 100644 --- a/Makefile +++ b/Makefile @@ -102,11 +102,7 @@ get-conan: cmake -P cmake/GetConan.cmake conan-profile-detect: get-conan - @if [ ! -f "$(DEFAULT_CONAN_PROFILE)" ]; then \ - echo "Default conan profile not found. Detecting a new one..."; \ - CONAN_HOME=$(CONAN_CACHE) $(CONAN_EXECUTABLE) profile detect --name=default --force; \ - fi - + cmake -P cmake/ConanProfileSetup.cmake # Rule for each profile $(PROFILES): conan-profile-detect diff --git a/cmake/ConanProfileSetup.cmake b/cmake/ConanProfileSetup.cmake new file mode 100644 index 00000000..1291b669 --- /dev/null +++ b/cmake/ConanProfileSetup.cmake @@ -0,0 +1,42 @@ +# Use the CONAN_HOME from the environment, or default to a local directory. +if(NOT DEFINED ENV{CONAN_HOME}) + set(CONAN_HOME "${CMAKE_SOURCE_DIR}/build/sdk") + message(STATUS "CONAN_HOME not set, defaulting to: ${CONAN_HOME}") +else() + set(CONAN_HOME "$ENV{CONAN_HOME}") +endif() + +set(DEFAULT_PROFILE "${CONAN_HOME}/profiles/default") + + +if(NOT EXISTS "${DEFAULT_PROFILE}") + message(STATUS "Conan default profile not found. Detecting a new one...") + set(ENV{CONAN_HOME} "${CONAN_HOME}") + execute_process( + COMMAND "${CMAKE_SOURCE_DIR}/build/bin/conan" profile detect --name=default --force + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + RESULT_VARIABLE return_code + ) + unset(ENV{CONAN_HOME}) + + if(NOT return_code EQUAL 0) + message(FATAL_ERROR "Conan profile detection failed with exit code: ${return_code}") + endif() +endif() + +message(STATUS "Appending custom settings to Conan default profile...") + +set(CUSTOM_SETTINGS " +compiler.cppstd=17 +") + +if(WIN32) + message(STATUS "Windows detected. Appending static runtime setting.") + string(APPEND CUSTOM_SETTINGS " +compiler.runtime=static +") +endif() + +file(APPEND "${DEFAULT_PROFILE}" "${CUSTOM_SETTINGS}") + +message(STATUS "Conan profile setup is complete.") \ No newline at end of file From 2c9ebb4a9ee6813691619ecd1024328315bbdfe2 Mon Sep 17 00:00:00 2001 From: snider Date: Mon, 6 Oct 2025 19:43:20 +0100 Subject: [PATCH 15/19] Refactor Conan profile setup to simplify CONAN_HOME assignment and remove Windows-specific runtime settings --- cmake/ConanProfileSetup.cmake | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/cmake/ConanProfileSetup.cmake b/cmake/ConanProfileSetup.cmake index 1291b669..4ab9c164 100644 --- a/cmake/ConanProfileSetup.cmake +++ b/cmake/ConanProfileSetup.cmake @@ -1,14 +1,8 @@ # Use the CONAN_HOME from the environment, or default to a local directory. -if(NOT DEFINED ENV{CONAN_HOME}) - set(CONAN_HOME "${CMAKE_SOURCE_DIR}/build/sdk") - message(STATUS "CONAN_HOME not set, defaulting to: ${CONAN_HOME}") -else() - set(CONAN_HOME "$ENV{CONAN_HOME}") -endif() +set(CONAN_HOME "${CMAKE_SOURCE_DIR}/build/sdk") set(DEFAULT_PROFILE "${CONAN_HOME}/profiles/default") - if(NOT EXISTS "${DEFAULT_PROFILE}") message(STATUS "Conan default profile not found. Detecting a new one...") set(ENV{CONAN_HOME} "${CONAN_HOME}") @@ -30,12 +24,12 @@ set(CUSTOM_SETTINGS " compiler.cppstd=17 ") -if(WIN32) - message(STATUS "Windows detected. Appending static runtime setting.") - string(APPEND CUSTOM_SETTINGS " -compiler.runtime=static -") -endif() +#if(WIN32) +# message(STATUS "Windows detected. Appending static runtime setting.") +# string(APPEND CUSTOM_SETTINGS " +#compiler.runtime=static +#") +#endif() file(APPEND "${DEFAULT_PROFILE}" "${CUSTOM_SETTINGS}") From 119f4cb1eb1972a760e1d0036a4b7a3016c93128 Mon Sep 17 00:00:00 2001 From: Snider Date: Mon, 6 Oct 2025 19:44:47 +0100 Subject: [PATCH 16/19] Update cmake/GetConan.cmake Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cmake/GetConan.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/GetConan.cmake b/cmake/GetConan.cmake index fb6e8666..833aeb26 100644 --- a/cmake/GetConan.cmake +++ b/cmake/GetConan.cmake @@ -81,7 +81,7 @@ if(NOT EXISTS "${CONAN_EXECUTABLE}") RESULT_VARIABLE result ) elseif(CONAN_ARCHIVE_TYPE STREQUAL "zip") - # Cmake -E tar can handle zip files + # CMake -E tar can handle zip files execute_process( COMMAND ${CMAKE_COMMAND} -E tar xf "${CONAN_ARCHIVE}" WORKING_DIRECTORY "${CONAN_INSTALL_DIR}" From ad0a24f62d23919d450e8adf9b46ffa64ff7d68e Mon Sep 17 00:00:00 2001 From: Snider Date: Mon, 6 Oct 2025 19:45:35 +0100 Subject: [PATCH 17/19] Update cmake/GetConan.cmake Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cmake/GetConan.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/GetConan.cmake b/cmake/GetConan.cmake index 833aeb26..1a60eb2e 100644 --- a/cmake/GetConan.cmake +++ b/cmake/GetConan.cmake @@ -96,7 +96,7 @@ if(NOT EXISTS "${CONAN_EXECUTABLE}") # Clean up the archive file(REMOVE "${CONAN_ARCHIVE}") - message(STATUS "Conan installed successfully in ${CONAN_INSTALL_DIR}/conan") + message(STATUS "Conan installed successfully at ${CONAN_EXECUTABLE}") else() - message(STATUS "Conan already installed in ${CONAN_INSTALL_DIR}/conan") + message(STATUS "Conan already installed at ${CONAN_EXECUTABLE}") endif() From 0ecf2e7ebd7cdec02fdf08ce3a11b9ce30aff830 Mon Sep 17 00:00:00 2001 From: snider Date: Mon, 6 Oct 2025 19:50:49 +0100 Subject: [PATCH 18/19] Simplify conditional checks in GitHub Actions workflow for build jobs --- .github/workflows/_on-pr.yml | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/.github/workflows/_on-pr.yml b/.github/workflows/_on-pr.yml index 82bb74df..0d7aca87 100644 --- a/.github/workflows/_on-pr.yml +++ b/.github/workflows/_on-pr.yml @@ -39,9 +39,7 @@ jobs: build-linux-intel: name: Chain - if: | - (github.actor == 'Snider' && github.event.pull_request.user.login == 'Snider') || - (github.event.review.state == 'approved' && !github.event.pull_request.draft) + if: ${{!github.event.pull_request.draft}} uses: ./.github/workflows/build-linux-intel.yml secrets: inherit with: @@ -49,9 +47,7 @@ jobs: build-linux-arm: name: Chain - if: | - (github.actor == 'Snider' && github.event.pull_request.user.login == 'Snider') || - (github.event.review.state == 'approved' && !github.event.pull_request.draft) + if: ${{!github.event.pull_request.draft}} uses: ./.github/workflows/build-linux-arm64.yml secrets: inherit with: @@ -59,9 +55,7 @@ jobs: build-windows-intel: name: Chain - if: | - (github.actor == 'Snider' && github.event.pull_request.user.login == 'Snider') || - (github.event.review.state == 'approved' && !github.event.pull_request.draft) + if: ${{!github.event.pull_request.draft}} uses: ./.github/workflows/build-windows-intel.yml secrets: inherit with: @@ -69,9 +63,7 @@ jobs: build-macos-arm64: name: Chain - if: | - (github.actor == 'Snider' && github.event.pull_request.user.login == 'Snider') || - (github.event.review.state == 'approved' && !github.event.pull_request.draft) + if: ${{!github.event.pull_request.draft}} uses: ./.github/workflows/build-macos-arm64.yml secrets: inherit with: @@ -79,9 +71,7 @@ jobs: build-macos-intel: name: Chain - if: | - (github.actor == 'Snider' && github.event.pull_request.user.login == 'Snider') || - (github.event.review.state == 'approved' && !github.event.pull_request.draft) + if: ${{!github.event.pull_request.draft}} uses: ./.github/workflows/build-macos-intel.yml secrets: inherit with: @@ -89,9 +79,7 @@ jobs: build-docker: name: Docker - if: | - (github.actor == 'Snider' && github.event.pull_request.user.login == 'Snider') || - (github.event.review.state == 'approved' && !github.event.pull_request.draft) + if: ${{!github.event.pull_request.draft}} uses: ./.github/workflows/build-docker.yml secrets: inherit with: @@ -99,7 +87,5 @@ jobs: build-docs: name: Docs - if: | - (github.actor == 'Snider' && github.event.pull_request.user.login == 'Snider') || - (github.event.review.state == 'approved' && !github.event.pull_request.draft) + if: ${{!github.event.pull_request.draft}} uses: ./.github/workflows/build-docs.yml From e3dfe68ec8776c3a72e0a348c40c0c042041216a Mon Sep 17 00:00:00 2001 From: snider Date: Mon, 6 Oct 2025 20:12:37 +0100 Subject: [PATCH 19/19] Refactor Conan executable path handling and remove Windows-specific runtime settings from Makefile --- Makefile | 11 ++--------- cmake/ConanProfileSetup.cmake | 10 ++++++---- cmake/GetConan.cmake | 2 +- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 8bd8fa9b..c12611af 100644 --- a/Makefile +++ b/Makefile @@ -66,14 +66,7 @@ CONAN_CACHE := $(CURDIR)/build/sdk DEFAULT_CONAN_PROFILE := $(CONAN_CACHE)/profiles/default CONAN_EXECUTABLE := $(CURDIR)/build/bin/conan CC_DOCKER_FILE?=utils/docker/images/lthn-chain/Dockerfile -CONAN_OPTIONS:= -s compiler.cppstd=17 -# Detect if we are on Windows -ifeq ($(OS), Windows_NT) - # If so, define a prefix to clear the problematic env vars - CONAN_OPTIONS+= -s compiler.runtime=static -else - # Otherwise, the prefix is empty -endif + all: help release: docs build @@ -92,7 +85,7 @@ debug: conan-profile-detect build-deps: conan-profile-detect @echo "Build Dependencies: $(BUILD_TYPE) testnet=$(TESTNET)" - CONAN_HOME=$(CONAN_CACHE) $(CONAN_EXECUTABLE) install . --build=missing -s build_type=$(BUILD_TYPE) $(CONAN_OPTIONS) + CONAN_HOME=$(CONAN_CACHE) $(CONAN_EXECUTABLE) install . --build=missing -s build_type=$(BUILD_TYPE) configure: build-deps @echo "Running Configure: $(BUILD_TYPE) testnet=$(TESTNET)" diff --git a/cmake/ConanProfileSetup.cmake b/cmake/ConanProfileSetup.cmake index 4ab9c164..c6a0e803 100644 --- a/cmake/ConanProfileSetup.cmake +++ b/cmake/ConanProfileSetup.cmake @@ -1,13 +1,15 @@ -# Use the CONAN_HOME from the environment, or default to a local directory. - set(CONAN_HOME "${CMAKE_SOURCE_DIR}/build/sdk") set(DEFAULT_PROFILE "${CONAN_HOME}/profiles/default") - +if(WIN32) + set(CONAN_EXECUTABLE "${CMAKE_SOURCE_DIR}/build/bin/conan.exe") +else() + set(CONAN_EXECUTABLE "${CMAKE_SOURCE_DIR}/build/bin/conan") +endif() if(NOT EXISTS "${DEFAULT_PROFILE}") message(STATUS "Conan default profile not found. Detecting a new one...") set(ENV{CONAN_HOME} "${CONAN_HOME}") execute_process( - COMMAND "${CMAKE_SOURCE_DIR}/build/bin/conan" profile detect --name=default --force + COMMAND "${CONAN_EXECUTABLE}" profile detect --name=default --force WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" RESULT_VARIABLE return_code ) diff --git a/cmake/GetConan.cmake b/cmake/GetConan.cmake index 1a60eb2e..9b7437ee 100644 --- a/cmake/GetConan.cmake +++ b/cmake/GetConan.cmake @@ -19,7 +19,7 @@ if(NOT CMAKE_BINARY_DIR) endif() if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") set(CONAN_INSTALL_DIR "${CMAKE_SOURCE_DIR}/build/bin") - set(CONAN_EXECUTABLE "${CONAN_INSTALL_DIR}/bin/conan.exe") + set(CONAN_EXECUTABLE "${CMAKE_SOURCE_DIR}/build/bin/conan.exe") else () set(CONAN_INSTALL_DIR "${CMAKE_SOURCE_DIR}/build") set(CONAN_EXECUTABLE "${CONAN_INSTALL_DIR}/bin/conan")