Skip to content

Commit 86efd2c

Browse files
committed
Add GCC 12.5 for Bullseye
1 parent f68bead commit 86efd2c

File tree

3 files changed

+212
-0
lines changed

3 files changed

+212
-0
lines changed

.github/workflows/debian.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,38 @@ 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+
- name: Prepare gcc image metadata
96+
if: ${{ matrix.os.release == 'bullseye' }}
97+
id: meta-gcc
98+
uses: docker/metadata-action@v5
99+
env:
100+
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,manifest-descriptor
101+
with:
102+
# NOTE, tag and image must match base of docker/debian/Dockerfile
103+
images: gcc
104+
tags: |
105+
type=raw,value=${{ matrix.os.compiler_version }}-${{ matrix.os.release }}
106+
labels: |
107+
org.opencontainers.image.authors=For inquiries, please use https://${{ github.repository }}/issues
108+
org.opencontainers.image.documentation=https://${{ github.repository }}
109+
org.opencontainers.image.vendor=XRPLF
110+
org.opencontainers.image.title=${{ env.CONTAINER_REPOSITORY }}-gcc
111+
- name: Build gcc image do not push
112+
if: ${{ matrix.os.release == 'bullseye' }}
113+
uses: docker/build-push-action@v6
114+
with:
115+
build-args: |
116+
BUILDKIT_DOCKERFILE_CHECK=skip=InvalidDefaultArgInFrom
117+
BUILDKIT_INLINE_CACHE=1
118+
context: .
119+
file: docker/debian/Dockerfile.gcc-${{ matrix.os.compiler_version }}-${{ matrix.os.release }}
120+
outputs: type=image,name=gcc,push=false
121+
platforms: ${{ matrix.architecture.platform }}
122+
provenance: mode=max
123+
push: false
124+
sbom: true
125+
labels: ${{ steps.meta-gcc.outputs.labels }}
126+
tags: ${{ steps.meta-gcc.outputs.tags }}
95127
- name: Prepare container metadata
96128
id: meta
97129
uses: docker/metadata-action@v5
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: 24 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 an older
43+
Debian releases, we keep a local copy of `Dockerfile` from the above repository,
44+
backported to an older Debian base image. Such dockerfiles are stored in `docker/debian`
45+
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 release. They also
47+
show in a comment the specific `Dockerfile` they have been sourced from.
48+
49+
If you want to build a build image for such an older release, you should first
50+
build GCC using an appropriate image, giving it the exact name and tag as
51+
used by the main `Dockerfile`, e.g. `gcc:12-bullseye`. This may require significant
52+
CPU resources and take some time (e.g. 30 minutes using 40 cores with fast NVME storage)
53+
and it's needed 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 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

0 commit comments

Comments
 (0)