2828 ln -s "/usr/local/zig-linux-$(uname -m)-${ZIG_VERSION}/zig" /usr/local/bin/zig
2929# Install cargo-binstall
3030RUN curl --retry 5 -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
31- # Install FoundationDB
32- # TODO According to https://github.com/apple/foundationdb/issues/11448#issuecomment-2417766293
33- # Once FoundationDB v7.3.53 gets released, we should be able to build the aarch64-unknown-linux-gnu target.
34- # The last command is for future build use, so if you are building on a native arm64 device, please use docker qemu.
35- 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)"
3631# Install cargo-chef & sccache & cargo-zigbuild
3732RUN cargo binstall --no-confirm cargo-chef sccache cargo-zigbuild
3833
@@ -56,24 +51,31 @@ ARG BUILD_ENV
5651SHELL ["/bin/bash", "-o", "pipefail", "-c"]
5752# Install toolchain and specify some env variables
5853RUN \
59- rustup set profile minimal && \
60- rustup target add ${TARGET} && \
61- mkdir -p artifact && \
62- touch /env-cargo && \
63- if [ ! -z "${BUILD_ENV}" ]; then \
64- echo "export ${BUILD_ENV}" >> /env-cargo; \
65- echo "Setting up ${BUILD_ENV}"; \
66- fi
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
6771# Cargo-chef Cache layer
6872RUN \
6973 --mount=type=secret,id=ACTIONS_CACHE_URL,env=ACTIONS_CACHE_URL \
7074 --mount=type=secret,id=ACTIONS_RUNTIME_TOKEN,env=ACTIONS_RUNTIME_TOKEN \
7175 --mount=type=cache,target=/usr/local/cargo/registry \
7276 --mount=type=cache,target=/usr/local/cargo/git \
73- # TODO According to https://github.com/apple/foundationdb/issues/11448#issuecomment-2417766293
74- # Once FoundationDB v7.3.53 gets released, we should be able to build the aarch64-unknown-linux-gnu target.
7577 source /env-cargo && \
76- if [ "${TARGET}" = "x86_64-unknown-linux-gnu " ]; then \
78+ if [ ! -z "${FDB_ARCH} " ]; then \
7779 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"; \
7880 fi
7981RUN \
@@ -88,16 +90,14 @@ RUN \
8890COPY . .
8991ENV RUSTC_WRAPPER="sccache" \
9092 SCCACHE_GHA_ENABLED=true
91- # Build foundationdb version
93+ # Build FoundationDB version
9294RUN \
9395 --mount=type=secret,id=ACTIONS_CACHE_URL,env=ACTIONS_CACHE_URL \
9496 --mount=type=secret,id=ACTIONS_RUNTIME_TOKEN,env=ACTIONS_RUNTIME_TOKEN \
9597 --mount=type=cache,target=/usr/local/cargo/registry \
9698 --mount=type=cache,target=/usr/local/cargo/git \
97- # TODO According to https://github.com/apple/foundationdb/issues/11448#issuecomment-2417766293
98- # Once FoundationDB v7.3.53 gets released, we should be able to build the aarch64-unknown-linux-gnu target.
9999 source /env-cargo && \
100- if [ "${TARGET}" = "x86_64-unknown-linux-gnu " ]; then \
100+ if [ ! -z "${FDB_ARCH} " ]; then \
101101 RUSTFLAGS="-L /usr/lib" cargo zigbuild --release --target ${TARGET} -p mail-server --no-default-features --features "foundationdb elastic s3 redis enterprise"; \
102102 mv /app/target/${TARGET}/release/stalwart-mail /app/artifact/stalwart-mail-foundationdb; \
103103 fi
0 commit comments