Skip to content

Commit 2582e62

Browse files
authored
Add GCC 12.5 for Bullseye (#39)
This is followup to #37 ; and it needs to be followed up with a change to move building GCC images to a separate workflow #39 (comment)
1 parent 4e8ac69 commit 2582e62

File tree

4 files changed

+246
-2
lines changed

4 files changed

+246
-2
lines changed

.github/workflows/debian.yml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
paths:
66
- .github/workflows/debian.yml
7-
- docker/debian/Dockerfile
7+
- docker/debian/Dockerfile*
88
- test
99
workflow_dispatch:
1010

@@ -92,6 +92,42 @@ jobs:
9292
echo "CONTAINER_IMAGE=${CONTAINER_REGISTRY}/${CONTAINER_REPO}/debian-${{ matrix.os.release }}" >> $GITHUB_ENV
9393
PLATFORM=${{ matrix.architecture.platform }}
9494
echo "PLATFORM_PAIR=${PLATFORM//\//-}" >> $GITHUB_ENV
95+
if [ "${{ matrix.os.release == 'bullseye' }}" == "true" ]; then
96+
echo "CONTAINER_REPOSITORY_GCC=${CONTAINER_REPO}/debian-gcc" >> $GITHUB_ENV
97+
echo "CONTAINER_IMAGE_GCC=${CONTAINER_REGISTRY}/${CONTAINER_REPO}/debian-gcc" >> $GITHUB_ENV
98+
fi
99+
- name: Prepare gcc image metadata
100+
if: ${{ env.CONTAINER_IMAGE_GCC }}
101+
id: meta-gcc
102+
uses: docker/metadata-action@v5
103+
env:
104+
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,manifest-descriptor
105+
with:
106+
images: ${{ env.CONTAINER_IMAGE_GCC }}
107+
labels: |
108+
org.opencontainers.image.authors=For inquiries, please use https://${{ github.repository }}/issues
109+
org.opencontainers.image.documentation=https://${{ github.repository }}
110+
org.opencontainers.image.vendor=XRPLF
111+
org.opencontainers.image.title=${{ env.CONTAINER_REPOSITORY_GCC }}
112+
- name: Build gcc image
113+
# Note, we always push this image, otherwise steps.build will fail.
114+
# Also, because we always push it, we intentionally do not tag it.
115+
# TODO: Move to separate workflow or job
116+
if: ${{ env.CONTAINER_IMAGE_GCC }}
117+
id: build-gcc
118+
uses: docker/build-push-action@v6
119+
with:
120+
build-args: |
121+
BUILDKIT_DOCKERFILE_CHECK=skip=InvalidDefaultArgInFrom
122+
BUILDKIT_INLINE_CACHE=1
123+
context: .
124+
file: docker/debian/Dockerfile.gcc-${{ matrix.os.compiler_version }}-${{ matrix.os.release }}
125+
outputs: type=image,name=${{ env.CONTAINER_IMAGE_GCC }},push-by-digest=true,name-canonical=true,push=true
126+
platforms: ${{ matrix.architecture.platform }}
127+
provenance: mode=max
128+
push: true
129+
sbom: true
130+
labels: ${{ steps.meta-gcc.outputs.labels }}
95131
- name: Prepare container metadata
96132
id: meta
97133
uses: docker/metadata-action@v5
@@ -120,6 +156,7 @@ jobs:
120156
GCOVR_VERSION=${{ env.GCOVR_VERSION }}
121157
CMAKE_VERSION=${{ env.CMAKE_VERSION }}
122158
DEBIAN_VERSION=${{ matrix.os.release }}
159+
BASE_IMAGE=${{ env.CONTAINER_IMAGE_GCC && format('{0}@{1}', env.CONTAINER_IMAGE_GCC, steps.build-gcc.outputs.digest) || format('gcc:{0}-{1}', matrix.os.compiler_version, matrix.os.release) }}
123160
context: .
124161
file: docker/debian/Dockerfile
125162
outputs: type=image,name=${{ env.CONTAINER_IMAGE }},push-by-digest=true,name-canonical=true,push=true

docker/debian/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
# image, even though it is not used for Clang.
99
ARG DEBIAN_VERSION
1010
ARG GCC_VERSION=invalid
11-
FROM gcc:${GCC_VERSION}-${DEBIAN_VERSION} AS gcc-src
11+
ARG BASE_IMAGE=gcc:${GCC_VERSION}-${DEBIAN_VERSION}
12+
FROM ${BASE_IMAGE} AS gcc-src
1213

1314
# ====================== BASE IMAGE ======================
1415
FROM debian:${DEBIAN_VERSION} AS base
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
FROM buildpack-deps:bullseye
2+
3+
## NOTE: EVERYTHING BELOW THIS COMMENT IS FROM
4+
## https://github.com/docker-library/gcc/blob/7070981b23d22d3ca790f87bff26f13f3614dd4c/12/Dockerfile
5+
6+
7+
RUN set -eux; \
8+
apt-get update; \
9+
apt-get install -y --no-install-recommends \
10+
# install abigail-tools so we can use abidiff later to verify that we don't break Debian packages
11+
abigail-tools \
12+
; \
13+
rm -rf /var/lib/apt/lists/*
14+
15+
# https://gcc.gnu.org/mirrors.html
16+
ENV GPG_KEYS \
17+
# 1024D/745C015A 1999-11-09 Gerald Pfeifer <gerald@pfeifer.com>
18+
B215C1633BCA0477615F1B35A5B3A004745C015A \
19+
# 1024D/B75C61B8 2003-04-10 Mark Mitchell <mark@codesourcery.com>
20+
B3C42148A44E6983B3E4CC0793FA9B1AB75C61B8 \
21+
# 1024D/902C9419 2004-12-06 Gabriel Dos Reis <gdr@acm.org>
22+
90AA470469D3965A87A5DCB494D03953902C9419 \
23+
# 1024D/F71EDF1C 2000-02-13 Joseph Samuel Myers <jsm@polyomino.org.uk>
24+
80F98B2E0DAB6C8281BDF541A7C8C3B2F71EDF1C \
25+
# 2048R/FC26A641 2005-09-13 Richard Guenther <richard.guenther@gmail.com>
26+
7F74F97C103468EE5D750B583AB00996FC26A641 \
27+
# 1024D/C3C45C06 2004-04-21 Jakub Jelinek <jakub@redhat.com>
28+
33C235A34C46AA3FFB293709A328C3A2C3C45C06 \
29+
# 4096R/09B5FA62 2020-05-28 Jakub Jelinek <jakub@redhat.com>
30+
D3A93CAD751C2AF4F8C7AD516C35B99309B5FA62
31+
32+
# https://gcc.gnu.org/mirrors.html
33+
ENV GCC_MIRRORS \
34+
https://ftpmirror.gnu.org/gcc \
35+
https://mirrors.kernel.org/gnu/gcc \
36+
https://bigsearcher.com/mirrors/gcc/releases \
37+
http://www.netgull.com/gcc/releases \
38+
https://ftpmirror.gnu.org/gcc \
39+
# "sourceware.org" is the canonical upstream release host (the host of "gcc.gnu.org")
40+
https://sourceware.org/pub/gcc/releases \
41+
# only attempt the origin FTP as a mirror of last resort
42+
ftp://ftp.gnu.org/gnu/gcc
43+
44+
# Last Modified: 2025-07-11
45+
ENV GCC_VERSION 12.5.0
46+
# Docker EOL: 2027-01-11
47+
48+
RUN set -ex; \
49+
\
50+
savedAptMark="$(apt-mark showmanual)"; \
51+
apt-get update; \
52+
apt-get install -y --no-install-recommends \
53+
dpkg-dev \
54+
flex \
55+
gnupg \
56+
; \
57+
rm -r /var/lib/apt/lists/*; \
58+
\
59+
_fetch() { \
60+
local fetch="$1"; shift; \
61+
local file="$1"; shift; \
62+
for mirror in $GCC_MIRRORS; do \
63+
if curl -fL "$mirror/$fetch" -o "$file"; then \
64+
return 0; \
65+
fi; \
66+
done; \
67+
echo >&2 "error: failed to download '$fetch' from several mirrors"; \
68+
return 1; \
69+
}; \
70+
\
71+
_fetch "gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.xz.sig" 'gcc.tar.xz.sig'; \
72+
_fetch "gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.xz" 'gcc.tar.xz'; \
73+
export GNUPGHOME="$(mktemp -d)"; \
74+
for key in $GPG_KEYS; do \
75+
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key"; \
76+
done; \
77+
gpg --batch --verify gcc.tar.xz.sig gcc.tar.xz; \
78+
gpgconf --kill all; \
79+
rm -rf "$GNUPGHOME"; \
80+
mkdir -p /usr/src/gcc; \
81+
tar -xf gcc.tar.xz -C /usr/src/gcc --strip-components=1; \
82+
rm gcc.tar.xz*; \
83+
\
84+
cd /usr/src/gcc; \
85+
\
86+
# "download_prerequisites" pulls down a bunch of tarballs and extracts them,
87+
# but then leaves the tarballs themselves lying around
88+
./contrib/download_prerequisites; \
89+
{ rm *.tar.* || true; }; \
90+
\
91+
# explicitly update autoconf config.guess and config.sub so they support more arches/libcs
92+
for f in config.guess config.sub; do \
93+
wget -O "$f" "https://git.savannah.gnu.org/cgit/config.git/plain/$f?id=7d3d27baf8107b630586c962c057e22149653deb"; \
94+
# find any more (shallow) copies of the file we grabbed and update them too
95+
find -mindepth 2 -name "$f" -exec cp -v "$f" '{}' ';'; \
96+
done; \
97+
\
98+
dir="$(mktemp -d)"; \
99+
cd "$dir"; \
100+
\
101+
extraConfigureArgs=''; \
102+
dpkgArch="$(dpkg --print-architecture)"; \
103+
case "$dpkgArch" in \
104+
# with-arch: https://salsa.debian.org/toolchain-team/gcc/-/blob/gcc-13-debian/debian/rules2#L533-573
105+
# with-float: https://salsa.debian.org/toolchain-team/gcc/-/blob/gcc-13-debian/debian/rules2#L521-523
106+
# with-mode: https://salsa.debian.org/toolchain-team/gcc/-/blob/gcc-13-debian/debian/rules2#L571
107+
armel) \
108+
extraConfigureArgs="$extraConfigureArgs --with-arch=armv5te --with-float=soft" \
109+
;; \
110+
armhf) \
111+
# https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1939379/comments/2
112+
extraConfigureArgs="$extraConfigureArgs --with-arch=armv7-a+fp --with-float=hard --with-mode=thumb" \
113+
;; \
114+
\
115+
# with-arch-32: https://salsa.debian.org/toolchain-team/gcc/-/blob/gcc-13-debian/debian/rules2#L670
116+
i386) \
117+
extraConfigureArgs="$extraConfigureArgs --with-arch-32=i686"; \
118+
;; \
119+
esac; \
120+
\
121+
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
122+
/usr/src/gcc/configure \
123+
--build="$gnuArch" \
124+
--disable-multilib \
125+
--enable-languages=c,c++,fortran,go \
126+
$extraConfigureArgs \
127+
; \
128+
make -j "$(nproc)"; \
129+
make install-strip; \
130+
\
131+
cd ..; \
132+
\
133+
rm -rf "$dir" /usr/src/gcc; \
134+
\
135+
apt-mark auto '.*' > /dev/null; \
136+
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \
137+
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false
138+
139+
# gcc installs .so files in /usr/local/lib64 (and /usr/local/lib)...
140+
RUN set -ex; \
141+
# this filename needs to sort higher than all the architecture filenames ("aarch64-...", "armeabi...", etc)
142+
{ echo '/usr/local/lib64'; echo '/usr/local/lib'; } > /etc/ld.so.conf.d/000-local-lib.conf; \
143+
ldconfig -v; \
144+
# the libc created by gcc might be too old for a newer Debian
145+
# check that the Debian libstdc++ doesn't have newer requirements than the gcc one
146+
deb="$(readlink -ve /usr/lib/*/libstdc++.so* | head -1)"; \
147+
gcc="$(readlink -ve /usr/local/lib*/libstdc++.so | head -1)"; \
148+
# using LD_PRELOAD to make sure "abidiff" itself doesn't fail with the exact error we're trying to test for 😂😭
149+
LD_PRELOAD="$deb" abidiff --no-added-syms "$deb" "$gcc"
150+
151+
# ensure that alternatives are pointing to the new compiler and that old one is no longer used
152+
RUN set -ex; \
153+
dpkg-divert --divert /usr/bin/gcc.orig --rename /usr/bin/gcc; \
154+
dpkg-divert --divert /usr/bin/g++.orig --rename /usr/bin/g++; \
155+
dpkg-divert --divert /usr/bin/gfortran.orig --rename /usr/bin/gfortran; \
156+
update-alternatives --install /usr/bin/cc cc /usr/local/bin/gcc 999

