Skip to content

Commit b0177db

Browse files
committed
Github Actions workflow to generate vmlinux.h
Define a workflow job that uses ./scripts to generate vmlinux.h from the latest Linux mainline release for various architectures. Rewrite scripts to make the workflow easy to write and understand the logs: kernel build and vmlinux.h generation execute in a separate step for each target architecture, while common dependencies are installed at the beginning. Signed-off-by: Ihor Solodrai <[email protected]>
1 parent 910d412 commit b0177db

File tree

4 files changed

+109
-55
lines changed

4 files changed

+109
-55
lines changed

.github/workflows/vmlinux.h.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Generate vmlinux.h
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
gen-headers:
8+
name: Generate vmlinux.h
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
13+
- uses: actions/checkout@v4
14+
15+
- name: Download Linux source
16+
shell: bash
17+
run: ./scripts/download-latest-linux-release.sh
18+
19+
- name: Install dependencies
20+
shell: bash
21+
run: |
22+
./scripts/install-dependencies.sh
23+
./scripts/install-pahole.sh
24+
./scripts/install-bpftool.sh
25+
26+
- name: x86_64/vmlinux.h
27+
shell: bash
28+
run: ./scripts/gen-vmlinux-header.sh x86_64
29+
30+
- name: aarch64/vmlinux.h
31+
shell: bash
32+
run: ./scripts/gen-vmlinux-header.sh aarch64
33+
34+
- name: arm/vmlinux.h
35+
shell: bash
36+
run: ./scripts/gen-vmlinux-header.sh arm
37+
38+
- name: loongarch64/vmlinux.h
39+
shell: bash
40+
run: ./scripts/gen-vmlinux-header.sh loongarch64
41+
42+
- name: ppc64le/vmlinux.h
43+
shell: bash
44+
run: ./scripts/gen-vmlinux-header.sh ppc64le
45+
46+
- name: riscv64/vmlinux.h
47+
shell: bash
48+
run: ./scripts/gen-vmlinux-header.sh riscv64
49+
50+
- name: s390x/vmlinux.h
51+
shell: bash
52+
run: ./scripts/gen-vmlinux-header.sh s390x
53+
54+
- name: Upload headers
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: vmlinux.h
58+
if-no-files-found: error
59+
path: ./vmlinux.h
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
usage () {
4-
echo "USAGE: ./gen-vmlinux-headers.sh <linux-repo-path> <kconfig-path>"
4+
echo "USAGE: ./gen-vmlinux-headers.sh <arch> [<linux-repo-path> <kconfig-path>]"
55
exit 1
66
}
77

@@ -10,12 +10,19 @@ set -eu
1010
source $(dirname "$0")/helpers.sh
1111

1212
WORKSPACE=$(pwd)
13-
BUILD_DIR="$WORKSPACE/build"
14-
15-
LINUX_REPO=${1-""}
16-
KCONFIG=${2-"$WORKSPACE/kconfig"}
13+
BUILD_DIR="${BUILD_DIR:-$WORKSPACE/build}"
14+
GCC_VERSION=${GCC_VERSION:-"13"}
1715
OUTPUT_DIR="${OUTPUT_DIR:-$WORKSPACE/vmlinux.h}"
1816

17+
TARGET_ARCH=$1
18+
LINUX_REPO=${2-"./linux"}
19+
KCONFIG=${3-"$WORKSPACE/kconfig"}
20+
21+
if [ -z "${TARGET_ARCH}" ]; then
22+
echo "Error: Target architecture is not set"
23+
usage
24+
fi
25+
1926
if [ ! -d "${LINUX_REPO}" ]; then
2027
echo "Error: Linux repo path is not found, LINUX_REPO=$LINUX_REPO"
2128
usage
@@ -26,24 +33,29 @@ if [ ! -f "${KCONFIG}" ]; then
2633
usage
2734
fi
2835

36+
mkdir -p "$BUILD_DIR"
2937
LINUX_REPO=$(realpath "$LINUX_REPO")
3038
KCONFIG=$(realpath "$KCONFIG")
3139

32-
mkdir -p "$BUILD_DIR"
33-
34-
(
35-
echo "Building bpftool..."
36-
cd "$LINUX_REPO/tools/bpf/bpftool"
37-
make &> "$BUILD_DIR/bpftool_build.txt"
38-
)
39-
40-
BPFTOOL="$LINUX_REPO/tools/bpf/bpftool/bpftool"
40+
# Install the cross-compiler
41+
if [ "${TARGET_ARCH}" != "x86_64" ]; then
42+
compiler_id=$(arch_compiler_id "$TARGET_ARCH")
43+
sudo apt install -y \
44+
"gcc-${GCC_VERSION}-${compiler_id}" \
45+
"binutils-${compiler_id}"
46+
sudo update-alternatives --install \
47+
/usr/bin/${compiler_id}-gcc \
48+
${compiler_id}-gcc \
49+
/usr/bin/${compiler_id}-gcc-${GCC_VERSION} 100
50+
sudo update-alternatives --set \
51+
${compiler_id}-gcc \
52+
/usr/bin/${compiler_id}-gcc-${GCC_VERSION}
53+
fi
4154

