Skip to content

Commit ff52208

Browse files
committed
migrate to using the dockerfile and yml as two different runners for the .sh
1 parent a851105 commit ff52208

File tree

3 files changed

+206
-304
lines changed

3 files changed

+206
-304
lines changed

.github/workflows/build_gcc.yml

Lines changed: 24 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -5,201 +5,52 @@ on:
55
branches: [ gcc ]
66

77
env:
8-
LIBC: gnu
9-
LIBC_VERSION: ""
8+
CT_NG_SRC_DIR: /tmp/crosstool-ng
9+
ARTIFACT_DIR: /tmp/toolchain/artifacts
10+
OUTPUT_DIR: /tmp/toolchain/output
11+
WORK_DIR: /tmp/toolchain/work
12+
BUILD_GCC_SH: ./infra/gcc/build_gcc.sh
13+
SUDO: "sudo"
14+
1015
GCC_VERSION: 15
16+
LIBC: gnu
17+
LIBC_VERSION: 2.34
1118
REBUILD_ID: 1
1219

1320
jobs:
1421
build:
1522
runs-on: ubuntu-latest
16-
timeout-minutes: 480 # 8 hours for toolchain build
17-
permissions:
18-
contents: write # Required for creating releases
19-
attestations: write # Required for build provenance
20-
id-token: write # Required for attestations
2123
steps:
2224
- name: Checkout repository
2325
uses: actions/checkout@v5.0.0
2426

25-
- name: Install Dependencies
26-
run: |
27-
sudo apt update
28-
sudo DEBIAN_FRONTEND=noninteractive apt install -y \
29-
build-essential \
30-
autoconf \
31-
flex \
32-
bison \
33-
texinfo \
34-
help2man \
35-
file \
36-
gawk \
37-
libtool \
38-
libtool-bin \
39-
libncurses-dev \
40-
python3 \
41-
python3-dev \
42-
unzip \
43-
git \
44-
wget \
45-
curl
46-
47-
- name: Build and Install crosstool-ng
27+
- name: Create Directories
4828
run: |
49-
git clone https://github.com/crosstool-ng/crosstool-ng /opt/crosstool-ng
50-
cd /opt/crosstool-ng
51-
./bootstrap
52-
./configure
53-
make
54-
sudo make install
29+
mkdir -p $CT_NG_SRC_DIR
30+
mkdir -p $ARTIFACT_DIR
31+
mkdir -p $OUTPUT_DIR
32+
mkdir -p $WORK_DIR
5533
56-
- name: Configure crosstool-ng
57-
run: |
58-
# Standard configs
59-
mkdir -p /opt/crosstool-ng-workdir
60-
cd /opt/crosstool-ng-workdir
61-
62-
echo 'CT_CONFIG_VERSION="4"' > defconfig
63-
echo 'CT_ARCH_X86=y' >> defconfig
64-
echo 'CT_OMIT_TARGET_VENDOR=y' >> defconfig
65-
echo 'CT_ARCH_64=y' >> defconfig
66-
echo 'CT_STATIC_TOOLCHAIN=y' >> defconfig
67-
echo 'CT_KERNEL_LINUX=y' >> defconfig
68-
echo 'CT_LOG_PROGRESS_BAR=n' >> defconfig
69-
echo 'CT_PREFIX_DIR_RO=n' >> defconfig
70-
echo 'CT_CC_LANG_CXX=y' >> defconfig
71-
echo 'CT_DEBUG_GDB=y' >> defconfig
72-
echo 'CT_PREFIX_DIR="/opt/crosstool-ng-output/"' >> defconfig
73-
echo 'CT_CC_GCC_LNK_HASH_STYLE_BOTH=y' >> defconfig
74-
75-
# GCC version configs
76-
if [ "$GCC_VERSION" = "15" ]; then
77-
echo 'CT_GCC_V_15=y' >> defconfig
78-
elif [ "$GCC_VERSION" = "14" ]; then
79-
echo 'CT_GCC_V_14=y' >> defconfig
80-
echo 'CT_GMP_EXTRA_CFLAGS="-std=gnu17"' >> defconfig
81-
echo 'CT_NCURSES_EXTRA_CFLAGS="-std=gnu17"' >> defconfig
82-
elif [ "$GCC_VERSION" = "13" ]; then
83-
echo 'CT_GCC_V_13=y' >> defconfig
84-
echo 'CT_GMP_EXTRA_CFLAGS="-std=gnu17"' >> defconfig
85-
echo 'CT_NCURSES_EXTRA_CFLAGS="-std=gnu17"' >> defconfig
86-
elif [ "$GCC_VERSION" = "12" ]; then
87-
echo 'CT_GCC_V_12=y' >> defconfig
88-
echo 'CT_GMP_EXTRA_CFLAGS="-std=gnu17"' >> defconfig
89-
echo 'CT_NCURSES_EXTRA_CFLAGS="-std=gnu17"' >> defconfig
90-
else
91-
echo "Error: Unsupported gcc_version: $GCC_VERSION" >&2
92-
echo "Supported versions: 15, 14, 13, 12" >&2
93-
exit 1
94-
fi
95-
96-
# glibc configs
97-
if [ "$LIBC" = "gnu" ]; then
98-
echo 'CT_GLIBC_KERNEL_VERSION_NONE=y' >> defconfig
99-
if [ -n "$LIBC_VERSION" ]; then
100-
echo "CT_GLIBC_V_$(echo $LIBC_VERSION | sed 's/\./_/g')=y" >> defconfig
101-
fi
102-
fi
103-
104-
# musl configs
105-
if [ "$LIBC" = "musl" ]; then
106-
echo 'CT_LIBC_MUSL=y' >> defconfig
107-
if [ -n "$LIBC_VERSION" ]; then
108-
echo "CT_MUSL_V_$(echo $LIBC_VERSION | sed 's/\./_/g')=y" >> defconfig
109-
fi
110-
fi
34+
- name: Install Dependencies
35+
run: $BUILD_GCC_SH install_dependencies
11136

