11# syntax=docker/dockerfile:1.4
2- FROM rust:1.82.0
2+ FROM rust:1.82.0 AS base
33
44# Install dependencies
55RUN apt-get update && apt-get install -y \
@@ -25,38 +25,36 @@ RUN git config --global --add safe.directory '*' && \
2525# Add osxcross to PATH
2626ENV PATH="/root/osxcross/target/bin:$PATH"
2727
28- # Install macOS target
29- RUN rustup target add x86_64-apple-darwin aarch64-apple-darwin
28+ # Common environment variables for cross-compilation
29+ ENV MACOSX_DEPLOYMENT_TARGET=10.7 \
30+ # Skip aws-lc-rs with rustls certs config when building for macOS
31+ RUSTFLAGS="--cfg tokio_unstable --cfg rustls_native_certs --cfg aws_lc_rs" \
32+ CARGO_FEATURE_RUSTLS_NATIVE_CERTS=0 \
33+ CARGO_RUSTLS_NATIVE_CERTS=0 \
34+ CARGO_INCREMENTAL=0 \
35+ CARGO_NET_GIT_FETCH_WITH_CLI=true
3036
31- # Configure Cargo for cross-compilation
37+ # Set working directory
38+ WORKDIR /build
39+
40+ # Build for x86_64 macOS
41+ FROM base AS x86_64-builder
42+
43+ # Install macOS x86_64 target
44+ RUN rustup target add x86_64-apple-darwin
45+
46+ # Configure Cargo for cross-compilation (x86_64)
3247RUN mkdir -p /root/.cargo && \
3348 echo '\
3449[target.x86_64-apple-darwin]\n \
3550linker = "x86_64-apple-darwin20.4-clang"\n \
3651ar = "x86_64-apple-darwin20.4-ar"\n \
37- \n \
38- [target.aarch64-apple-darwin]\n \
39- linker = "aarch64-apple-darwin20.4-clang"\n \
40- ar = "aarch64-apple-darwin20.4-ar"\n \
4152' > /root/.cargo/config.toml
4253
43- # Set environment variables for cross-compilation
54+ # Set environment variables for x86_64 cross-compilation
4455ENV CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER=x86_64-apple-darwin20.4-clang \
45- CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER=aarch64-apple-darwin20.4-clang \
4656 CC_x86_64_apple_darwin=x86_64-apple-darwin20.4-clang \
47- CXX_x86_64_apple_darwin=x86_64-apple-darwin20.4-clang++ \
48- CC_aarch64_apple_darwin=aarch64-apple-darwin20.4-clang \
49- CXX_aarch64_apple_darwin=aarch64-apple-darwin20.4-clang++ \
50- MACOSX_DEPLOYMENT_TARGET=10.7 \
51- # Skip aws-lc-rs with rustls certs config when building for macOS
52- RUSTFLAGS="--cfg tokio_unstable --cfg rustls_native_certs --cfg aws_lc_rs" \
53- CARGO_FEATURE_RUSTLS_NATIVE_CERTS=0 \
54- CARGO_RUSTLS_NATIVE_CERTS=0 \
55- CARGO_INCREMENTAL=0 \
56- CARGO_NET_GIT_FETCH_WITH_CLI=true
57-
58- # Set working directory
59- WORKDIR /build
57+ CXX_x86_64_apple_darwin=x86_64-apple-darwin20.4-clang++
6058
6159# Copy the source code
6260COPY . .
@@ -69,12 +67,5 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \
6967 mkdir -p /artifacts && \
7068 cp target/x86_64-apple-darwin/release/rivet /artifacts/rivet-x86_64-apple-darwin
7169
72- # Build for ARM64 macOS
73- RUN --mount=type=cache,target=/usr/local/cargo/registry \
74- --mount=type=cache,target=/usr/local/cargo/git \
75- --mount=type=cache,target=/build/target \
76- cargo build --bin rivet --release --target aarch64-apple-darwin && \
77- cp target/aarch64-apple-darwin/release/rivet /artifacts/rivet-aarch64-apple-darwin
78-
7970# Default command to show help
80- CMD ["ls" , "-la" , "/artifacts" ]
71+ CMD ["ls" , "-la" , "/artifacts" ]
0 commit comments