# syntax=docker/dockerfile:1 ######################## # Stage 1: build deps # ######################## FROM alpine:3.19 AS builder # Enable static builds with musl ENV CFLAGS="-static -O2" \ CXXFLAGS="-static -O2" \ LDFLAGS="-static" # Install build dependencies RUN apk add --no-cache \ build-base \ cmake \ ninja \ git \ wget \ curl \ openssl-dev \ zlib-static \ zlib-dev \ linux-headers \ bash \ ccache \ mold \ musl-dev \ gcc \ g++ \ make \ python3 \ bison \ flex \ texinfo \ gperf \ help2man \ gettext-dev \ autoconf \ automake \ libtool \ patch \ gawk \ xz-dev # 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 RUN mkdir -p /tmp/ct-ng && \ cd /tmp/ct-ng && \ ct-ng aarch64-unknown-linux-musl && \ 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 && \ 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 && \ sed -i 's/CT_PARALLEL_JOBS=0/CT_PARALLEL_JOBS=$(nproc)/' .config # Build the toolchain RUN cd /tmp/ct-ng && \ ct-ng build # Install the toolchain RUN mkdir -p /opt/cross && \ cp -r /tmp/ct-ng/.build/aarch64-unknown-linux-musl/* /opt/cross/ && \ rm -rf /tmp/ct-ng # Add toolchain to PATH ENV PATH="/opt/cross/bin:${PATH}" ######################################## # nlohmann/json (compiled static .a) # ######################################## ARG JSON_VERSION=3.11.3 RUN git clone --depth 1 --branch v${JSON_VERSION} https://github.com/nlohmann/json.git /tmp/json && \ cmake -S /tmp/json -B /tmp/json/build \ -DJSON_BuildTests=OFF \ -DJSON_MultipleHeaders=OFF \ -DBUILD_SHARED_LIBS=OFF && \ cmake --build /tmp/json/build --config Release && \ cmake --install /tmp/json/build ############################# # cpp‑httplib (header‑only) # ############################# RUN wget -q https://raw.githubusercontent.com/yhirose/cpp-httplib/master/httplib.h \ -O /usr/local/include/httplib.h ################################## # libassert (build static .a) # ################################## ARG LIBASSERT_VERSION=v2.1.5 RUN git clone --depth 1 --branch ${LIBASSERT_VERSION} https://github.com/jeremy-rifkin/libassert.git /tmp/libassert && \ cmake -S /tmp/libassert -B /tmp/libassert/build \ -DLIBASSERT_BUILD_TESTS=OFF \ -DLIBASSERT_BUILD_EXAMPLES=OFF \ -DLIBASSERT_BUILD_STATIC=ON && \ cmake --build /tmp/libassert/build --config Release && \ cmake --install /tmp/libassert/build ##################### # zlib (static .a) # ##################### ARG ZLIB_VERSION=1.3.1 RUN wget -q https://zlib.net/zlib-${ZLIB_VERSION}.tar.gz && \ tar xzf zlib-${ZLIB_VERSION}.tar.gz && \ cd zlib-${ZLIB_VERSION} && \ ./configure --static && \ make -j$(nproc) && \ make install && \ cd .. && rm -rf zlib-${ZLIB_VERSION}* ############################## # Reduce size of .a archives # ############################## RUN strip --strip-unneeded /usr/local/lib/*.a ############################ # Stage 2: final build kit # ############################ FROM alpine:3.19 # Install core toolchain for building apps RUN apk add --no-cache \ build-base \ cmake \ ninja \ git \ openssl-dev \ zlib-static \ bash \ wget \ curl \ linux-headers \ ccache \ mold \ ncurses-dev \ ncurses-terminfo-base # Configure mold as the default linker ENV LD=mold # Copy pre‑built static libs + headers and cross-compiler toolchain COPY --from=builder /usr/local /usr/local COPY --from=builder /opt/cross /opt/cross # Add toolchain to PATH ENV PATH="/opt/cross/bin:${PATH}" ENV CFLAGS="-static -O2" \ CXXFLAGS="-static -O2" \ LDFLAGS="-static" WORKDIR /workspace ENTRYPOINT ["/bin/bash"]