diff --git a/.github/workflows/Android-cmake.yml b/.github/workflows/Android-cmake.yml deleted file mode 100644 index 2a4abd02..00000000 --- a/.github/workflows/Android-cmake.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Android Build - -on: - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-latest - env: - ANDROID_NDK_HOME: ${{github.workspace}}/android-ndk/android-ndk-r25b - ANDROID_TOOLCHAIN: ${{github.workspace}}/android-ndk/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin - NDK_URL: "https://dl.google.com/android/repository/android-ndk-r25b-linux.zip" - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: "recursive" - - - name: Set clang as the default compiler - run: | - sudo update-alternatives --install /usr/bin/cc cc $(which clang) 100 - sudo update-alternatives --install /usr/bin/c++ c++ $(which clang++) 100 - sudo update-alternatives --set cc $(which clang) - sudo update-alternatives --set c++ $(which clang++) - - - name: Download Android NDK - run: | - mkdir -p "${{github.workspace}}/android-ndk" - cd "${{github.workspace}}/android-ndk" - curl -o ndk.zip ${{ env.NDK_URL }} - unzip ndk.zip - rm ndk.zip - echo "$ANDROID_TOOLCHAIN" >> $GITHUB_PATH - - - name: Add Rust targets - run: rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android - - - name: Install bindgen - run: cargo install cbindgen - - - name: Install Ninja - run: sudo apt install ninja-build -y - - - name: Configure CMake - run: cmake -S build/Android/ -DANDROID_ABI="arm64-v8a" -B build/Android/Release -DCMAKE_ANDROID_NDK=$ANDROID_NDK -DANDROID_TOOLCHAIN=clang -DCMAKE_BUILD_TYPE=Release -G Ninja - - - name: Build project - run: cmake --build build/Android/Release --config Release -j diff --git a/.github/workflows/Android-test-cmake.yml b/.github/workflows/Android-test-cmake.yml deleted file mode 100644 index f6b1d470..00000000 --- a/.github/workflows/Android-test-cmake.yml +++ /dev/null @@ -1,63 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: Android Test Build - -# Controls when the workflow will run -# Triggers the workflow on push or pull request events and manually from the Actions tab -on: - workflow_dispatch: - -env: - CMAKE_BUILD_PARALLEL_LEVEL: 8 - -jobs: - Android: - runs-on: ubuntu-latest - - steps: - - name: Setup Git to make sure crlf -> lf - run: | - git config --global core.autocrlf false - git config --global core.eol lf - echo "ANDROID_TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_ENV - echo "MAKEFLAGS=\"-j 8\"" >> $GITHUB_ENV - echo "ANDROID_NDK=$ANDROID_NDK_HOME" >> $GITHUB_ENV - echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME" >> $GITHUB_ENV - - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v3 - with: - submodules: 'recursive' - path: '.' - - - # ndk is already installed in Ubuntu 22 - - - name: Create Build Directory - run: cmake -E make_directory ${{github.workspace}}/.build - - - name: Set PATH - run: echo "${{env.ANDROID_TOOLCHAIN}}" >> $GITHUB_PATH - - - name: Configure CMake - env: - CC: clang - - working-directory: ${{github.workspace}}/.build - run: | - export ANDROID_NDK=${{env.ANDROID_NDK_HOME}} - export ANDROID_NDK_HOME=${{env.ANDROID_NDK_HOME}} - export ANDROID_TOOLCHAIN=${{env.ANDROID_TOOLCHAIN}} - echo $PATH - export PATH=${{env.ANDROID_TOOLCHAIN}}:$PATH - echo $PATH - echo $CC - ls -la $ANDROID_TOOLCHAIN - echo "Check clang path:" - which clang - env - cmake -S ../build/Android/ -DANDROID_ABI="arm64-v8a" -DCMAKE_ANDROID_NDK=$ANDROID_NDK -DANDROID_TOOLCHAIN=clang - - name: Compile - working-directory: ${{github.workspace}}/.build - run: make Boost - diff --git a/.github/workflows/Android.yml b/.github/workflows/Android.yml new file mode 100644 index 00000000..c9741a4d --- /dev/null +++ b/.github/workflows/Android.yml @@ -0,0 +1,12 @@ +name: Android +on: + workflow_dispatch: + pull_request: + +jobs: + android-build: + uses: ./.github/workflows/build.yml + with: + target: Android + build-type: Release + abi: arm64-v8a \ No newline at end of file diff --git a/.github/workflows/Build-Artifacts.yml b/.github/workflows/Build-Artifacts.yml deleted file mode 100644 index 445ab77a..00000000 --- a/.github/workflows/Build-Artifacts.yml +++ /dev/null @@ -1,100 +0,0 @@ -# This is a reusable workflow to build libraries for Linux, Android, iOS, OSX and Windows, -# with Release, Debug variants - -name: Build Third Party Artifacts - -# Controls when the workflow will run -# Triggers the workflow on push or pull request events and manually from the Actions tab -on: - workflow_call: - inputs: - build-type: - required: true - type: string - target-build-data: - required: true - type: string - libraries: - required: true - type: string - CACHE_MULTI_PARAMETER_KEYS: - required: true - type: string - CACHE_MULTI_PARAMETER_PATHS: - required: true - type: string - -env: - CMAKE_BUILD_PARALLEL_LEVEL: 8 - MAKEFLAGS: "-j 8" - GITHUB_TOKEN: ${{ github.token }} - -jobs: - build-artifacts: - strategy: - fail-fast: false - matrix: - include: ${{ fromJSON(inputs.target-build-data) }} - - runs-on: ${{ matrix.runs-on }} - - steps: - - name: dumping matrix for each run - run: | - cat <<"EOF" - inputs: ${{ toJson(inputs) }} - matrix: ${{ toJson(matrix) }} - EOF - -# libraries: ${{ fromJSON(inputs.libraries) }} -# -# runs-on: ${{ matrix.target-build-data.runs-on }}# matrix: ${{ toJson(matrix) }} -# uses: ${{ matrix.target_build_data.install-uses.uses || '/dev/null' }} -# with: ${{ matrix.target_build_data.install-uses.with || '' }} -# - name: Restore thirdparty base directory and code -# uses: GeniusVentures/cache-multi/restore@v3.2.2 -# id: cache-tp-source-directory -# with: -# path: | -# !.git/** -# ./** -# key: thirdparty-${{ github.sha }} -# -# - name: Load the source Cache(s) into the system -# uses: GeniusVentures/cache-multi/restoremulti@v3.2.2 -# with: -# keys: ${{ inputs.CACHE_MULTI_PARAMETER_KEYS }} -# paths: ${{ inputs.CACHE_MULTI_PARAMETER_PATHS }} - -# - if: matrix.target-build-data.install-uses -# name: ${{ matrix.target-build-data.install-uses.name || "Executing uses step" }} -# uses: ${{ matrix.target-build-data.install-uses.uses || "/dev/null" }} -# with: ${{ fromJSON(matrix.target-build-data.install-uses.with || {} ) }} -# -# -# - if: matrix.target-build-data.setup-script -# name: "Executing Setup Script" -# run: | -# ${{ matrix.target-build-data.setup-script }} -# working-directory: ${{ github.workspace }} -# shell: ${{ matrix.target-build-data.shell }} -# -# - name: Build artifact -# run: | -# ${{ matrix.target-build-data.cmake-script }} -# working-directory: ${{ github.workspace }} -# shell: ${{ matrix.target-build-data.shell }} -# -# - name: Create tar for artifact -# run: | -# tar --posix --use-compress-program zstdmt -cf ../lib-${{ matrix.target-build-data.libraries.libraryName }}.tzst -# working-directory: ${{ github.workspace }}/build/${{ matrix.target-os}}/Release/${{ matrix.target-build-data.libraries.libraryName }} -# shell: ${{ matrix.target-build-data.shell }} -# -# - name: Upload artifact -# uses: actions/upload-artifact@v3 -# with: -# name: lib-${{ matrix.target-build-data.libraries.libraryName }}-${{ env.LIBRARY_VERSION }}.tzst -# path: ${{ github.workspace }}/build/${{ matrix.target-os}}/Release/lib-${{ matrix.target-build-data.libraries.libraryName }}.tzst -# - diff --git a/.github/workflows/Cache-source.yml b/.github/workflows/Cache-source.yml deleted file mode 100644 index fcb36eaf..00000000 --- a/.github/workflows/Cache-source.yml +++ /dev/null @@ -1,146 +0,0 @@ -# This is a workflow to cache the sources for all the builds - -name: Cache Source Files - -# Controls when the workflow will run -# Triggers the workflow on push or pull request events and manually from the Actions tab -on: - workflow_dispatch: - -env: - GITHUB_TOKEN: ${{ github.token }} - -jobs: - setup: - runs-on: ubuntu-latest - outputs: - matrix: ${{ steps.set-matrix.outputs.matrix }} - steps: - - name: Cache main Source Files without .git - uses: GeniusVentures/cache-multi@v3.2.2 - id: cache-source-directory - with: - path: | - !.git/** - ${{github.workspace}}/** - key: thirdparty-${{ github.sha }} - - - name: Check out main third party without submodules - if: steps.cache-source-directory.outputs.cache-hit != 'true' - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 - with: - path: ${{github.workspace}} - - - name: Set matrix of submodules - id: set-matrix - run: | - content=$(git submodule) - jsonContent="{ \"include\": [ " - first="true" - while read longsha name; do - longsha="${longsha/'-'/}" - shortsha="${longsha:0:7}" - if [[ "$first" != "true" ]]; then - jsonContent+="," - fi - jsonContent+="{ \"name\": \"$name\", \"shortsha\": \"$shortsha\", \"longsha\": \"$slongsha\" }" - first="false" - done <<<"$content" - jsonContent+="] }" - echo "matrix=$jsonContent" >> $GITHUB_OUTPUT - shell: bash - working-directory: ${{github.workspace}} - - cache_src: - needs: setup - runs-on: ubuntu-latest - strategy: - fail-fast: true - matrix: ${{ fromJson(needs.setup.outputs.matrix) }} - if: false - steps: - - uses: GeniusVentures/cache-multi@v3.2.2 - id: cache-tp-source-directory - with: - path: | - !.git/** - ${{github.workspace}}/** - key: thirdparty-${{ github.sha }} - - - if: steps.cache-tp-source-directory.outputs.cache-hit != 'true' - run: | - echo "Couldn't find cached thirdparty code, thirdparty-${{ github.sha }} fatal error!" - exit 1 - - - name: Cache Submodule Source Files without .git - id: cache-source-directory - uses: GeniusVentures/cache-multi@v3.2.2 - with: - path: | - !.git/** - ${{github.workspace}}/${{ matrix.name }}/** - key: ${{ matrix.name }}-${{ matrix.shortsha }} - - - name: Git clone submodule source code - if: steps.cache-source-directory.outputs.cache-hit != 'true' - run: | - echo "Cloning source for ${{ matrix.name }}" - git submodule update --init --recursive -- ${{ matrix.name }} - shell: bash - working-directory: ${{github.workspace}} - - build_targets: - needs: [setup] - runs-on: ubuntu-latest - steps: - - uses: GeniusVentures/cache-multi/restore@v3.2.2 - id: cache-tp-source-directory - with: - path: | - !.git/** - ${{github.workspace}}/** - key: thirdparty-${{ github.sha }} - - - if: steps.cache-tp-source-directory.outputs.cache-hit != 'true' - run: | - echo "Couldn't find cached thirdparty code, thirdparty-${{ github.sha }} fatal error!" - exit 1 - - - name: Create Inputs for src caches to load - id: cache-multi-parameters - run: | - # now reload the json content into variables list - reloadcontent=$(echo '${{ needs.setup.outputs.matrix }}' | perl -pe "s/.*?(?:\{[ \t]*?\"name\":[ \t]*?\"(.+?)\".[ \t]*?\"shortsha\":[ \t]*?\"(.+?)\"(.*?)\}),*\]*[ \t]*\}*/\1 \2\n/g") - - keysJsonContent="" - pathsJsonContent="" - first="true" - while read name shortsha; do - if [[ "$first" != "true" ]]; then - keysJsonContent+=$'\n' - pathsJsonContent+=$'\n' - fi - keysJsonContent+="$name-$shortsha" - pathsJsonContent+="[\"!.git/**\", \"${{github.workspace}}/$name/**\"]" - first="false" - done <<<"$reloadcontent" - keysJsonContent+="" - pathsJsonContent+="" - - echo "CACHE_MULTI_PARAMETER_KEYS<> $GITHUB_ENV - echo "$keysJsonContent" >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV - - echo "CACHE_MULTI_PARAMETER_PATHS<> $GITHUB_ENV - echo "$pathsJsonContent" >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV - - shell: bash - working-directory: ${{github.workspace}} - - - name: Load the source Cache(s) into the system - uses: GeniusVentures/cache-multi/restoremulti@v3.2.2 - with: - keys: ${{ env.CACHE_MULTI_PARAMETER_KEYS }} - paths: ${{ env.CACHE_MULTI_PARAMETER_PATHS }} diff --git a/.github/workflows/Linux-cmake.yml b/.github/workflows/Linux-cmake.yml deleted file mode 100644 index ef5cce3b..00000000 --- a/.github/workflows/Linux-cmake.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Linux Build - -on: - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: "recursive" - - - name: Set clang as the default compiler - run: | - sudo update-alternatives --install /usr/bin/cc cc $(which clang) 100 - sudo update-alternatives --install /usr/bin/c++ c++ $(which clang++) 100 - sudo update-alternatives --set cc $(which clang) - sudo update-alternatives --set c++ $(which clang++) - - - name: Add Rust target - run: rustup target add wasm32-unknown-emscripten - - - name: Install Ninja - run: sudo apt install ninja-build -y - - - name: Install ccache - run: sudo apt install ccache -y - - - name: Configure CMake - run: cmake -S build/Linux/ -B build/Linux/Release -DCMAKE_BUILD_TYPE=Release -G Ninja - - - name: Build project - run: cmake --build build/Linux/Release --config Release -j diff --git a/.github/workflows/Linux.yml b/.github/workflows/Linux.yml new file mode 100644 index 00000000..5ab820f7 --- /dev/null +++ b/.github/workflows/Linux.yml @@ -0,0 +1,11 @@ +name: Linux +on: + workflow_dispatch: + pull_request: + +jobs: + linux-build: + uses: ./.github/workflows/build.yml + with: + target: Linux + build-type: Release diff --git a/.github/workflows/OSX-cmake.yml b/.github/workflows/OSX-cmake.yml deleted file mode 100644 index 74068f67..00000000 --- a/.github/workflows/OSX-cmake.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Mac OSX Build - -on: - workflow_dispatch: - -jobs: - MacOS: - runs-on: macos-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: "recursive" - - - name: Add Rust targets - run: | - rustup target add aarch64-apple-darwin - rustup target add wasm32-unknown-emscripten - - - name: Install bindgen - run: cargo install cbindgen - - - name: Install Ninja - run: brew install ninja - - - name: Install ccache - run: brew install ccache - - - name: Configure CMake - run: cmake -S build/OSX -B build/OSX/Release -DCMAKE_BUILD_TYPE=Release -G Ninja - - - name: Compile - run: cmake --build build/OSX/Release --config Release -j diff --git a/.github/workflows/Windows-cmake.yml b/.github/workflows/Windows-cmake.yml deleted file mode 100644 index 97825755..00000000 --- a/.github/workflows/Windows-cmake.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Windows Build - -on: - workflow_dispatch: - -jobs: - build: - runs-on: windows-2022 - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: "recursive" - - - name: Add Rust target - run: rustup target add wasm32-unknown-emscripten - - - name: Install ccache - run: choco install ccache -y - - - name: Configure CMake - run: cmake -S build/Windows -B build/Windows/Release -DCMAKE_BUILD_TYPE=Release - - - name: Build project - run: cmake --build build/Windows/Release --config Release -j diff --git a/.github/workflows/Windows.yml b/.github/workflows/Windows.yml new file mode 100644 index 00000000..64b0be0d --- /dev/null +++ b/.github/workflows/Windows.yml @@ -0,0 +1,11 @@ +name: Windows +on: + workflow_dispatch: + pull_request: + +jobs: + windows-build: + uses: ./.github/workflows/build.yml + with: + target: Windows + build-type: Release diff --git a/.github/workflows/build-targets.yml b/.github/workflows/build-targets.yml index dba0a438..6dc9dabe 100644 --- a/.github/workflows/build-targets.yml +++ b/.github/workflows/build-targets.yml @@ -1,6 +1,4 @@ -# This is a workflow to cache the sources and build all the artifacts for target OSs - -name: Cache Sources and build Artifact Libraries per OS +name: Multiplatform build and upload on: workflow_dispatch: @@ -8,1010 +6,263 @@ on: env: GH_TOKEN: ${{ secrets.GNUS_TOKEN_1 }} jobs: - setup-src-cache: - runs-on: ubuntu-latest - outputs: - THIRD_PARTY_CACHE_NAME_KEY: ${{ steps.tp-check.outputs.THIRD_PARTY_CACHE_NAME_KEY }} - FOUND_THIRD_PARTY_CURRENT: ${{ steps.tp-check.outputs.FOUND_THIRD_PARTY_CURRENT }} - CACHE_MATRIX: ${{ steps.set-cache-matrix.outputs.CACHE_MATRIX }} - NEEDS_CACHE: ${{ steps.set-cache-matrix.outputs.NEEDS_CACHE }} - CACHE_MULTI_PARAMETER_NAME_KEYS: ${{ steps.set-cache-matrix.outputs.CACHE_MULTI_PARAMETER_NAME_KEYS }} - CACHE_MULTI_PARAMETER_PATHS: ${{ steps.set-cache-matrix.outputs.CACHE_MULTI_PARAMETER_PATHS }} + build: + env: + GRPC_BUILD_ENABLE_CCACHE: "ON" + runs-on: ${{matrix.host}} + strategy: + fail-fast: false + matrix: + target: [Android, iOS, OSX, Linux, Windows] + build-type: [Debug, Release] + include: + - target: Linux + host: ubuntu-latest + - target: Windows + host: windows-latest + - target: OSX + host: macos-latest + - target: Android + host: ubuntu-latest + abi: arm64-v8a + - target: iOS + host: macos-latest steps: - - name: Check out main third party without submodules + - name: Checkout uses: actions/checkout@v4 with: - submodules: false + submodules: "recursive" - - name: Install GH cli extension actions-cache + - name: Configure Linux host + if: ${{ runner.os == 'Linux'}} run: | - gh extension install actions/gh-actions-cache + sudo update-alternatives --install /usr/bin/cc cc $(which clang) 100 + sudo update-alternatives --install /usr/bin/c++ c++ $(which clang++) 100 + sudo update-alternatives --set cc $(which clang) + sudo update-alternatives --set c++ $(which clang++) - # get currently authenticated user rate limit info - rateRemaining=`gh api rate_limit --jq ".rate | .remaining"` - echo "Rate limit remaining is $rateRemaining" + sudo apt install ccache libvulkan-dev ninja-build ripgrep -y + echo "CMAKE_GENERATOR=Ninja" >> $GITHUB_ENV - echo "REPO=${{ github.repository }}" >> $GITHUB_ENV - echo "BRANCH=${{ github.ref_name }}" >> $GITHUB_ENV - - - name: Find cache and clean out old caches of `thirdparty` - id: tp-check + - name: Configure Windows host + if: ${{ runner.os == 'Windows'}} run: | - echo "Fetching list of thirdparty cache keys to check if any old ones need deleting" - cacheList=$(gh cache list -k ${BRANCH}/thirdparty --json key --jq ".[].key") - - longSHA="${{ github.sha }}" - shortSHA="${longSHA:0:7}" - tpCacheNameSHA="$BRANCH/thirdparty-$shortSHA" - - notMatched="$(comm -3 --output-delimiter="" <(echo -en "$tpCacheNameSHA") <(echo -en "$cachesList"))" - oldCaches="$(comm -13 --output-delimiter="" <(echo -en "$tpCacheNameSHA") <(echo -en "$notMatched"))" - notCached="$(comm -12 --output-delimiter="" <(echo -en "$tpCacheNameSHA") <(echo -en "$notMatched"))" - - echo -e "notMatched: $notMatched" - echo -e "oldCaches: $oldCaches" - echo -e "notCached: $notCached" + choco install ccache ripgrep -A - foundThirdPartyCurrent="true" - if [[ $notCached == "$tpCacheNameSHA" ]]; then - foundThirdPartyCurrent="false" - fi - - # Set the field separator to new line - IFS=$'\n' - for oldCache in $oldCaches; do - echo -e "Deleting old cache $oldCache" - gh actions-cache delete $oldCache -R $REPO -B $BRANCH --confirm - done - - echo "FOUND_THIRD_PARTY_CURRENT=$foundThirdPartyCurrent" >> $GITHUB_OUTPUT - echo "THIRD_PARTY_CACHE_NAME_KEY=$tpCacheNameSHA" >> $GITHUB_OUTPUT - shell: bash - working-directory: ${{github.workspace}} - - - name: Cache source files - if: ( steps.tp-check.outputs.FOUND_THIRD_PARTY_CURRENT == 'false' ) - uses: GeniusVentures/cache-multi@v3.3.1 - id: cache-source-directory - with: - key: ${{ steps.tp-check.outputs.THIRD_PARTY_CACHE_NAME_KEY }} - enableCrossOsArchive: true - path: | - !.git/** - ./** - - - name: Set matrix of src submodules that need updating - id: set-cache-matrix + - name: Configure macOS host + if: ${{ runner.os == 'macOS'}} run: | - echo "Fetching list of cache keys to check if any old ones need deleting" - cacheNames="" - while read -r mode stage longsha location; do - shortSHA="${longsha:0:7}" - cacheNames+="s/$BRANCH/$location-$shortSHA\n" - done <<< $(git ls-tree -r HEAD | grep "160000 commit") - - cacheNames="$(echo -en "$cacheNames" | sort)" - cachesList=$(gh api -H "Accept: application/vnd.github+json" --paginate repos/GeniusVentures/thirdparty/actions/caches?key="s/${BRANCH}" | jq -r ".actions_caches[].key" | sort) - - notMatched="$(comm -3 --output-delimiter="" <(echo -en "$cacheNames") <(echo -en "$cachesList"))" - oldCaches="$(comm -13 --output-delimiter="" <(echo -en "$cacheNames") <(echo -en "$notMatched"))" - notCached="$(comm -12 --output-delimiter="" <(echo -en "$cacheNames") <(echo -en "$notMatched"))" - - # Matrix of source code to cache - cacheMatrix="[]" - - # Set the field separator to new line - IFS=$'\n' - for toCache in $notCached; do - len=${#toCache} - startPos=$((len - 7)) - lenBranch=${#BRANCH} - matrixItem=$(jq -n \ - --arg cacheName "${toCache}" \ - --arg name "${toCache:$((2 + lenBranch + 1)):$((len - 10 - lenBranch - 1))}" \ - '{name: $name, cacheName: $cacheName}' - ) - - cacheMatrix=$(jq -c --argjson obj "$matrixItem" '. + [$obj]' <<<"$cacheMatrix") - done + brew install ccache ninja ripgrep bash + echo "CMAKE_GENERATOR=Ninja" >> $GITHUB_ENV - echo "Cache matrix:" - jq <<<"$cacheMatrix" + - name: Add Darwin toolchain + if: ${{ matrix.target == 'OSX'}} + run: rustup target add x86_64-apple-darwin - # Delete old caches - for oldCache in $oldCaches; do - echo "Deleting old cache $oldCache" - gh actions-cache delete $oldCache -R $REPO -B $BRANCH --confirm - done - - echo "CACHE_MATRIX=$cacheMatrix" >> $GITHUB_OUTPUT - if [[ "$notCached" != "" ]]; then - echo "NEEDS_CACHE=true" >> $GITHUB_OUTPUT - else - echo "NEEDS_CACHE=false" >> $GITHUB_OUTPUT - fi - - cacheNameKeysContent="[ " - cachePathsContent="[ " - first='true' - for cacheName in $cacheNames; do - len=${#cacheName} - startPos=$((len - 7)) - shortSHA="${cacheName:$startPos:7}" - lenBranch=${#BRANCH} - # - 10 - lenBranch - 1 for s/$BRANCH/ + '-' + shortSHA - name="${cacheName:$((2 + lenBranch + 1)):$((len - 10 - lenBranch - 1))}" - if [[ "$first" != "true" ]]; then - cacheNameKeysContent+=", " - cachePathsContent+=", " - fi - first='false' - cacheNameKeysContent+="\"$cacheName\"" - cachePathsContent+="[\"!./$name/.git/**\", \"./$name/**\"]" - done - - cacheNameKeysContent+=" ]" - echo "CACHE_MULTI_PARAMETER_NAME_KEYS=$cacheNameKeysContent" >> $GITHUB_OUTPUT - - cachePathsContent+=" ]" - echo "CACHE_MULTI_PARAMETER_PATHS=$cachePathsContent" >> $GITHUB_OUTPUT - - shell: bash - working-directory: ${{github.workspace}} - - cache-src: - needs: setup-src-cache - if: (needs.setup-src-cache.outputs.NEEDS_CACHE == 'true') - runs-on: ubuntu-latest - strategy: - fail-fast: true - matrix: - include: ${{ fromJson(needs.setup-src-cache.outputs.CACHE_MATRIX) }} - steps: - - name: Setup + - name: Add iOS toolchain + if: ${{ matrix.target == 'iOS' }} run: | - sudo apt install zstd -y + rustup toolchain install nightly-aarch64-apple-darwin + rustup component add rust-src --toolchain nightly-aarch64-apple-darwin + rustup target add aarch64-apple-ios - - name: Cache third party directory - uses: GeniusVentures/cache-multi/restore@v3.3.1 - id: cache-tp-source-directory - with: - key: ${{ needs.setup-src-cache.outputs.THIRD_PARTY_CACHE_NAME_KEY }} - enableCrossOsArchive: true - path: | - !.git/** - ./** - - - if: (steps.cache-tp-source-directory.outputs.cache-hit != 'true') - run: | - echo "Couldn't find cached thirdparty code, ${{ needs.setup-src-cache.outputs.THIRD_PARTY_CACHE_NAME_KEY }} fatal error!" - exit 1 - - - name: Git clone submodule source code + - name: Add Android toolchain + if: ${{ matrix.target == 'Android' }} run: | - echo "Cloning source for ${{ matrix.name }}" - git submodule update --init --recommend-shallow --recursive -- ${{ matrix.name }} - shell: bash - working-directory: ${{github.workspace}} + NDK_VERSION="r27b" + wget https://dl.google.com/android/repository/android-ndk-$NDK_VERSION-linux.zip -O ndk.zip + unzip ndk.zip -d $HOME - - name: Cache submodule source files - id: cache-source-directory - uses: GeniusVentures/cache-multi@v3.3.1 - with: - key: ${{ matrix.cacheName }} - enableCrossOsArchive: true - path: | - !./${{ matrix.name }}/.git/** - ./${{ matrix.name }}/** - - create-targets-matrix: - needs: [setup-src-cache, cache-src] - if: | - always() && - needs.setup-src-cache.result == 'success' && - (needs.cache-src.result == 'success' || needs.cache-src.result == 'skipped') - runs-on: ubuntu-latest - outputs: - TARGET_NAMES: ${{ steps.create-target-info.outputs.TARGET_NAMES }} - TARGET_SHAS: ${{ steps.create-target-info.outputs.TARGET_SHAS }} - TARGET_DIRECTORIES: ${{ steps.create-target-info.outputs.TARGET_DIRECTORIES }} - TARGET_REPO_NAMES: ${{ steps.create-target-info.outputs.TARGET_REPO_NAMES }} - steps: - - name: Setup - run: sudo apt install zstd -y + echo "ANDROID_NDK_HOME=$HOME/android-ndk-$NDK_VERSION" >> $GITHUB_ENV - - name: Restore cache third party directory - uses: GeniusVentures/cache-multi/restore@v3.3.1 - id: cache-tp-source-directory - with: - key: ${{ needs.setup-src-cache.outputs.THIRD_PARTY_CACHE_NAME_KEY }} - enableCrossOsArchive: true - path: | - !.git/** - ./** + rustup target add aarch64-linux-android - - if: (steps.cache-tp-source-directory.outputs.cache-hit != 'true') - run: | - echo "Couldn't find cached thirdparty code, ${{ needs.setup-src-cache.outputs.THIRD_PARTY_CACHE_NAME_KEY }} fatal error!" - exit 1 + - name: Install bindgen + run: cargo install cbindgen - - name: Restore submodule source files - id: cache-source-directory - uses: GeniusVentures/cache-multi/restoremulti@v3.3.1 - with: - multi-keys: ${{ needs.setup-src-cache.outputs.CACHE_MULTI_PARAMETER_NAME_KEYS }} - enableCrossOsArchive: true - paths: ${{ needs.setup-src-cache.outputs.CACHE_MULTI_PARAMETER_PATHS }} + - name: Add wasm Rust target + run: rustup target add wasm32-unknown-emscripten - - name: Create base target library names for target cache to create - id: create-target-info + - name: Set build directory run: | - cmake -S build/Linux -B build/Linux/Release -DCMAKE_BUILD_TYPE=Release - - cd build/Linux/Release/CMakeFiles - declare -A cmakeBuildDir - while IFS=',' read -r cmakeName buildDir; do - cmakeBuildDir["$cmakeName"]="$buildDir" - done < <(grep -m1 -R --include "build.make" -e ".*-complete:.*-build" * | - sed -E -n 's/^(.*)\.dir.*-complete: ([^/]*?)\/src.*/\1,\2/p') - - cd .. - declare -A cmakeNamesRepos - for key in "${!cmakeBuildDir[@]}"; do - sourceDir=$(find . -type f -name "${key}-source_dirinfo.txt" -exec sed -n "s|^source_dir=$GITHUB_WORKSPACE\/\(.*\)|\1|p" {} \;) - cmakeNamesRepos["$key"]=$sourceDir - echo "cmakeNameRepos = ${sourceDir}" - done - - declare -A gitLibModules - cd $GITHUB_WORKSPACE - while IFS=',' read -r longSHA sourceDir; do - gitLibModules["$sourceDir"]="$longSHA" - done < <(git ls-tree -r HEAD | sed -E -n 's/^.*(commit|tree)\s+([a-f0-9]+)\s+(\S+)/\2,\3/p') - - # Initialize the variables - cmakeNames="" - buildDirectoryNames="" - repoNames="" - shortSHAs="" - - # Define column widths - name_width=20 - build_dir_width=20 - source_dir_width=20 - - # Print header - printf "%-${name_width}s | %-${build_dir_width}s | %-${source_dir_width}s | %-${sha_width}s\n" "Name" "Build dir" "Source dir" "SHA" - for key in "${!cmakeBuildDir[@]}"; do - buildDir="${cmakeBuildDir[$key]}" - sourceDir="${cmakeNamesRepos[$key]}" - shortSHA="${gitLibModules[$sourceDir]:0:7}" - cmakeNames+="${key}\n" - buildDirectoryNames+="${buildDir}\n" - repoNames+="${sourceDir}\n" - shortSHAs+="${shortSHA}\n" - printf "%-${name_width}s | %-${build_dir_width}s | %-${source_dir_width}s | %s\n" "${key}" "${buildDir}" "${sourceDir}" "${shortSHA}" - done + if ${{matrix.target == 'Android'}}; then + BUILD_DIRECTORY=build/${{matrix.target}}/${{matrix.build-type}}/${{matrix.abi}} + else + BUILD_DIRECTORY=build/${{matrix.target}}/${{matrix.build-type}} + fi + echo "BUILD_DIRECTORY=$BUILD_DIRECTORY" >> $GITHUB_ENV + shell: bash - echo "TARGET_NAMES=$cmakeNames" >> $GITHUB_OUTPUT - echo "TARGET_SHAS=$shortSHAs" >> $GITHUB_OUTPUT - echo "TARGET_DIRECTORIES=$buildDirectoryNames" >> $GITHUB_OUTPUT - echo "TARGET_REPO_NAMES=$repoNames" >> $GITHUB_OUTPUT + - name: Configure CMake for Mac x86 + if: ${{ matrix.target == 'OSX'}} + run: cmake -S build/${{matrix.target}} -B $BUILD_DIRECTORY -DCMAKE_BUILD_TYPE=${{matrix.build-type}} -DPLATFORM=MAC - shell: bash - working-directory: ${{github.workspace}} - - save-target-sources: - needs: [setup-src-cache, cache-src, create-targets-matrix] - if: | - always() && - needs.setup-src-cache.result == 'success' && - needs.create-targets-matrix.result == 'success' && - (needs.cache-src.result == 'success' || needs.cache-src.result == 'skipped') && - needs.create-targets-matrix.result == 'success' - strategy: - fail-fast: false - matrix: - target-os: [Linux, Windows, OSX, iOS, Android] - build-type: [Release, Debug] - runs-on: ubuntu-latest - steps: - - name: Setup - run: | - sudo apt install zstd -y + - name: Configure CMake for iOS + if: ${{ matrix.target == 'iOS'}} + run: cmake -S build/${{matrix.target}} -B $BUILD_DIRECTORY -DCMAKE_BUILD_TYPE=${{matrix.build-type}} -DPLATFORM=OS64 - - name: Create library Keys and Paths to release sources - id: create-src-cache-keys - run: | - TARGET_OS="${{ matrix.target-os }}" - BUILD_TYPE="${{ matrix.build-type }}" - BRANCH=${{ github.ref_name }} - GITHUB_RELEASE_NAME=${TARGET_OS}-${BRANCH}-${BUILD_TYPE} - - echo "TARGET_OS=${TARGET_OS}" >> $GITHUB_OUTPUT - echo "BUILD_TYPE=${BUILD_TYPE}" >> $GITHUB_OUTPUT - echo "BRANCH=${BRANCH}" >> $GITHUB_OUTPUT - echo "GITHUB_RELEASE_NAME=${GITHUB_RELEASE_NAME}" >> $GITHUB_OUTPUT - - - name: Cache Third Party Directory - uses: GeniusVentures/cache-multi/restore@v3.3.1 - id: cache-tp-source-directory - with: - key: ${{ needs.setup-src-cache.outputs.THIRD_PARTY_CACHE_NAME_KEY }} - enableCrossOsArchive: true - path: | - !.git/** - ./** + - name: Configure CMake for Android + if: ${{ matrix.target == 'Android'}} + run: cmake -S build/${{matrix.target}} -B $BUILD_DIRECTORY -DCMAKE_BUILD_TYPE=${{matrix.build-type}} -DANDROID_ABI=${{matrix.abi}} - - if: (steps.cache-tp-source-directory.outputs.cache-hit != 'true') - run: | - echo "Couldn't find cached thirdparty code, ${{ needs.setup-src-cache.outputs.THIRD_PARTY_CACHE_NAME_KEY }} fatal error!" - exit 1 + - name: Configure CMake for Windows + if: ${{ matrix.target == 'Windows' }} + run: cmake -S build/${{matrix.target}} -B $env:BUILD_DIRECTORY -DCMAKE_BUILD_TYPE=${{matrix.build-type}} - - name: Cache Submodule source files without .git - id: cache-source-directory - uses: GeniusVentures/cache-multi/restoremulti@v3.3.1 - with: - multi-keys: ${{ needs.setup-src-cache.outputs.CACHE_MULTI_PARAMETER_NAME_KEYS }} - enableCrossOsArchive: true - paths: ${{ needs.setup-src-cache.outputs.CACHE_MULTI_PARAMETER_PATHS }} + - name: Configure CMake for Linux + if: ${{ matrix.target == 'Linux' }} + run: cmake -S build/${{matrix.target}} -B $BUILD_DIRECTORY -DCMAKE_BUILD_TYPE=${{matrix.build-type}} - - name: Creating github release tag - id: create-github-release-tag + - name: Create release tag + id: create-release-tag run: | - echo "Check if github release tag ${{ steps.create-src-cache-keys.outputs.GITHUB_RELEASE_NAME }} available." + RELEASE_TAG='${{matrix.target}}-${{ github.ref_name }}-${{matrix.build-type}}' + echo "RELEASE_TAG=${RELEASE_TAG}" >> $GITHUB_ENV + + echo "Check if GitHub release tag $RELEASE_TAG available." set +e - gh release view ${{ steps.create-src-cache-keys.outputs.GITHUB_RELEASE_NAME }} + gh release view $RELEASE_TAG releaseFound=$? set -e - if [[ $releaseFound -ne 0 ]]; - then - echo "gh release view return value: ${releaseFound}" - echo "Creating github release with tag: ${{ steps.create-src-cache-keys.outputs.GITHUB_RELEASE_NAME }}" - - RELEASE_TYPE="--latest" - if [[ "${{ steps.create-src-cache-keys.outputs.BUILD_TYPE }}" != "Release" ]]; - then - RELEASE_TYPE="--prerelease" - fi - - # Create release on github - gh release create ${{ steps.create-src-cache-keys.outputs.GITHUB_RELEASE_NAME }} \ - -n "${{ steps.create-src-cache-keys.outputs.BRANCH }} branch" \ - --target "${{ steps.create-src-cache-keys.outputs.BRANCH }}" \ - ${RELEASE_TYPE} \ - -t "${{ steps.create-src-cache-keys.outputs.TARGET_OS }} ${{ steps.create-src-cache-keys.outputs.BRANCH }} branch ${{ steps.create-src-cache-keys.outputs.BUILD_TYPE }} build" - - releaseCreated=$? - if [[ $releaseCreated -ne 0 ]]; - then - echo "gh release create return value: ${releaseCreated}" - echo "Failed to create github release with tag: ${{ steps.create-src-cache-keys.outputs.GITHUB_RELEASE_NAME }}" - exit 1 - fi - fi - - - name: Compress and upload targets source folder - id: compress-targets-source - working-directory: ${{github.workspace}} - run: | - # build array of library names - IFS=$'\n' read -d '|' -ra TARGET_NAMES <<< "$(echo -ne '${{ needs.create-targets-matrix.outputs.TARGET_NAMES }}|')" - IFS=$'\n' read -d '|' -ra TARGET_SHAS <<< "$(echo -ne '${{ needs.create-targets-matrix.outputs.TARGET_SHAS }}|')" - IFS=$'\n' read -d '|' -ra TARGET_REPO_NAMES <<< "$(echo -ne '${{ needs.create-targets-matrix.outputs.TARGET_REPO_NAMES }}|')" - - # Check if release.json file already available - jsonStr="[]" - jsonFound=`gh release view ${{ steps.create-src-cache-keys.outputs.GITHUB_RELEASE_NAME }} --json assets --jq "any(.assets[]; .name == \"release.json\")"` - if [ $? -eq 0 ] - then - echo "Downloading release.json file" - set +e - gh release download ${{ steps.create-src-cache-keys.outputs.GITHUB_RELEASE_NAME }} --pattern "release.json" --clobber - if [ $? -eq 0 ] - then - echo "Loading release.json file" - jsonStr=`cat release.json` - fi - set -e - fi - - RELEASE_ASSETS=`gh release view ${{ steps.create-src-cache-keys.outputs.GITHUB_RELEASE_NAME }} --json assets` - - # get currently authenticated user rate limit info - rateRemaining=`gh api rate_limit --jq ".rate | .remaining"` - echo "Rate limit remaining is $rateRemaining" - - # if we don't have at least 50 requests left, wait until reset - if [[ $rateRemaining -lt 50 ]]; - then - rateReset=`gh api rate_limit --jq ".rate | .reset"` - wait=$((rateReset - `date +%s`)); - echo "Rate limit remaining is $rateRemaining, waiting for $wait seconds to reset" - while [ $wait -ge 0 ] - do - sleep 5 - wait=$((rateReset - `date +%s`)); - echo "Waiting $wait seconds to reset rate limit" - done - rateRemaining=`gh api rate_limit --jq ".rate | .remaining"` - echo "Rate limit has reset to $rateRemaining requests" - fi - - - for i in "${!TARGET_NAMES[@]}"; do - TARGET_NAME="${TARGET_NAMES[i]}" - TARGET_REPO_NAME="${TARGET_REPO_NAMES[i]}" - TARGET_SHA="${TARGET_SHAS[i]}" - COMPRESSED_TARGET_SRC="${TARGET_NAME}-src.tar.gz" - - shaFound=$(jq ".[] | select(.name == \"${TARGET_NAME}\") | .sha" <<<${jsonStr}) - COMPRESSED_TARGET_SRC_URL=$(jq '.assets[] | select(.name == "${COMPRESSED_TARGET_SRC}") | .url' <<<${RELEASE_ASSETS}) - if [ -z "$COMPRESSED_TARGET_SRC_URL" ] || [[ "${shaFound}" != \"${TARGET_SHA}\" ]]; - then - echo "Compressing ${TARGET_OS} version ${TARGET_SHA} of ${TARGET_REPO_NAME} source folder" - tar -zcf ${COMPRESSED_TARGET_SRC} ${TARGET_REPO_NAME} - echo "Uploading target ${COMPRESSED_TARGET_SRC} to github release ${{ steps.create-src-cache-keys.outputs.GITHUB_RELEASE_NAME }}" - gh release upload --clobber ${{ steps.create-src-cache-keys.outputs.GITHUB_RELEASE_NAME }} ${COMPRESSED_TARGET_SRC} - fi - done - - build-targets-matrix: - needs: - [setup-src-cache, cache-src, create-targets-matrix, save-target-sources] - if: | - always() && - needs.setup-src-cache.result == 'success' && - needs.create-targets-matrix.result == 'success' && - (needs.cache-src.result == 'success' || needs.cache-src.result == 'skipped') && - (needs.save-target-sources.result == 'success' || needs.save-target-sources.result == 'skipped') - strategy: - fail-fast: false - matrix: - build-type: [Release, Debug] - target-build-data: - - target-os: Linux - runs-on: ubuntu-latest - shell: bash - setup-script: | - # Set clang as cc - sudo update-alternatives --install /usr/bin/cc cc $(which clang) 100 - sudo update-alternatives --install /usr/bin/c++ c++ $(which clang++) 100 - sudo update-alternatives --set cc $(which clang) - sudo update-alternatives --set c++ $(which clang++) - - sudo apt install vulkan-tools vulkan-validationlayers-dev libvulkan-dev -y - sudo apt install zstd ninja-build ccache -y - echo "CMAKE_GENERATOR=Ninja" >> $GITHUB_ENV - cmake-init-script: | - cmake -B $BUILD_TYPE -DCMAKE_BUILD_TYPE=$BUILD_TYPE - - - target-os: Android - runs-on: ubuntu-latest - shell: bash - env: - CC: clang - setup-script: | - # Set clang as cc - sudo update-alternatives --install /usr/bin/cc cc $(which clang) 100 - sudo update-alternatives --install /usr/bin/c++ c++ $(which clang++) 100 - sudo update-alternatives --set cc $(which clang) - sudo update-alternatives --set c++ $(which clang++) - - echo "ANDROID_NDK=$ANDROID_NDK_HOME" >> $GITHUB_ENV - echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME" >> $GITHUB_ENV - - sudo apt install zstd ninja-build ccache -y - echo "CMAKE_GENERATOR=Ninja" >> $GITHUB_ENV - - rustup target add aarch64-linux-android - arch: | - arm64-v8a - x86_64 - x86 - armeabi-v7a - cmake-init-script: | - cmake -B $BUILD_TYPE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DANDROID_ABI="arm64-v8a" -DCMAKE_ANDROID_NDK=$ANDROID_NDK -DANDROID_TOOLCHAIN=clang - - - target-os: OSX - runs-on: macos-latest - shell: bash - setup-script: | - brew install zstd ninja md5sha1sum ccache - echo "CMAKE_GENERATOR=Ninja" >> $GITHUB_ENV - - cargo install cbindgen - - rustup target add x86_64-apple-darwin - cmake-init-script: | - cmake -B $BUILD_TYPE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DPLATFORM=MAC - - - target-os: iOS - runs-on: macos-latest - shell: bash - setup-script: | - brew install zstd ninja md5sha1sum ccache - echo "CMAKE_GENERATOR=Ninja" >> $GITHUB_ENV - - cargo install cbindgen - - rustup toolchain install nightly-aarch64-apple-darwin - rustup component add rust-src --toolchain nightly-aarch64-apple-darwin - rustup target add aarch64-apple-ios - - cmake-init-script: | - cmake -B $BUILD_TYPE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DiOS_ABI=arm64-v8a -DENABLE_ARC=0 -DENABLE_BITCODE=0 -DENABLE_VISIBILITY=1 -DPLATFORM=OS64 - - - target-os: Windows - runs-on: windows-2022 - shell: bash - setup-script: | - choco install ccache -A - echo "C:\Strawberry\perl\bin" >> $GITHUB_PATH - echo "C:\Perl64\bin" >> $GITHUB_PATH - cmake-init-script: | - cmake -B $BUILD_TYPE -DCMAKE_BUILD_TYPE=$BUILD_TYPE - - target-save-data: - - target-os: $TARGET_OS - runs-on: $TARGET_RUNS_ON - shell: bash - upload-release-json: | - GITHUB_RELEASE_NAME=${TARGET_OS}-${BRANCH}-${BUILD_TYPE} - - retValue=1 - numberOfTries=1 - until [[ $retValue -eq 0 ]] - do - if [[ $numberOfTries -gt 5 ]]; then - break - fi - - echo "#${numberOfTries} Uploading release.json to github release ${GITHUB_RELEASE_NAME}" - gh release upload --clobber ${GITHUB_RELEASE_NAME} release.json - retValue=$? - - if [[ $retValue -ne 0 ]]; then - echo "gh release upload failed, sleep 2 sec before next try" - sleep 2 - fi - - ((numberOfTries++)) - done - - if [[ $retValue -ne 0 ]]; then - echo "Failed to upload release.json to github release ${GITHUB_RELEASE_NAME}" - exit 1 - fi + if [[ $releaseFound -ne 0 ]]; then + echo "Release not found, creating with tag: $RELEASE_TAG" - release-target: | - # Check if release already defined e.g. Linux-master-release - GITHUB_RELEASE_NAME=${TARGET_OS}-${BRANCH}-${BUILD_TYPE} - gh release view ${GITHUB_RELEASE_NAME} - if [ $? -ne 0 ] - then - echo "Creating github release with tag: ${GITHUB_RELEASE_NAME}" - - RELEASE_TYPE="--latest" - if [[ "${BUILD_TYPE}" != "Release" ]]; - then + RELEASE_TYPE="--latest" + if [ '${{ matrix.build-type }}' != 'Release' ]; then RELEASE_TYPE="--prerelease" - fi - - # Create release on github - gh release create ${GITHUB_RELEASE_NAME} -n "${BRANCH} branch" --target ${BRANCH} ${RELEASE_TYPE} -t "${TARGET_OS} ${BRANCH} branch ${BUILD_TYPE} build" - if [ $? -ne 0 ] - then - echo "Failed to create github release with tag: ${GITHUB_RELEASE_NAME}" - exit 1 - fi - fi - - COMPRESSED_TARGET="${TARGET_NAME}-lib.tar.gz" - echo "Compressing ${TARGET_OS} version ${TARGET_SHA} of ${TARGET_NAME} ${BUILD_TYPE} mode (target build folder: ${TARGET_DIRECTORY})" - tar --exclude="$TARGET_NAME/src" --exclude="$TARGET_NAME/tmp" -zcf ${COMPRESSED_TARGET} ${TARGET_DIRECTORY} - - retValue=1 - numberOfTries=1 - until [[ $retValue -eq 0 ]] - do - if [[ $numberOfTries -gt 5 ]]; then - break - fi - - echo "#${numberOfTries} Uploading target ${COMPRESSED_TARGET} to github release ${GITHUB_RELEASE_NAME}" - gh release upload --clobber ${GITHUB_RELEASE_NAME} ${COMPRESSED_TARGET} - retValue=$? - - if [[ $retValue -ne 0 ]]; then - echo "gh release upload failed, sleep 2 sec before next try" - sleep 2 - fi - - ((numberOfTries++)) - done - - if [[ $retValue -ne 0 ]]; then - echo "Failed to upload target ${COMPRESSED_TARGET} to github release ${GITHUB_RELEASE_NAME}" - exit 1 fi - runs-on: ${{ matrix.target-build-data.runs-on }} - outputs: - TARGET_BUILT: ${{ steps.cache-library-directory.outputs.TARGET_BUILT }} - steps: - - name: Create library keys and paths to cache/build - id: create-lib-cache-keys + # Create release on GitHub + gh release create $RELEASE_TAG \ + -n '${{ github.ref_name }} branch' \ + --target '${{ github.ref_name }}' \ + ${RELEASE_TYPE} \ + -t '${{ matrix.target }} ${{ github.ref_name }} branch ${{ matrix.build-type }} build' + fi shell: bash - run: | - # build array of library names - IFS=$'\n' read -d '|' -ra TARGET_REPO_NAMES <<< "$(echo -ne '${{ needs.create-targets-matrix.outputs.TARGET_REPO_NAMES }}|')" - IFS=$'\n' read -d '|' -ra TARGET_SHAS <<< "$(echo -ne '${{ needs.create-targets-matrix.outputs.TARGET_SHAS }}|')" - IFS=$'\n' read -d '|' -ra TARGET_DIRECTORIES <<< "$(echo -ne '${{ needs.create-targets-matrix.outputs.TARGET_DIRECTORIES }}|')" - LIB_CACHE_NAME_KEYS="[ " - LIB_CACHE_PATHS="[ " - first=true - for i in "${!TARGET_REPO_NAMES[@]}"; do - if [[ "$first" != "true" ]]; then - LIB_CACHE_NAME_KEYS+=", " - LIB_CACHE_PATHS+=", " - fi - first=false - LIB_CACHE_NAME_KEYS+="\"l/${{ matrix.target-os }}/${{ matrix.build-type }}/${TARGET_REPO_NAMES[i]}-${TARGET_SHAS[i]}\"" - LIB_CACHE_PATHS+="[\"./build/${{ matrix.target-os }}/${{ matrix.build-type }}/${TARGET_DIRECTORIES[i]}/**\"]" - done - - LIB_CACHE_NAME_KEYS+=" ]" - echo "LIB_CACHE_NAME_KEYS=$LIB_CACHE_NAME_KEYS" >> $GITHUB_OUTPUT - LIB_CACHE_PATHS+=" ]" - echo "LIB_CACHE_PATHS=$LIB_CACHE_PATHS" >> $GITHUB_OUTPUT - - - name: Remove old libraries that are cached. + - name: Check which targets need updating + id: check-targets + working-directory: ${{env.BUILD_DIRECTORY}} run: | - echo "We really should remove old library caches here" + declare -A target_shas + declare -A target_build_directories - - name: Install configuration - uses: ChristopherHX/conditional@main - with: - if: ${{ matrix.target-build-data.install-uses != null }} - step: | - uses: ${{ matrix.target-build-data.install-uses.uses || '' }} - with: ${{ (matrix.target-build-data.install-uses.with && toJSON(matrix.target-build-data.install-uses.with)) || '{}' }} - - - name: Cache Third Party Directory - uses: GeniusVentures/cache-multi/restore@v3.3.1 - id: cache-tp-source-directory - with: - key: ${{ needs.setup-src-cache.outputs.THIRD_PARTY_CACHE_NAME_KEY }} - enableCrossOsArchive: true - path: | - !.git/** - ./** + echo Detecting targets: - - if: (steps.cache-tp-source-directory.outputs.cache-hit != 'true') - run: | - echo "Couldn't find cached thirdparty code, ${{ needs.setup-src-cache.outputs.THIRD_PARTY_CACHE_NAME_KEY }} fatal error!" - exit 1 + while IFS=':' read -r file src_dir; do + if ${{runner.os == 'Windows'}}; then + file=$(cygpath -u ${file}) + src_dir=$(cygpath -u ${src_dir}) + fi + target="${file%-source_dirinfo.txt}" + target="${target##*/}" - - name: Cache Submodule source files without .git - id: cache-source-directory - uses: GeniusVentures/cache-multi/restoremulti@v3.3.1 - with: - multi-keys: ${{ needs.setup-src-cache.outputs.CACHE_MULTI_PARAMETER_NAME_KEYS }} - enableCrossOsArchive: true - paths: ${{ needs.setup-src-cache.outputs.CACHE_MULTI_PARAMETER_PATHS }} + echo ${target}: ${src_dir} - - name: Run setup script for target OS - shell: bash - run: | - ${{ matrix.target-build-data.setup-script }} + sha=$(git -C ${src_dir} rev-parse HEAD) + target_shas[$target]=$sha - - name: Configure CMake - shell: bash - run: | - TARGET_OS="${{ matrix.target-build-data.target-os }}" - BUILD_TYPE="${{ matrix.build-type }}" - WORKSPACE=${{ github.workspace }} - cd build/$TARGET_OS - ${{ matrix.target-build-data.cmake-init-script }} - - - name: Load built library caches if any - id: cache-library-directory - shell: bash - run: | - TARGET_OS="${{ matrix.target-build-data.target-os }}" - BUILD_TYPE="${{ matrix.build-type }}" - BRANCH=${{ github.ref_name }} - IFS=$'\n' read -d '|' -ra TARGET_NAMES <<< "$(echo -ne '${{ needs.create-targets-matrix.outputs.TARGET_NAMES }}|')" - IFS=$'\n' read -d '|' -ra TARGET_SHAS <<< "$(echo -ne '${{ needs.create-targets-matrix.outputs.TARGET_SHAS }}|')" + build_directory=$(echo $file | sed 's|^\(\./[^/]*\).*|\1|') + target_build_directories[$target]=$build_directory + done < <(rg 'source_dir=(.*)' -u -r '$1' -g '*-source_dirinfo.txt' .) + echo "Downloading release.json file" set +e + gh release download $RELEASE_TAG --pattern "release.json" --clobber + set -e - GITHUB_RELEASE_NAME=${TARGET_OS}-${BRANCH}-${BUILD_TYPE} - - # check if release.json file already available - jsonStr="[]" - jsonFound=`gh release view ${GITHUB_RELEASE_NAME} --json assets --jq "any(.assets[]; .name == \"release.json\")"` - if [ $? -eq 0 ] - then - echo "Downloading release.json file" - gh release download ${GITHUB_RELEASE_NAME} --pattern "release.json" --clobber - if [ $? -eq 0 ] - then - echo "Loading release.json file" - jsonStr=`cat release.json` - fi + declare -A release_shas + + if [[ -f "release.json" ]]; then + while IFS="=" read -r target sha; do + # We remove the carriage return because `jq` adds them on Windows + release_shas[$target]="${sha//$'\r'/}" + done < <(jq -r '.[] | "\(.name)=\(.sha)"' release.json) fi - set -e + targets_to_update=() + sha_of_targets_to_update=() + build_directories_of_targets_to_update=() + up_to_date_targets=() - targetBuiltList="" - for i in "${!TARGET_NAMES[@]}"; do - TARGET_NAME="${TARGET_NAMES[i]}" - TARGET_SHA="${TARGET_SHAS[i]}" - COMPRESSED_TARGET="${TARGET_NAME}-lib.tar.gz" - - targetBuilt=false - shaFound=`jq ".[] | select(.name == \"${TARGET_NAME}\") | .sha" <<< ${jsonStr}` - if [[ "${shaFound}" == \"${TARGET_SHA}\" ]]; - then - targetBuilt=true - fi - - echo "Check if ${COMPRESSED_TARGET} found on ${GITHUB_RELEASE_NAME}: ${targetBuilt}" - targetBuiltList+="${targetBuilt}\n" + echo "Checking SHAs:" + + for target in "${!target_shas[@]}"; do + if [[ -v release_shas["$target"] && "${target_shas[$target]}" == "${release_shas[$target]}" ]]; then + echo "$target: up to date" + up_to_date_targets+=("${target}") + else + echo "$target: out of date" + targets_to_update+=("${target}") + sha_of_targets_to_update+=("${target_shas[$target]}") + build_directories_of_targets_to_update+=("${target_build_directories[$target]}") + fi done - echo "TARGET_BUILT=$targetBuiltList" >> $GITHUB_OUTPUT + echo "TARGETS_TO_UPDATE=${targets_to_update[@]}" >>$GITHUB_OUTPUT + echo "SHA_OF_TARGETS_TO_UPDATE=${sha_of_targets_to_update[@]}" >>$GITHUB_OUTPUT + echo "BUILD_DIRECTORIES_OF_TARGETS_TO_UPDATE=${build_directories_of_targets_to_update[@]}" >>$GITHUB_OUTPUT + echo "UP_TO_DATE_TARGETS=${up_to_date_targets}" >>$GITHUB_OUTPUT + shell: bash - - name: Install Rust target for wasm - run: rustup target add wasm32-unknown-emscripten + - name: Download up to date targets + working-directory: ${{env.BUILD_DIRECTORY}} + run: | + up_to_date_targets=(${{steps.check-targets.outputs.UP_TO_DATE_TARGETS}}) + for target in "${up_to_date_targets[@]}"; do + compressed_target="${target}-lib.tar.gz" + echo Downloading ${compressed_target} + gh release download ${RELEASE_TAG} --pattern "${compressed_target}" --clobber + tar -xzf ${compressed_target} + done + shell: bash + # Workaround GitHub shell - name: Build OpenSSL - if: ${{ matrix.target-build-data.target-os == 'Windows' }} + if: ${{ runner.os == 'Windows' }} + working-directory: ${{env.BUILD_DIRECTORY}} shell: cmd - run: | - set TARGET_OS=${{ matrix.target-build-data.target-os }} - set TARGET_RUNS_ON=${{ matrix.target-build-data.runs-on }} - set BUILD_TYPE=${{ matrix.build-type }} - cmake --build "%GITHUB_WORKSPACE%\build\%TARGET_OS%\%BUILD_TYPE%" --target openssl --config %BUILD_TYPE% -j + run: cmake --build . --target openssl - - name: Build any updated libraries - id: build-updated-libraries - shell: bash + - name: Build, compress and upload targets + working-directory: ${{env.BUILD_DIRECTORY}} run: | - TARGET_OS="${{ matrix.target-build-data.target-os }}" - TARGET_RUNS_ON="${{ matrix.target-build-data.runs-on }}" - BUILD_TYPE="${{ matrix.build-type }}" - BRANCH=${{ github.ref_name }} - WORKSPACE=${{ github.workspace }} - - GITHUB_RELEASE_NAME=${TARGET_OS}-${BRANCH}-${BUILD_TYPE} - - IFS=$'\n' read -d '|' -ra TARGET_NAMES <<< "$(echo -ne '${{ needs.create-targets-matrix.outputs.TARGET_NAMES }}|')" - IFS=$'\n' read -d '|' -ra TARGET_SHAS <<< "$(echo -ne '${{ needs.create-targets-matrix.outputs.TARGET_SHAS }}|')" - IFS=$'\n' read -d '|' -ra TARGET_BUILT <<< "$(echo -ne '${{ steps.cache-library-directory.outputs.TARGET_BUILT }}|')" - IFS=$'\n' read -d '|' -ra TARGET_DIRECTORIES <<< "$(echo -ne '${{ needs.create-targets-matrix.outputs.TARGET_DIRECTORIES }}|')" - - cd "build/${TARGET_OS}/${BUILD_TYPE}" - - jsonStr="[]" - declare -a listOfTargetNamesToBuild - declare -a listOfTargetSHAsToBuild - declare -a listOfTargetDirToBuild - - for i in "${!TARGET_NAMES[@]}"; do - TARGET_NAME="${TARGET_NAMES[i]}" - TARGET_SHA="${TARGET_SHAS[i]}" - TARGET_DIRECTORY="${TARGET_DIRECTORIES[i]}" - COMPRESSED_TARGET="${TARGET_NAME}-lib.tar.gz" - - echo "${TARGET_NAME} release found: ${TARGET_BUILT[i]} (Target direcory: $TARGET_DIRECTORY)" - - if [ "${TARGET_BUILT[i]}" == "true" ]; then - echo "Downloading cached target: $TARGET_NAME, sha: $TARGET_SHA" - gh release download ${GITHUB_RELEASE_NAME} --pattern "${COMPRESSED_TARGET}" --clobber - if [ $? -eq 0 ] - then - echo "Extracting cached target: ${COMPRESSED_TARGET}" - tar -xf ${COMPRESSED_TARGET} - FOLDER_HASH=$(find ./${TARGET_DIRECTORY} -xdev -type f -exec cat {} + | md5sum | awk '{print $1}') - - echo "Cached target folder hash: ${FOLDER_HASH}" - jsonStrHash=$(jq -n \ - --arg name "$TARGET_NAME" \ - --arg sha "$TARGET_SHA" \ - --arg binFolderName "$TARGET_DIRECTORY" \ - --arg binFolderHash "$FOLDER_HASH" \ - '{name: $name, sha: $sha, binFolderName: $binFolderName, binFolderHash: $binFolderHash}') - - jsonStr=$(jq -c --argjson obj "$jsonStrHash" '. + [$obj]' <<< "$jsonStr") - - echo "Target extracted to `pwd`/${TARGET_DIRECTORY}" - echo "Contents of target folder `pwd`/${TARGET_DIRECTORY}" - ls -la ./${TARGET_DIRECTORY} - else - echo "Failed to download cached target: ${COMPRESSED_TARGET} - need to rebuild it" - listOfTargetNamesToBuild+=("${TARGET_NAME}") - listOfTargetSHAsToBuild+=("${TARGET_SHA}") - listOfTargetDirToBuild+=("${TARGET_DIRECTORY}") - fi - else - echo "Cached target not found: ${COMPRESSED_TARGET} - need to rebuild it" - listOfTargetNamesToBuild+=("${TARGET_NAME}") - listOfTargetSHAsToBuild+=("${TARGET_SHA}") - listOfTargetDirToBuild+=("${TARGET_DIRECTORY}") - fi - done + targets_to_update=(${{steps.check-targets.outputs.TARGETS_TO_UPDATE}}) + build_directories=(${{steps.check-targets.outputs.BUILD_DIRECTORIES_OF_TARGETS_TO_UPDATE}}) + sha_of_targets=(${{steps.check-targets.outputs.SHA_OF_TARGETS_TO_UPDATE}}) - # Print hash JSON file - jq <<< $jsonStr + declare -A release_shas - # save hash JSON file - jq <<< $jsonStr > hash.json + if [[ -f "release.json" ]]; then + while IFS="=" read -r target sha; do + release_shas[$target]="${sha//$'\r'/}" + done < <(jq -r '.[] | "\(.name)=\(.sha)"' release.json) + fi - # check if release.json file already available - releaseJsonStr="[]" + for i in "${!targets_to_update[@]}"; do + target=${targets_to_update[$i]} + compressed_file="${target}-lib.tar.gz" + directory_to_compress=$(basename "${build_directories[$i]}") - set +e + cmake --build . --target $target -j - jsonFound=`gh release view ${GITHUB_RELEASE_NAME} --json assets --jq "any(.assets[]; .name == \"release.json\")"` - if [ $? -eq 0 ] - then - echo "Downloading release.json file" - gh release download ${GITHUB_RELEASE_NAME} --pattern "release.json" --clobber - if [ $? -eq 0 ] - then - echo "Loading release.json file" - releaseJsonStr=`cat release.json` - fi - fi + echo ${target}: $directory_to_compress + tar --exclude="${directory_to_compress}/src" --exclude="${directory_to_compress}/tmp" -czf ${compressed_file} ${directory_to_compress} - set -e + echo -e "Uploading ${compressed_file}" + gh release upload --clobber ${RELEASE_TAG} ${compressed_file} - for i in "${!listOfTargetNamesToBuild[@]}"; do - TARGET_NAME="${listOfTargetNamesToBuild[i]}" - TARGET_SHA="${listOfTargetSHAsToBuild[i]}" - TARGET_DIRECTORY="${listOfTargetDirToBuild[i]}" - COMPRESSED_TARGET="${TARGET_NAME}-lib.tar.gz" - COMPRESSED_TARGET_SRC="${TARGET_NAME}-src.tar.gz" - - echo "Compiling $TARGET_OS version $TARGET_SHA of $TARGET_NAME $BUILD_TYPE mode" - cmake --build . --target $TARGET_NAME --config $BUILD_TYPE -j - - echo "Starting to upload target: ${COMPRESSED_TARGET}" - # Upload released target - ${{ matrix.target-save-data.release-target }} - - RELEASE_ASSETS=`gh release view ${GITHUB_RELEASE_NAME} --json assets` - - # Updating release.json - # Get source url - TARGET_SOURCE=`jq ".assets[] | select(.name == \"${COMPRESSED_TARGET_SRC}\") | .url" <<< ${RELEASE_ASSETS}` - # Get target url - TARGET_BINARY=`jq ".assets[] | select(.name == \"${COMPRESSED_TARGET}\") | .url" <<< ${RELEASE_ASSETS}` - - releaseFound=$(jq ".[] | select(.name == \"${TARGET_NAME}\")" <<<${releaseJsonStr}) - if [ ${#releaseFound} -gt 0 ] - then - echo "Updating release.json file with target ${TARGET_NAME}" - releaseJsonStr=$(jq --arg name "${TARGET_NAME}" \ - --arg sha "${TARGET_SHA}" \ - --arg binFolderName "${TARGET_DIRECTORY}" \ - --arg source "${TARGET_SOURCE}" \ - --arg binary "${TARGET_BINARY}" \ - '(.[] | select(.name == $name)) |= (.sha = $sha | .binFolderName = $binFolderName | .source = $source | .binary = $binary)' <<<"${releaseJsonStr}") - - else - echo "Adding target ${TARGET_NAME} to release.json file" - jsonStrTarget=$(jq -n \ - --arg name "${TARGET_NAME}" \ - --arg sha "${TARGET_SHA}" \ - --arg binFolderName "${TARGET_DIRECTORY}" \ - --arg source "${TARGET_SOURCE}" \ - --arg binary "${TARGET_BINARY}" \ - '{name: $name, sha: $sha, binFolderName: $binFolderName, source: $source, binary: $binary}') - - releaseJsonStr=$(jq -c --argjson obj "$jsonStrTarget" '. + [$obj]' <<<"$releaseJsonStr") - fi - - # Upload JSON file release - jq <<< $releaseJsonStr > release.json - - echo "Uploading JSON file release" - ${{ matrix.target-save-data.upload-release-json }} + release_shas[${target}]="${sha_of_targets[i]}" - done + json_data=$(for key in "${!release_shas[@]}"; do + printf '{"name": "%s", "sha": "%s"}\n' "$key" "${release_shas[$key]}" + done | jq -s '.') - - name: Upload JSON file release on build failure - if: ${{ failure() && steps.build-updated-libraries.conclusion == 'failure' }} - shell: bash - run: | - TARGET_OS="${{ matrix.target-build-data.target-os }}" - BUILD_TYPE="${{ matrix.build-type }}" - BRANCH=${{ github.ref_name }} - - GITHUB_RELEASE_NAME=${TARGET_OS}-${BRANCH}-${BUILD_TYPE} - - retValue=1 - numberOfTries=1 - until [[ $retValue -eq 0 ]] - do - if [[ $numberOfTries -gt 5 ]]; then - break - fi - - echo "#${numberOfTries} Uploading release.json to github release ${GITHUB_RELEASE_NAME}" - gh release upload --clobber ${GITHUB_RELEASE_NAME} release.json - retValue=$? - - if [[ $retValue -ne 0 ]]; then - echo "gh release upload failed, sleep 2 sec before next try" - sleep 2 - fi - - ((numberOfTries++)) + echo "$json_data" >release.json + gh release upload --clobber ${RELEASE_TAG} release.json done - - - name: Save target OS SDK as github release shell: bash - run: | - TARGET_OS="${{ matrix.target-build-data.target-os }}" - TARGET_RUNS_ON="${{ matrix.target-build-data.runs-on }}" - BUILD_TYPE="${{ matrix.build-type }}" - BRANCH=${{ github.ref_name }} - IFS=$'\n' read -d '|' -ra TARGET_NAMES <<< "$(echo -ne '${{ needs.create-targets-matrix.outputs.TARGET_NAMES }}|')" - IFS=$'\n' read -d '|' -ra TARGET_SHAS <<< "$(echo -ne '${{ needs.create-targets-matrix.outputs.TARGET_SHAS }}|')" - IFS=$'\n' read -d '|' -ra TARGET_BUILT <<< "$(echo -ne '${{ steps.cache-library-directory.outputs.TARGET_BUILT }}|')" - IFS=$'\n' read -d '|' -ra TARGET_DIRECTORIES <<< "$(echo -ne '${{ needs.create-targets-matrix.outputs.TARGET_DIRECTORIES }}|')" - - GITHUB_RELEASE_NAME=${TARGET_OS}-${BRANCH}-${BUILD_TYPE} - - RELEASE_ASSETS=`gh release view ${GITHUB_RELEASE_NAME} --json assets` - - jsonStr="[]" - cd "build/${TARGET_OS}/${BUILD_TYPE}" - for i in "${!TARGET_NAMES[@]}"; do - TARGET_NAME="${TARGET_NAMES[i]}" - TARGET_SHA="${TARGET_SHAS[i]}" - TARGET_DIRECTORY="${TARGET_DIRECTORIES[i]}" - - COMPRESSED_TARGET="${TARGET_NAME}-lib.tar.gz" - COMPRESSED_TARGET_SRC="${TARGET_NAME}-src.tar.gz" - echo "${TARGET_NAME} release found: ${TARGET_BUILT[i]}" - - if [ "${TARGET_BUILT[i]}" == "true" ]; then - # Compare uncompressed original hash of the binary folder with current to see if any changes has been made - originalHash=`jq ".[] | select(.name == \"${TARGET_NAME}\") | .binFolderHash" hash.json` - currentHash=$(find ./${TARGET_DIRECTORY} -xdev -type f -exec cat {} + | md5sum | awk '{print $1}') - if [[ "${originalHash}" != \"${currentHash}\" ]]; - then - echo "originalHash: ${originalHash}" - echo "currentHash: \"${currentHash}\"" - echo "Has does not match, uploading already installed modified target: ${TARGET_NAME}, sha: ${TARGET_SHA}" - ${{ matrix.target-save-data.release-target }} - else - echo "Target ${TARGET_NAME} binary folder did not change, no need to update release" - fi - fi - - # Update JSON file - # Get source url - TARGET_SOURCE=`jq ".assets[] | select(.name == \"${COMPRESSED_TARGET_SRC}\") | .url" <<< ${RELEASE_ASSETS}` - # Get target url - TARGET_BINARY=`jq ".assets[] | select(.name == \"${COMPRESSED_TARGET}\") | .url" <<< ${RELEASE_ASSETS}` - jsonStrTarget=`jq ". + { \"name\": \"${TARGET_NAME}\", \"sha\" : \"${TARGET_SHA}\", \"binFolderName\" : \"${TARGET_DIRECTORY}\", \"source\" : ${TARGET_SOURCE}, \"binary\" : ${TARGET_BINARY} }" <<< "{}"` - jsonStr=$(jq -c --argjson obj "$jsonStrTarget" '. + [$obj]' <<<"$jsonStr") - done - - # Print final JSON file - jq <<< $jsonStr - - # Upload JSON file release - jq <<< $jsonStr > release.json - - ${{ matrix.target-save-data.upload-release-json }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..aaa644b6 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,104 @@ +name: Build + +on: + workflow_call: + inputs: + target: + required: true + type: string + abi: + required: false + type: string + build-type: + required: true + type: string +jobs: + build: + env: + GRPC_BUILD_ENABLE_CCACHE: "ON" + runs-on: ${{ contains(fromJson('["Android", "Linux"]'), inputs.target) && 'ubuntu-latest' || contains(fromJson('["iOS", "OSX"]'), inputs.target) && 'macos-latest' || 'windows-latest' }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: "recursive" + + - name: Configure Linux host + if: ${{ runner.os == 'Linux'}} + run: | + sudo update-alternatives --install /usr/bin/cc cc $(which clang) 100 + sudo update-alternatives --install /usr/bin/c++ c++ $(which clang++) 100 + sudo update-alternatives --set cc $(which clang) + sudo update-alternatives --set c++ $(which clang++) + + sudo apt install ccache ninja-build libvulkan-dev -y + echo "CMAKE_GENERATOR=Ninja" >> $GITHUB_ENV + + - name: Configure Windows host + if: ${{ runner.os == 'Windows'}} + run: | + choco install ccache -A + + - name: Configure macOS host + if: ${{ runner.os == 'macOS'}} + run: | + brew install ccache ninja + echo "CMAKE_GENERATOR=Ninja" >> $GITHUB_ENV + + - name: Add Darwin toolchain + if: ${{ inputs.target == 'OSX'}} + run: rustup target add x86_64-apple-darwin + + - name: Add iOS toolchain + if: ${{ inputs.target == 'iOS' }} + run: | + rustup toolchain install nightly-aarch64-apple-darwin + rustup component add rust-src --toolchain nightly-aarch64-apple-darwin + rustup target add aarch64-apple-ios + + - name: Add Android toolchain + if: ${{ inputs.target == 'Android' }} + run: | + NDK_VERSION="r27b" + wget https://dl.google.com/android/repository/android-ndk-$NDK_VERSION-linux.zip -O ndk.zip + unzip ndk.zip -d $HOME + + echo "ANDROID_NDK_HOME=$HOME/android-ndk-$NDK_VERSION" >> $GITHUB_ENV + + rustup target add aarch64-linux-android + + - name: Install bindgen + run: cargo install cbindgen + + - name: Add wasm Rust target + run: rustup target add wasm32-unknown-emscripten + + - name: Set build directory + id: build-dir + run: | + if [ '${{inputs.target}}' == 'Android' ] ; then + BUILD_DIRECTORY=build/${{inputs.target}}/${{inputs.build-type}}/${{inputs.abi}} + else + BUILD_DIRECTORY=build/${{inputs.target}}/${{inputs.build-type}} + fi + echo "BUILD_DIRECTORY=$BUILD_DIRECTORY" >>$GITHUB_OUTPUT + shell: bash + + - name: Configure CMake for Mac x86 + if: ${{ inputs.target == 'OSX'}} + run: cmake -S build/${{inputs.target}} -B ${{steps.build-dir.outputs.BUILD_DIRECTORY}} -DCMAKE_BUILD_TYPE=${{inputs.build-type}} -DPLATFORM=MAC + + - name: Configure CMake for iOS + if: ${{ inputs.target == 'iOS'}} + run: cmake -S build/${{inputs.target}} -B ${{steps.build-dir.outputs.BUILD_DIRECTORY}} -DCMAKE_BUILD_TYPE=${{inputs.build-type}} -DPLATFORM=OS64 + + - name: Configure SuperGenius CMake for Android + if: ${{ inputs.target == 'Android'}} + run: cmake -S build/${{inputs.target}} -B ${{steps.build-dir.outputs.BUILD_DIRECTORY}} -DCMAKE_BUILD_TYPE=${{inputs.build-type}} -DANDROID_ABI=${{inputs.abi}} + + - name: Configure CMake + if: ${{ inputs.target != 'OSX' && inputs.target != 'iOS' && inputs.target != 'Android' }} + run: cmake -S build/${{inputs.target}} -B ${{steps.build-dir.outputs.BUILD_DIRECTORY}} -DCMAKE_BUILD_TYPE=${{inputs.build-type}} + + - name: Build project + run: cmake --build ${{steps.build-dir.outputs.BUILD_DIRECTORY}} --config ${{inputs.build-type}} -j diff --git a/.github/workflows/iOS-cmake.yml b/.github/workflows/iOS-cmake.yml deleted file mode 100644 index 8ee8d9ac..00000000 --- a/.github/workflows/iOS-cmake.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: iOS Build - -on: - workflow_dispatch: - -jobs: - iOS: - runs-on: macos-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: "recursive" - - # Workaround for arm64 build - - name: Ensure latest macOS SDK is used - run: | - sudo xcode-select --switch "$(find /Applications -mindepth 1 -maxdepth 1 ! -type l | grep "Xcode_*[\.0-9]*app" | sort -V | tail -1)/Contents/Developer" - sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/* - - - name: Install Rust dependencies - run: | - rustup target add x86_64-apple-ios aarch64-apple-ios-sim aarch64-apple-ios aarch64-apple-darwin x86_64-apple-darwin - - - name: Install bindgen - run: cargo install cbindgen cargo-lipo - - - name: Configure CMake - run: cmake -S build/iOS -B build/iOS/Release -DCMAKE_BUILD_TYPE=Release -DiOS_ABI=arm64-v8a -DIOS_ARCH="arm64" -DENABLE_ARC=0 -DENABLE_BITCODE=0 -DENABLE_VISIBILITY=1 -DCMAKE_OSX_ARCHITECTURES=arm64 -DCMAKE_SYSTEM_PROCESSOR=arm64 -DCMAKE_TOOLCHAIN_FILE=${{github.workspace}}/build/iOS/iOS.cmake - - - name: Build project - run: cmake --build build/iOS/Release --config Release diff --git a/.github/workflows/iOS.yml b/.github/workflows/iOS.yml new file mode 100644 index 00000000..0cd3dbae --- /dev/null +++ b/.github/workflows/iOS.yml @@ -0,0 +1,11 @@ +name: iOS +on: + workflow_dispatch: + pull_request: + +jobs: + ios-build: + uses: ./.github/workflows/build.yml + with: + target: iOS + build-type: Release diff --git a/.github/workflows/macOS.yml b/.github/workflows/macOS.yml new file mode 100644 index 00000000..3a95ddfe --- /dev/null +++ b/.github/workflows/macOS.yml @@ -0,0 +1,11 @@ +name: macOS +on: + workflow_dispatch: + pull_request: + +jobs: + macos-build: + uses: ./.github/workflows/build.yml + with: + target: OSX + build-type: Release diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml index 7f2ced65..4f5000b1 100644 --- a/.github/workflows/test-build.yml +++ b/.github/workflows/test-build.yml @@ -1,108 +1,58 @@ -name: Build per OS +name: Multiplatform build on: workflow_dispatch: jobs: - build: - env: - GRPC_BUILD_ENABLE_CCACHE: "ON" - runs-on: ${{matrix.host}} - strategy: - fail-fast: false - matrix: - target: [Android, iOS, OSX, Linux, Windows] - build_type: [Debug, Release] - include: - - target: Linux - host: ubuntu-latest - - target: Windows - host: windows-latest - - target: OSX - host: macos-latest - - target: Android - host: ubuntu-latest - android_abi: arm64-v8a - - target: iOS - host: macos-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: "recursive" - - - name: Set clang as the default compiler - if: ${{ matrix.host == 'ubuntu-latest' }} - run: | - sudo update-alternatives --install /usr/bin/cc cc $(which clang) 100 - sudo update-alternatives --install /usr/bin/c++ c++ $(which clang++) 100 - sudo update-alternatives --set cc $(which clang) - sudo update-alternatives --set c++ $(which clang++) - - - name: Install Linux host dependencies - if: ${{ matrix.host == 'ubuntu-latest' }} - run: | - sudo apt install ccache ninja-build -y - sudo apt install vulkan-tools vulkan-utility-libraries-dev libvulkan-dev -y - echo "CMAKE_GENERATOR=Ninja" >> $GITHUB_ENV - - - name: Install Windows host dependencies - if: ${{ matrix.host == 'windows-latest' }} - run: | - choco install ccache -A - - - name: Install Darwin host dependencies - if: ${{ matrix.host == 'macos-latest' }} - run: | - brew install ccache ninja - echo "CMAKE_GENERATOR=Ninja" >> $GITHUB_ENV - - - name: Add Darwin toolchain - if: ${{ matrix.target == 'OSX' }} - run: rustup target add x86_64-apple-darwin - - - name: Add iOS toolchain - if: ${{ matrix.target == 'iOS' }} - run: | - rustup toolchain install nightly-aarch64-apple-darwin - rustup component add rust-src --toolchain nightly-aarch64-apple-darwin - rustup target add aarch64-apple-ios - - - name: Add Android toolchain - if: ${{ matrix.target == 'Android' }} - run: | - rustup target add aarch64-linux-android - - - name: Install bindgen - run: cargo install cbindgen - - - name: Add Rust target - run: rustup target add wasm32-unknown-emscripten - - - name: Set ABI specific path based on target - if: ${{ matrix.host != 'windows-latest' }} - run: | - if [ "${{ matrix.target }}" = "Android" ]; then - echo "ABI_DIR=/${{ matrix.android_abi }}" >> $GITHUB_ENV - else - echo "ABI_DIR=" >> $GITHUB_ENV - fi - - - name: Configure CMake for Mac x86 - if: ${{ matrix.target == 'OSX' }} - run: cmake -S build/${{ matrix.target }} -B build/${{ matrix.target }}/${{ matrix.build_type }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DPLATFORM=MAC - - - name: Configure CMake for iOS - if: ${{ matrix.target == 'iOS' }} - run: cmake -S build/${{ matrix.target }} -B build/${{ matrix.target }}/${{ matrix.build_type }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DPLATFORM=OS64 - - - name: Configure CMake for Android - if: ${{ matrix.target == 'Android' }} - run: cmake -S build/${{ matrix.target }} -B build/${{ matrix.target }}/${{ matrix.build_type }}$ABI_DIR -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DANDROID_ABI=${{ matrix.android_abi }} - - - name: Configure CMake for other platforms - if: ${{ matrix.target != 'OSX' && matrix.target != 'iOS' && matrix.target != 'Android' }} - run: cmake -S build/${{ matrix.target }} -B build/${{ matrix.target }}/${{ matrix.build_type }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} - - - name: Build project - run: cmake --build build/${{ matrix.target }}/${{ matrix.build_type }}${{ env.ABI_DIR }} --config ${{ matrix.build_type }} -j \ No newline at end of file + android-debug: + uses: ./.github/workflows/build.yml + with: + target: Android + build-type: Debug + abi: arm64 + ios-debug: + uses: ./.github/workflows/build.yml + with: + target: iOS + build-type: Debug + linux-debug: + uses: ./.github/workflows/build.yml + with: + target: Linux + build-type: Debug + macos-debug: + uses: ./.github/workflows/build.yml + with: + target: OSX + build-type: Debug + windows-debug: + uses: ./.github/workflows/build.yml + with: + target: Windows + build-type: Debug + android-release: + uses: ./.github/workflows/build.yml + with: + target: Android + build-type: Release + abi: arm64 + ios-release: + uses: ./.github/workflows/build.yml + with: + target: iOS + build-type: Release + linux-release: + uses: ./.github/workflows/build.yml + with: + target: Linux + build-type: Release + macos-release: + uses: ./.github/workflows/build.yml + with: + target: OSX + build-type: Release + windows-release: + uses: ./.github/workflows/build.yml + with: + target: Windows + build-type: Release diff --git a/.github/workflows/test-install-config.yml b/.github/workflows/test-install-config.yml deleted file mode 100644 index 603c3c48..00000000 --- a/.github/workflows/test-install-config.yml +++ /dev/null @@ -1,51 +0,0 @@ - -name: test install functionality with if - -# Controls when the workflow will run -# Triggers the workflow on push or pull request events and manually from the Actions tab -on: - workflow_dispatch: - -jobs: - build-targets-matrix-test: - strategy: - matrix: - build-type: [ Release ] - target-build-data: - - target-os: OSX - runs-on: macos-latest - shell: bash - setup-script: | - echo "Setup for OSX Build" - sudo xcode-select --switch "$(find /Applications/Xcode*.app -maxdepth 0 | sort -V | tail -1)/Contents/Developer" - sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/* - cmake-script: | - cd build/$TARGET_OS - mkdir Release - cd Release - cmake -S .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE - echo "Compiling $TARGET_OS version $LIBRARY_VERSION of $LIBRARY_NAME" - make $LIBRARY_NAME - - - target-os: Windows - runs-on: windows-2022 - setup-script: | - echo "Setup for Windows Build" - install-uses: - name: Configure build for Windows 10 x64 - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: amd64 - sdk: 10.0.22621.0 - vsversion: 17 - - runs-on: ubuntu-latest - steps: - - name: Install configuration - uses: ChristopherHX/conditional@main - with: - if: ${{ matrix.target-build-data.install-uses != null }} - step: | - uses: ${{ matrix.target-build-data.install-uses.uses || '' }} - with: ${{ (matrix.target-build-data.install-uses.with && toJSON(matrix.target-build-data.install-uses.with)) || '{}' }} - diff --git a/.github/workflows/test-needs.yml b/.github/workflows/test-needs.yml deleted file mode 100644 index 659a946b..00000000 --- a/.github/workflows/test-needs.yml +++ /dev/null @@ -1,48 +0,0 @@ - -name: test needs functionality with if - -# Controls when the workflow will run -# Triggers the workflow on push or pull request events and manually from the Actions tab -on: - workflow_dispatch: - -jobs: - setup-test: - runs-on: ubuntu-latest - outputs: - has-matrix: ${{ steps.set-matrix.outputs.has-matrix }} - TARGET_LIBRARY_NAMES: ${{ steps.set-targets-list.outputs.TARGET_LIBRARY_NAMES }} - TARGET_KEYS: ${{ steps.set-matrix.outputs.TARGET_KEYS }} - TARGET_PATHS: ${{ steps.set-matrix.outputs.TARGET_PATHS }} - steps: - - name: Set the keys/paths to try and restore - id: set-matrix - run: | - echo "TARGET_KEYS=[ \"abseil-cpp-522606b\", \"Boost.DI-c5287ee\", \"boost-32da69a\" ]" >> $GITHUB_OUTPUT - echo "TARGET_PATHS=[ [ \""'!'".git/**\", \"abseil-cpp/**\"], [ \""'!'".git/**\", \"Boost.DI/**\" ], [ \""'!'".git/**\", \"boost/**\"] ]" >> $GITHUB_OUTPUT - echo "has-matrix='true'" >> $GITHUB_OUTPUT - - - name: Build the targets list - id: set-targets-list - run: | - echo "TARGET_LIBRARY_NAMES=[ \"absl\", \"libname\", \"Boost.DI\", \"Boost\" ]" >> $GITHUB_OUTPUT -# - libname: Boost.DI${{os.EOL}}- libname: Boost${{os.EOL}}- libname: cares${{os.EOL}}- libname: ed25519${{os.EOL}}- libname: fmt${{os.EOL}}- libname: generated${{os.EOL}}- libname: grpc${{os.EOL}}- libname: GTest${{os.EOL}}- libname: ipfs-bitswap-cpp${{os.EOL}}- libname: ipfs-lite-cpp${{os.EOL}}- libname: ipfs-pubsub${{os.EOL}}- libname: kompute${{os.EOL}}- libname: libp2p${{os.EOL}}- libname: libsecp256k1${{os.EOL}}- libname: Microsoft.GSL${{os.EOL}}- libname: openssl${{os.EOL}}- libname: rapidjson${{os.EOL}}- libname: rocksdb${{os.EOL}}- libname: soralog${{os.EOL}}- libname: spdlog${{os.EOL}}- Libname: sqlite3${{os.EOL}}- libname: SQLiteModernCpp${{os.EOL}}- libname: sr25519-donna${{os.EOL}}- libname: tsl_hat_trie${{os.EOL}}- libname: xxhash${{os.EOL}}- libname: yaml-cpp"' >> $GITHUB_OUTPUT - - cache-src-test: - needs: setup-test - runs-on: ubuntu-latest - strategy: - matrix: - libraries: [ abs, libname, Boost.DI, Boost ] - steps: - - name: Output the passed matrix - id: cache-me - run: | - echo "Results: ${{ needs.setup-test.outputs.has-matrix }}" - echo "libName = ${{ matrix.libname }}" - - - name: Check build library - uses: GeniusVentures/cache-multi/restoremulti@develop - with: - keys: ${{ needs.setup-test.outputs.TARGET_KEYS }} - paths: ${{ needs.setup-test.outputs.TARGET_PATHS }} diff --git a/README.md b/README.md index b3c26197..85e56f3d 100644 --- a/README.md +++ b/README.md @@ -1,234 +1,111 @@ -This is the repository for third party of SuperGenius -=================================== +This is the repository for third party of [SuperGenius](https://github.com/GeniusVentures/SuperGenius/). -# CI/CD Status -| | | | -|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:---|:---| -| [![WIndows Master](https://github.com/GeniusVentures/thirdparty/actions/workflows/Windows-cmake.yml/badge.svg?branch=master)](https://github.com/GeniusVentures/thirdparty/actions/workflows/Windows-cmake.yml) | [![OSX Master](https://github.com/GeniusVentures/thirdparty/actions/workflows/OSX-cmake.yml/badge.svg?branch=master)](https://github.com/GeniusVentures/thirdparty/actions/workflows/OSX-cmake.yml) | [![Linux Master](https://github.com/GeniusVentures/thirdparty/actions/workflows/Linux-cmake.yml/badge.svg?branch=master)](https://github.com/GeniusVentures/thirdparty/actions/workflows/Linux-cmake.yml) | -| [![iOS Master](https://github.com/GeniusVentures/thirdparty/actions/workflows/iOS-cmake.yml/badge.svg?branch=master)](https://github.com/GeniusVentures/thirdparty/actions/workflows/iOS-cmake.yml) | [![Android Master](https://github.com/GeniusVentures/thirdparty/actions/workflows/Android-cmake.yml/badge.svg?branch=master)](https://github.com/GeniusVentures/thirdparty/actions/workflows/Android-cmake.yml) || +![Android](https://github.com/GeniusVentures/thirdparty/actions/workflows/Android.yml/badge.svg?branch=master) +![iOS](https://github.com/GeniusVentures/thirdparty/actions/workflows/iOS.yml/badge.svg?branch=master) +![Linux](https://github.com/GeniusVentures/thirdparty/actions/workflows/Linux.yml/badge.svg?branch=master) +![macOS](https://github.com/GeniusVentures/thirdparty/actions/workflows/macOS.yml/badge.svg?branch=master) +![Windows](https://github.com/GeniusVentures/thirdparty/actions/workflows/Windows.yml/badge.svg?branch=master) +=================================== -### Speeding up the build tools -Set two environment variables -- CMAKE_BUILD_PARALLEL_LEVEL=8 -- MAKEFLAGS="-j8" # this errors on Windows nmake, so don't use on Windows +# Download pre-built libraries -# Download Prebuilt libs +Pre-built libraries are available on the [release page](https://github.com/GeniusVentures/thirdparty/releases). The tags are named with the following convention: -Requirements: -- Python3 (3.7+) -- pip install tqdm -- pip install aiohttp +`${PLATFORM}-${BRANCH}-${BUILD_TYPE}` -In thirdparty root directory, with GeniusNetwork as root directory -python ../util/install_from_github.py build/tp-dl-prebuilt-config.txt +Where: -# Download thirdparty project for development +- `PLATFORM` is Android, iOS, Linux, OSX or Windows +- `BUILD_TYPE` is either Debug or Release -```bash -git clone git@github.com:GeniusVentures/thirdparty.git -cd thirdparty -git checkout develop -git submodule update --init --recursive -``` -# Building +The `master` branch receives few merges, download from the `develop` branch to get the newest builds. -Chose the CMAKE_BUILD_TYPE according to the desired configuration (Debug or Release). +# Building -## Windows +If you want to build `thirdparty` for yourself, you'll need to recursively checkout every submodule. -Using Visual Studio 17 2022 to compile thirdparty project. +## Requirements -### Requirements - CMake -- Visual Studio 2019 or 2022 -- Strawberry Perl (https://strawberryperl.com/) -- Python >=3.5 -- rvm/Ruby 2.7.8 - - ```rvm --default use ruby-2.7.8``` -- wallet-core dependency tools - - Rust, cargo - - ```rustup set default-host x86_64-pc-windows-msvc``` - - ```rustup target add x86_64-pc-windows-msvc``` - - ```cargo install cbindgen cargo-lipo``` - - ```rustup target add wasm32-unknown-emscripten``` (to be deprecated) - - -### Build instructions -```bash -cd build/Windows -mkdir [Debug or Release] -cd [Debug or Release] -cmake .. -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=[Debug or Release] -cmake --build . --config [Debug or Release] -``` +- Perl +- `wallet-core` dependency tools + - Ruby + - Rust + - `bindgen` (install with `cargo install cbindgen`) + - WASM target (install with `rustup target add wasm32-unknown-emscripten`) + - On Mac don't use homebrew to install rust, use the recommended install procedure on the official website +- `clang` or `MSVC` as a compiler + - On Linux setting cc and c++ to clang might be needed (using `update-alternatives`) -## Linux -### Requirements - -- Ubuntu 22.04 (or compatible) recommended +### Android -Open a terminal as root ("sudo" without su won't do it because of Ruby installation) +- NDK, preferably version 27b + - Remember to set the environment variable `ANDROID_NDK_HOME` to point to the install path +- Rust Android target + - Installable with `rustup target add aarch64-linux-android` -```bash -sudo su root -``` +Note: we do not test cross-compiling for Android using Windows. -Install default requirements +### iOS -```bash -#!/bin/bash -apt-get -y update -apt-get -y install g++ clang llvm cmake ntp zlib1g-dev libgtk-3-dev ninja-build libjsoncpp25 libsecret-1-0 libjsoncpp-dev libsecret-1-dev git cmake default-jre curl libc++-dev libc++abi-dev -cd /usr/local/src -wget --no-check-certificate https://www.openssl.org/source/openssl-1.1.1t.tar.gz -tar -xf openssl-1.1.1t.tar.gz -cd openssl-1.1.1t/ -./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib >build.log -make install >>build.log -cd ~/ -curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y -. "$HOME/.cargo/env" -cargo install cbindgen >rust-install.log -rustup target add x86_64-unknown-linux-gnu >rust-install.log -cp -R /root/.cargo /home/$SUDO_USER -cp -R /root/.rustup /home/$SUDO_USER -chown -R $SUDO_USER:$SUDO_USER /home//$SUDO_USER/.cargo /home//$SUDO_USER/.rustup -apt-get -y install gnupg2 -curl -sSL https://rvm.io/mpapis.asc | gpg2 --import - -curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import - -curl -sSL https://get.rvm.io | bash -s stable >>ruby-build.log -source /etc/profile.d/rvm.sh -rvm install ruby-2.7.8 --with-openssl-dir=/usr/local/ssl/ >>ruby-build.log -rvm --default use ruby-2.7.8 -ln -s /usr/bin/python3 /usr/bin/python -``` +- Rust iOS target and toolchain ```bash -# exit sudo su root -exit -source /etc/profile.d/rvm.sh -# this updates the path -rvm --default use ruby-2.7.8 -echo '. "$HOME/.cargo/env"' >> $HOME/.bashrc -# default to use clang -sudo update-alternatives --set c++ /usr/bin/clang++ -sudo update-alternatives --set cc /usr/bin/clang +rustup toolchain install nightly-aarch64-apple-darwin +rustup component add rust-src --toolchain nightly-aarch64-apple-darwin +rustup target add aarch64-apple-ios ``` -These steps were extracted from the bootstrap.sh script on TestVMS [**(here)**](../../../TestVMs/blob/master/Ubuntu64Desktop/bootstrap.sh) -The following Rust target is needed for now but will be deprecated soon: +## CMake + +In the `build` directory, there'll be a folder for every supported platform, and inside each there will be a `CMakeLists.txt` file. To build, you must configure CMake using this platform-specific subdirectory and build from there. -- ```rustup target add wasm32-unknown-emscripten``` # this will be deprecated on wallet-core soon - -### Build instructions +Our convention is to create a subdirectory inside `build/${PLATFORM}`, called either `Debug` or `Release`, depending on the `BUILD_TYPE`. So to build the debug version for Linux, you would: ```bash cd build/Linux -mkdir [Debug or Release] -cd [Debug or Release] -cmake .. -DCMAKE_BUILD_TYPE=[Debug or Release] -make +cmake -B Debug -CMAKE_BUILD_TYPE=Debug +cmake --build Debug --config Debug -j ``` -## Android Cross-Compile on Linux/OSX Hosts +Some CMake projects rely on having `CMAKE_BUILD_TYPE` set, so even if you're using a multi-config generator like Visual Studio, it is important to set it accordingly. + +Another example, for Windows using release mode: -### Requirements -- CMake -- Android NDK r25b Version [(link)](https://github.com/android/ndk/wiki/Unsupported-Downloads) -- rvm/Ruby 2.7.8 - - ```rvm --default use ruby-2.7.8``` -- wallet-core dependency tools - - Rust, cargo - - ```rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android``` -#### Host settings in .bash_profile (ex.) - ○ export ANDROID_NDK=/path/to/android-ndk-r25b - ○ export ANDROID_TOOLCHAIN="$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin" - ○ export PATH="$ANDROID_TOOLCHAIN":"$PATH" -### Build instructions -* armeabi-v7a -```bash -cd build/Android -mkdir -p [Debug or Release]/armeabi-v7a -cd [Debug or Release]/armeabi-v7a -cmake ../../ -DCMAKE_BUILD_TYPE=[Debug or Release] -DANDROID_ABI="armeabi-v7a" -DCMAKE_ANDROID_NDK=$ANDROID_NDK -DANDROID_TOOLCHAIN=clang -make -``` -* arm64-v8a ```bash -cd build/Android -mkdir -p [Debug or Release]/arm64-v8a -cd [Debug or Release]/arm64-v8a -cmake ../../ -DCMAKE_BUILD_TYPE=[Debug or Release] -DANDROID_ABI="arm64-v8a" -DCMAKE_ANDROID_NDK=$ANDROID_NDK -DANDROID_TOOLCHAIN=clang -make +cd build/Windows +cmake -B Release -G "Visual Studio 17 2022" -A x64 -CMAKE_BUILD_TYPE=Release +cmake --build Release --config Release -j ``` -* x86_64 + +When building for Android, we expect each ABI to have its own subdirectory. You need to configure the ABI to be built. The ABIs supported are: + +- `armeabi-v7a` for Android **x86** +- `arm64-v8a ` for Android **arm64** +- `x86_64` for Android **emulator** + + +Example for Android arm64: + ```bash cd build/Android -mkdir -p [Debug or Release]/x86_64 -cd [Debug or Release]/x86_64 -cmake ../../ -DCMAKE_BUILD_TYPE=[Debug or Release] -DANDROID_ABI="x86_64" -DCMAKE_ANDROID_NDK=$ANDROID_NDK -DANDROID_TOOLCHAIN=clang -make +mkdir Debug && cd Debug +cmake -S .. -B arm64-v8a -CMAKE_BUILD_TYPE=Debug -DANDROID_ABI=arm64-v8a +cmake --build arm64-v8a --config Debug -j ``` -## OSX -### Requirements -- CMake -- Python >=3.5 -- xCode Command line Tools & SDK -- rvm/Ruby 2.7.8 install - - Undo OpenSSL 3 install - - ```brew unlink openssl@3``` - - ```brew link openssl@1.1 --force``` - - Install RVM - - ```curl -sSL https://get.rvm.io | bash -s stable``` - - Install version 2.7.8 - - ```rvm install ruby-2.7.8``` - - use 2.7.8 as default - - ```rvm --default use ruby-2.7.8``` -- wallet-core dependency tools - - Rust, cargo - ```bash - rustup update - rustup toolchain install stable - rustup default stable - rustup target add x86_64-apple-darwin - rustup target add aarch64-apple-darwin - rustup target add wasm32-unknown-emscripten - cargo install cbindgen cargo-lipo - ``` - -### Build instructions + +When building for Apple platforms, you'll need to configure the project with the `PLATFORM` variable set to one of these values: + +- `OS64` for iOS +- `MAC` for macOS **x86** +- `MAC_ARM64` for macOS **arm64** +- `MAC_UNIVERSAL` for macOS **arm64 + x86** + +Example for macOS x86: + ```bash cd build/OSX -mkdir [Debug or Release] -cd [Debug or Release] -cmake .. -DCMAKE_BUILD_TYPE=[Debug or Release] -make -``` - -## iOS cross compile -### Requirements -- CMake -- xCode Command line Tools & SDK -- rvm/Ruby 2.7.8 -- wallet-core dependency tools - - Rust, cargo - ```bash - rustup update - rustup toolchain install stable - rustup default stable - rustup toolchain install stable-x86_64-apple-darwin - rustup toolchain install nightly-x86_64-apple-darwin - rustup component add rust-src --toolchain nightly-x86_64-apple-darwin - rustup component add rust-src --toolchain nightly-aarch64-apple-darwin - rustup target add x86_64-apple-ios aarch64-apple-ios-sim aarch64-apple-ios - cargo install cbindgen cargo-lipo - ``` - -### Build instructions -``` bash -cd build/iOS -mkdir [Debug or Release] -cd [Debug or Release] -cmake .. -DCMAKE_BUILD_TYPE=[Debug or Release] -make +cmake -B Release -CMAKE_BUILD_TYPE=Release -DPLATFORM=MAC +cmake --build Release --config Release -j ```