This commit is contained in:
j842 2025-05-26 15:32:33 +12:00
parent 2755339c39
commit 1c0edcaf2b

View File

@ -10,8 +10,13 @@ ENV CFLAGS="-static -O2" \
CXXFLAGS="-static -O2" \ CXXFLAGS="-static -O2" \
LDFLAGS="-static" LDFLAGS="-static"
# Create non-root user
RUN adduser -D -u 1000 builder
# Install build dependencies # Install build dependencies
RUN apk add --no-cache \ RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
apk update && \
apk add --no-cache \
build-base \ build-base \
cmake \ cmake \
ninja \ ninja \
@ -41,53 +46,25 @@ RUN apk add --no-cache \
libtool \ libtool \
patch \ patch \
gawk \ gawk \
xz-dev xz-dev \
crosstool-ng
# Build ncurses from source
RUN cd /tmp && \
wget https://invisible-mirror.net/archives/ncurses/ncurses-6.4.tar.gz && \
tar xf ncurses-6.4.tar.gz && \
cd ncurses-6.4 && \
./configure --prefix=/usr \
--without-shared \
--with-normal \
--enable-pc-files \
--with-pkg-config-libdir=/usr/lib/pkgconfig \
--enable-widec \
--disable-database \
--with-fallbacks=linux \
--with-panel \
--with-panel-libs && \
make -j$(nproc) && \
make install && \
cd .. && \
rm -rf ncurses-6.4*
# Build crosstool-ng
RUN cd /tmp && \
wget https://github.com/crosstool-ng/crosstool-ng/releases/download/crosstool-ng-1.25.0/crosstool-ng-1.25.0.tar.xz && \
tar xf crosstool-ng-1.25.0.tar.xz && \
cd crosstool-ng-1.25.0 && \
export CPPFLAGS="-I/usr/include/ncursesw" && \
./configure --prefix=/usr && \
make -j$(nproc) && \
make install && \
cd .. && \
rm -rf crosstool-ng-1.25.0*
# Create crosstool-ng config # Create crosstool-ng config
RUN mkdir -p /tmp/ct-ng && \ RUN mkdir -p /tmp/ct-ng && \
chown -R builder:builder /tmp/ct-ng && \
cd /tmp/ct-ng && \ cd /tmp/ct-ng && \
ct-ng aarch64-unknown-linux-musl && \ su builder -c "ct-ng aarch64-unknown-linux-musl" && \
sed -i 's/CT_MUSL_VERSION="1.2.4"/CT_MUSL_VERSION="1.2.4"/' .config && \ su builder -c "sed -i 's/CT_MUSL_VERSION=\"1.2.4\"/CT_MUSL_VERSION=\"1.2.4\"/' .config" && \
sed -i 's/CT_GCC_VERSION="13.1.0"/CT_GCC_VERSION="13.1.0"/' .config && \ su builder -c "sed -i 's/CT_GCC_VERSION=\"13.1.0\"/CT_GCC_VERSION=\"13.1.0\"/' .config" && \
sed -i 's/CT_BINUTILS_VERSION="2.41"/CT_BINUTILS_VERSION="2.41"/' .config && \ su builder -c "sed -i 's/CT_BINUTILS_VERSION=\"2.41\"/CT_BINUTILS_VERSION=\"2.41\"/' .config" && \
sed -i 's/CT_LINUX_VERSION="6.1.28"/CT_LINUX_VERSION="6.1.28"/' .config && \ su builder -c "sed -i 's/CT_LINUX_VERSION=\"6.1.28\"/CT_LINUX_VERSION=\"6.1.28\"/' .config" && \
sed -i 's/CT_PARALLEL_JOBS=0/CT_PARALLEL_JOBS=$(nproc)/' .config su builder -c "sed -i 's/CT_PARALLEL_JOBS=0/CT_PARALLEL_JOBS=$(nproc)/' .config" && \
su builder -c "echo 'CT_EXTRA_CFLAGS_FOR_BUILD=\"-D_FILE_OFFSET_BITS=64\"' >> .config" && \
su builder -c "echo 'CT_EXTRA_CFLAGS_FOR_HOST=\"-D_FILE_OFFSET_BITS=64\"' >> .config"
# Build the toolchain # Build the toolchain
RUN cd /tmp/ct-ng && \ RUN cd /tmp/ct-ng && \
ct-ng build su builder -c "unset CFLAGS CXXFLAGS LDFLAGS && ct-ng build"
# Install the toolchain # Install the toolchain
RUN mkdir -p /opt/cross && \ RUN mkdir -p /opt/cross && \
@ -150,7 +127,9 @@ RUN strip --strip-unneeded /usr/local/lib/*.a
FROM alpine:3.19 FROM alpine:3.19
# Install core toolchain for building apps # Install core toolchain for building apps
RUN apk add --no-cache \ RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
apk update && \
apk add --no-cache \
build-base \ build-base \
cmake \ cmake \
ninja \ ninja \
@ -163,8 +142,7 @@ RUN apk add --no-cache \
linux-headers \ linux-headers \
ccache \ ccache \
mold \ mold \
ncurses-dev \ crosstool-ng
ncurses-terminfo-base
# Configure mold as the default linker # Configure mold as the default linker
ENV LD=mold ENV LD=mold