136 lines (119 loc) · 5.2 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# SPDX-FileCopyrightText: 2022 - 2023 Serdar Sayın <https://serdarsayin.com>
#
# SPDX-License-Identifier: MIT
name: build
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
types: [ opened, synchronize, reopened ]
jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-22.04
env:
BUILD_TYPE: Debug
SONAR_SCANNER_VERSION: 4.6.1.2450 # Find the latest version in the "Linux" link on this page:
RISCV32_TOOLCHAIN_GZIP: riscv32-embecosm-gcc-ubuntu2204-20221030
# https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/
SONAR_HOST_URL: "https://sonarcloud.io"
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Update GCC
run: |
sudo apt-get update
sudo apt install gcc-12 g++-12
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 100 --slave /usr/bin/g++ g++ /usr/bin/g++-12 --slave /usr/bin/gcov gcov /usr/bin/gcov-12
- name: Get GCC Version
shell: bash
run: |
gcc --version > gcc-ver.txt
- name: Upload GCC Version
uses: actions/upload-artifact@v3
with:
name: gcc-ver
path: gcc-ver.txt
retention-days: 1
- name: Install Ninja
run: |
sudo apt-get update -y
sudo apt-get install -y ninja-build gcovr
- name: Cache RV32 GCC Toolchain
id: cache-riscv-toolchain
uses: actions/cache@v3
with:
path: ~/.riscv-gcc
key: ${{ runner.os }}-riscv-gcc
restore-keys: ${{ runner.os }}-riscv-gcc
- name: Download & Extract RISCV32 GCC Toolchain
if: steps.cache-riscv-toolchain.outputs.cache-hit != 'true'
shell: bash
env:
RISCV32_TOOLCHAIN_URL: https://buildbot.embecosm.com/job/riscv32-gcc-ubuntu2204/30/artifact/riscv32-embecosm-gcc-ubuntu2204-20221030.tar.gz
run: |
mkdir -p $HOME/.riscv-gcc
wget -q ${{env.RISCV32_TOOLCHAIN_URL}}
tar xf ${{env.RISCV32_TOOLCHAIN_GZIP}}.tar.gz -C $HOME/.riscv-gcc/
- name: Set up ENV
run: echo "$HOME/.riscv-gcc/${{env.RISCV32_TOOLCHAIN_GZIP}}/bin" >> $GITHUB_PATH
- name: Cache riscv-tests
id: cache-riscv-tests
uses: actions/cache@v3
with:
path: ~/.riscv-gcc/${{env.RISCV32_TOOLCHAIN_GZIP}}/share
key: ${{ runner.os }}-riscv-tests
restore-keys: ${{ runner.os }}-riscv-tests
- name: Set-up riscv-tests
if: steps.cache-riscv-tests.outputs.cache-hit != 'true'
shell: bash
run: |
mkdir tmp0
cd tmp0
git clone --recurse-submodules https://github.com/riscv-software-src/riscv-tests.git; cd riscv-tests
git submodule update --init --recursive
# Patch Makefile.in
git clone https://gist.github.com/b5c1b033143cbdce51afa0c1280970a8.git
patch < b5c1b033143cbdce51afa0c1280970a8/patch1.diff
# Configure and Make
autoupdate
autoconf
mkdir build; cd build
RISCV=$HOME/.riscv-gcc/${{env.RISCV32_TOOLCHAIN_GZIP}}
../configure --prefix=$RISCV --with-xlen=32
make install
cd ..
- name: Build & Test
shell: bash
run: |
cmake -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTS=ON -DCOVERAGE=ON -DBUILD_RUNTIME=ON -DENABLE_TCP=OFF -DISA_TESTS_DIR=$HOME/.riscv-gcc/${{env.RISCV32_TOOLCHAIN_GZIP}}/share/riscv-tests/isa -S . -B ${{env.BUILD_TYPE}} -GNinja
ninja -C ${{env.BUILD_TYPE}}
ctest --output-on-failure --test-dir ${{env.BUILD_TYPE}}
gcovr -e external -e build --sonarqube > coverage.xml
- name: Cache SonarQube packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Download and set up sonar-scanner
env:
SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip
run: |
mkdir -p $HOME/.sonar
curl -sSLo $HOME/.sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }}
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
echo "$HOME/.sonar/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-linux/bin" >> $GITHUB_PATH
- name: Run sonar-scanner
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
# Set the property "sonar.cfamily.compile-commands" to the compilation database file
sonar-scanner --define sonar.host.url="${{ env.SONAR_HOST_URL }}" --define sonar.cfamily.compile-commands=${{env.BUILD_TYPE}}/compile_commands.json