diff --git a/bb64/Dockerfile.dropshell-build b/bb64/Dockerfile.dropshell-build new file mode 100644 index 0000000..b5416cc --- /dev/null +++ b/bb64/Dockerfile.dropshell-build @@ -0,0 +1,67 @@ +ARG IMAGE_TAG +FROM gitea.jde.nz/public/dropshell-build-base:latest AS builder + +ARG PROJECT +ARG CMAKE_BUILD_TYPE=Debug + +# Set working directory +WORKDIR /app + +SHELL ["/bin/bash", "-c"] + +# Create cache directories +RUN mkdir -p /ccache + +# Set up ccache +ENV CCACHE_DIR=/ccache +ENV CCACHE_COMPILERCHECK=content +ENV CCACHE_MAXSIZE=2G + +# Copy only build files first (for better layer caching) +#COPY CMakeLists.txt cmake_prebuild.sh ./ +#COPY src/version.hpp.in src/ + +# Run prebuild script early (this rarely changes) +#RUN bash cmake_prebuild.sh + +# Copy source files (this invalidates cache when source changes) +COPY src/ src/ +COPY CMakeLists.txt ./ + +# Configure project (this step is cached unless CMakeLists.txt changes) +RUN --mount=type=cache,target=/ccache \ + --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 -g" \ + -DCMAKE_CXX_FLAGS="-g -fno-omit-frame-pointer" \ + -DCMAKE_C_FLAGS="-g -fno-omit-frame-pointer" \ + -DPROJECT_NAME="${PROJECT}" \ + -DCMAKE_STRIP=OFF \ + ${CMAKE_TOOLCHAIN_FILE:+-DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE} + +# Build project (ccache will help here when only some files change) +RUN --mount=type=cache,target=/ccache \ + --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} \; + +# if we're a release build, then run upx on the binary. +RUN if [ "${CMAKE_BUILD_TYPE}" = "Release" ]; then \ + upx /output/${PROJECT}; \ + fi + +# 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} + diff --git a/bb64/publish.sh b/bb64/publish.sh index bc016b1..3f3d1ad 100755 --- a/bb64/publish.sh +++ b/bb64/publish.sh @@ -13,15 +13,16 @@ if [ "$ARCH" = "aarch64" ]; then fi # Increment version -if [ ! -f version.h ]; then - echo "version.h not found!" >&2 +VERSION_FILE="${SCRIPT_DIR}/src/version.hpp" +if [ ! -f "${VERSION_FILE}" ]; then + echo "${VERSION_FILE} not found!" >&2 exit 1 else - v=$(cat version.h | grep -o 'static const char \*VERSION = "[0-9.]*";' | cut -d'"' -f2) + v=$(cat "${VERSION_FILE}" | grep -o 'static const char \*VERSION = "[0-9.]*";' | cut -d'"' -f2) oldv=$v v=$((v+1)) echo "Incrementing version from $oldv to $v" >&2 - echo "static const char *VERSION = \"$v\";" > version.h + echo "static const char *VERSION = \"$v\";" > "${VERSION_FILE}" fi TAG="v$v" diff --git a/bb64/b64ed.cpp b/bb64/src/b64ed.cpp similarity index 100% rename from bb64/b64ed.cpp rename to bb64/src/b64ed.cpp diff --git a/bb64/b64ed.hpp b/bb64/src/b64ed.hpp similarity index 100% rename from bb64/b64ed.hpp rename to bb64/src/b64ed.hpp diff --git a/bb64/bb64.cpp b/bb64/src/bb64.cpp similarity index 100% rename from bb64/bb64.cpp rename to bb64/src/bb64.cpp diff --git a/bb64/version.h b/bb64/src/version.h similarity index 100% rename from bb64/version.h rename to bb64/src/version.h