112-
- name: Current defconfig
113-
run: |
114-
cd /opt/crosstool-ng-workdir
115-
cat defconfig
37+
- name: Build crosstool-NG
38+
run: $BUILD_GCC_SH build_crosstool_ng
11639

117-
- name: Current .config
118-
run: |
119-
cd /opt/crosstool-ng-workdir
120-
ct-ng defconfig
121-
cat .config
40+
- name: Configure Toolchain
41+
run: $BUILD_GCC_SH configure_toolchain
12242

12343
- name: Build Toolchain
124-
run: |
125-
cd /opt/crosstool-ng-workdir
126-
ct-ng build
44+
run: $BUILD_GCC_SH build_toolchain
12745

12846
- name: Package Toolchain
129-
run: |
130-
gcc_full_version=$(/opt/crosstool-ng-output//bin/x86_64-linux-${LIBC}-gcc --version | head -n1 | awk '{print $NF}')
131-
cd /opt/crosstool-ng-output/
132-
133-
XZ_OPT=-e9 tar cJf /opt/crosstool-ng-output/gcc-${gcc_full_version}-x86_64-linux-${LIBC}-r${REBUILD_ID}.tar.xz \
134-
bin/ \
135-
libexec/ \
136-
x86_64-linux-${LIBC}/lib/ \
137-
x86_64-linux-${LIBC}/bin/
138-
139-
XZ_OPT=-e9 tar cJf /opt/crosstool-ng-output/libgcc-${gcc_full_version}-x86_64-linux-${LIBC}-r${REBUILD_ID}.tar.xz \
140-
lib/
141-
142-
XZ_OPT=-e9 tar cJf /opt/crosstool-ng-output/libstdcxx-${gcc_full_version}-x86_64-linux-${LIBC}-r${REBUILD_ID}.tar.xz \
143-
x86_64-linux-${LIBC}/include/ \
144-
x86_64-linux-${LIBC}/lib64/
145-
146-
XZ_OPT=-e9 tar cJf /opt/crosstool-ng-output/sysroot-x86_64-linux-${LIBC}-r${REBUILD_ID}.tar.xz \
147-
x86_64-linux-${LIBC}/sysroot/
47+
run: $BUILD_GCC_SH package_toolchain
14848

14949
- name: Upload Toolchain Artifacts
15050
uses: actions/upload-artifact@v4
15151
with:
15252
name: gcc-toolchain-packages
15353
path: |
154-
/opt/crosstool-ng-output/gcc-*.tar.xz
155-
/opt/crosstool-ng-output/libgcc-*.tar.xz
156-
/opt/crosstool-ng-output/libstdcxx-*.tar.xz
157-
/opt/crosstool-ng-output/sysroot-*.tar.xz
158-
/opt/crosstool-ng-workdir/build.log
54+
$ARTIFACT_DIR/*
55+
$WORK_DIR/build.log
15956
retention-days: 30
160-
161-
# - name: Set Release Variables
162-
# id: release_vars
163-
# run: |
164-
# gcc_full_version=$(~/x-tools/x86_64-linux-${LIBC}/bin/x86_64-linux-${LIBC}-gcc --version | head -n1 | awk '{print $NF}')
165-
# release_name="gcc-${gcc_full_version}-x86_64-linux-${LIBC}-r${REBUILD_ID}"
166-
# echo "release_name=${release_name}" >> $GITHUB_OUTPUT
167-
# echo "gcc_full_version=${gcc_full_version}" >> $GITHUB_OUTPUT
168-
169-
# - name: Create Release
170-
# id: create_release
171-
# run: |
172-
# gh release create ${{ steps.release_vars.outputs.release_name }} \
173-
# --title "${{ steps.release_vars.outputs.release_name }}" \
174-
# --notes "GCC Toolchain Release
175-
176-
# **Details:**
177-
# - GCC Version: ${{ steps.release_vars.outputs.gcc_full_version }}
178-
# - Target: x86_64-linux-${{ env.LIBC }}
179-
# - Rebuild ID: ${{ env.REBUILD_ID }}
180-
# - Build Commit: 1b5a2410b266af3bc7aaae0550e7d44ea9dcf878
181-
182-
# **Packages:**
183-
# - \`gcc-${{ steps.release_vars.outputs.gcc_full_version }}-x86_64-linux-${{ env.LIBC }}-r${{ env.REBUILD_ID }}.tar.xz\` - GCC compiler binaries
184-
# - \`libgcc-${{ steps.release_vars.outputs.gcc_full_version }}-x86_64-linux-${{ env.LIBC }}-r${{ env.REBUILD_ID }}.tar.xz\` - GCC runtime libraries
185-
# - \`libstdcxx-${{ steps.release_vars.outputs.gcc_full_version }}-x86_64-linux-${{ env.LIBC }}-r${{ env.REBUILD_ID }}.tar.xz\` - C++ standard library
186-
# - \`sysroot-x86_64-linux-${{ env.LIBC }}-r${{ env.REBUILD_ID }}.tar.xz\` - System root files
187-
# - \`build.log\` - Build log" \
188-
# --target 1b5a2410b266af3bc7aaae0550e7d44ea9dcf878 \
189-
# ~/gcc-${{ steps.release_vars.outputs.gcc_full_version }}-x86_64-linux-${{ env.LIBC }}-r${{ env.REBUILD_ID }}.tar.xz \
190-
# ~/libgcc-${{ steps.release_vars.outputs.gcc_full_version }}-x86_64-linux-${{ env.LIBC }}-r${{ env.REBUILD_ID }}.tar.xz \
191-
# ~/libstdcxx-${{ steps.release_vars.outputs.gcc_full_version }}-x86_64-linux-${{ env.LIBC }}-r${{ env.REBUILD_ID }}.tar.xz \
192-
# ~/sysroot-x86_64-linux-${{ env.LIBC }}-r${{ env.REBUILD_ID }}.tar.xz \
193-
# ~/build.log
194-
# env:
195-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
196-
197-
# - name: Generate Build Provenance Attestation
198-
# uses: actions/attest-build-provenance@v1
199-
# with:
200-
# subject-path: |
201-
# ~/gcc-${{ steps.release_vars.outputs.gcc_full_version }}-x86_64-linux-${{ env.LIBC }}-r${{ env.REBUILD_ID }}.tar.xz
202-
# ~/libgcc-${{ steps.release_vars.outputs.gcc_full_version }}-x86_64-linux-${{ env.LIBC }}-r${{ env.REBUILD_ID }}.tar.xz
203-
# ~/libstdcxx-${{ steps.release_vars.outputs.gcc_full_version }}-x86_64-linux-${{ env.LIBC }}-r${{ env.REBUILD_ID }}.tar.xz
204-
# ~/sysroot-x86_64-linux-${{ env.LIBC }}-r${{ env.REBUILD_ID }}.tar.xz
205-

infra/gcc/Dockerfile

Lines changed: 24 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,26 @@
11
FROM ubuntu:latest
22

3-
# ==========================
4-
# || Install Dependencies ||
5-
# ==========================
6-
RUN apt update && \
7-
DEBIAN_FRONTEND=noninteractive apt install -y \
8-
build-essential \
9-
autoconf \
10-
flex \
11-
bison \
12-
texinfo \
13-
help2man \
14-
file \
15-
gawk \
16-
libtool \
17-
libtool-bin \
18-
libncurses-dev \
19-
python3 \
20-
python3-dev \
21-
unzip \
22-
git \
23-
wget \
24-
curl \
25-
sudo
26-
27-
# ========================
28-
# || Build crosstool-ng ||
29-
# ========================
30-
RUN git clone https://github.com/crosstool-ng/crosstool-ng /opt/crosstool-ng
31-
WORKDIR /opt/crosstool-ng
32-
RUN ./bootstrap && \
33-
./configure && \
34-
make && \
35-
make install
36-
37-
# ================
38-
# || Create User||
39-
# ================
40-
RUN useradd -m -s /bin/bash builder && \
41-
usermod -aG sudo builder
42-
RUN echo "builder ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
43-
USER builder
44-
WORKDIR /home/builder
45-
46-
# ============================
47-
# || Configure crosstool-ng ||
48-
# ============================
49-
ARG libc=gnu
50-
ARG libc_version
51-
ARG gcc_version=15
52-
ARG rebuild_id=1
53-
54-
# Standard configs
55-
RUN echo 'CT_CONFIG_VERSION="4"' > defconfig && \
56-
echo 'CT_ARCH_X86=y' >> defconfig && \
57-
echo 'CT_OMIT_TARGET_VENDOR=y' >> defconfig && \
58-
echo 'CT_ARCH_64=y' >> defconfig && \
59-
echo 'CT_STATIC_TOOLCHAIN=y' >> defconfig && \
60-
echo 'CT_KERNEL_LINUX=y' >> defconfig && \
61-
echo 'CT_LOG_PROGRESS_BAR=n' >> defconfig && \
62-
echo 'CT_PREFIX_DIR_RO=n' >> defconfig && \
63-
echo 'CT_CC_LANG_CXX=y' >> defconfig && \
64-
echo 'CT_DEBUG_GDB=y' >> defconfig && \
65-
echo 'CT_CC_GCC_LNK_HASH_STYLE_BOTH=y' >> defconfig
66-
67-
# GCC version configs
68-
RUN if [ "$gcc_version" = "15" ]; then \
69-
echo 'CT_GCC_V_15=y' >> defconfig; \
70-
elif [ "$gcc_version" = "14" ]; then \
71-
echo 'CT_GCC_V_14=y' >> defconfig && \
72-
echo 'CT_GMP_EXTRA_CFLAGS="-std=gnu17"' >> defconfig && \
73-
echo 'CT_NCURSES_EXTRA_CFLAGS="-std=gnu17"' >> defconfig; \
74-
elif [ "$gcc_version" = "13" ]; then \
75-
echo 'CT_GCC_V_13=y' >> defconfig && \
76-
echo 'CT_GMP_EXTRA_CFLAGS="-std=gnu17"' >> defconfig && \
77-
echo 'CT_NCURSES_EXTRA_CFLAGS="-std=gnu17"' >> defconfig; \
78-
elif [ "$gcc_version" = "12" ]; then \
79-
echo 'CT_GCC_V_12=y' >> defconfig && \
80-
echo 'CT_GMP_EXTRA_CFLAGS="-std=gnu17"' >> defconfig && \
81-
echo 'CT_NCURSES_EXTRA_CFLAGS="-std=gnu17"' >> defconfig; \
82-
else \
83-
echo "Error: Unsupported gcc_version: $gcc_version" >&2 && \
84-
echo "Supported versions: 15, 14, 13, 12" >&2 && \
85-
exit 1; \
86-
fi
87-
88-
# glibc configs
89-
RUN if [ "$libc" = "gnu" ]; then \
90-
echo 'CT_GLIBC_KERNEL_VERSION_NONE=y' >> defconfig; \
91-
if [ -n "$libc_version" ]; then \
92-
echo "CT_GLIBC_V_$(echo $libc_version | sed 's/\./_/g')=y" >> defconfig; \
93-
fi; \
94-
fi
95-
96-
# musl configs
97-
RUN if [ "$libc" = "musl" ]; then \
98-
echo 'CT_LIBC_MUSL=y' >> defconfig; \
99-
if [ -n "$libc_version" ]; then \
100-
echo "CT_MUSL_V_$(echo $libc_version | sed 's/\./_/g')=y" >> defconfig; \
101-
fi; \
102-
fi
103-
104-
# =====================
105-
# || Build Toolchain ||
106-
# =====================
107-
RUN ct-ng defconfig
108-
RUN ct-ng build
109-
110-
# TODO: move these to toolchains_cc
111-
# RUN cd /home/builder/x-tools/x86_64-linux-${libc}/x86_64-linux-${libc}/sysroot/lib && \
112-
# ln -s ../../../lib/gcc/ .
113-
114-
# RUN cd /home/builder/x-tools/x86_64-linux-${libc}/x86_64-linux-${libc}/sysroot/usr/include && \
115-
# ln -s ../../../include/c++/ .
116-
117-
# =======================
118-
# || Package Toolchain ||
119-
# =======================
120-
RUN gcc_full_version=$(/home/builder/x-tools/x86_64-linux-${libc}/bin/x86_64-linux-${libc}-gcc --version | head -n1 | awk '{print $NF}') && \
121-
cd /home/builder/x-tools/x86_64-linux-${libc} && \
122-
XZ_OPT=-e9 tar cJf /home/builder/gcc-${gcc_full_version}-x86_64-linux-${libc}-r${rebuild_id}.tar.xz \
123-
bin/ \
124-
libexec/ \
125-
x86_64-linux-${libc}/lib/ \
126-
x86_64-linux-${libc}/bin/ && \
127-
XZ_OPT=-e9 tar cJf /home/builder/libgcc-${gcc_full_version}-x86_64-linux-${libc}-r${rebuild_id}.tar.xz \
128-
lib/ && \
129-
XZ_OPT=-e9 tar cJf /home/builder/libstdcxx-${gcc_full_version}-x86_64-linux-${libc}-r${rebuild_id}.tar.xz \
130-
x86_64-linux-${libc}/include/ \
131-
x86_64-linux-${libc}/lib64/ && \
132-
XZ_OPT=-e9 tar cJf /home/builder/sysroot-x86_64-linux-${libc}-r${rebuild_id}.tar.xz \
133-
x86_64-linux-${libc}/sysroot/
3+
ENV CT_NG_SRC_DIR="/tmp/crosstool-ng"
4+
ENV ARTIFACT_DIR="/tmp/toolchain/artifacts"
5+
ENV OUTPUT_DIR="/tmp/toolchain/output"
6+
ENV WORK_DIR="/tmp/toolchain/work"
7+
ENV BUILD_GCC_SH="/tmp/build_gcc.sh"
8+
ENV SUDO=""
9+
10+
RUN mkdir -p $CT_NG_SRC_DIR
11+
RUN mkdir -p $ARTIFACT_DIR
12+
RUN mkdir -p $OUTPUT_DIR
13+
RUN mkdir -p $WORK_DIR
14+
15+
COPY build_gcc.sh $BUILD_GCC_SH
16+
17+
ARG GCC_VERSION=15
18+
ARG LIBC=gnu
19+
ARG LIBC_VERSION=2.34
20+
ARG REBUILD_ID=1
21+
22+
RUN $BUILD_GCC_SH install_dependencies
23+
RUN $BUILD_GCC_SH build_crosstool_ng
24+
RUN $BUILD_GCC_SH configure_toolchain
25+
RUN $BUILD_GCC_SH build_toolchain
26+
RUN $BUILD_GCC_SH package_toolchain

0 commit comments

Comments
 (0)