Skip to content

Commit 89209fc

Browse files
jwnrtluismarques
authored andcommitted
Add GitHub Actions workflow for building toolchains
1 parent 4e44e0c commit 89209fc

File tree

3 files changed

+172
-0
lines changed

3 files changed

+172
-0
lines changed

.github/workflows/toolchain_build.yml

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Build toolchains
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags:
8+
- "*"
9+
pull_request:
10+
branches:
11+
- master
12+
13+
env:
14+
ARTIFACT_STAGING_DIR: artifact
15+
16+
jobs:
17+
build:
18+
strategy:
19+
matrix:
20+
include:
21+
- name: rv32imcb
22+
display_name: Toolchains targeting Ibex with bit-manipulation extensions
23+
target: riscv32-unknown-elf
24+
output_dir: /tools/riscv
25+
march: rv32imc_zba_zbb_zbc_zbs
26+
mabi: ilp32
27+
mcmodel: medany
28+
- name: rv64imac
29+
display_name: GCC and Clang/LLVM toolchains targeting RV64IMAC (Muntjac)
30+
target: riscv64-unknown-elf
31+
output_dir: /tools/riscv
32+
march: rv64imac
33+
mabi: lp64
34+
mcmodel: medany
35+
# - name: multilib-baremetal
36+
# display_name: RV64 GCC (Multilib Baremetal)
37+
# target: riscv64-unknown-elf
38+
# output_dir: /opt/riscv-baremetal-toolchain
39+
# - name: multilib-linux
40+
# display_name: RV64 GCC (Multilib Linux)
41+
# target: riscv64-unknown-linux-gnu
42+
# output_dir: /opt/riscv-linux-toolchain
43+
44+
name: ${{ matrix.display_name }}
45+
runs-on: ubuntu-20.04
46+
timeout-minutes: 360
47+
48+
steps:
49+
- uses: actions/checkout@v4
50+
51+
- name: Setup environment
52+
run: |
53+
echo ::group::Install dependencies
54+
./prepare-ubuntu-20.04.sh
55+
./install-crosstool-ng.sh
56+
echo ::endgroup::
57+
58+
echo Preparing toolchain destination directory...
59+
sudo mkdir -p /tools/riscv
60+
sudo chmod 0777 /tools/riscv
61+
62+
echo ::group::Set the release tag env var
63+
echo "RELEASE_TAG=$(./release_tag.sh)" >> "$GITHUB_ENV"
64+
echo ::endgroup::
65+
66+
echo Creating artifact staging directory...
67+
mkdir "$ARTIFACT_STAGING_DIR"
68+
69+
- name: Build GCC toolchain
70+
run: |
71+
./build-gcc-with-args.sh \
72+
"lowrisc-toolchain-gcc-${{ matrix.name }}" \
73+
"${{ matrix.target }}" \
74+
"${{ matrix.output_dir }}" \
75+
"${{ matrix.march }}" \
76+
"${{ matrix.mabi}}" \
77+
"${{ matrix.mcmodel }}" \
78+
"${{ matrix.cflags }}"
79+
80+
- name: Build Clang toolchain
81+
run: |
82+
./build-clang-with-args.sh \
83+
"lowrisc-toolchain-${{ matrix.name }}" \
84+
"${{ matrix.target }}" \
85+
"${{ matrix.output_dir }}" \
86+
"${{ matrix.march }}" \
87+
"${{ matrix.mabi}}" \
88+
"${{ matrix.mcmodel }}" \
89+
"${{ matrix.cflags }}"
90+
91+
- uses: actions/upload-artifact@v3
92+
with:
93+
name: ${{ matrix.name }}-toolchains
94+
path: ${{ env.ARTIFACT_STAGING_DIR }}
95+
96+
- name: Check tarballs
97+
run: |
98+
set -e
99+
for f in "${ARTIFACT_STAGING_DIR}"/*.tar.xz; do
100+
./check-tarball.sh "$f"
101+
done
102+
103+
- name: Release
104+
if: github.ref_type == 'tag'
105+
env:
106+
GH_TOKEN: ${{ github.token }}
107+
run: |
108+
# Create the release if it doesn't already exist.
109+
gh release create "$RELEASE_TAG" --prerelease || echo "release exists"
110+
# Upload this job's artifacts.
111+
gh release upload "$RELEASE_TAG" --clobber \
112+
"${ARTIFACT_STAGING_DIR}/lowrisc-toolchain-${{ matrix.name }}-${RELEASE_TAG}.tar.xz" \
113+
"${ARTIFACT_STAGING_DIR}/lowrisc-toolchain-gcc-${{ matrix.name }}-${RELEASE_TAG}.tar.xz"

prepare-ubuntu-20.04.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
# Copyright lowRISC contributors.
3+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
set -e
7+
set -x
8+
9+
# Install prerequisite packages.
10+
#
11+
# Notes:
12+
# - liblzma-dev is removed to prevent it being dynamically linked to GDB.
13+
# - libxml2-dev is removed to prevent it being dynamically linked to LD.
14+
sudo apt install -y \
15+
bison \
16+
curl \
17+
flex \
18+
gawk \
19+
gettext \
20+
git \
21+
help2man \
22+
libffi-dev \
23+
libncurses-dev \
24+
libpixman-1-dev \
25+
libtool-bin \
26+
texinfo \
27+
xz-utils \
28+
zlib1g \
29+
zlib1g-dev
30+
31+
sudo apt remove -y \
32+
liblzma-dev \
33+
libxml2-dev

release_tag.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
# Determine the release tag from Git based on the type of release being made.
4+
5+
set -e
6+
set -x
7+
8+
# git-describe --always almost does what we want, but we need to connect the
9+
# `RELEASE_TAG` variable contents to how this build was triggered, which we
10+
# will find out using `$GITHUB_REF_TYPE` (a GitHub Actions variable).
11+
#
12+
# Importantly, a few things are going on here:
13+
# - If we were triggered by a tag, we need to output exactly the tag name,
14+
# so that the artifacts are named correctly. If we cannot do this, the
15+
# build needs to fail rather than uploading artifacts to some other
16+
# random tag.
17+
# - If we were triggered by a branch build, we need to be more careful, as
18+
# tagged commits are also pushed to branches. Branch builds explicitly use
19+
# the longer format so that if the built commit matches a tag, the
20+
# `RELEASE_TAG` is not a tag name.
21+
if [[ "$GITHUB_REF_TYPE" == tag ]]; then
22+
echo "$GITHUB_REF_NAME"
23+
else
24+
# Branch Build: Always use '<TAG>-<N>-<SHA>' format.
25+
git describe --long
26+
fi

0 commit comments

Comments
 (0)