@@ -14,20 +14,24 @@ ENV DEBIAN_FRONTEND="noninteractive" \
1414 TERM=xterm-256color
1515# With zig, we only need libclang and make
1616RUN \
17- --mount=type=cache,target=/var/cache/apt,sharing=locked \
18- --mount=type=cache,target=/var/lib/apt,sharing=locked \
19- rm -f /etc/apt/apt.conf.d/docker-clean && \
20- echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' >/etc/apt/apt.conf.d/keep-cache && \
21- apt-get update && \
22- apt-get install -yq --no-install-recommends curl jq xz-utils make libclang-16-dev
17+ --mount=type=cache,target=/var/cache/apt,sharing=locked \
18+ --mount=type=cache,target=/var/lib/apt,sharing=locked \
19+ rm -f /etc/apt/apt.conf.d/docker-clean && \
20+ echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' >/etc/apt/apt.conf.d/keep-cache && \
21+ apt-get update && \
22+ apt-get install -yq --no-install-recommends curl jq xz-utils make libclang-16-dev
2323# Install zig
24- RUN \
25- ZIG_VERSION=$(curl --retry 5 -sL "https://api.github.com/repos/ziglang/zig/releases/latest" | jq -r '.tag_name') && \
24+ RUN ZIG_VERSION=$(curl --retry 5 -sL "https://api.github.com/repos/ziglang/zig/releases/latest" | jq -r '.tag_name') && \
2625 [ ! -z "$ZIG_VERSION" ] && \
2726 curl --retry 5 -Ls "https://ziglang.org/download/${ZIG_VERSION}/zig-linux-$(uname -m)-${ZIG_VERSION}.tar.xz" | tar -J -x -C /usr/local && \
2827 ln -s "/usr/local/zig-linux-$(uname -m)-${ZIG_VERSION}/zig" /usr/local/bin/zig
2928# Install cargo-binstall
3029RUN curl --retry 5 -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
30+ # Install FoundationDB
31+ # TODO According to https://github.com/apple/foundationdb/issues/11448#issuecomment-2417766293
32+ # Once FoundationDB v7.3.53 gets released, we should be able to build the aarch64-unknown-linux-gnu target.
33+ # The last command is for future build use, so if you are building on a native arm64 device, please use docker qemu.
34+ RUN curl --retry 5 -Lso /usr/lib/libfdb_c.so "$(curl --retry 5 -Ls 'https://api.github.com/repos/apple/foundationdb/releases' | jq --arg arch "$(uname -m)" -r '.[] | select(.prerelease == false) | .assets[] | select(.name | test("libfdb_c." + $arch + ".so")) | .browser_download_url' | head -n1)"
3135# Install cargo-chef & sccache & cargo-zigbuild
3236RUN cargo binstall --no-confirm cargo-chef sccache cargo-zigbuild
3337
@@ -51,31 +55,24 @@ ARG BUILD_ENV
5155SHELL ["/bin/bash", "-o", "pipefail", "-c"]
5256# Install toolchain and specify some env variables
5357RUN \
54- rustup set profile minimal && \
55- rustup target add ${TARGET} && \
56- mkdir -p artifact && \
57- touch /env-cargo && \
58- if [ ! -z "${BUILD_ENV}" ]; then \
59- echo "export ${BUILD_ENV}" >> /env-cargo; \
60- echo "Setting up ${BUILD_ENV}"; \
61- fi && \
62- if [[ "${TARGET}" == *gnu ]]; then \
63- echo "export FDB_ARCH=${TARGET%%-*}" >> /env-cargo; \
64- fi
65- # Install FoundationDB
66- RUN \
67- source /env-cargo && \
68- if [ ! -z "${FDB_ARCH}" ]; then \
69- curl --retry 5 -Lso /usr/lib/libfdb_c.so "$(curl --retry 5 -Ls 'https://api.github.com/repos/apple/foundationdb/releases' | jq --arg FDB_ARCH "$FDB_ARCH" -r '.[] | select(.prerelease == false) | .assets[] | select(.name | test("libfdb_c." + $FDB_ARCH + ".so")) | .browser_download_url' | head -n1)"; \
70- fi
58+ rustup set profile minimal && \
59+ rustup target add ${TARGET} && \
60+ mkdir -p artifact && \
61+ touch /env-cargo && \
62+ if [ ! -z "${BUILD_ENV}" ]; then \
63+ echo "export ${BUILD_ENV}" >> /env-cargo; \
64+ echo "Setting up ${BUILD_ENV}"; \
65+ fi
7166# Cargo-chef Cache layer
7267RUN \
7368 --mount=type=secret,id=ACTIONS_CACHE_URL,env=ACTIONS_CACHE_URL \
7469 --mount=type=secret,id=ACTIONS_RUNTIME_TOKEN,env=ACTIONS_RUNTIME_TOKEN \
7570 --mount=type=cache,target=/usr/local/cargo/registry \
7671 --mount=type=cache,target=/usr/local/cargo/git \
72+ # TODO According to https://github.com/apple/foundationdb/issues/11448#issuecomment-2417766293
73+ # Once FoundationDB v7.3.53 gets released, we should be able to build the aarch64-unknown-linux-gnu target.
7774 source /env-cargo && \
78- if [ ! -z "${FDB_ARCH} " ]; then \
75+ if [ "${TARGET}" = "x86_64-unknown-linux-gnu " ]; then \
7976 RUSTFLAGS="-L /usr/lib" cargo chef cook --recipe-path recipe.json --zigbuild --release --target ${TARGET} -p mail-server --no-default-features --features "foundationdb elastic s3 redis enterprise"; \
8077 fi
8178RUN \
@@ -90,14 +87,16 @@ RUN \
9087COPY . .
9188ENV RUSTC_WRAPPER="sccache" \
9289 SCCACHE_GHA_ENABLED=true
93- # Build FoundationDB version
90+ # Build foundationdb version
9491RUN \
9592 --mount=type=secret,id=ACTIONS_CACHE_URL,env=ACTIONS_CACHE_URL \
9693 --mount=type=secret,id=ACTIONS_RUNTIME_TOKEN,env=ACTIONS_RUNTIME_TOKEN \
9794 --mount=type=cache,target=/usr/local/cargo/registry \
9895 --mount=type=cache,target=/usr/local/cargo/git \
96+ # TODO According to https://github.com/apple/foundationdb/issues/11448#issuecomment-2417766293
97+ # Once FoundationDB v7.3.53 gets released, we should be able to build the aarch64-unknown-linux-gnu target.
9998 source /env-cargo && \
100- if [ ! -z "${FDB_ARCH} " ]; then \
99+ if [ "${TARGET}" = "x86_64-unknown-linux-gnu " ]; then \
101100 RUSTFLAGS="-L /usr/lib" cargo zigbuild --release --target ${TARGET} -p mail-server --no-default-features --features "foundationdb elastic s3 redis enterprise"; \
102101 mv /app/target/${TARGET}/release/stalwart-mail /app/artifact/stalwart-mail-foundationdb; \
103102 fi
0 commit comments