GAHHH!
This commit is contained in:
parent
6dc0b7c9c1
commit
e62c526d49
78
Dockerfile
78
Dockerfile
@ -5,42 +5,48 @@
|
|||||||
########################
|
########################
|
||||||
FROM alpine:latest AS builder
|
FROM alpine:latest AS builder
|
||||||
|
|
||||||
ARG TARGET_ARCH
|
ARG B_TARGET_ARCH
|
||||||
RUN case $TARGET_ARCH in \
|
ARG B_TARGET_TRIPLE
|
||||||
"arm64") export TARGET_TRIPLE="aarch64-linux-musl";; \
|
ARG B_CC
|
||||||
"amd64") export TARGET_TRIPLE="x86_64-linux-musl";; \
|
ARG B_CXX
|
||||||
*) echo "Unsupported architecture"; exit 1;; \
|
|
||||||
esac && \
|
|
||||||
export CC="${TARGET_TRIPLE}-gcc" && \
|
|
||||||
export CXX="${TARGET_TRIPLE}-g++"
|
|
||||||
|
|
||||||
|
ENV TARGET_ARCH=$B_TARGET_ARCH
|
||||||
|
ENV TARGET_TRIPLE=$B_TARGET_TRIPLE
|
||||||
|
ENV CC=$B_CC
|
||||||
|
ENV CXX=$B_CXX
|
||||||
|
|
||||||
# Enable static builds with musl
|
# Enable static builds with musl
|
||||||
ENV CFLAGS="-static -O2" \
|
ENV CFLAGS="-static -O2" \
|
||||||
CXXFLAGS="-static -O2" \
|
CXXFLAGS="-static -O2" \
|
||||||
LDFLAGS="-static"
|
LDFLAGS="-static"
|
||||||
|
|
||||||
|
# Add cross-compiler to PATH
|
||||||
|
ENV PATH="/opt/cross/bin:${PATH}"
|
||||||
|
|
||||||
# Install build dependencies
|
# Install build dependencies
|
||||||
RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
|
RUN apk update && \
|
||||||
apk update && \
|
|
||||||
apk add --no-cache \
|
apk add --no-cache \
|
||||||
build-base \
|
build-base \
|
||||||
|
make \
|
||||||
cmake \
|
cmake \
|
||||||
ninja \
|
ninja \
|
||||||
git \
|
git \
|
||||||
wget \
|
|
||||||
curl \
|
|
||||||
openssl-dev \
|
openssl-dev \
|
||||||
zlib-static \
|
zlib-static \
|
||||||
zlib-dev \
|
|
||||||
linux-headers \
|
|
||||||
bash \
|
bash \
|
||||||
|
wget \
|
||||||
|
curl \
|
||||||
|
linux-headers \
|
||||||
ccache \
|
ccache \
|
||||||
mold \
|
mold \
|
||||||
musl-dev \
|
musl-dev \
|
||||||
|
gcc-cross-embedded \
|
||||||
|
g++-cross-embedded \
|
||||||
gcc \
|
gcc \
|
||||||
g++ \
|
g++
|
||||||
make \
|
|
||||||
|
RUN apk add --no-cache \
|
||||||
|
zlib-dev \
|
||||||
python3 \
|
python3 \
|
||||||
bison \
|
bison \
|
||||||
flex \
|
flex \
|
||||||
@ -53,15 +59,16 @@ RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repo
|
|||||||
libtool \
|
libtool \
|
||||||
patch \
|
patch \
|
||||||
gawk \
|
gawk \
|
||||||
xz-dev \
|
xz-dev
|
||||||
gcc-cross-embedded
|
|
||||||
|
# Configure mold as the default linker
|
||||||
|
ENV LD=mold
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
# nlohmann/json (compiled static .a) #
|
# nlohmann/json (compiled static .a) #
|
||||||
########################################
|
########################################
|
||||||
ARG JSON_VERSION=3.11.3
|
RUN git clone --depth 1 https://github.com/nlohmann/json.git /tmp/json
|
||||||
RUN git clone --depth 1 --branch v${JSON_VERSION} https://github.com/nlohmann/json.git /tmp/json && \
|
RUN cmake -S /tmp/json -B /tmp/json/build \
|
||||||
cmake -S /tmp/json -B /tmp/json/build \
|
|
||||||
-DJSON_BuildTests=OFF \
|
-DJSON_BuildTests=OFF \
|
||||||
-DJSON_MultipleHeaders=OFF \
|
-DJSON_MultipleHeaders=OFF \
|
||||||
-DBUILD_SHARED_LIBS=OFF && \
|
-DBUILD_SHARED_LIBS=OFF && \
|
||||||
@ -108,11 +115,21 @@ RUN strip --strip-unneeded /usr/local/lib/*.a
|
|||||||
############################
|
############################
|
||||||
FROM alpine:3.19
|
FROM alpine:3.19
|
||||||
|
|
||||||
|
ARG B_TARGET_ARCH
|
||||||
|
ARG B_TARGET_TRIPLE
|
||||||
|
ARG B_CC
|
||||||
|
ARG B_CXX
|
||||||
|
|
||||||
|
ENV TARGET_ARCH=$B_TARGET_ARCH
|
||||||
|
ENV TARGET_TRIPLE=$B_TARGET_TRIPLE
|
||||||
|
ENV CC=$B_CC
|
||||||
|
ENV CXX=$B_CXX
|
||||||
|
|
||||||
# Install core toolchain for building apps
|
# Install core toolchain for building apps
|
||||||
RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
|
RUN apk update && \
|
||||||
apk update && \
|
|
||||||
apk add --no-cache \
|
apk add --no-cache \
|
||||||
build-base \
|
build-base \
|
||||||
|
make \
|
||||||
cmake \
|
cmake \
|
||||||
ninja \
|
ninja \
|
||||||
git \
|
git \
|
||||||
@ -124,19 +141,20 @@ RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repo
|
|||||||
linux-headers \
|
linux-headers \
|
||||||
ccache \
|
ccache \
|
||||||
mold \
|
mold \
|
||||||
gcc-cross-embedded
|
musl-dev \
|
||||||
|
gcc-cross-embedded \
|
||||||
|
g++-cross-embedded \
|
||||||
|
gcc \
|
||||||
|
g++
|
||||||
|
|
||||||
# Configure mold as the default linker
|
# Configure mold as the default linker
|
||||||
ENV LD=mold
|
ENV LD=mold
|
||||||
|
|
||||||
# Copy pre‑built static libs + headers and cross-compiler toolchain
|
# Copy pre‑built static libs + headers
|
||||||
COPY --from=builder /usr/local /usr/local
|
COPY --from=builder /usr/local /usr/local
|
||||||
|
|
||||||
# Add toolchain to PATH
|
ENV CFLAGS="-static" \
|
||||||
ENV PATH="/opt/cross/bin:${PATH}"
|
CXXFLAGS="-static" \
|
||||||
|
|
||||||
ENV CFLAGS="-static -O2" \
|
|
||||||
CXXFLAGS="-static -O2" \
|
|
||||||
LDFLAGS="-static"
|
LDFLAGS="-static"
|
||||||
|
|
||||||
WORKDIR /workspace
|
WORKDIR /workspace
|
||||||
|
20
build.sh
20
build.sh
@ -1,7 +1,22 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
docker build --build-arg TARGET_ARCH=arm64 -t cpp-httplib-builder:arm64 .
|
set -e
|
||||||
docker build --build-arg TARGET_ARCH=amd64 -t cpp-httplib-builder:amd64 .
|
|
||||||
|
docker build \
|
||||||
|
--build-arg B_TARGET_ARCH=arm64 \
|
||||||
|
--build-arg B_TARGET_TRIPLE=aarch64-linux-musl \
|
||||||
|
--build-arg B_CC=aarch64-none-elf-gcc \
|
||||||
|
--build-arg B_CXX=aarch64-none-elf-g++ \
|
||||||
|
-t cpp-httplib-builder:arm64 \
|
||||||
|
.
|
||||||
|
|
||||||
|
docker build \
|
||||||
|
--build-arg B_TARGET_ARCH=amd64 \
|
||||||
|
--build-arg B_TARGET_TRIPLE=x86_64-linux-musl \
|
||||||
|
--build-arg B_CC=x86_64-alpine-linux-musl-gcc \
|
||||||
|
--build-arg B_CXX=x86_64-alpine-linux-musl-g++ \
|
||||||
|
-t cpp-httplib-builder:amd64 \
|
||||||
|
.
|
||||||
|
|
||||||
docker tag cpp-httplib-builder:arm64 gitea.jde.nz/public/cpp-httplib-builder:arm64
|
docker tag cpp-httplib-builder:arm64 gitea.jde.nz/public/cpp-httplib-builder:arm64
|
||||||
docker tag cpp-httplib-builder:amd64 gitea.jde.nz/public/cpp-httplib-builder:amd64
|
docker tag cpp-httplib-builder:amd64 gitea.jde.nz/public/cpp-httplib-builder:amd64
|
||||||
@ -9,3 +24,4 @@ docker tag cpp-httplib-builder:amd64 gitea.jde.nz/public/cpp-httplib-builder:lat
|
|||||||
|
|
||||||
docker push gitea.jde.nz/public/cpp-httplib-builder:arm64
|
docker push gitea.jde.nz/public/cpp-httplib-builder:arm64
|
||||||
docker push gitea.jde.nz/public/cpp-httplib-builder:amd64
|
docker push gitea.jde.nz/public/cpp-httplib-builder:amd64
|
||||||
|
docker push gitea.jde.nz/public/cpp-httplib-builder:latest
|
||||||
|
@ -38,14 +38,21 @@ function build() {
|
|||||||
cp /app/build/$PROJECT /app/src/$OUTDIR/$PROJECT.$ARCH && \
|
cp /app/build/$PROJECT /app/src/$OUTDIR/$PROJECT.$ARCH && \
|
||||||
chown -R $(id -u):$(id -g) /app/src/$OUTDIR"
|
chown -R $(id -u):$(id -g) /app/src/$OUTDIR"
|
||||||
|
|
||||||
|
|
||||||
|
case $ARCH in
|
||||||
|
"arm64") export TARGET_TRIPLE="aarch64-linux-musl";;
|
||||||
|
"amd64") export TARGET_TRIPLE="x86_64-linux-musl";;
|
||||||
|
*) echo "Unsupported architecture $ARCH"; exit 1;;
|
||||||
|
esac
|
||||||
|
export CC="ccache ${TARGET_TRIPLE}-gcc"
|
||||||
|
export CXX="ccache ${TARGET_TRIPLE}-g++"
|
||||||
|
|
||||||
# Run the build in the container
|
# Run the build in the container
|
||||||
docker run --rm \
|
docker run --rm \
|
||||||
-v cppbuild-cache:/app/build \
|
-v cppbuild-cache:/app/build \
|
||||||
-v $(pwd):/app/src \
|
-v $(pwd):/app/src \
|
||||||
-w /app/src \
|
-w /app/src \
|
||||||
-e CCACHE_DIR=/app/build/.ccache \
|
-e CCACHE_DIR=/app/build/.ccache \
|
||||||
-e CC="ccache gcc" \
|
|
||||||
-e CXX="ccache g++" \
|
|
||||||
-e LD=mold \
|
-e LD=mold \
|
||||||
-e CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) \
|
-e CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) \
|
||||||
-e NINJA_STATUS="[%f/%t] " \
|
-e NINJA_STATUS="[%f/%t] " \
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
#!/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"
|
|
Loading…
x
Reference in New Issue
Block a user