CI: refactor Nim compiler building (#579)

This commit is contained in:
Ștefan Talpalaru 2021-05-31 22:21:17 +02:00 committed by Dmitriy Ryajov
parent ac47964377
commit fbe888a3aa
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
1 changed files with 18 additions and 74 deletions

View File

@ -1,4 +1,4 @@
name: nim-libp2p CI name: CI
on: [push, pull_request] on: [push, pull_request]
jobs: jobs:
@ -7,24 +7,18 @@ jobs:
fail-fast: false fail-fast: false
max-parallel: 20 max-parallel: 20
matrix: matrix:
branch: [v1.2.6]
target: target:
# Unit tests # Unit tests
- os: linux - os: linux
cpu: amd64 cpu: amd64
TEST_KIND: unit-tests
- os: linux - os: linux
cpu: i386 cpu: i386
TEST_KIND: unit-tests
- os: macos - os: macos
cpu: amd64 cpu: amd64
TEST_KIND: unit-tests
- os: windows - os: windows
cpu: i386 cpu: i386
TEST_KIND: unit-tests
- os: windows - os: windows
cpu: amd64 cpu: amd64
TEST_KIND: unit-tests
include: include:
- target: - target:
os: linux os: linux
@ -35,17 +29,20 @@ jobs:
- target: - target:
os: windows os: windows
builder: windows-2019 builder: windows-2019
name: '${{ matrix.target.os }}-${{ matrix.target.cpu }} (${{ matrix.branch }})'
defaults:
run:
shell: bash
name: '${{ matrix.target.os }}-${{ matrix.target.cpu }}'
runs-on: ${{ matrix.builder }} runs-on: ${{ matrix.builder }}
steps: steps:
- name: Checkout nim-libp2p - name: Checkout nim-libp2p
uses: actions/checkout@v2 uses: actions/checkout@v2
with: with:
path: nim-libp2p
submodules: true submodules: true
- name: Derive environment variables - name: Derive environment variables
shell: bash
run: | run: |
if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then
ARCH=64 ARCH=64
@ -59,6 +56,7 @@ jobs:
ncpu= ncpu=
ext= ext=
MAKE_CMD="make"
case '${{ runner.os }}' in case '${{ runner.os }}' in
'Linux') 'Linux')
ncpu=$(nproc) ncpu=$(nproc)
@ -69,11 +67,13 @@ jobs:
'Windows') 'Windows')
ncpu=$NUMBER_OF_PROCESSORS ncpu=$NUMBER_OF_PROCESSORS
ext=.exe ext=.exe
MAKE_CMD="mingw32-make"
;; ;;
esac esac
[[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1 [[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1
echo "ncpu=$ncpu" >> $GITHUB_ENV echo "ncpu=$ncpu" >> $GITHUB_ENV
echo "ext=$ext" >> $GITHUB_ENV echo "ext=$ext" >> $GITHUB_ENV
echo "MAKE_CMD=${MAKE_CMD}" >> $GITHUB_ENV
- name: Install build dependencies (Linux i386) - name: Install build dependencies (Linux i386)
if: runner.os == 'Linux' && matrix.target.cpu == 'i386' if: runner.os == 'Linux' && matrix.target.cpu == 'i386'
@ -115,7 +115,6 @@ jobs:
if: > if: >
steps.windows-mingw-cache.outputs.cache-hit != 'true' && steps.windows-mingw-cache.outputs.cache-hit != 'true' &&
runner.os == 'Windows' runner.os == 'Windows'
shell: bash
run: | run: |
mkdir -p external mkdir -p external
curl -L "https://nim-lang.org/download/mingw$ARCH.7z" -o "external/mingw-${{ matrix.target.cpu }}.7z" curl -L "https://nim-lang.org/download/mingw$ARCH.7z" -o "external/mingw-${{ matrix.target.cpu }}.7z"
@ -126,7 +125,6 @@ jobs:
if: > if: >
steps.windows-dlls-cache.outputs.cache-hit != 'true' && steps.windows-dlls-cache.outputs.cache-hit != 'true' &&
runner.os == 'Windows' runner.os == 'Windows'
shell: bash
run: | run: |
mkdir -p external mkdir -p external
curl -L "https://nim-lang.org/download/windeps.zip" -o external/windeps.zip curl -L "https://nim-lang.org/download/windeps.zip" -o external/windeps.zip
@ -135,80 +133,31 @@ jobs:
- name: Path to cached dependencies (Windows) - name: Path to cached dependencies (Windows)
if: > if: >
runner.os == 'Windows' runner.os == 'Windows'
shell: bash
run: | run: |
echo "${{ github.workspace }}/external/mingw-${{ matrix.target.cpu }}/bin" >> $GITHUB_PATH echo "${{ github.workspace }}/external/mingw-${{ matrix.target.cpu }}/bin" >> $GITHUB_PATH
echo "${{ github.workspace }}/external/dlls-${{ matrix.target.cpu }}" >> $GITHUB_PATH echo "${{ github.workspace }}/external/dlls-${{ matrix.target.cpu }}" >> $GITHUB_PATH
- name: Setup environment
shell: bash
run: echo '${{ github.workspace }}/nim/bin' >> $GITHUB_PATH
- name: Get latest Nim commit hash - name: Get latest Nim commit hash
id: versions id: versions
shell: bash
run: | run: |
getHash() { getHash() {
git ls-remote "https://github.com/$1" "${2:-HEAD}" | cut -f 1 git ls-remote "https://github.com/$1" "${2:-HEAD}" | cut -f 1
} }
nimHash=$(getHash nim-lang/Nim '${{ matrix.branch }}') nbsHash=$(getHash status-im/nimbus-build-system)
csourcesHash=$(getHash nim-lang/csources) echo "::set-output name=nimbus_build_system::$nbsHash"
echo "::set-output name=nim::$nimHash"
echo "::set-output name=csources::$csourcesHash"
- name: Restore prebuilt Nim from cache - name: Restore prebuilt Nim from cache
id: nim-cache id: nim-cache
uses: actions/cache@v1 uses: actions/cache@v2
with: with:
path: nim path: NimBinaries
key: "nim-${{ matrix.target.os }}-${{ matrix.target.cpu }}-${{ steps.versions.outputs.nim }}" key: 'NimBinaries-${{ matrix.target.os }}-${{ matrix.target.cpu }}-${{ steps.versions.outputs.nimbus_build_system }}'
- name: Restore prebuilt csources from cache
if: steps.nim-cache.outputs.cache-hit != 'true'
id: csources-cache
uses: actions/cache@v1
with:
path: csources/bin
key: "csources-${{ matrix.target.os }}-${{ matrix.target.cpu }}-${{ steps.versions.outputs.csources }}"
- name: Checkout Nim csources
if: >
steps.csources-cache.outputs.cache-hit != 'true' &&
steps.nim-cache.outputs.cache-hit != 'true'
uses: actions/checkout@v2
with:
repository: nim-lang/csources
path: csources
ref: ${{ steps.versions.outputs.csources }}
- name: Checkout Nim
if: steps.nim-cache.outputs.cache-hit != 'true'
uses: actions/checkout@v2
with:
repository: nim-lang/Nim
path: nim
ref: ${{ steps.versions.outputs.nim }}
- name: Build Nim and associated tools - name: Build Nim and associated tools
if: steps.nim-cache.outputs.cache-hit != 'true'
shell: bash
run: | run: |
[[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1 curl -O -L -s -S https://raw.githubusercontent.com/status-im/nimbus-build-system/master/scripts/build_nim.sh
if [[ ! -e csources/bin/nim$ext ]]; then env MAKE="${MAKE_CMD} -j${ncpu}" ARCH_OVERRIDE=${PLATFORM} CC=gcc bash build_nim.sh nim csources dist/nimble NimBinaries
make -C csources -j $ncpu CC=gcc ucpu='${{ matrix.target.cpu }}' echo '${{ github.workspace }}/nim/bin' >> $GITHUB_PATH
else
echo 'Using prebuilt csources'
fi
cp -v csources/bin/nim$ext nim/bin
cd nim
nim c koch
./koch boot -d:release
./koch tools -d:release
# clean up to save cache space
rm koch
rm -rf nimcache
rm -rf dist
rm -rf .git
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
@ -216,16 +165,11 @@ jobs:
go-version: '^1.15.5' go-version: '^1.15.5'
- name: Install p2pd - name: Install p2pd
shell: bash
run: | run: |
cd nim-libp2p
V=1 bash scripts/build_p2pd.sh p2pdCache v0.3.0 V=1 bash scripts/build_p2pd.sh p2pdCache v0.3.0
- name: Run nim-libp2p tests - name: Run nim-libp2p tests
shell: bash
run: | run: |
export UCPU="$cpu"
cd nim-libp2p
nimble install -y --depsOnly nimble install -y --depsOnly
nimble test nimble test