From 38e6e8ec2af458396d46ea7b369124833c53ae98 Mon Sep 17 00:00:00 2001 From: "Lance R. Vick" Date: Thu, 9 Nov 2023 05:41:25 -0800 Subject: [PATCH] refactor gcc to build with stub bootstrap image --- Makefile | 35 ++++++--- packages/bootstrap/Dockerfile | 5 ++ packages/gcc/Dockerfile | 140 ++++------------------------------ 3 files changed, 45 insertions(+), 135 deletions(-) create mode 100644 packages/bootstrap/Dockerfile diff --git a/Makefile b/Makefile index ccefb5a..dd8fbe1 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,29 @@ -out/gcc.oci.tgz: - docker build -f packages/gcc/Dockerfile -t ocirep/gcc . +export SOURCE_DATE_EPOCH = 0 -out/glibc.oci.tgz: - docker build -f packages/glibc/Dockerfile -t ocirep/glibc . +out/bootstrap.oci.tgz: + docker build -t ocirep/bootstrap --output type=oci,dest=$@ packages/bootstrap -out/bash.oci.tgz: - docker build -f packages/bash/Dockerfile -t ocirep/bash . +out/gcc.oci.tgz: \ + out/bootstrap.oci.tgz + docker build -t ocirep/gcc --output type=oci,dest=$@ packages/gcc -out/busybox.oci.tgz: - docker build -f packages/busybox/Dockerfile -t ocirep/busybox . +out/glibc.oci.tgz: \ + out/gcc.oci.tgz + docker build -t ocirep/glibc --output type=oci,dest=$@ packages/glibc -out/go.oci.tgz: - docker build -f packages/go/Dockerfile -t ocirep/go . +out/bash.oci.tgz: \ + out/gcc.oci.tgz \ + out/glibc.oci.tgz + docker build -t ocirep/bash --output type=oci,dest=$@ packages/bash + +out/busybox.oci.tgz: \ + out/gcc.oci.tgz \ + out/glibc.oci.tgz + docker build -t ocirep/busybox --output type=oci,dest=$@ packages/busybox + +out/go.oci.tgz: \ + out/gcc.oci.tgz \ + out/glibc.oci.tgz \ + out/busybox.oci.tgz \ + out/bash.oci.tgz + docker build -t ocirep/go --output type=oci,dest=$@ packages/go diff --git a/packages/bootstrap/Dockerfile b/packages/bootstrap/Dockerfile new file mode 100644 index 0000000..55c039e --- /dev/null +++ b/packages/bootstrap/Dockerfile @@ -0,0 +1,5 @@ +FROM buildpack-deps@sha256:8465175ca53f8f2e756d069658b3f353bb3732926b1f33f34332cfbf597ad0c0 as build + +RUN set -ex; \ + apt-get update; \ + apt-get install -y --no-install-recommends flex diff --git a/packages/gcc/Dockerfile b/packages/gcc/Dockerfile index da6f74c..14a2296 100644 --- a/packages/gcc/Dockerfile +++ b/packages/gcc/Dockerfile @@ -1,137 +1,27 @@ -FROM buildpack-deps@sha256:8465175ca53f8f2e756d069658b3f353bb3732926b1f33f34332cfbf597ad0c0 as build - -# https://gcc.gnu.org/mirrors.html -ENV GPG_KEYS \ -# 1024D/745C015A 1999-11-09 Gerald Pfeifer - B215C1633BCA0477615F1B35A5B3A004745C015A \ -# 1024D/B75C61B8 2003-04-10 Mark Mitchell - B3C42148A44E6983B3E4CC0793FA9B1AB75C61B8 \ -# 1024D/902C9419 2004-12-06 Gabriel Dos Reis - 90AA470469D3965A87A5DCB494D03953902C9419 \ -# 1024D/F71EDF1C 2000-02-13 Joseph Samuel Myers - 80F98B2E0DAB6C8281BDF541A7C8C3B2F71EDF1C \ -# 2048R/FC26A641 2005-09-13 Richard Guenther - 7F74F97C103468EE5D750B583AB00996FC26A641 \ -# 1024D/C3C45C06 2004-04-21 Jakub Jelinek - 33C235A34C46AA3FFB293709A328C3A2C3C45C06 \ -# 4096R/09B5FA62 2020-05-28 Jakub Jelinek - D3A93CAD751C2AF4F8C7AD516C35B99309B5FA62 - -RUN set -ex; \ - apt-get update; \ - apt-get install -y --no-install-recommends \ - gnupg \ - ; \ - rm -rf /var/lib/apt/lists/*; \ - for key in $GPG_KEYS; do \ - gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key"; \ - done - -# https://gcc.gnu.org/mirrors.html -ENV GCC_MIRRORS \ - https://ftpmirror.gnu.org/gcc \ - https://mirrors.kernel.org/gnu/gcc \ - https://bigsearcher.com/mirrors/gcc/releases \ - http://www.netgull.com/gcc/releases \ - https://ftpmirror.gnu.org/gcc \ -# only attempt the origin FTP as a mirror of last resort - ftp://ftp.gnu.org/gnu/gcc +FROM ocirep/bootstrap:latest as build +ENV GCC_SITE https://mirrors.kernel.org/gnu/gcc ENV GCC_VERSION 13.2.0 +ENV GCC_HASH e275e76442a6067341a27f04c5c6b83d8613144004c0413528863dc6b5c743da +RUN wget ${GCC_SITE}/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.xz +RUN echo "${GCC_HASH} gcc-${GCC_VERSION}.tar.xz" | sha256sum -c +RUN tar -xf gcc-${GCC_VERSION}.tar.xz +WORKDIR gcc-${GCC_VERSION} RUN set -ex; \ - \ - savedAptMark="$(apt-mark showmanual)"; \ - apt-get update; \ - apt-get install -y --no-install-recommends \ - dpkg-dev \ - flex \ - ; \ - rm -r /var/lib/apt/lists/*; \ - \ - _fetch() { \ - local fetch="$1"; shift; \ - local file="$1"; shift; \ - for mirror in $GCC_MIRRORS; do \ - if curl -fL "$mirror/$fetch" -o "$file"; then \ - return 0; \ - fi; \ - done; \ - echo >&2 "error: failed to download '$fetch' from several mirrors"; \ - return 1; \ - }; \ - \ - _fetch "gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.xz.sig" 'gcc.tar.xz.sig'; \ - _fetch "gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.xz" 'gcc.tar.xz'; \ - gpg --batch --verify gcc.tar.xz.sig gcc.tar.xz; \ - mkdir -p /usr/src/gcc; \ - tar -xf gcc.tar.xz -C /usr/src/gcc --strip-components=1; \ - rm gcc.tar.xz*; \ - \ - cd /usr/src/gcc; \ - \ -# "download_prerequisites" pulls down a bunch of tarballs and extracts them, -# but then leaves the tarballs themselves lying around ./contrib/download_prerequisites; \ - { rm *.tar.* || true; }; \ - \ -# explicitly update autoconf config.guess and config.sub so they support more arches/libcs - for f in config.guess config.sub; do \ - wget -O "$f" "https://git.savannah.gnu.org/cgit/config.git/plain/$f?id=7d3d27baf8107b630586c962c057e22149653deb"; \ -# find any more (shallow) copies of the file we grabbed and update them too - find -mindepth 2 -name "$f" -exec cp -v "$f" '{}' ';'; \ - done; \ - \ - dir="$(mktemp -d)"; \ - cd "$dir"; \ - \ - extraConfigureArgs=''; \ - dpkgArch="$(dpkg --print-architecture)"; \ - case "$dpkgArch" in \ -# with-arch: https://salsa.debian.org/toolchain-team/gcc/-/blob/gcc-11-debian/debian/rules2#L462-502 -# with-float: https://salsa.debian.org/toolchain-team/gcc/-/blob/gcc-11-debian/debian/rules.defs#L502-512 -# with-mode: https://salsa.debian.org/toolchain-team/gcc/-/blob/gcc-11-debian/debian/rules.defs#L480 - armel) \ - extraConfigureArgs="$extraConfigureArgs --with-arch=armv5te --with-float=soft" \ - ;; \ - armhf) \ - # https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1939379/comments/2 - extraConfigureArgs="$extraConfigureArgs --with-arch=armv7-a+fp --with-float=hard --with-mode=thumb" \ - ;; \ - \ -# with-arch-32: https://salsa.debian.org/toolchain-team/gcc/-/blob/gcc-11-debian/debian/rules2#L598 - i386) \ - extraConfigureArgs="$extraConfigureArgs --with-arch-32=i686"; \ - ;; \ - esac; \ - \ - gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ - /usr/src/gcc/configure \ - --build="$gnuArch" \ + { rm *.tar.* || true; } +RUN set -ex; \ + ./configure \ + --build="x86_64-linux-gnu" \ --disable-multilib \ - --enable-languages=c,c++,fortran,go \ - --prefix /opt/gcc \ - $extraConfigureArgs \ + --enable-languages=c,c++ \ + --prefix /rootfs \ ; \ make -j "$(nproc)"; \ - make install-strip; \ - cd ..; \ - \ - rm -rf "$dir" /usr/src/gcc; \ - \ - apt-mark auto '.*' > /dev/null; \ - [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \ - apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false - -COPY --from=library/busybox@sha256:f553b7484625f0c73bfa3888e013e70e99ec6ae1c424ee0e8a85052bd135a28a / rootfs/ - -RUN \ - echo "nogroup:*:100:nobody" > rootfs/etc/group \ - && echo "nobody:*:100:100:::" > rootfs/etc/passwd \ - && mkdir -p rootfs \ - && cp -RHp /opt/gcc/* rootfs/ + make install-strip FROM scratch -COPY --from=build --chown=100:100 /rootfs /usr/local +COPY --from=build /rootfs / ENTRYPOINT ["/bin/gcc"] CMD ["--version"]