docker/debian/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,30 @@ Build image for `gcc` supports packaging.
3434
In order to build an image, run the commands below from the root directory of
3535
the repository.
3636

37+
#### Note on old Debian releases
38+
39+
This image supports variety of releases of Debian, GCC and Clang.
40+
41+
The GCC binaries are sourced from [Docker "Official Image" for gcc](https://github.com/docker-library/gcc)
42+
with an important caveat - in order to install a GCC release in older
43+
Debian versions, we keep a local copy of `Dockerfile` from the above repository,
44+
backported to an older Debian base image. Such dockerfiles are stored in this
45+
directory with special file extension, e.g. `gcc-12-bullseye`. They are not altered from
46+
the source, except for change of the base image to older Debian version. They also
47+
show in a comment the specific `Dockerfile` they have been sourced from.
48+
49+
If you want to build a Docker image for GCC and an older Debian version, you should
50+
first build GCC using an appropriate image, giving it the _exact_ name and tag as
51+
passed later to the main `Dockerfile` as `BASE_IMAGE`. This may require significant
52+
CPU resources and take some time (e.g. 30 minutes using 40 cores) and it's needed
53+
to ensure that we do not use an old GCC release with known, and fixed, bugs.
54+
55+
For example:
56+
57+
```shell
58+
docker buildx build . --progress plain --file docker/debian/Dockerfile.gcc-12-bullseye --tag localhost.localdomain/gcc:12-bullseye
59+
```
60+
3761
#### Building the Docker image for GCC
3862

3963
Ensure you've run the login command above to authenticate with the Docker
@@ -60,6 +84,32 @@ docker buildx build . \
6084
--tag ${CONTAINER_REGISTRY}/${CONTAINER_IMAGE}
6185
```
6286

87+
If you have prepared a GCC image for an older Debian version, you also need
88+
to explicitly set `BASE_IMAGE` build argument, e.g.
89+
90+
```shell
91+
DEBIAN_VERSION=bullseye
92+
GCC_VERSION=12
93+
CONAN_VERSION=2.19.1
94+
GCOVR_VERSION=8.3
95+
CMAKE_VERSION=3.31.6
96+
BASE_IMAGE=localhost.localdomain/gcc:12-bullseye
97+
CONTAINER_IMAGE=xrplf/ci/debian-${DEBIAN_VERSION}:gcc-${GCC_VERSION}
98+
99+
docker buildx build . \
100+
--file docker/debian/Dockerfile \
101+
--target gcc \
102+
--build-arg BUILDKIT_DOCKERFILE_CHECK=skip=InvalidDefaultArgInFrom \
103+
--build-arg BUILDKIT_INLINE_CACHE=1 \
104+
--build-arg CONAN_VERSION=${CONAN_VERSION} \
105+
--build-arg DEBIAN_VERSION=${DEBIAN_VERSION} \
106+
--build-arg GCC_VERSION=${GCC_VERSION} \
107+
--build-arg GCOVR_VERSION=${GCOVR_VERSION} \
108+
--build-arg CMAKE_VERSION=${CMAKE_VERSION} \
109+
--build-arg BASE_IMAGE=${BASE_IMAGE} \
110+
--tag ${CONTAINER_REGISTRY}/${CONTAINER_IMAGE}
111+
```
112+
63113
#### Building the Docker image for Clang
64114

65115
Ensure you've run the login command above to authenticate with the Docker

0 commit comments

Comments
 (0)