Hmm, can't build crosstool-ng yet.

This commit is contained in:
j842 2025-05-26 14:51:00 +12:00
parent 436a3c085f
commit 2755339c39
3 changed files with 135 additions and 6 deletions

View File

@ -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 prebuilt static libs + headers
# Copy prebuilt 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" \

View File

@ -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")

34
test/crossbuild.sh Executable file
View File

@ -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"