dropshell-build/Dockerfile.dropshell-build
Your Name efefdd8b70
All checks were successful
dropshell-build / build (push) Successful in 30s
'Generic Commit'
2025-06-03 22:57:56 +12:00

69 lines
1.9 KiB
Docker

FROM --platform=$BUILDPLATFORM alpine:latest AS builder
ARG PROJECT
# Install ccache along with other dependencies
RUN apk add --no-cache \
build-base \
cmake \
git \
musl-dev \
curl \
bash \
musl \
g++ \
ninja \
linux-headers \
mold \
zlib-static \
ccache \
libunwind-dev \
libdwarf-dev \
binutils \
elfutils-dev
RUN apk add --no-cache --update --repository=https://dl-cdn.alpinelinux.org/alpine/v3.16/main/ libexecinfo-dev
# Set working directory
WORKDIR /app
COPY . .
# Configure and build with ccache
RUN --mount=type=cache,target=/build \
mkdir -p /build && \
cmake -G Ninja -S /app -B /build \
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=mold -static" \
-DCMAKE_FIND_LIBRARY_SUFFIXES=".a" \
-DZLIB_BUILD_SHARED=OFF \
-DZLIB_BUILD_STATIC=ON \
-DBUILD_SHARED_LIBS=OFF \
-DCPPTRACE_UNWIND_WITH_UNWIND=ON \
-DCPPTRACE_GET_SYMBOLS_WITH_LIBDWARF=ON \
-DCPPTRACE_GET_SYMBOLS_WITH_ADDR2LINE=ON \
-DPROJECT_NAME="${PROJECT}" \
-DCMAKE_STRIP=OFF \
${CMAKE_TOOLCHAIN_FILE:+-DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE}
# Explicitly build dependencies first (cached separately)
RUN --mount=type=cache,target=/build cmake --build /build --target run_prebuild_script
RUN --mount=type=cache,target=/build cmake --build /build
# Copy the built executable to a regular directory for the final stage
RUN --mount=type=cache,target=/build mkdir -p /output && \
find /build -type f -executable -name "*${PROJECT}*" -exec cp {} /output/${PROJECT} \; || \
find /build -type f -executable -exec cp {} /output/${PROJECT} \;
# Final stage that only contains the binary
FROM scratch AS project
ARG PROJECT
# Copy the actual binary from the regular directory
COPY --from=builder /output/${PROJECT} /${PROJECT}