160 lines
3.7 KiB
Docker
160 lines
3.7 KiB
Docker
# syntax=docker/dockerfile:1
|
||
|
||
########################
|
||
# Stage 1: build deps #
|
||
########################
|
||
FROM alpine:latest AS builder
|
||
|
||
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
|
||
|
||
# Enable static builds with musl
|
||
ENV CFLAGS="-static -O2" \
|
||
CXXFLAGS="-static -O2" \
|
||
LDFLAGS="-static"
|
||
|
||
# Install build dependencies
|
||
RUN apk update && \
|
||
apk add --no-cache \
|
||
build-base \
|
||
make \
|
||
cmake \
|
||
ninja \
|
||
git \
|
||
openssl-dev \
|
||
zlib-static \
|
||
bash \
|
||
wget \
|
||
curl \
|
||
linux-headers \
|
||
ccache \
|
||
mold \
|
||
musl-dev \
|
||
gcc-cross-embedded \
|
||
g++-cross-embedded \
|
||
gcc \
|
||
g++
|
||
|
||
RUN apk add --no-cache \
|
||
zlib-dev \
|
||
python3 \
|
||
bison \
|
||
flex \
|
||
texinfo \
|
||
gperf \
|
||
help2man \
|
||
gettext-dev \
|
||
autoconf \
|
||
automake \
|
||
libtool \
|
||
patch \
|
||
gawk \
|
||
xz-dev
|
||
|
||
# Configure mold as the default linker
|
||
ENV LD=mold
|
||
|
||
########################################
|
||
# nlohmann/json (compiled static .a) #
|
||
########################################
|
||
RUN git clone --depth 1 https://github.com/nlohmann/json.git /tmp/json
|
||
RUN 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
|
||
|
||
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
|
||
RUN apk update && \
|
||
apk add --no-cache \
|
||
build-base \
|
||
make \
|
||
cmake \
|
||
ninja \
|
||
git \
|
||
openssl-dev \
|
||
zlib-static \
|
||
bash \
|
||
wget \
|
||
curl \
|
||
linux-headers \
|
||
ccache \
|
||
mold \
|
||
musl-dev \
|
||
gcc-cross-embedded \
|
||
g++-cross-embedded \
|
||
gcc \
|
||
g++
|
||
|
||
# Configure mold as the default linker
|
||
ENV LD=mold
|
||
|
||
# Copy pre‑built static libs + headers
|
||
COPY --from=builder /usr/local /usr/local
|
||
|
||
ENV CFLAGS="-static" \
|
||
CXXFLAGS="-static" \
|
||
LDFLAGS="-static"
|
||
|
||
WORKDIR /workspace
|
||
|
||
ENTRYPOINT ["/bin/bash"]
|