From 2755339c39892169da86ece67704c36a5f6d7725 Mon Sep 17 00:00:00 2001 From: j842 Date: Mon, 26 May 2025 14:51:00 +1200 Subject: [PATCH] Hmm, can't build crosstool-ng yet. --- Dockerfile | 86 +++++++++++++++++++++++++++--- test/cmake/aarch64-linux-gnu.cmake | 21 ++++++++ test/crossbuild.sh | 34 ++++++++++++ 3 files changed, 135 insertions(+), 6 deletions(-) create mode 100644 test/cmake/aarch64-linux-gnu.cmake create mode 100755 test/crossbuild.sh diff --git a/Dockerfile b/Dockerfile index 96c79fc..729a3a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ ENV CFLAGS="-static -O2" \ CXXFLAGS="-static -O2" \ LDFLAGS="-static" -# Base build tools + musl-dev, etc. +# Install build dependencies RUN apk add --no-cache \ build-base \ cmake \ @@ -24,10 +24,78 @@ RUN apk add --no-cache \ linux-headers \ bash \ ccache \ - mold + mold \ + musl-dev \ + gcc \ + g++ \ + make \ + python3 \ + bison \ + flex \ + texinfo \ + gperf \ + help2man \ + gettext-dev \ + autoconf \ + automake \ + libtool \ + patch \ + gawk \ + xz-dev -# Configure mold as the default linker -ENV LD=mold +# 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) # @@ -94,13 +162,19 @@ RUN apk add --no-cache \ curl \ linux-headers \ ccache \ - mold + mold \ + ncurses-dev \ + ncurses-terminfo-base # Configure mold as the default linker ENV LD=mold -# Copy pre‑built static libs + headers +# 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" \ diff --git a/test/cmake/aarch64-linux-gnu.cmake b/test/cmake/aarch64-linux-gnu.cmake new file mode 100644 index 0000000..757e625 --- /dev/null +++ b/test/cmake/aarch64-linux-gnu.cmake @@ -0,0 +1,21 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR aarch64) + +# Specify the cross compilers +set(CMAKE_C_COMPILER /opt/cross/bin/aarch64-unknown-linux-musl-gcc) +set(CMAKE_CXX_COMPILER /opt/cross/bin/aarch64-unknown-linux-musl-g++) + +# Where is the target environment +set(CMAKE_FIND_ROOT_PATH /opt/cross/aarch64-unknown-linux-musl) + +# Search for programs in the build host directories +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + +# Search for libraries and headers in the target directories +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + +# Set compiler flags +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a") \ No newline at end of file diff --git a/test/crossbuild.sh b/test/crossbuild.sh new file mode 100755 index 0000000..6020c75 --- /dev/null +++ b/test/crossbuild.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +TARGET_ARCH="aarch64" +OUTDIR="output-${TARGET_ARCH}" + +# Create volume if it doesn't exist +docker volume create cppbuild-cache-${TARGET_ARCH} + +# Build command to run in the container +BUILD_COMMAND="mkdir -p /app/build && \ + cd /app/build && \ + cmake -G Ninja \ + -DCMAKE_TOOLCHAIN_FILE=/app/src/cmake/${TARGET_ARCH}-linux-gnu.cmake \ + /app/src && \ + ninja -j$(nproc) && \ + mkdir -p /app/src/$OUTDIR && \ + cp /app/build/ipdemo /app/src/$OUTDIR/ipdemo && \ + chown -R $(id -u):$(id -g) /app/src/$OUTDIR" + +# Run the build in the container +docker run --rm \ + -v cppbuild-cache-${TARGET_ARCH}:/app/build \ + -v $(pwd):/app/src \ + -w /app/src \ + -e CCACHE_DIR=/app/build/.ccache \ + -e CC="ccache /opt/cross/bin/aarch64-unknown-linux-musl-gcc" \ + -e CXX="ccache /opt/cross/bin/aarch64-unknown-linux-musl-g++" \ + -e LD=mold \ + -e CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) \ + -e NINJA_STATUS="[%f/%t] " \ + cpp-httplib-builder:latest \ + -c "$BUILD_COMMAND" + +echo "Build completed. Output is in $OUTDIR directory" \ No newline at end of file