From b6d50d7124a5778658989ac85ac3c6bf4669c7d7 Mon Sep 17 00:00:00 2001 From: "Lance R. Vick" Date: Mon, 22 Jan 2024 11:44:49 -0800 Subject: [PATCH] working stage2 and initial stage3 --- src/bootstrap/build.mk | 6 ++- src/bootstrap/stage2/Dockerfile | 47 +++++++++++------ src/bootstrap/stage3/Dockerfile | 94 +++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+), 18 deletions(-) create mode 100644 src/bootstrap/stage3/Dockerfile diff --git a/src/bootstrap/build.mk b/src/bootstrap/build.mk index 902d42d..6ca0976 100644 --- a/src/bootstrap/build.mk +++ b/src/bootstrap/build.mk @@ -2,7 +2,8 @@ bootstrap: \ out/stage0.tgz \ out/stage1.tgz \ - out/stage2.tgz + out/stage2.tgz \ + out/stage3.tgz out/stage0.tgz: $(call build,bootstrap,stage0) @@ -12,3 +13,6 @@ out/stage1.tgz: out/stage0.tgz out/stage2.tgz: out/stage1.tgz $(call build,bootstrap,stage2) + +out/stage3.tgz: out/stage2.tgz + $(call build,bootstrap,stage3) diff --git a/src/bootstrap/stage2/Dockerfile b/src/bootstrap/stage2/Dockerfile index ff26321..4b6a516 100644 --- a/src/bootstrap/stage2/Dockerfile +++ b/src/bootstrap/stage2/Dockerfile @@ -1,7 +1,7 @@ ARG REGISTRY=local -FROM ${REGISTRY}/live-bootstrap:latest as live-bootstrap +FROM ${REGISTRY}/stage1:latest as stage1 -FROM live-bootstrap as base +FROM stage1 as base ENV TARGET=x86_64-linux-musl ENV GCC_VERSION 13.1.0 ENV GCC_FILE gcc-$GCC_VERSION.tar.xz @@ -24,6 +24,10 @@ ENV BINUTILS_VERSION 2.41 ENV BINUTILS_SITE https://ftp.gnu.org/gnu/binutils ENV BINUTILS_FILE binutils-${BINUTILS_VERSION}.tar.xz ENV BINUTILS_HASH ae9a5789e23459e59606e6714723f2d3ffc31c03174191ef0d015bdf06007450 +ENV BINUTILS_DIR ${HOME}/build-binutils +ENV GCC_DIR ${HOME}/build-gcc +ENV MUSL_DIR ${HOME}/build-musl +ENV SYSROOT_DIR ${HOME}/build-sysroot FROM base as fetch WORKDIR ${HOME} @@ -53,10 +57,6 @@ RUN set -eux; \ ./contrib/download_prerequisites FROM extract as build -ENV BINUTILS_DIR ${HOME}/build-binutils -ENV GCC_DIR ${HOME}/build-gcc -ENV MUSL_DIR ${HOME}/build-musl -ENV SYSROOT_DIR ${HOME}/build-sysroot # Phase 1: Build cross binutils in build-binutils WORKDIR ${BINUTILS_DIR} @@ -122,10 +122,10 @@ RUN set -eux; \ WORKDIR ${MUSL_DIR} RUN set -eux; \ ../musl-${MUSL_VERSION}/configure \ - CC="${GCC_DIR}/gcc/xgcc -B ${HOME}/build-gcc/gcc" \ + CC="${GCC_DIR}/gcc/xgcc -B ${GCC_DIR}/gcc" \ LIBCC="${GCC_DIR}/${TARGET}/libgcc/libgcc.a" \ --prefix= \ - --host=x86_64-linux-musl; \ + --host=${TARGET}; \ make DESTDIR=${SYSROOT_DIR} install-headers # Phase 5: Compile libgcc @@ -142,18 +142,31 @@ RUN set -eux; \ # Phase 6: Compile remaining gcc targets WORKDIR ${GCC_DIR} -RUN make - -FROM build as package +RUN make all FROM build as install WORKDIR ${HOME} +USER 0:0 +COPY --from=stage1 . /rootfs/ RUN set -eux; \ - env -C build-musl make DESTDIR=${SYSROOT_DIR} install; \ - env -C build-gcc make DESTDIR=${SYSROOT_DIR} install; \ - env -C build-binutils make DESTDIR=${SYSROOT_DIR} install; \ - find ${SYSROOT_DIR} -exec touch -hcd "@0" "{}" + + rm /rootfs/lib; \ + env -C build-musl make DESTDIR=/rootfs/${TARGET} install; \ + env -C build-gcc make DESTDIR=/rootfs/ install; \ + env -C build-binutils make DESTDIR=/rootfs/ install; \ + ln -s /usr/lib/ld-musl-i386.so.1 /rootfs/lib/libc.so; \ + ln -s /usr/lib/ld-musl-i386.so.1 /rootfs/lib/ld-musl-i386.so.1; \ + ln -s /${TARGET}/lib/ld-musl-x86_64.so.1 /rootfs/lib/ld-musl-x86_64.so.1; \ + find /rootfs -exec touch -hcd "@0" "{}" + -FROM live-bootstrap as package -COPY --from=install ${SYSROOT_DIR} /${TARGET} +FROM scratch as package +COPY --from=install /rootfs/ / +USER 1000:1000 +ENTRYPOINT ["/bin/bash"] +ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +ENV USER=user +ENV HOME=/home/user +ENV TZ=UTC +ENV LANG=C.UTF-8 +ENV SOURCE_DATE_EPOCH=1 +ENV KCONFIG_NOTIMESTAMP=1 ENV PS1="stage2 $ " diff --git a/src/bootstrap/stage3/Dockerfile b/src/bootstrap/stage3/Dockerfile new file mode 100644 index 0000000..250a8a6 --- /dev/null +++ b/src/bootstrap/stage3/Dockerfile @@ -0,0 +1,94 @@ +ARG REGISTRY=local +FROM ${REGISTRY}/stage2 as stage2 + +FROM stage2 as base +ENV TARGET=x86_64-linux-musl +ENV BUILD=i386-unknown-linux-musl +ENV MUSL_VERSION 1.2.4 +ENV MUSL_SITE http://musl.libc.org/releases +ENV MUSL_FILE musl-${MUSL_VERSION}.tar.gz +ENV MUSL_HASH 7a35eae33d5372a7c0da1188de798726f68825513b7ae3ebe97aaaa52114f039 +ENV MUSL_DIR=${HOME}/build-musl +ENV BASH_SITE=https://ftp.gnu.org/gnu/bash +ENV BASH_VERSION_=5.2.21 +ENV BASH_HASH c8e31bdc59b69aaffc5b36509905ba3e5cbb12747091d27b4b977f078560d5b8 +ENV BASH_FILE bash-${BASH_VERSION_}.tar.gz +ENV BASH_DIR=${HOME}/build-bash +ENV COREUTILS_SITE=https://ftp.gnu.org/gnu/coreutils +ENV COREUTILS_VERSION=9.4 +ENV COREUTILS_HASH 5f600d9093973b0afe25393d9bc18c44f2232657f4ca0d95ea31c702eb66b739 +ENV COREUTILS_FILE coreutils-${COREUTILS_VERSION}.tar.gz +ENV COREUTILS_DIR=${HOME}/build-coreutils + +FROM base as fetch +WORKDIR /home/user +RUN set -eux; \ + curl --insecure -OJ ${MUSL_SITE}/${MUSL_FILE}; \ + echo "${MUSL_HASH} ${MUSL_FILE}" | sha256sum -c; \ + curl --insecure -OJ ${BASH_SITE}/${BASH_FILE}; \ + echo "${BASH_HASH} ${BASH_FILE}" | sha256sum -c; \ + curl --insecure -OJ ${COREUTILS_SITE}/${COREUTILS_FILE}; \ + echo "${COREUTILS_HASH} ${COREUTILS_FILE}" | sha256sum -c + +FROM fetch as build +RUN set -eux; \ + tar -xzf ${MUSL_FILE}; \ + tar -xzf ${BASH_FILE}; \ + tar -xzf ${COREUTILS_FILE} +WORKDIR ${MUSL_DIR} +RUN set -eux; \ + ../musl-${MUSL_VERSION}/configure \ + --prefix= \ + --build=${BUILD} \ + --host=${TARGET}; \ + make +WORKDIR ${BASH_DIR} +RUN set -eux; \ + echo "${BASH_VERSION_}"; \ + ../bash-${BASH_VERSION_}/configure \ + --build=${BUILD} \ + --host=${TARGET} \ + --prefix=/usr \ + --bindir=/bin \ + --mandir=/usr/share/man \ + --infodir=/usr/share/info \ + --disable-nls \ + --enable-readline \ + --without-curses \ + --without-bash-malloc; \ + make + +WORKDIR ${COREUTILS_DIR} +RUN set -eux; \ + echo "${COREUTILS_VERSION}"; \ + ../coreutils-${COREUTILS_VERSION}/configure \ + --build=${BUILD} \ + --host=${TARGET} \ + --prefix=/usr \ + --bindir=/bin \ + --mandir=/usr/share/man \ + --infodir=/usr/share/info \ + --disable-nls \ + --enable-single-binary=symlinks; \ + make + +FROM build as install +USER 0:0 +RUN set -eux; \ + env -C ${MUSL_DIR} make DESTDIR=/rootfs install; \ + env -C ${BASH_DIR} make DESTDIR=/rootfs install; \ + env -C ${COREUTILS_DIR} make DESTDIR=/rootfs install; \ + find /rootfs -exec touch -hcd "@0" "{}" + + +FROM scratch as package +COPY --from=install /rootfs / +USER 1000:1000 +ENTRYPOINT ["/bin/bash"] +ENV PATH=/x86_64-linux-musl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +ENV USER=user +ENV HOME=/home/user +ENV TZ=UTC +ENV LANG=C.UTF-8 +ENV SOURCE_DATE_EPOCH=1 +ENV KCONFIG_NOTIMESTAMP=1 +ENV PS1="stage3 $ "