|
| 1 | +name: Install Nim |
| 2 | +inputs: |
| 3 | + os: |
| 4 | + description: "Operating system to build for" |
| 5 | + required: true |
| 6 | + cpu: |
| 7 | + description: "CPU to build for" |
| 8 | + default: "amd64" |
| 9 | + nim_ref: |
| 10 | + description: "Nim version" |
| 11 | + default: "version-1-6" |
| 12 | + shell: |
| 13 | + description: "Shell to run commands in" |
| 14 | + default: "bash --noprofile --norc -e -o pipefail" |
| 15 | + |
| 16 | +runs: |
| 17 | + using: "composite" |
| 18 | + steps: |
| 19 | + - name: Install build dependencies (Linux i386) |
| 20 | + shell: ${{ inputs.shell }} |
| 21 | + if: inputs.os == 'Linux' && inputs.cpu == 'i386' |
| 22 | + run: | |
| 23 | + sudo dpkg --add-architecture i386 |
| 24 | + sudo apt-get update -qq |
| 25 | + sudo DEBIAN_FRONTEND='noninteractive' apt-get install \ |
| 26 | + --no-install-recommends -yq gcc-multilib g++-multilib \ |
| 27 | + libssl-dev:i386 |
| 28 | + mkdir -p external/bin |
| 29 | + cat << EOF > external/bin/gcc |
| 30 | + #!/bin/bash |
| 31 | + exec $(which gcc) -m32 "\$@" |
| 32 | + EOF |
| 33 | + cat << EOF > external/bin/g++ |
| 34 | + #!/bin/bash |
| 35 | + exec $(which g++) -m32 "\$@" |
| 36 | + EOF |
| 37 | + chmod 755 external/bin/gcc external/bin/g++ |
| 38 | + echo '${{ github.workspace }}/external/bin' >> $GITHUB_PATH |
| 39 | +
|
| 40 | + - name: MSYS2 (Windows i386) |
| 41 | + if: inputs.os == 'Windows' && inputs.cpu == 'i386' |
| 42 | + uses: msys2/setup-msys2@v2 |
| 43 | + with: |
| 44 | + path-type: inherit |
| 45 | + msystem: MINGW32 |
| 46 | + install: >- |
| 47 | + base-devel |
| 48 | + git |
| 49 | + mingw-w64-i686-toolchain |
| 50 | +
|
| 51 | + - name: MSYS2 (Windows amd64) |
| 52 | + if: inputs.os == 'Windows' && inputs.cpu == 'amd64' |
| 53 | + uses: msys2/setup-msys2@v2 |
| 54 | + with: |
| 55 | + path-type: inherit |
| 56 | + install: >- |
| 57 | + base-devel |
| 58 | + git |
| 59 | + mingw-w64-x86_64-toolchain |
| 60 | +
|
| 61 | + - name: Restore Nim DLLs dependencies (Windows) from cache |
| 62 | + if: inputs.os == 'Windows' |
| 63 | + id: windows-dlls-cache |
| 64 | + uses: actions/cache@v4 |
| 65 | + with: |
| 66 | + path: external/dlls |
| 67 | + key: 'dlls' |
| 68 | + |
| 69 | + - name: Install DLL dependencies (Windows) |
| 70 | + shell: ${{ inputs.shell }} |
| 71 | + if: > |
| 72 | + steps.windows-dlls-cache.outputs.cache-hit != 'true' && |
| 73 | + inputs.os == 'Windows' |
| 74 | + run: | |
| 75 | + mkdir -p external |
| 76 | + curl -L "https://nim-lang.org/download/windeps.zip" -o external/windeps.zip |
| 77 | + 7z x external/windeps.zip -oexternal/dlls |
| 78 | +
|
| 79 | + - name: Path to cached dependencies (Windows) |
| 80 | + shell: ${{ inputs.shell }} |
| 81 | + if: > |
| 82 | + inputs.os == 'Windows' |
| 83 | + run: | |
| 84 | + echo '${{ github.workspace }}'"/external/dlls" >> $GITHUB_PATH |
| 85 | +
|
| 86 | + - name: Derive environment variables |
| 87 | + shell: ${{ inputs.shell }} |
| 88 | + run: | |
| 89 | + if [[ '${{ inputs.cpu }}' == 'amd64' ]]; then |
| 90 | + PLATFORM=x64 |
| 91 | + elif [[ '${{ inputs.cpu }}' == 'arm64' ]]; then |
| 92 | + PLATFORM=arm64 |
| 93 | + else |
| 94 | + PLATFORM=x86 |
| 95 | + fi |
| 96 | + echo "PLATFORM=$PLATFORM" >> $GITHUB_ENV |
| 97 | +
|
| 98 | + ncpu= |
| 99 | + MAKE_CMD="make" |
| 100 | + case '${{ inputs.os }}' in |
| 101 | + 'Linux') |
| 102 | + ncpu=$(nproc) |
| 103 | + ;; |
| 104 | + 'macOS') |
| 105 | + ncpu=$(sysctl -n hw.ncpu) |
| 106 | + ;; |
| 107 | + 'Windows') |
| 108 | + ncpu=$NUMBER_OF_PROCESSORS |
| 109 | + MAKE_CMD="mingw32-make" |
| 110 | + ;; |
| 111 | + esac |
| 112 | + [[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1 |
| 113 | + echo "ncpu=$ncpu" >> $GITHUB_ENV |
| 114 | + echo "MAKE_CMD=${MAKE_CMD}" >> $GITHUB_ENV |
| 115 | + echo '${{ github.workspace }}/nim/bin' >> $GITHUB_PATH |
| 116 | +
|
| 117 | + - name: Restore Nim from cache |
| 118 | + id: nim-cache |
| 119 | + uses: actions/cache@v4 |
| 120 | + with: |
| 121 | + path: '${{ github.workspace }}/nim' |
| 122 | + key: ${{ inputs.os }}-${{ inputs.cpu }}-nim-${{ inputs.nim_ref }}-cache-${{ env.cache_nonce }} |
| 123 | + |
| 124 | + - name: Build Nim and Nimble |
| 125 | + shell: ${{ inputs.shell }} |
| 126 | + if: ${{ steps.nim-cache.outputs.cache-hit != 'true' }} |
| 127 | + run: | |
| 128 | + # We don't want partial matches of the cache restored |
| 129 | + rm -rf nim |
| 130 | + curl -O -L -s -S https://raw.githubusercontent.com/status-im/nimbus-build-system/master/scripts/build_nim.sh |
| 131 | + env MAKE="${MAKE_CMD} -j${ncpu}" ARCH_OVERRIDE=${PLATFORM} NIM_COMMIT=${{ inputs.nim_ref }} \ |
| 132 | + QUICK_AND_DIRTY_COMPILER=1 QUICK_AND_DIRTY_NIMBLE=1 CC=gcc \ |
| 133 | + bash build_nim.sh nim csources dist/nimble NimBinaries |
0 commit comments