From 89209fcdf08bc8d7a2c654def8cbd8e7e59de252 Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Fri, 8 Dec 2023 13:57:17 +0000 Subject: [PATCH] Add GitHub Actions workflow for building toolchains --- .github/workflows/toolchain_build.yml | 113 ++++++++++++++++++++++++++ prepare-ubuntu-20.04.sh | 33 ++++++++ release_tag.sh | 26 ++++++ 3 files changed, 172 insertions(+) create mode 100644 .github/workflows/toolchain_build.yml create mode 100755 prepare-ubuntu-20.04.sh create mode 100755 release_tag.sh diff --git a/.github/workflows/toolchain_build.yml b/.github/workflows/toolchain_build.yml new file mode 100644 index 0000000..34a9f97 --- /dev/null +++ b/.github/workflows/toolchain_build.yml @@ -0,0 +1,113 @@ +name: Build toolchains + +on: + push: + branches: + - master + tags: + - "*" + pull_request: + branches: + - master + +env: + ARTIFACT_STAGING_DIR: artifact + +jobs: + build: + strategy: + matrix: + include: + - name: rv32imcb + display_name: Toolchains targeting Ibex with bit-manipulation extensions + target: riscv32-unknown-elf + output_dir: /tools/riscv + march: rv32imc_zba_zbb_zbc_zbs + mabi: ilp32 + mcmodel: medany + - name: rv64imac + display_name: GCC and Clang/LLVM toolchains targeting RV64IMAC (Muntjac) + target: riscv64-unknown-elf + output_dir: /tools/riscv + march: rv64imac + mabi: lp64 + mcmodel: medany +# - name: multilib-baremetal +# display_name: RV64 GCC (Multilib Baremetal) +# target: riscv64-unknown-elf +# output_dir: /opt/riscv-baremetal-toolchain +# - name: multilib-linux +# display_name: RV64 GCC (Multilib Linux) +# target: riscv64-unknown-linux-gnu +# output_dir: /opt/riscv-linux-toolchain + + name: ${{ matrix.display_name }} + runs-on: ubuntu-20.04 + timeout-minutes: 360 + + steps: + - uses: actions/checkout@v4 + + - name: Setup environment + run: | + echo ::group::Install dependencies + ./prepare-ubuntu-20.04.sh + ./install-crosstool-ng.sh + echo ::endgroup:: + + echo Preparing toolchain destination directory... + sudo mkdir -p /tools/riscv + sudo chmod 0777 /tools/riscv + + echo ::group::Set the release tag env var + echo "RELEASE_TAG=$(./release_tag.sh)" >> "$GITHUB_ENV" + echo ::endgroup:: + + echo Creating artifact staging directory... + mkdir "$ARTIFACT_STAGING_DIR" + + - name: Build GCC toolchain + run: | + ./build-gcc-with-args.sh \ + "lowrisc-toolchain-gcc-${{ matrix.name }}" \ + "${{ matrix.target }}" \ + "${{ matrix.output_dir }}" \ + "${{ matrix.march }}" \ + "${{ matrix.mabi}}" \ + "${{ matrix.mcmodel }}" \ + "${{ matrix.cflags }}" + + - name: Build Clang toolchain + run: | + ./build-clang-with-args.sh \ + "lowrisc-toolchain-${{ matrix.name }}" \ + "${{ matrix.target }}" \ + "${{ matrix.output_dir }}" \ + "${{ matrix.march }}" \ + "${{ matrix.mabi}}" \ + "${{ matrix.mcmodel }}" \ + "${{ matrix.cflags }}" + + - uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.name }}-toolchains + path: ${{ env.ARTIFACT_STAGING_DIR }} + + - name: Check tarballs + run: | + set -e + for f in "${ARTIFACT_STAGING_DIR}"/*.tar.xz; do + ./check-tarball.sh "$f" + done + + - name: Release + if: github.ref_type == 'tag' + env: + GH_TOKEN: ${{ github.token }} + run: | + # Create the release if it doesn't already exist. + gh release create "$RELEASE_TAG" --prerelease || echo "release exists" + # Upload this job's artifacts. + gh release upload "$RELEASE_TAG" --clobber \ + "${ARTIFACT_STAGING_DIR}/lowrisc-toolchain-${{ matrix.name }}-${RELEASE_TAG}.tar.xz" \ + "${ARTIFACT_STAGING_DIR}/lowrisc-toolchain-gcc-${{ matrix.name }}-${RELEASE_TAG}.tar.xz" diff --git a/prepare-ubuntu-20.04.sh b/prepare-ubuntu-20.04.sh new file mode 100755 index 0000000..636ab5f --- /dev/null +++ b/prepare-ubuntu-20.04.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# Copyright lowRISC contributors. +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 + +set -e +set -x + +# Install prerequisite packages. +# +# Notes: +# - liblzma-dev is removed to prevent it being dynamically linked to GDB. +# - libxml2-dev is removed to prevent it being dynamically linked to LD. +sudo apt install -y \ + bison \ + curl \ + flex \ + gawk \ + gettext \ + git \ + help2man \ + libffi-dev \ + libncurses-dev \ + libpixman-1-dev \ + libtool-bin \ + texinfo \ + xz-utils \ + zlib1g \ + zlib1g-dev + +sudo apt remove -y \ + liblzma-dev \ + libxml2-dev diff --git a/release_tag.sh b/release_tag.sh new file mode 100755 index 0000000..6a72d5b --- /dev/null +++ b/release_tag.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +# Determine the release tag from Git based on the type of release being made. + +set -e +set -x + +# git-describe --always almost does what we want, but we need to connect the +# `RELEASE_TAG` variable contents to how this build was triggered, which we +# will find out using `$GITHUB_REF_TYPE` (a GitHub Actions variable). +# +# Importantly, a few things are going on here: +# - If we were triggered by a tag, we need to output exactly the tag name, +# so that the artifacts are named correctly. If we cannot do this, the +# build needs to fail rather than uploading artifacts to some other +# random tag. +# - If we were triggered by a branch build, we need to be more careful, as +# tagged commits are also pushed to branches. Branch builds explicitly use +# the longer format so that if the built commit matches a tag, the +# `RELEASE_TAG` is not a tag name. +if [[ "$GITHUB_REF_TYPE" == tag ]]; then + echo "$GITHUB_REF_NAME" +else + # Branch Build: Always use '--' format. + git describe --long +fi