[ci] Extract setup of nimbus build system into separate file

This commit is contained in:
Mark Spanbroek 2022-11-08 10:19:05 +01:00
parent 4175689745
commit fa2fa3574f
No known key found for this signature in database
GPG Key ID: FBE3E9548D427C00
2 changed files with 177 additions and 142 deletions

View File

@ -0,0 +1,168 @@
# Adapted from:
# https://github.com/status-im/nimbus-eth2/blob/stable/.github/workflows/ci.yml
name: Setup Nimbus Build System
inputs:
os:
description: "Operating system to build for"
required: true
cpu:
description: "CPU to build for"
required: true
nim_branch:
description: "Nim version"
default: "version-1-6"
shell:
description: "Shell to run commands in"
default: "bash --noprofile --norc -e -o pipefail"
cache_nonce:
description: "Change to a new value to ignore previously cached versions"
default: 0
runs:
using: "composite"
steps:
- name: APT (Linux amd64)
if: inputs.os == 'linux' && inputs.cpu == 'amd64'
shell: ${{ inputs.shell }} {0}
run: |
sudo apt-fast update -qq
sudo DEBIAN_FRONTEND='noninteractive' apt-fast install \
--no-install-recommends -yq lcov
- name: APT (Linux i386)
if: inputs.os == 'linux' && inputs.cpu == 'i386'
shell: ${{ inputs.shell }} {0}
run: |
sudo dpkg --add-architecture i386
sudo apt-fast update -qq
sudo DEBIAN_FRONTEND='noninteractive' apt-fast install \
--no-install-recommends -yq gcc-multilib g++-multilib
- name: Homebrew (macOS)
if: inputs.os == 'macos'
shell: ${{ inputs.shell }} {0}
run: |
brew install libomp
- name: MSYS2 (Windows amd64)
if: inputs.os == 'windows' && inputs.cpu == 'amd64'
uses: msys2/setup-msys2@v2
with:
msystem: UCRT64
install: >
base-devel
git
mingw-w64-ucrt-x86_64-toolchain
mingw-w64-ucrt-x86_64-cmake
mingw-w64-ucrt-x86_64-ntldd-git
- name: MSYS2 (Windows i386)
if: inputs.os == 'windows' && inputs.cpu == 'i386'
uses: msys2/setup-msys2@v2
with:
msystem: MINGW32
install: >
base-devel
git
mingw-w64-i686-toolchain
mingw-w64-i686-cmake
mingw-w64-i686-ntldd-git
- name: Derive environment variables
shell: ${{ inputs.shell }} {0}
run: |
quote () {
local quoted=${1//\'/\'\\\'\'};
printf "'%s'" "$quoted"
}
if [[ '${{ inputs.cpu }}' == 'amd64' ]]; then
PLATFORM=x64
else
PLATFORM=x86
fi
echo "PLATFORM=${PLATFORM}" >> ${GITHUB_ENV}
# Stack usage on Linux amd64
if [[ '${{ inputs.os }}' == 'linux' && '${{ inputs.cpu }}' == 'amd64' ]]; then
NIMFLAGS="${NIMFLAGS} -d:limitStackUsage"
echo "NIMFLAGS=${NIMFLAGS}" >> $GITHUB_ENV
fi
# Disable ADX on Linux i386
if [[ '${{ inputs.os }}' == 'linux' && '${{ inputs.cpu }}' == 'i386' ]]; then
CFLAGS="${CFLAGS} -m32 -mno-adx"
echo "CFLAGS=${CFLAGS}" >> ${GITHUB_ENV}
CXXFLAGS="${CXXFLAGS} -m32 -mno-adx"
echo "CXXFLAGS=${CXXFLAGS}" >> ${GITHUB_ENV}
mkdir -p external/bin
cat << EOF > external/bin/gcc
#!/bin/bash
exec $(which gcc) -m32 -mno-adx "\$@"
EOF
cat << EOF > external/bin/g++
#!/bin/bash
exec $(which g++) -m32 -mno-adx "\$@"
EOF
chmod 755 external/bin/gcc external/bin/g++
echo "$(pwd)/external/bin" >> ${GITHUB_PATH}
# --passC:'-m32 -mno-adx' is redundant but harmless, and can be
# helpful when reviewing build output with increased verbosity
NIMFLAGS="${NIMFLAGS} $(quote "--passC:'-m32 -mno-adx' -d:LeopardCmakeFlags='-DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=$(pwd)/external/bin/gcc -DCMAKE_CXX_COMPILER=$(pwd)/external/bin/g++'")"
echo "NIMFLAGS=${NIMFLAGS}" >> $GITHUB_ENV
fi
# Disable ADX on Windows i386
if [[ '${{ inputs.os }}' == 'windows' && '${{ inputs.cpu }}' == 'i386' ]]; then
CFLAGS="${CFLAGS} -mno-adx"
echo "CFLAGS=${CFLAGS}" >> ${GITHUB_ENV}
CXXFLAGS="${CXXFLAGS} -mno-adx"
echo "CXXFLAGS=${CXXFLAGS}" >> ${GITHUB_ENV}
NIMFLAGS="${NIMFLAGS} --passC:-mno-adx"
echo "NIMFLAGS=${NIMFLAGS}" >> $GITHUB_ENV
fi
# Enable OpenMP on macOS
if [[ '${{ inputs.os }}' == 'macos' ]]; then
libomp_lib_dir="$(brew --prefix)/opt/libomp/lib"
# See https://github.com/actions/virtual-environments/pull/5819
llvm_dir="$(ls -d $(brew --prefix)/opt/llvm* | tail -1)"
llvm_bin_dir="${llvm_dir}/bin"
llvm_lib_dir="${llvm_dir}/lib"
echo "${llvm_bin_dir}" >> ${GITHUB_PATH}
echo "LDFLAGS=${LDFLAGS} -L${libomp_lib_dir} -L${llvm_lib_dir} -Wl,-rpath,${llvm_lib_dir}" >> ${GITHUB_ENV}
NIMFLAGS="${NIMFLAGS} $(quote "-d:LeopardCmakeFlags='-DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=${llvm_bin_dir}/clang -DCMAKE_CXX_COMPILER=${llvm_bin_dir}/clang++' -d:LeopardExtraCompilerlags='-fopenmp' -d:LeopardExtraLinkerFlags='-fopenmp -L${libomp_lib_dir}'")"
echo "NIMFLAGS=${NIMFLAGS}" >> $GITHUB_ENV
fi
# Use all available CPUs for build process
ncpu=""
case '${{ inputs.os }}' in
'linux')
ncpu=$(nproc)
;;
'macos')
ncpu=$(sysctl -n hw.ncpu)
;;
'windows')
ncpu=${NUMBER_OF_PROCESSORS}
;;
esac
[[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1
echo "ncpu=${ncpu}" >> ${GITHUB_ENV}
- name: Restore Nim toolchain binaries from cache
id: nim-cache
uses: actions/cache@v3
with:
path: NimBinaries
key: ${{ inputs.os }}-${{ inputs.cpu }}-nim-${{ inputs.nim_branch }}-cache_nonce:${{ inputs.cache_nonce }}
- name: Build Nim and Codex dependencies
shell: ${{ inputs.shell }} {0}
run: |
make -j${ncpu} CI_CACHE=NimBinaries NIM_COMMIT=${{ inputs.nim_branch }} ARCH_OVERRIDE=${PLATFORM} QUICK_AND_DIRTY_COMPILER=1 update
echo
./env.sh nim --version

View File

@ -1,6 +1,3 @@
# Adapted from:
# https://github.com/status-im/nimbus-eth2/blob/stable/.github/workflows/ci.yml
name: CI
on:
push:
@ -32,11 +29,11 @@ jobs:
- target:
os: linux
builder: ubuntu-latest
shell: bash --noprofile --norc -eo pipefail
shell: bash --noprofile --norc -e -o pipefail
- target:
os: macos
builder: macos-latest
shell: bash --noprofile --norc -eo pipefail
shell: bash --noprofile --norc -e -o pipefail
- target:
os: windows
builder: windows-latest
@ -53,144 +50,14 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v3
- name: APT (Linux amd64)
if: runner.os == 'Linux' && matrix.target.cpu == 'amd64'
run: |
sudo apt-fast update -qq
sudo DEBIAN_FRONTEND='noninteractive' apt-fast install \
--no-install-recommends -yq lcov
- name: APT (Linux i386)
if: runner.os == 'Linux' && matrix.target.cpu == 'i386'
run: |
sudo dpkg --add-architecture i386
sudo apt-fast update -qq
sudo DEBIAN_FRONTEND='noninteractive' apt-fast install \
--no-install-recommends -yq gcc-multilib g++-multilib
- name: Homebrew (macOS)
if: runner.os == 'macOS'
run: |
brew install libomp
- name: MSYS2 (Windows amd64)
if: runner.os == 'Windows' && matrix.target.cpu == 'amd64'
uses: msys2/setup-msys2@v2
- name: Setup Nimbus Build System
uses: ./.github/actions/nimbus-build-system
with:
msystem: UCRT64
install: >
base-devel
git
mingw-w64-ucrt-x86_64-toolchain
mingw-w64-ucrt-x86_64-cmake
mingw-w64-ucrt-x86_64-ntldd-git
- name: MSYS2 (Windows i386)
if: runner.os == 'Windows' && matrix.target.cpu == 'i386'
uses: msys2/setup-msys2@v2
with:
msystem: MINGW32
install: >
base-devel
git
mingw-w64-i686-toolchain
mingw-w64-i686-cmake
mingw-w64-i686-ntldd-git
- name: Derive environment variables
run: |
quote () {
local quoted=${1//\'/\'\\\'\'};
printf "'%s'" "$quoted"
}
if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then
PLATFORM=x64
else
PLATFORM=x86
fi
echo "PLATFORM=${PLATFORM}" >> ${GITHUB_ENV}
# Stack usage on Linux amd64
if [[ '${{ runner.os }}' == 'Linux' && '${{ matrix.target.cpu }}' == 'amd64' ]]; then
NIMFLAGS="${NIMFLAGS} -d:limitStackUsage"
echo "NIMFLAGS=${NIMFLAGS}" >> $GITHUB_ENV
fi
# Disable ADX on Linux i386
if [[ '${{ runner.os }}' == 'Linux' && '${{ matrix.target.cpu }}' == 'i386' ]]; then
CFLAGS="${CFLAGS} -m32 -mno-adx"
echo "CFLAGS=${CFLAGS}" >> ${GITHUB_ENV}
CXXFLAGS="${CXXFLAGS} -m32 -mno-adx"
echo "CXXFLAGS=${CXXFLAGS}" >> ${GITHUB_ENV}
mkdir -p external/bin
cat << EOF > external/bin/gcc
#!/bin/bash
exec $(which gcc) -m32 -mno-adx "\$@"
EOF
cat << EOF > external/bin/g++
#!/bin/bash
exec $(which g++) -m32 -mno-adx "\$@"
EOF
chmod 755 external/bin/gcc external/bin/g++
echo "$(pwd)/external/bin" >> ${GITHUB_PATH}
# --passC:'-m32 -mno-adx' is redundant but harmless, and can be
# helpful when reviewing build output with increased verbosity
NIMFLAGS="${NIMFLAGS} $(quote "--passC:'-m32 -mno-adx' -d:LeopardCmakeFlags='-DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=$(pwd)/external/bin/gcc -DCMAKE_CXX_COMPILER=$(pwd)/external/bin/g++'")"
echo "NIMFLAGS=${NIMFLAGS}" >> $GITHUB_ENV
fi
# Disable ADX on Windows i386
if [[ '${{ runner.os }}' == 'Windows' && '${{ matrix.target.cpu }}' == 'i386' ]]; then
CFLAGS="${CFLAGS} -mno-adx"
echo "CFLAGS=${CFLAGS}" >> ${GITHUB_ENV}
CXXFLAGS="${CXXFLAGS} -mno-adx"
echo "CXXFLAGS=${CXXFLAGS}" >> ${GITHUB_ENV}
NIMFLAGS="${NIMFLAGS} --passC:-mno-adx"
echo "NIMFLAGS=${NIMFLAGS}" >> $GITHUB_ENV
fi
# Enable OpenMP on macOS
if [[ '${{ runner.os }}' == 'macOS' ]]; then
libomp_lib_dir="$(brew --prefix)/opt/libomp/lib"
# See https://github.com/actions/virtual-environments/pull/5819
llvm_dir="$(ls -d $(brew --prefix)/opt/llvm* | tail -1)"
llvm_bin_dir="${llvm_dir}/bin"
llvm_lib_dir="${llvm_dir}/lib"
echo "${llvm_bin_dir}" >> ${GITHUB_PATH}
echo "LDFLAGS=${LDFLAGS} -L${libomp_lib_dir} -L${llvm_lib_dir} -Wl,-rpath,${llvm_lib_dir}" >> ${GITHUB_ENV}
NIMFLAGS="${NIMFLAGS} $(quote "-d:LeopardCmakeFlags='-DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=${llvm_bin_dir}/clang -DCMAKE_CXX_COMPILER=${llvm_bin_dir}/clang++' -d:LeopardExtraCompilerlags='-fopenmp' -d:LeopardExtraLinkerFlags='-fopenmp -L${libomp_lib_dir}'")"
echo "NIMFLAGS=${NIMFLAGS}" >> $GITHUB_ENV
fi
# Use all available CPUs for build process
ncpu=""
case '${{ runner.os }}' in
'Linux')
ncpu=$(nproc)
;;
'macOS')
ncpu=$(sysctl -n hw.ncpu)
;;
'Windows')
ncpu=${NUMBER_OF_PROCESSORS}
;;
esac
[[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1
echo "ncpu=${ncpu}" >> ${GITHUB_ENV}
- name: Restore Nim toolchain binaries from cache
id: nim-cache
uses: actions/cache@v3
with:
path: NimBinaries
key: ${{ matrix.target.os }}-${{ matrix.target.cpu }}-nim-${{ matrix.nim_branch }}-cache_nonce:${{ matrix.cache_nonce }}
- name: Build Nim and Codex dependencies
run: |
make -j${ncpu} CI_CACHE=NimBinaries NIM_COMMIT=${{ matrix.nim_branch }} ARCH_OVERRIDE=${PLATFORM} QUICK_AND_DIRTY_COMPILER=1 update
echo
./env.sh nim --version
os: ${{ matrix.target.os }}
cpu: ${{ matrix.target.cpu }}
nim_branch: ${{ matrix.nim_branch }}
shell: ${{ matrix.shell }}
cache_nonce: ${{ matrix.cache_nonce }}
# Rely on NodeJS LTS installed in GitHub Actions virtual environments
- name: Start Ethereum node with Codex contracts