This commit is contained in:
parent
3b51a511a6
commit
08794e6480
@ -1,82 +1,20 @@
|
|||||||
# syntax=docker/dockerfile:1.4
|
FROM alpine AS compiler
|
||||||
FROM --platform=$BUILDPLATFORM alpine:3.19 AS deps
|
|
||||||
|
|
||||||
# Install build dependencies
|
ARG VERSION=0.13.0
|
||||||
RUN apk add --no-cache \
|
ARG OPTIONS=-Doptimize=ReleaseSafe
|
||||||
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
|
|
||||||
|
|
||||||
FROM deps AS build
|
RUN apk update && apk add curl tar xz
|
||||||
|
|
||||||
ARG TARGETARCH
|
# zig-linux-aarch64-0.10.1.tar.xz
|
||||||
WORKDIR /source
|
# ziglang.org/download/<ver>/zig-linux-<architecture>-<ver>.tar.xz
|
||||||
COPY . .
|
|
||||||
|
|
||||||
# Create and run build script
|
RUN curl https://ziglang.org/download/$VERSION/zig-linux-$(uname -m)-$VERSION.tar.xz -O && \
|
||||||
RUN printf '#!/bin/bash\n\
|
tar -xf *.tar.xz && \
|
||||||
set -e\n\
|
mv zig-linux-$(uname -m)-$VERSION /compiler
|
||||||
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
|
|
||||||
|
|
||||||
# Final stage: copy out the binary
|
WORKDIR /build
|
||||||
FROM scratch AS export-stage
|
COPY . /build
|
||||||
ARG TARGETARCH
|
RUN /compiler/zig build $OPTIONS
|
||||||
COPY --from=build /build/build_${TARGETARCH}/dropshell /dropshell
|
|
||||||
|
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"
|
mkdir -p "$OUTPUT_DIR"
|
||||||
|
|
||||||
# Ensure buildx is available
|
options="-Doptimize=ReleaseSafe -Dtarget=x86_64-linux-musl"
|
||||||
if ! docker buildx version &>/dev/null; then
|
docker build \
|
||||||
echo "Docker Buildx is required. Please install Docker Buildx." >&2
|
--platform "linux/amd64" \
|
||||||
exit 1
|
--build-arg "OPTIONS=$options" \
|
||||||
fi
|
-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:"
|
echo "Builds complete:"
|
||||||
ls -lh "$OUTPUT_DIR"/dropshell.*
|
ls -lh "$OUTPUT_DIR"/dropshell.*
|
Loading…
x
Reference in New Issue
Block a user