Skip to content

Commit 89c8652

Browse files
committed
setup-build-env: configurable GCC version
Refactor setup-build-env to accept optional gcc-version action input to control what version of GCC is installed. Refactor "setup environment" step into a separate install_packages.sh script. Simplify install_clang.sh by utilizing officially distributed installation script [1]. Use update-alternatives to make sure the specified version of GCC is the system default, when installed via setup-build-env action. [1] https://apt.llvm.org/ Signed-off-by: Ihor Solodrai <[email protected]>
1 parent be750c4 commit 89c8652

File tree

5 files changed

+63
-47
lines changed

5 files changed

+63
-47
lines changed

setup-build-env/action.yml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ inputs:
1313
description: 'llvm version'
1414
required: false
1515
default: '16'
16+
gcc-version:
17+
required: false
18+
default: '13'
1619
arch:
1720
description: 'arch'
1821
required: true
@@ -21,27 +24,27 @@ runs:
2124
steps:
2225
- name: Setup environment
2326
shell: bash
27+
env:
28+
GCC_VERSION: ${{ inputs.gcc-version }}
2429
run: |
25-
echo "::group::Setup"
26-
sudo apt-get update
27-
sudo apt-get install -y cmake flex bison build-essential libssl-dev ncurses-dev xz-utils bc rsync libguestfs-tools qemu-kvm qemu-utils zstd libzstd-dev binutils-dev elfutils libcap-dev libelf-dev libdw-dev python3-docutils texinfo libpcap-dev pkg-config
28-
echo "::endgroup::"
30+
${GITHUB_ACTION_PATH}/install_packages.sh
2931
- name: Install clang
3032
shell: bash
33+
env:
34+
LLVM_VERSION: ${{ inputs.llvm-version }}
3135
run: |
32-
export LLVM_VERSION=${{ inputs.llvm-version }}
3336
${GITHUB_ACTION_PATH}/install_clang.sh
3437
- name: Install pahole
3538
shell: bash
39+
env:
40+
PAHOLE_BRANCH: ${{ inputs.pahole }}
41+
PAHOLE_ORIGIN: ${{ inputs.pahole-origin }}
3642
run: |
37-
export PAHOLE_BRANCH=${{ inputs.pahole }}
38-
export PAHOLE_ORIGIN=${{ inputs.pahole-origin }}
3943
${GITHUB_ACTION_PATH}/build_pahole.sh
40-
- name: set pahole location
41-
shell: bash
42-
run: |
4344
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}:/usr/local/lib" >> $GITHUB_ENV
4445
- name: Install cross compilation toolchain
4546
shell: bash
47+
env:
48+
GCC_VERSION: ${{ inputs.gcc-version }}
4649
run: |
4750
${GITHUB_ACTION_PATH}/install_cross_compilation_toolchain.sh ${{ inputs.arch }}

setup-build-env/build_pahole.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ source $(cd $(dirname $0) && pwd)/../helpers.sh
1414

1515
foldable start build_pahole "Building pahole"
1616

17-
sudo apt-get update && sudo apt-get install elfutils libelf-dev libdw-dev
17+
sudo apt-get update -y
18+
sudo apt-get install -y --no-install-recommends elfutils libelf-dev libdw-dev
1819

1920
CWD=$(pwd)
2021

setup-build-env/install_clang.sh

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,13 @@
11
#!/bin/bash
22
set -eu
33

4-
source $(cd $(dirname $0) && pwd)/../helpers.sh
4+
THISDIR="$(cd "$(dirname "$0")" && pwd)"
5+
source "${THISDIR}"/../helpers.sh
56

6-
# Install required packages
7-
foldable start install_clang "Installing Clang/LLVM"
8-
sudo apt-get update
9-
sudo apt-get install -y g++ libelf-dev
7+
foldable start install_clang "Install LLVM ${LLVM_VERSION}"
108

11-
if [[ "${LLVM_VERSION}" == $(llvm_latest_version) ]] ; then
12-
REPO_DISTRO_SUFFIX=""
13-
else
14-
REPO_DISTRO_SUFFIX="-${LLVM_VERSION}"
15-
fi
9+
curl -O https://apt.llvm.org/llvm.sh
10+
chmod +x llvm.sh
11+
sudo ./llvm.sh ${LLVM_VERSION}
1612

