From e4ff164f0d3afe16bc83faf96068fb66d5efe78d Mon Sep 17 00:00:00 2001 From: Snider Date: Mon, 6 Oct 2025 22:38:29 +0100 Subject: [PATCH] Build Simplification (#24) --- .github/workflows/_on-pr-fast.yml | 28 ------ .github/workflows/_on-pr.yml | 41 +++------ .github/workflows/_on-push.yml | 10 +-- .github/workflows/build-docs.yml | 32 +++---- .github/workflows/build-linux-arm64.yml | 52 ++++++++--- .github/workflows/build-linux-intel.yml | 52 +++++++++-- .github/workflows/build-macos-arm64.yml | 55 ++++++++---- .github/workflows/build-macos-intel.yml | 48 +++++++--- .github/workflows/build-windows-intel.yml | 49 ++++++++--- CMakeLists.txt | 22 +++-- Makefile | 54 ++++-------- cmake/CPackConfig.cmake | 2 +- cmake/CleanBuild.cmake | 58 ++++++++++++ cmake/ConanProfileSetup.cmake | 38 ++++++++ cmake/FindCcache.cmake | 8 ++ cmake/GetConan.cmake | 102 ++++++++++++++++++++++ cmake/conan_provider.cmake | 18 +++- conanfile.py | 7 +- utils/docker/images/lthn-chain/Dockerfile | 2 +- 19 files changed, 496 insertions(+), 182 deletions(-) delete mode 100644 .github/workflows/_on-pr-fast.yml create mode 100644 cmake/CleanBuild.cmake create mode 100644 cmake/ConanProfileSetup.cmake create mode 100644 cmake/FindCcache.cmake create mode 100644 cmake/GetConan.cmake diff --git a/.github/workflows/_on-pr-fast.yml b/.github/workflows/_on-pr-fast.yml deleted file mode 100644 index ee099f16..00000000 --- a/.github/workflows/_on-pr-fast.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: PR Fast -permissions: - contents: write -on: - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - pull_request: - types: - - opened - - synchronize - - reopened - branches: - - dev - - main - - dev-* - paths-ignore: - - '**.md' - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -jobs: - build-macos-arm64: - name: Compile - uses: ./.github/workflows/build-macos-arm64.yml - with: - chain-network: ${{ github.ref_name == 'main' && 'mainnet' || 'testnet' }} diff --git a/.github/workflows/_on-pr.yml b/.github/workflows/_on-pr.yml index 82bb74df..51a4bced 100644 --- a/.github/workflows/_on-pr.yml +++ b/.github/workflows/_on-pr.yml @@ -7,7 +7,9 @@ on: pull_request_review: pull_request: types: - - review_requested + - opened + - synchronize + - reopened - closed concurrency: @@ -38,50 +40,39 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 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) + name: Linux + if: ${{!github.event.pull_request.draft}} uses: ./.github/workflows/build-linux-intel.yml secrets: inherit with: chain-network: ${{ github.ref_name == 'main' && 'mainnet' || 'testnet' }} 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) + name: Linux + if: ${{!github.event.pull_request.draft}} uses: ./.github/workflows/build-linux-arm64.yml secrets: inherit with: chain-network: ${{ github.ref_name == 'main' && 'mainnet' || 'testnet' }} 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) + name: Windows + if: ${{!github.event.pull_request.draft}} uses: ./.github/workflows/build-windows-intel.yml secrets: inherit with: chain-network: ${{ github.ref_name == 'main' && 'mainnet' || 'testnet' }} 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) + name: MacOS uses: ./.github/workflows/build-macos-arm64.yml secrets: inherit with: chain-network: ${{ github.ref_name == 'main' && 'mainnet' || 'testnet' }} 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) + name: MacOS + if: ${{!github.event.pull_request.draft}} uses: ./.github/workflows/build-macos-intel.yml secrets: inherit with: @@ -89,9 +80,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 +88,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 diff --git a/.github/workflows/_on-push.yml b/.github/workflows/_on-push.yml index 38d9fb4c..747735e5 100644 --- a/.github/workflows/_on-push.yml +++ b/.github/workflows/_on-push.yml @@ -16,31 +16,31 @@ concurrency: jobs: build-linux-intel: - name: Chain + name: Linux uses: ./.github/workflows/build-linux-intel.yml with: chain-network: ${{ github.ref_name == 'main' && 'mainnet' || 'testnet' }} build-linux-arm: - name: Chain + name: Linux uses: ./.github/workflows/build-linux-arm64.yml with: chain-network: ${{ github.ref_name == 'main' && 'mainnet' || 'testnet' }} build-windows-intel: - name: Chain + name: Windows uses: ./.github/workflows/build-windows-intel.yml with: chain-network: ${{ github.ref_name == 'main' && 'mainnet' || 'testnet' }} build-macos-arm64: - name: Chain + name: MacOS uses: ./.github/workflows/build-macos-arm64.yml with: chain-network: ${{ github.ref_name == 'main' && 'mainnet' || 'testnet' }} build-macos-intel: - name: Chain + name: MacOS uses: ./.github/workflows/build-macos-intel.yml with: chain-network: ${{ github.ref_name == 'main' && 'mainnet' || 'testnet' }} diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index 336e75c3..6300c622 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: @@ -17,16 +17,13 @@ jobs: with: python-version: 3.x - - name: Install Conan - uses: conan-io/setup-conan@v1 + - name: Cache SDK Folder + uses: actions/cache@v4 with: - home: ${{ github.workspace }}/build/sdk - cache_packages: true - - - uses: actions/cache@v4 - with: - key: ${{ github.ref }} - path: .cache + path: | + ${{ github.workspace }}/build/sdk + ${{ github.workspace }}/build/bin + key: ${{ runner.os }}-${{ runner.arch }}-sdk - run: sudo apt-get install -y libcairo2-dev libfreetype6-dev libffi-dev libjpeg-dev libpng-dev libz-dev pngquant - run: pip install mkdocs-git-revision-date-localized-plugin mkdocs-git-committers-plugin-2 mkdocs-git-authors-plugin mkdocs-material[imaging] @@ -34,13 +31,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..6e15b24d 100644 --- a/.github/workflows/build-linux-arm64.yml +++ b/.github/workflows/build-linux-arm64.yml @@ -11,8 +11,45 @@ on: type: string jobs: + cache: + name: cache-arm64 + runs-on: ubuntu-22.04-arm + steps: + - name: Cache SDK Folder + id: cache + uses: actions/cache@v4 + with: + path: | + ${{ github.workspace }}/build/sdk + ${{ github.workspace }}/build/bin + key: ${{ runner.os }}-${{ runner.arch }}-sdk + + - name: Checkout Project + if: steps.cache.outputs.cache-hit != 'true' + uses: actions/checkout@v4.2.2 + with: + fetch-depth: 0 + submodules: recursive + + - name: install dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: sudo apt-get install -y autotools-dev git build-essential libcairo2-dev libfreetype6-dev libffi-dev libjpeg-dev libpng-dev libz-dev pngquant + + - uses: actions/setup-python@v5 + if: steps.cache.outputs.cache-hit != 'true' + with: + python-version: 3.x + + - if: steps.cache.outputs.cache-hit != 'true' + run: pip install mkdocs-material mkdocs-git-revision-date-localized-plugin mkdocs-git-committers-plugin-2 mkdocs-git-authors-plugin "mkdocs-material[imaging]" + + - name: Compile Dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: make build-deps CPU_CORES=4 TESTNET=${{ inputs.chain-network == 'testnet' && '1' || '0' }} + build: - name: gcc-linux-arm64 + name: compile-arm64 + needs: cache runs-on: ubuntu-22.04-arm steps: - name: Checkout Project @@ -27,7 +64,9 @@ jobs: - name: Cache SDK Folder uses: actions/cache@v4 with: - path: ${{ github.workspace }}/build/sdk + path: | + ${{ github.workspace }}/build/sdk + ${{ github.workspace }}/build/bin key: ${{ runner.os }}-${{ runner.arch }}-sdk - uses: actions/setup-python@v5 @@ -36,13 +75,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 +84,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..ba68329a 100644 --- a/.github/workflows/build-linux-intel.yml +++ b/.github/workflows/build-linux-intel.yml @@ -11,8 +11,46 @@ on: type: string jobs: + cache: + name: cache-x86_64 + runs-on: ubuntu-22.04 + steps: + - name: Cache SDK Folder + id: cache + uses: actions/cache@v4 + with: + lookup-only: true + path: | + ${{ github.workspace }}/build/sdk + ${{ github.workspace }}/build/bin + key: ${{ runner.os }}-${{ runner.arch }}-sdk + + - name: Checkout Project + if: steps.cache.outputs.cache-hit != 'true' + uses: actions/checkout@v4.2.2 + with: + fetch-depth: 0 + submodules: recursive + + - name: install dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: sudo apt-get install -y autotools-dev git build-essential + + - uses: actions/setup-python@v5 + if: steps.cache.outputs.cache-hit != 'true' + with: + python-version: 3.x + - if: steps.cache.outputs.cache-hit != 'true' + run: pip install mkdocs-material mkdocs-git-revision-date-localized-plugin mkdocs-git-committers-plugin-2 mkdocs-git-authors-plugin "mkdocs-material[imaging]" + + - name: Compile Dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: make build-deps CPU_CORES=4 TESTNET=${{ inputs.chain-network == 'testnet' && '1' || '0' }} + + build: - name: gcc-linux-x86_64 + name: compile-x86_64 + needs: cache runs-on: ubuntu-22.04 steps: - name: Checkout Project @@ -27,7 +65,9 @@ jobs: - name: Cache SDK Folder uses: actions/cache@v4 with: - path: ${{ github.workspace }}/build/sdk + path: | + ${{ github.workspace }}/build/sdk + ${{ github.workspace }}/build/bin key: ${{ runner.os }}-${{ runner.arch }}-sdk - uses: actions/setup-python@v5 @@ -35,12 +75,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 +84,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..8477d630 100644 --- a/.github/workflows/build-macos-arm64.yml +++ b/.github/workflows/build-macos-arm64.yml @@ -12,8 +12,42 @@ on: jobs: - build-cli: - name: apple-clang-armv8 + cache: + name: cache-armv8 + runs-on: macos-15 + steps: + - name: Cache SDK Folder + id: cache + uses: actions/cache@v4 + with: + lookup-only: true + path: | + ${{ github.workspace }}/build/sdk + ${{ github.workspace }}/build/bin + key: ${{ runner.os }}-${{ runner.arch }}-sdk + + - name: Checkout Project + if: steps.cache.outputs.cache-hit != 'true' + uses: actions/checkout@v4.2.2 + with: + fetch-depth: 0 + submodules: recursive + + - uses: actions/setup-python@v5 + if: steps.cache.outputs.cache-hit != 'true' + with: + python-version: 3.x + + - if: steps.cache.outputs.cache-hit != 'true' + run: pip install mkdocs-material mkdocs-git-revision-date-localized-plugin mkdocs-git-committers-plugin-2 mkdocs-git-authors-plugin "mkdocs-material[imaging]" + + - name: Compile Dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: make build-deps CPU_CORES=3 TESTNET=${{ inputs.chain-network == 'testnet' && '1' || '0' }} + + build: + name: compile-armv8 + needs: cache runs-on: macos-15 steps: - name: Checkout Project @@ -22,11 +56,12 @@ jobs: fetch-depth: 0 submodules: recursive - - name: Cache SDK Folder uses: actions/cache@v4 with: - path: ${{ github.workspace }}/build/sdk + path: | + ${{ github.workspace }}/build/sdk + ${{ github.workspace }}/build/bin key: ${{ runner.os }}-${{ runner.arch }}-sdk - uses: actions/setup-python@v5 @@ -35,23 +70,13 @@ 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' }} - - name: Compile Release run: make release CPU_CORES=3 TESTNET=${{ inputs.chain-network == 'testnet' && '1' || '0' }} - - name: CLI Artifacts uses: ./.github/actions/upload-artifacts with: 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..697df5fd 100644 --- a/.github/workflows/build-macos-intel.yml +++ b/.github/workflows/build-macos-intel.yml @@ -11,8 +11,41 @@ on: type: string jobs: + cache: + name: cache-x86_64 + runs-on: macos-13 + steps: + - name: Cache SDK Folder + id: cache + uses: actions/cache@v4 + with: + lookup-only: true + path: | + ${{ github.workspace }}/build/sdk + ${{ github.workspace }}/build/bin + key: ${{ runner.os }}-${{ runner.arch }}-sdk + + - name: Checkout Project + if: steps.cache.outputs.cache-hit != 'true' + uses: actions/checkout@v4.2.2 + with: + fetch-depth: 0 + submodules: recursive + + - uses: actions/setup-python@v5 + if: steps.cache.outputs.cache-hit != 'true' + with: + python-version: 3.x + - if: steps.cache.outputs.cache-hit != 'true' + run: pip install mkdocs-material mkdocs-git-revision-date-localized-plugin mkdocs-git-committers-plugin-2 mkdocs-git-authors-plugin "mkdocs-material[imaging]" + + - name: Compile Dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: make build-deps CPU_CORES=4 TESTNET=${{ inputs.chain-network == 'testnet' && '1' || '0' }} + build: - name: apple-clang-x86_64 + name: compile-x86_64 + needs: cache runs-on: macos-13 steps: - name: Checkout Project @@ -21,11 +54,12 @@ jobs: fetch-depth: 0 submodules: recursive - - name: Cache SDK Folder uses: actions/cache@v4 with: - path: ${{ github.workspace }}/build/sdk + path: | + ${{ github.workspace }}/build/sdk + ${{ github.workspace }}/build/bin key: ${{ runner.os }}-${{ runner.arch }}-sdk - uses: actions/setup-python@v5 @@ -33,12 +67,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 +76,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..d5bb77f0 100644 --- a/.github/workflows/build-windows-intel.yml +++ b/.github/workflows/build-windows-intel.yml @@ -11,8 +11,41 @@ on: type: string jobs: - msvc-194: - name: msvc-194-x86_64 + cache: + name: cache-x86_64 + runs-on: windows-latest + steps: + - name: Cache SDK Folder + id: cache + uses: actions/cache@v4 + with: + lookup-only: true + path: | + ${{ github.workspace }}/build/sdk + ${{ github.workspace }}/build/bin + key: ${{ runner.os }}-${{ runner.arch }}-sdk + + - name: Checkout Project + if: steps.cache.outputs.cache-hit != 'true' + uses: actions/checkout@v4.2.2 + with: + fetch-depth: 0 + submodules: recursive + + - uses: actions/setup-python@v5 + if: steps.cache.outputs.cache-hit != 'true' + with: + python-version: 3.x + - if: steps.cache.outputs.cache-hit != 'true' + run: pip install mkdocs-material mkdocs-git-revision-date-localized-plugin mkdocs-git-committers-plugin-2 mkdocs-git-authors-plugin "mkdocs-material[imaging]" + + - name: Compile Dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: make build-deps CPU_CORES=4 TESTNET=${{ inputs.chain-network == 'testnet' && '1' || '0' }} + + build: + name: compile-x86_64 + needs: cache runs-on: windows-latest steps: - name: Checkout Project @@ -24,7 +57,9 @@ jobs: - name: Cache SDK Folder uses: actions/cache@v4 with: - path: ${{ github.workspace }}/build/sdk + path: | + ${{ github.workspace }}/build/sdk + ${{ github.workspace }}/build/bin key: ${{ runner.os }}-${{ runner.arch }}-sdk - uses: actions/setup-python@v5 @@ -32,12 +67,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 +76,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/CMakeLists.txt b/CMakeLists.txt index ecaf33c5..f5f5cf58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,15 +6,11 @@ set(DISABLE_TOR TRUE CACHE BOOL "Disable TOR library(and related tor-connect sub 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}") +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -include(DocBuilder) if(POLICY CMP0043) cmake_policy(SET CMP0043 NEW) @@ -22,6 +18,9 @@ endif() if(POLICY CMP0043) cmake_policy(SET CMP0074 NEW) endif() +if(POLICY CMP0091) + cmake_policy(SET CMP0091 NEW) +endif() if(POLICY CMP0144) cmake_policy(SET CMP0144 NEW) endif() @@ -29,6 +28,14 @@ if(POLICY CMP0167) cmake_policy(SET CMP0167 OLD) endif() +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() + #option (USE_CCACHE "Use ccache if a usable instance is found" ON) #if (USE_CCACHE) # include(FindCcache) # Has to be included after the project() macro, to be able to read the CXX variable. @@ -36,8 +43,7 @@ endif() # message(STATUS "ccache deselected") #endif() -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) + if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android") diff --git a/Makefile b/Makefile index e0b51891..c12611af 100644 --- a/Makefile +++ b/Makefile @@ -52,76 +52,55 @@ 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) - # If so, define a prefix to clear the problematic env vars - FIX_ENV := CFLAGS="" CXXFLAGS="" -else - # Otherwise, the prefix is empty - FIX_ENV := -endif + 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 + 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) + 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: - @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; \ - fi - +conan-profile-detect: get-conan + cmake -P cmake/ConanProfileSetup.cmake # 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) + 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 +108,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 +127,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 +148,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/CleanBuild.cmake b/cmake/CleanBuild.cmake new file mode 100644 index 00000000..0a1146db --- /dev/null +++ b/cmake/CleanBuild.cmake @@ -0,0 +1,58 @@ +# 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/.ccache" + "${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() diff --git a/cmake/ConanProfileSetup.cmake b/cmake/ConanProfileSetup.cmake new file mode 100644 index 00000000..c6a0e803 --- /dev/null +++ b/cmake/ConanProfileSetup.cmake @@ -0,0 +1,38 @@ +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 "${CONAN_EXECUTABLE}" 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 diff --git a/cmake/FindCcache.cmake b/cmake/FindCcache.cmake new file mode 100644 index 00000000..4b440f5a --- /dev/null +++ b/cmake/FindCcache.cmake @@ -0,0 +1,8 @@ +find_program(CCACHE_FOUND ccache) +if (CCACHE_FOUND) + 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 "ccache NOT found! Please install it for faster rebuilds.") +endif() \ No newline at end of file diff --git a/cmake/GetConan.cmake b/cmake/GetConan.cmake new file mode 100644 index 00000000..9b7437ee --- /dev/null +++ b/cmake/GetConan.cmake @@ -0,0 +1,102 @@ +# 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 the installation directory +if(NOT CMAKE_BINARY_DIR) + set(CMAKE_BINARY_DIR "${CONAN_INSTALL_DIR}") +endif() +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + set(CONAN_INSTALL_DIR "${CMAKE_SOURCE_DIR}/build/bin") + 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") +endif () +# 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}") + + # Determine the processor architecture, with a fallback + if(CMAKE_HOST_SYSTEM_PROCESSOR) + set(HOST_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}) + else() + cmake_host_system_information(RESULT HOST_PROCESSOR QUERY OS_PLATFORM) + endif() + + # Detect the operating system and architecture + message(STATUS "Detecting OS and architecture: ${HOST_PROCESSOR} on ${CMAKE_HOST_SYSTEM_NAME}") + if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") + if(HOST_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(HOST_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(HOST_PROCESSOR MATCHES "aarch64|arm64|ARM64") + 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 at ${CONAN_EXECUTABLE}") +else() + message(STATUS "Conan already installed at ${CONAN_EXECUTABLE}") +endif() diff --git a/cmake/conan_provider.cmake b/cmake/conan_provider.cmake index d39187c6..1a6d9ec6 100644 --- a/cmake/conan_provider.cmake +++ b/cmake/conan_provider.cmake @@ -565,7 +565,23 @@ 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) + 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" + 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/conanfile.py b/conanfile.py index efed9a7b..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): @@ -15,9 +15,12 @@ class BlockchainConan(ConanFile): } default_options = { "static": False, - "testnet": False + "testnet": False, + "boost/*:without_test": True } + tool_requires = "ccache/4.11" + requires = [ "zlib/1.3.1", "boost/1.85.0", 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 /