This commit is contained in:
parent
3b51a511a6
commit
08794e6480
@ -1,82 +1,20 @@
|
||||
# syntax=docker/dockerfile:1.4
|
||||
FROM --platform=$BUILDPLATFORM alpine:3.19 AS deps
|
||||
FROM alpine AS compiler
|
||||
|
||||
# Install build dependencies
|
||||
RUN apk add --no-cache \
|
||||
build-base \
|
||||
cmake \
|
||||
git \
|
||||
linux-headers \
|
||||
musl-dev \
|
||||
zlib \
|
||||
zlib-dev \
|
||||
zlib-static \
|
||||
bzip2-static \
|
||||
xz-static \
|
||||
zstd-static \
|
||||
curl \
|
||||
bash \
|
||||
gcc \
|
||||
g++ \
|
||||
libstdc++ \
|
||||
ccache \
|
||||
ninja \
|
||||
pkgconfig
|
||||
ARG VERSION=0.13.0
|
||||
ARG OPTIONS=-Doptimize=ReleaseSafe
|
||||
|
||||
FROM deps AS build
|
||||
RUN apk update && apk add curl tar xz
|
||||
|
||||
ARG TARGETARCH
|
||||
WORKDIR /source
|
||||
COPY . .
|
||||
# zig-linux-aarch64-0.10.1.tar.xz
|
||||
# ziglang.org/download/<ver>/zig-linux-<architecture>-<ver>.tar.xz
|
||||
|
||||
# Create and run build script
|
||||
RUN printf '#!/bin/bash\n\
|
||||
set -e\n\
|
||||
echo "Setting up build directory..."\n\
|
||||
mkdir -p /build/ccache\n\
|
||||
mkdir -p /build/build_${TARGETARCH}\n\
|
||||
\n\
|
||||
echo "Checking static libraries..."\n\
|
||||
ls -la /usr/lib/libz.a /usr/lib/libstdc++.a /usr/lib/libc.a || true\n\
|
||||
\n\
|
||||
echo "Setting up ccache..."\n\
|
||||
export CCACHE_DIR=/build/ccache\n\
|
||||
export CCACHE_MAXSIZE=2G\n\
|
||||
export PATH="/usr/lib/ccache/bin:$PATH"\n\
|
||||
\n\
|
||||
echo "Running CMake configuration..."\n\
|
||||
cd /build/build_${TARGETARCH}\n\
|
||||
cmake /source -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_FIND_LIBRARY_SUFFIXES=".a" \
|
||||
-DBUILD_SHARED_LIBS=OFF \
|
||||
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
|
||||
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
|
||||
-DCMAKE_POLICY_DEFAULT_CMP0074=NEW \
|
||||
-DZLIB_INCLUDE_DIR=/usr/include \
|
||||
-DZLIB_USE_STATIC_LIBS=TRUE \
|
||||
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-Bstatic -lz -lstdc++ -static-libgcc" \
|
||||
-DCMAKE_C_FLAGS="-fPIC" \
|
||||
-DCMAKE_CXX_FLAGS="-fPIC" \
|
||||
-DCMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX=".a" 2>&1 | tee cmake.log\n\
|
||||
\n\
|
||||
echo "Starting build..."\n\
|
||||
ninja -v -j$(nproc) 2>&1 | tee build.log\n\
|
||||
\n\
|
||||
echo "Build complete. Checking for binary..."\n\
|
||||
if [ ! -f dropshell ]; then\n\
|
||||
echo "Build failed. Directory contents:"\n\
|
||||
ls -la\n\
|
||||
echo "CMake log:"\n\
|
||||
cat cmake.log\n\
|
||||
echo "Build log:"\n\
|
||||
cat build.log\n\
|
||||
exit 1\n\
|
||||
fi\n\
|
||||
\n\
|
||||
echo "ccache stats:"\n\
|
||||
ccache -s\n' > /source/docker_build.sh && chmod +x /source/docker_build.sh && /source/docker_build.sh
|
||||
RUN curl https://ziglang.org/download/$VERSION/zig-linux-$(uname -m)-$VERSION.tar.xz -O && \
|
||||
tar -xf *.tar.xz && \
|
||||
mv zig-linux-$(uname -m)-$VERSION /compiler
|
||||
|
||||
# Final stage: copy out the binary
|
||||
FROM scratch AS export-stage
|
||||
ARG TARGETARCH
|
||||
COPY --from=build /build/build_${TARGETARCH}/dropshell /dropshell
|
||||
WORKDIR /build
|
||||
COPY . /build
|
||||
RUN /compiler/zig build $OPTIONS
|
||||
|
||||
FROM scratch AS output
|
||||
COPY --from=compiler /build/zig-out/bin /bin
|
41
source/build.zig
Normal file
41
source/build.zig
Normal file
@ -0,0 +1,41 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "dropshell",
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.root_source_file = .{ .cwd_relative = "src/main.cpp" },
|
||||
});
|
||||
|
||||
// Link with C++ standard library
|
||||
exe.linkLibCpp();
|
||||
|
||||
// Add include directories if needed
|
||||
exe.addIncludePath(.{ .cwd_relative = "include" });
|
||||
|
||||
b.installArtifact(exe);
|
||||
|
||||
const run_cmd = b.addRunArtifact(exe);
|
||||
run_cmd.step.dependOn(b.getInstallStep());
|
||||
|
||||
if (b.args) |args| {
|
||||
run_cmd.addArgs(args);
|
||||
}
|
||||
|
||||
const run_step = b.step("run", "Run the app");
|
||||
run_step.dependOn(&run_cmd.step);
|
||||
|
||||
const unit_tests = b.addTest(.{
|
||||
.root_source_file = .{ .cwd_relative = "src/main.cpp" },
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const run_unit_tests = b.addRunArtifact(unit_tests);
|
||||
const test_step = b.step("test", "Run unit tests");
|
||||
test_step.dependOn(&run_unit_tests.step);
|
||||
}
|
@ -12,37 +12,13 @@ DOCKERFILE="$SCRIPT_DIR/Dockerfile.multiarch"
|
||||
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
|
||||
# Ensure buildx is available
|
||||
if ! docker buildx version &>/dev/null; then
|
||||
echo "Docker Buildx is required. Please install Docker Buildx." >&2
|
||||
exit 1
|
||||
fi
|
||||
options="-Doptimize=ReleaseSafe -Dtarget=x86_64-linux-musl"
|
||||
docker build \
|
||||
--platform "linux/amd64" \
|
||||
--build-arg "OPTIONS=$options" \
|
||||
-f Dockerfile.multiarch \
|
||||
-t dropshell-build .
|
||||
|
||||
# Build for x86_64
|
||||
DOCKER_BUILDKIT=1 docker buildx build --platform linux/amd64 \
|
||||
-f "$DOCKERFILE" \
|
||||
--output type=local,dest="$OUTPUT_DIR/amd64_tmp" \
|
||||
--cache-from type=local,src=/tmp/dropshell-cache \
|
||||
--cache-to type=local,dest=/tmp/dropshell-cache,mode=max \
|
||||
"$SCRIPT_DIR"
|
||||
|
||||
mv "$OUTPUT_DIR/amd64_tmp/dropshell" "$OUTPUT_DIR/dropshell.amd64"
|
||||
rm -rf "$OUTPUT_DIR/amd64_tmp"
|
||||
|
||||
echo "Built output/dropshell.amd64"
|
||||
|
||||
# Build for aarch64
|
||||
DOCKER_BUILDKIT=1 docker buildx build --platform linux/arm64 \
|
||||
-f "$DOCKERFILE" \
|
||||
--output type=local,dest="$OUTPUT_DIR/arm64_tmp" \
|
||||
--cache-from type=local,src=/tmp/dropshell-cache \
|
||||
--cache-to type=local,dest=/tmp/dropshell-cache,mode=max \
|
||||
"$SCRIPT_DIR"
|
||||
|
||||
mv "$OUTPUT_DIR/arm64_tmp/dropshell" "$OUTPUT_DIR/dropshell.arm64"
|
||||
rm -rf "$OUTPUT_DIR/arm64_tmp"
|
||||
|
||||
echo "Built output/dropshell.arm64"
|
||||
|
||||
echo "Builds complete:"
|
||||
ls -lh "$OUTPUT_DIR"/dropshell.*
|
Loading…
x
Reference in New Issue
Block a user