From e06bd198a9eb1cfaeac8623d174e1eb19d3caf4d Mon Sep 17 00:00:00 2001 From: Nazareno Bruschi Date: Mon, 13 Nov 2023 14:18:27 +0100 Subject: [PATCH] Add CI --- .github/workflows/gcc-ci-merge-request.yml | 62 ++++ .github/workflows/gcc-ci-push.yml | 62 ++++ build-corev-gcc-tools.sh | 318 +++++++++++++++++++++ 3 files changed, 442 insertions(+) create mode 100644 .github/workflows/gcc-ci-merge-request.yml create mode 100644 .github/workflows/gcc-ci-push.yml create mode 100644 build-corev-gcc-tools.sh diff --git a/.github/workflows/gcc-ci-merge-request.yml b/.github/workflows/gcc-ci-merge-request.yml new file mode 100644 index 00000000000..84e87b2846d --- /dev/null +++ b/.github/workflows/gcc-ci-merge-request.yml @@ -0,0 +1,62 @@ +name: GCC MR CI +on: pull_request +jobs: + Regression-Tests: + name: Regression Tests + runs-on: ubuntu-latest + steps: + - run: echo "The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v2 + - run: echo "The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "The workflow is now ready to test your code on the runner." + - name: Build Toolchain + run: | + cd ${{ github.workspace }} + cd .. + git clone https://github.com/EEESlab/corev-binutils-gdb.git + git clone https://github.com/riscv/riscv-newlib.git + git clone https://github.com/riscvarchive/riscv-dejagnu.git + sudo apt-get update -y + sudo apt-get install -y expect + sudo apt-get install -y libgmp10 + sudo apt-get install -y libgmp-dev + sudo apt-get install -y libmpfr6 + sudo apt-get install -y libmpfr-dev + cd riscv-dejagnu + ./configure + aclocal + automake + sudo make all install + cd ${{ github.workspace }} + source build-corev-gcc-tools.sh --all + cd ${{ github.workspace }} + export -p > temp_env + - name: Launch GCC Regression Tests + run: | + cd ${{ github.workspace }} + source temp_env + cd ${BUILD_STAGE2_PREFIX} + make check-gcc RUNTESTFLAGS="riscv.exp --target_board=riscv-sim" > ${{ github.workspace }}/regression_report.txt + cd ${{ github.workspace }} + export -p > temp_env + - name: Read GCC Regression Report + run: | + cd ${{ github.workspace }} + source temp_env + echo "Reading regression report from $(pwd) folder" + cat regression_report.txt + cd ${{ github.workspace }} + export -p > temp_env + - name: Upload GCC Regression Report + uses: actions/upload-artifact@v3 + with: + name: regression_report + path: regression_report.txt + - name: Exit from GCC CI + run: | + echo "This job's status is ${{ job.status }}." + if grep -q "unexpected failures" ${{ github.workspace }}/regression_report.txt; then exit 1; fi + if grep -q "unexpected passes" ${{ github.workspace }}/regression_report.txt; then exit 1; fi diff --git a/.github/workflows/gcc-ci-push.yml b/.github/workflows/gcc-ci-push.yml new file mode 100644 index 00000000000..707c0f3f0a9 --- /dev/null +++ b/.github/workflows/gcc-ci-push.yml @@ -0,0 +1,62 @@ +name: GCC PUSH CI +on: push +jobs: + Regression-Tests: + name: Regression Tests + runs-on: ubuntu-latest + steps: + - run: echo "The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v2 + - run: echo "The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "The workflow is now ready to test your code on the runner." + - name: Build Toolchain + run: | + cd ${{ github.workspace }} + cd .. + git clone https://github.com/EEESlab/corev-binutils-gdb.git + git clone https://github.com/riscv/riscv-newlib.git + git clone https://github.com/riscvarchive/riscv-dejagnu.git + sudo apt-get update -y + sudo apt-get install -y expect + sudo apt-get install -y libgmp10 + sudo apt-get install -y libgmp-dev + sudo apt-get install -y libmpfr6 + sudo apt-get install -y libmpfr-dev + cd riscv-dejagnu + ./configure + aclocal + automake + sudo make all install + cd ${{ github.workspace }} + source build-corev-gcc-tools.sh --all + cd ${{ github.workspace }} + export -p > temp_env + - name: Launch GCC Regression Tests + run: | + cd ${{ github.workspace }} + source temp_env + cd ${BUILD_STAGE2_PREFIX} + make check-gcc RUNTESTFLAGS="riscv.exp --target_board=riscv-sim" > ${{ github.workspace }}/regression_report.txt + cd ${{ github.workspace }} + export -p > temp_env + - name: Read GCC Regression Report + run: | + cd ${{ github.workspace }} + source temp_env + echo "Reading regression report from $(pwd) folder" + cat regression_report.txt + cd ${{ github.workspace }} + export -p > temp_env + - name: Upload GCC Regression Report + uses: actions/upload-artifact@v3 + with: + name: regression_report + path: regression_report.txt + - name: Exit from GCC CI + run: | + echo "This job's status is ${{ job.status }}." + if grep -q "unexpected failures" ${{ github.workspace }}/regression_report.txt; then exit 1; fi + if grep -q "unexpected passes" ${{ github.workspace }}/regression_report.txt; then exit 1; fi diff --git a/build-corev-gcc-tools.sh b/build-corev-gcc-tools.sh new file mode 100644 index 00000000000..2894d34066b --- /dev/null +++ b/build-corev-gcc-tools.sh @@ -0,0 +1,318 @@ +#!/bin/bash + +# Build script for the CORE-V GCC and GNU tools. + +# Copyright (C) 2020 Embecosm Limited +# Contributor Jessica Mills + +# This file is part of the Embecosm GNU toolchain build system for RISC-V. + +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation; either version 3 of the License, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. + +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +export ROOT_PREFIX=$(cd ../ && pwd) + +export GCC_FOLDER=corev-gcc +export GCC_PREFIX=${ROOT_PREFIX}/${GCC_FOLDER} + +export STAGE1_FOLDER=${GCC_FOLDER}-stage1 +export STAGE2_FOLDER=${GCC_FOLDER}-stage2 + +export NEWLIB_FOLDER=riscv-newlib +export NEWLIB_PREFIX=${ROOT_PREFIX}/${NEWLIB_FOLDER} + +export BINUTILS_GDB_FOLDER=corev-binutils-gdb +export BINUTILS_GDB_PREFIX=${ROOT_PREFIX}/${BINUTILS_PREFIX} + +export BUILD_GCC_FOLDER=build-${GCC_FOLDER} +export BUILD_GCC_PREFIX=${ROOT_PREFIX}/${BUILD_GCC_FOLDER} + +export BUILD_BINUTILS_FOLDER=build-${BINUTILS_GDB_FOLDER} +export BUILD_BINUTILS_PREFIX=${ROOT_PREFIX}/${BUILD_BINUTILS_FOLDER} + +export INSTALL_FOLDER=toolchain-install +export INSTALL_PREFIX=${ROOT_PREFIX}/${INSTALL_FOLDER} +mkdir -p ${INSTALL_PREFIX} + +PARALLEL_JOBS=$(nproc) +DEFAULTARCH=rv32im +DEFAULTABI=ilp32 + +if [[ $* == *--gcc-stage1* || $* == *--all* ]]; then + if [[ $* == *--debug* ]]; then + export BUILD_STAGE1_PREFIX=${BUILD_GCC_PREFIX}-DEBUG/${STAGE1_FOLDER} + else + export BUILD_STAGE1_PREFIX=${BUILD_GCC_PREFIX}/${STAGE1_FOLDER} + fi + mkdir -p ${GCC_PREFIX} +fi +if [[ $* == *--newlib* || $* == *--all* ]]; then + if [[ $* == *--debug* ]]; then + export BUILD_NEWLIB_PREFIX=${BUILD_GCC_PREFIX}-DEBUG/${NEWLIB_FOLDER} + else + export BUILD_NEWLIB_PREFIX=${BUILD_GCC_PREFIX}/${NEWLIB_FOLDER} + fi + mkdir -p ${GCC_PREFIX} +fi +if [[ $* == *--gcc-stage2* || $* == *--all* ]]; then + if [[ $* == *--debug* ]]; then + export BUILD_STAGE2_PREFIX=${BUILD_GCC_PREFIX}-DEBUG/${STAGE2_FOLDER} + else + export BUILD_STAGE2_PREFIX=${BUILD_GCC_PREFIX}/${STAGE2_FOLDER} + fi + mkdir -p ${GCC_PREFIX} +fi +if [[ $* == *--binutilts-gdb* || $* == *--all* ]]; then + if [[ $* == *--debug* ]]; then + export BUILD_BINGDB_PREFIX=${ROOT_PREFIX}/${BUILD_BINUTILS_FOLDER}-DEBUG + else + export BUILD_BINGDB_PREFIX=${ROOT_PREFIX}/${BUILD_BINUTILS_FOLDER} + fi +fi + +installs=( + "riscv32-corev-elf-addr2line" + "riscv32-corev-elf-nm" + "riscv32-corev-elf-ar" + "riscv32-corev-elf-objcopy" + "riscv32-corev-elf-objdump" + "riscv32-corev-elf-ranlib" + "riscv32-corev-elf-c++filt" + "riscv32-corev-elf-readelf" + "riscv32-corev-elf-run" + "riscv32-corev-elf-elfedit" + "riscv32-corev-elf-gdb" + "riscv32-corev-elf-size" + "riscv32-corev-elf-gprof" + "riscv32-corev-elf-strings" + "riscv32-corev-elf-ld" + "riscv32-corev-elf-strip" + "riscv32-corev-elf-ld.bfd" + "riscv32-corev-elf-as" + "riscv32-corev-elf-gcc-ar" + "riscv32-corev-elf-gcc-nm" + "riscv32-corev-elf-gcc-ranlib" + "riscv32-corev-elf-gcov" + "riscv32-corev-elf-gcov-dump" + "riscv32-corev-elf-cpp" + "riscv32-corev-elf-gcov-tool" + "riscv32-corev-elf-gcc" + "riscv32-corev-elf-gcc-7.1.1" + "riscv32-corev-elf-c++" + "riscv32-corev-elf-g++" + +) + +if [[ $* == *--help* || $* == *-h* ]]; then + echo "Usage: build-corev-gcc-tools.sh [--all] [--binutils-gdb] [--gcc-stage1] [--newlib] [--gcc-stage2] [--clean] [--debug] [--help | -h]" + echo " Builds and installs the PULP tool chain" + echo " Build directory is the peer directory 'build', install directory is the peer directory 'install'" + echo " Generates installation summary - this is the only action if no options are specified" + echo "The options are:" + echo " --all Build all components" + echo " --binutils-gdb Build binutils and GDB" + echo " --gcc-stage1 Build GCC stage 1" + echo " --newlib Build newlib" + echo " --gcc-stage2 Build GCC stage 2" + echo " --clean Remove build directory" + echo " --debug Include debugging CFLAGS" + echo " --help | -h Print this help message and exit" + exit 0 +fi + + +if [[ $* == *--clean* ]]; then + if [[ -d ${BUILD_STAGE1_PREFIX} ]]; then + echo Cleaning... ${BUILD_STAGE1_PREFIX} + rm -rf ${BUILD_STAGE1_PREFIX} + fi + if [[ -d ${BUILD_NEWLIB_PREFIX} ]]; then + echo Cleaning... ${BUILD_NEWLIB_PREFIX} + rm -rf ${BUILD_NEWLIB_PREFIX} + fi + if [[ -d ${BUILD_STAGE2_PREFIX} ]]; then + echo Cleaning... ${BUILD_STAGE2_PREFIX} + rm -rf ${BUILD_STAGE2_PREFIX} + fi + if [[ -d ${BUILD_BINGDB_PREFIX} ]]; then + echo Cleaning... ${BUILD_BINGDB_PREFIX} + rm -rf ${BUILD_BINGDB_PREFIX} + fi +fi + +# Binutils-gdb +if [[ $* == *--binutils-gdb* || $* == *--all* ]]; then + mkdir -p ${BUILD_BINGDB_PREFIX} + cd ${BUILD_BINGDB_PREFIX} + ../${BINUTILS_GDB_FOLDER}/configure \ + --target=riscv32-corev-elf \ + --prefix=${INSTALL_PREFIX} \ + --disable-werror + + #CFLAGS as option for debugging + if [[ $* == *--debug* ]]; then + if ! make CFLAGS="-O0 -ggdb3" -j${PARALLEL_JOBS}; then + echo "The build has failed during binutils-gdb!" >/dev/stderr + exit 1 + fi + if ! make CFLAGS="-O0 -ggdb3" install; then + echo "The build has failed during binutils-gdb!" >/dev/stderr + exit 1 + fi + else + if ! make -j${PARALLEL_JOBS}; then + echo "The build has failed during binutils-gdb!" >/dev/stderr + exit 1 + fi + if ! make install; then + echo "The build has failed during binutils-gdb!" >/dev/stderr + exit 1 + fi + fi +fi + +# GCC (Stage 1) +if [[ $* == *--gcc-stage1* || $* == *--all* ]]; then + cd ${GCC_PREFIX} + ./contrib/download_prerequisites + mkdir -p ${BUILD_STAGE1_PREFIX} + cd ${BUILD_STAGE1_PREFIX} + ../../${GCC_FOLDER}/configure \ + --with-system-zlib \ + --target=riscv32-corev-elf \ + --prefix=${INSTALL_PREFIX} \ + --with-sysroot=${INSTALL_PREFIX}/riscv32-corev-elf \ + --with-newlib \ + --without-headers \ + --disable-shared \ + --enable-languages=c \ + --disable-werror \ + --disable-libatomic \ + --disable-libmudflap \ + --disable-libssp \ + --disable-quadmath \ + --disable-libgomp \ + --disable-nls \ + --disable-bootstrap \ + --enable-multilib \ + --with-arch=${DEFAULTARCH} \ + --with-abi=${DEFAULTABI} + + #CFLAGS as option for debugging + if [[ $* == *--debug* ]]; then + if ! make CFLAGS="-O0 -g3" CXXFLAGS="-O0 -g3" -j${PARALLEL_JOBS}; then + echo "The build has failed during gcc-stage1!" >/dev/stderr + exit 1 + fi + if ! make CFLAGS="-O0 -g3" CXXFLAGS="-O0 -g3" install; then + echo "The build has failed during gcc-stage1!" >/dev/stderr + exit 1 + fi + else + if ! make -j${PARALLEL_JOBS}; then + echo "The build has failed during gcc-stage1!" >/dev/stderr + exit 1 + fi + if ! make install; then + echo "The build has failed during gcc-stage1!" >/dev/stderr + exit 1 + fi + fi +fi + +# Newlib - need target tools in PATH from now on +if [[ $* == *--newlib* || $* == *--all* ]]; then + PATH=${INSTALL_PREFIX}/bin:${PATH} + mkdir -p ${BUILD_NEWLIB_PREFIX} + cd ${BUILD_NEWLIB_PREFIX} + ../../${NEWLIB_FOLDER}/configure \ + --target=riscv32-corev-elf \ + --prefix=${INSTALL_PREFIX} \ + --with-arch=${DEFAULTARCH} \ + --with-abi=${DEFAULTABI} \ + --enable-multilib + + #CFLAGS as option for debugging + if [[ $* == *--debug* ]]; then + if ! make CFLAGS="-O0 -ggdb3" -j${PARALLEL_JOBS}; then + echo "The build has failed during newlib!" >/dev/stderr + exit 1 + fi + if ! make CFLAGS="-O0 -ggdb3" install; then + echo "The build has failed during newlib!" >/dev/stderr + exit 1 + fi + else + if ! make -j${PARALLEL_JOBS}; then + echo "The build has failed during newlib!" >/dev/stderr + exit 1 + fi + if ! make install; then + echo "The build has failed during newlib!" >/dev/stderr + exit 1 + fi + fi +fi + +# GCC (Stage 2) +if [[ $* == *--gcc-stage2* || $* == *--all* ]]; then + mkdir -p ${BUILD_STAGE2_PREFIX} + cd ${BUILD_STAGE2_PREFIX} + ../../${GCC_FOLDER}/configure \ + --with-system-zlib \ + --target=riscv32-corev-elf \ + --prefix=${INSTALL_PREFIX} \ + --with-sysroot=${INSTALL_PREFIX}/riscv32-corev-elf \ + --with-native-system-header-dir=/include \ + --with-newlib \ + --disable-shared \ + --enable-languages=c,c++ \ + --enable-tls \ + --disable-werror \ + --disable-libmudflap \ + --disable-libssp \ + --disable-quadmath \ + --disable-libgomp \ + --disable-nls \ + --enable-multilib \ + --with-arch=${DEFAULTARCH} \ + --with-abi=${DEFAULTABI} + + #CFLAGS as option for debugging + if [[ $* == *--debug* ]]; then + if ! make CFLAGS="-O0 -g3" CXXFLAGS="-O0 -g3" -j${PARALLEL_JOBS}; then + echo "The build has failed during gcc-stage2!" >/dev/stderr + exit 1 + fi + if ! make CFLAGS="-O0 -g3" CXXFLAGS="-O0 -g3" install; then + echo "The build has failed during gcc-stage2!" >/dev/stderr + exit 1 + fi + else + if ! make -j${PARALLEL_JOBS}; then + echo "The build has failed during gcc-stage2!" >/dev/stderr + exit 1 + fi + if ! make install; then + echo "The build has failed during gcc-stage2!" >/dev/stderr + exit 1 + fi + fi +fi + +echo ===== Install summary ===== +echo ${INSTALL_PREFIX}/bin/ +for install in "${installs[@]}" +do + [ -f ${INSTALL_PREFIX}/bin/${install} ] && echo "${install} ... exists." || echo "${install} ... does not exist." +done