17-
DISTRIB_CODENAME=$(distrib_codename)
18-
19-
echo "deb https://apt.llvm.org/${DISTRIB_CODENAME}/ llvm-toolchain-${DISTRIB_CODENAME}${REPO_DISTRO_SUFFIX} main" | sudo tee /etc/apt/sources.list.d/llvm.list
20-
n=0
21-
while [ $n -lt 5 ]; do
22-
set +e && \
23-
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - && \
24-
sudo apt-get update && \
25-
sudo apt-get install -y clang-${LLVM_VERSION} lld-${LLVM_VERSION} llvm-${LLVM_VERSION} && \
26-
set -e && \
27-
break
28-
n=$(($n + 1))
29-
done
30-
if [ $n -ge 5 ] ; then
31-
echo "clang install failed"
32-
exit 1
33-
fi
3413
foldable end install_clang

setup-build-env/install_cross_compilation_toolchain.sh

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ source /etc/os-release
2020
DEB_ARCH="$(platform_to_deb_arch "${TARGET_ARCH}")"
2121
DEB_HOST_ARCH="$(dpkg --print-architecture)"
2222
UBUNTU_CODENAME=${VERSION_CODENAME:-noble}
23+
GCC_VERSION=${GCC_VERSION:-14}
2324

2425
cat <<EOF | sudo tee /etc/apt/sources.list.d/ubuntu.sources
2526
Types: deb
@@ -48,15 +49,22 @@ Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
4849
EOF
4950

5051
sudo apt-get update -y
51-
52-
sudo apt-get install -y \
53-
"crossbuild-essential-${DEB_ARCH}" \
54-
"binutils-${TARGET_ARCH}-linux-gnu" \
55-
"gcc-${TARGET_ARCH}-linux-gnu" \
56-
"g++-${TARGET_ARCH}-linux-gnu" \
57-
"linux-libc-dev:${DEB_ARCH}" \
58-
"libelf-dev:${DEB_ARCH}" \
59-
"libssl-dev:${DEB_ARCH}" \
52+
sudo apt-get install -y --no-install-recommends \
53+
"gcc-${GCC_VERSION}-${TARGET_ARCH}-linux-gnu" \
54+
"g++-${GCC_VERSION}-${TARGET_ARCH}-linux-gnu" \
55+
"linux-libc-dev:${DEB_ARCH}" \
56+
"libelf-dev:${DEB_ARCH}" \
57+
"libssl-dev:${DEB_ARCH}" \
6058
"zlib1g-dev:${DEB_ARCH}"
6159

60+
sudo update-alternatives --install \
61+
/usr/bin/${TARGET_ARCH}-linux-gnu-gcc \
62+
${TARGET_ARCH}-linux-gnu-gcc \
63+
/usr/bin/${TARGET_ARCH}-linux-gnu-gcc-${GCC_VERSION} 10
64+
65+
sudo update-alternatives --install \
66+
/usr/bin/${TARGET_ARCH}-linux-gnu-g++ \
67+
${TARGET_ARCH}-linux-gnu-g++ \
68+
/usr/bin/${TARGET_ARCH}-linux-gnu-g++-${GCC_VERSION} 10
69+
6270
foldable end install_crosscompile
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
THISDIR="$(cd "$(dirname "$0")" && pwd)"
6+
source "${THISDIR}"/../helpers.sh
7+
8+
export DEBIAN_FRONTEND=noninteractive
9+
export GCC_VERSION=${GCC_VERSION:-14}
10+
11+
foldable start install_packages
12+
13+
sudo apt-get update -y
14+
15+
sudo -E apt-get install --no-install-recommends -y \
16+
bc binutils-dev bison build-essential cmake curl elfutils flex \
17+
libcap-dev libdw-dev libelf-dev libguestfs-tools libpcap-dev \
18+
libssl-dev libzstd-dev ncurses-dev pkg-config python3-docutils \
19+
qemu-kvm qemu-utils rsync texinfo tzdata xz-utils zstd
20+
21+
sudo apt-get install -y gcc-${GCC_VERSION} g++-${GCC_VERSION}
22+
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_VERSION} 10
23+
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-${GCC_VERSION} 10
24+
25+
foldable end install_packages

0 commit comments

Comments
 (0)