diff --git a/.github/actions/install_nim/action.yml b/.github/actions/install_nim/action.yml new file mode 100644 index 000000000..5d5541a9f --- /dev/null +++ b/.github/actions/install_nim/action.yml @@ -0,0 +1,65 @@ +name: Install Nim +inputs: + os: + description: "Operating system to build for" + required: true + cpu: + description: "CPU to build for" + default: "amd64" + nim_ref: + description: "Nim version" + default: "v2.2.6" + shell: + description: "Shell to run commands in" + default: "bash --noprofile --norc -e -o pipefail" + +runs: + using: "composite" + steps: + - name: Derive environment variables + shell: ${{ inputs.shell }} + run: | + if [[ '${{ inputs.cpu }}' == 'amd64' ]]; then + PLATFORM=x64 + elif [[ '${{ inputs.cpu }}' == 'arm64' ]]; then + PLATFORM=arm64 + else + PLATFORM=x86 + fi + echo "PLATFORM=$PLATFORM" >> $GITHUB_ENV + + ncpu= + MAKE_CMD="make" + case '${{ inputs.os }}' in + 'Linux') + ncpu=$(nproc) + ;; + 'macOS') + ncpu=$(sysctl -n hw.ncpu) + ;; + 'Windows') + ncpu=$NUMBER_OF_PROCESSORS + MAKE_CMD="mingw32-make" + ;; + esac + [[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1 + echo "ncpu=$ncpu" >> $GITHUB_ENV + echo "MAKE_CMD=${MAKE_CMD}" >> $GITHUB_ENV + echo '${{ github.workspace }}/nim/bin' >> $GITHUB_PATH + + - name: Restore Nim from cache + id: nim-cache + uses: actions/cache@v4 + with: + path: '${{ github.workspace }}/nim' + key: ${{ inputs.os }}-${{ inputs.cpu }}-nim-${{ inputs.nim_ref }}-cache-${{ env.cache_nonce }} + + - name: Build Nim and Nimble + shell: ${{ inputs.shell }} + if: ${{ steps.nim-cache.outputs.cache-hit != 'true' }} + run: | + rm -rf nim + curl -O -L -s -S https://raw.githubusercontent.com/status-im/nimbus-build-system/master/scripts/build_nim.sh + env MAKE="${MAKE_CMD} -j${ncpu}" ARCH_OVERRIDE=${PLATFORM} NIM_COMMIT=${{ inputs.nim_ref }} \ + QUICK_AND_DIRTY_COMPILER=1 QUICK_AND_DIRTY_NIMBLE=1 CC=gcc \ + bash build_nim.sh nim csources dist/nimble NimBinaries diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 560073899..3e6389eec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -127,19 +127,13 @@ jobs: sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 14 sudo update-alternatives --set gcc /usr/bin/gcc-14 - - name: Install Nim (pinned) - uses: iffy/install-nim@v5 + - name: Setup Nim + uses: "./.github/actions/install_nim" with: - version: "2.2.6" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Install Nimble (pinned) - if: runner.os != 'Windows' - uses: nim-lang/setup-nimble-action@v1 - with: - nimble-version: '0.20.1' - repo-token: ${{ secrets.GITHUB_TOKEN }} + os: ${{ runner.os }} + cpu: ${{ matrix.platform.cpu }} + shell: ${{ matrix.shell }} + nim_ref: v2.2.6 - name: Platform info run: | @@ -280,19 +274,13 @@ jobs: sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 14 sudo update-alternatives --set gcc /usr/bin/gcc-14 - - name: Install Nim (pinned) - uses: iffy/install-nim@v5 + - name: Setup Nim + uses: "./.github/actions/install_nim" with: - version: "2.2.6" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Install Nimble (pinned) - if: runner.os != 'Windows' - uses: nim-lang/setup-nimble-action@v1 - with: - nimble-version: '0.20.1' - repo-token: ${{ secrets.GITHUB_TOKEN }} + os: ${{ runner.os }} + cpu: ${{ matrix.platform.cpu }} + shell: ${{ matrix.shell }} + nim_ref: v2.2.6 - name: Platform info run: | @@ -392,18 +380,12 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Install Nim (pinned) - uses: iffy/install-nim@v5 + - name: Setup Nim + uses: "./.github/actions/install_nim" with: - version: "2.2.6" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Install Nimble (pinned) - uses: nim-lang/setup-nimble-action@v1 - with: - nimble-version: '0.20.1' - repo-token: ${{ secrets.GITHUB_TOKEN }} + os: ${{ runner.os }} + cpu: amd64 + nim_ref: v2.2.6 - name: Build nph run: |