4255
build_arch(){
4356
local arch="$1"
4457
local kbuild_output="$(realpath $BUILD_DIR/$arch)"
4558
mkdir -p "$kbuild_output"
46-
local kernel_log="$BUILD_DIR/linux_build_$arch.log"
4759
local arch_slug=$(arch_slug "$arch")
4860
local compiler_id=$(arch_compiler_id "$arch")
4961

@@ -52,39 +64,23 @@ build_arch(){
5264
cd "$LINUX_REPO"
5365
make O="$kbuild_output" \
5466
ARCH=$arch_slug CROSS_COMPILE="${compiler_id}-" \
55-
tinyconfig &> "$kernel_log"
67+
tinyconfig
5668
"$LINUX_REPO/scripts/kconfig/merge_config.sh" -m \
5769
-O "$kbuild_output" \
58-
"$kbuild_output/.config" "${KCONFIG}" \
59-
&>> "$kernel_log"
70+
"$kbuild_output/.config" "${KCONFIG}"
6071
make O="$kbuild_output" \
6172
ARCH=$arch_slug CROSS_COMPILE="${compiler_id}-" \
62-
olddefconfig &>> "$kernel_log"
73+
olddefconfig
6374

6475
make O="$kbuild_output" \
6576
ARCH=$arch_slug CROSS_COMPILE="${compiler_id}-" \
66-
-j$(nproc) all &>> "$kernel_log"
77+
-j$(nproc) all
6778

6879
mkdir -p "$OUTPUT_DIR/$arch"
69-
"$BPFTOOL" btf dump \
80+
bpftool btf dump \
7081
file "$kbuild_output/vmlinux" format c \
7182
> "$OUTPUT_DIR/$arch/vmlinux.h"
7283
)
7384
}
7485

75-
for arch in x86_64 aarch64 s390x ppc64le riscv64 arm loongarch64; do
76-
build_arch $arch
77-
done
78-
79-
# Fixup the output to match the repo structure
80-
(
81-
cd $OUTPUT_DIR
82-
mv ppc64le powerpc
83-
mv x86_64 x86
84-
ln -s x86 x86_64
85-
ln -s aarch64 arm64
86-
ln -s riscv64 riscv
87-
ln -s loongarch64 loongarch
88-
)
89-
90-
echo "Done!"
86+
build_arch $TARGET_ARCH

scripts/install-bpftool.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -eux
4+
5+
LINUX_REPO=${1:-"./linux"}
6+
7+
if [ ! -d "${LINUX_REPO}" ]; then
8+
echo "Error: Linux repo path is not found, LINUX_REPO=$LINUX_REPO"
9+
exit 1
10+
fi
11+
12+
sudo apt install -y clang libcap-dev libbfd-dev zlib1g-dev
13+
14+
cd "$LINUX_REPO/tools/bpf/bpftool"
15+
make -j
16+
sudo make install

scripts/install-dependencies.sh

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,6 @@ export GCC_VERSION=${GCC_VERSION:-"13"}
88
# Assume Ubuntu/Debian x86_64
99

1010
sudo apt update -y
11-
DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata
11+
DEBIAN_FRONTEND=noninteractive sudo apt install -y tzdata
1212
sudo apt install -y bc bison build-essential elfutils flex make ncurses-dev python3-docutils zstd
1313
sudo apt install -y libelf-dev libdw-dev
14-
15-
# Install cross-compilers
16-
for arch in aarch64 s390x ppc64le riscv64 arm loongarch64; do
17-
compiler_id=$(arch_compiler_id "$arch")
18-
sudo apt install -y \
19-
"gcc-${GCC_VERSION}-${compiler_id}" \
20-
"binutils-${compiler_id}"
21-
sudo update-alternatives --install \
22-
/usr/bin/${compiler_id}-gcc \
23-
${compiler_id}-gcc \
24-
/usr/bin/${compiler_id}-gcc-${GCC_VERSION} 100
25-
sudo update-alternatives --set \
26-
${compiler_id}-gcc \
27-
/usr/bin/${compiler_id}-gcc-${GCC_VERSION}
28-
done
29-
30-
$(dirname "$0")/install-pahole.sh

0 commit comments

Comments
 (0)