From 74a37d2f36cf515e34df9a3b53dc667a352ffc9d Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Wed, 4 Jun 2025 10:18:16 -0700 Subject: [PATCH] chore: add Linux ARM64 and Windows build targets --- .github/workflows/release.yaml | 6 +- docker/toolchain/build.sh | 26 +++++-- docker/toolchain/linux-aarch64.Dockerfile | 58 +++++++++++++++ ...nux.Dockerfile => linux-x86_64.Dockerfile} | 33 +++++---- docker/toolchain/macos-aarch64.Dockerfile | 71 +++++++++++++++++++ ...cos.Dockerfile => macos-x86_64.Dockerfile} | 53 ++++++-------- 6 files changed, 193 insertions(+), 54 deletions(-) create mode 100644 docker/toolchain/linux-aarch64.Dockerfile rename docker/toolchain/{linux.Dockerfile => linux-x86_64.Dockerfile} (81%) create mode 100644 docker/toolchain/macos-aarch64.Dockerfile rename docker/toolchain/{macos.Dockerfile => macos-x86_64.Dockerfile} (64%) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 5ec02468aa..6084b2fa10 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -92,16 +92,18 @@ jobs: - platform: linux runner: [self-hosted, Linux, X64] target: x86_64-unknown-linux-musl + - platform: linux + runner: [self-hosted, Linux, ARM64] + target: aarch64-unknown-linux-musl # - platform: windows # runner: [self-hosted, Linux, X64] - # target: x86_64-pc-windows-musl + # target: x86_64-pc-windows-gnu - platform: macos runner: [self-hosted, Linux, X64] target: x86_64-apple-darwin - platform: macos runner: [self-hosted, Linux, ARM64] target: aarch64-apple-darwin - arch: arm64 runs-on: ${{ matrix.runner }} steps: - uses: actions/checkout@v4 diff --git a/docker/toolchain/build.sh b/docker/toolchain/build.sh index 611238d8e1..29c602f852 100755 --- a/docker/toolchain/build.sh +++ b/docker/toolchain/build.sh @@ -7,22 +7,32 @@ TARGET=${1:-x86_64-unknown-linux-musl} case $TARGET in x86_64-unknown-linux-musl) echo "Building for Linux x86_64 platform" - DOCKERFILE="linux.Dockerfile" + DOCKERFILE="linux-x86_64.Dockerfile" + TARGET_STAGE="x86_64-builder" + BINARY="rivet-$TARGET" + ;; + aarch64-unknown-linux-musl) + echo "Building for Linux ARM64 platform" + DOCKERFILE="linux-aarch64.Dockerfile" + TARGET_STAGE="aarch64-builder" BINARY="rivet-$TARGET" ;; aarch64-apple-darwin) echo "Building for macOS ARM64 platform" - DOCKERFILE="macos.Dockerfile" + DOCKERFILE="macos-aarch64.Dockerfile" + TARGET_STAGE="aarch64-builder" BINARY="rivet-$TARGET" ;; x86_64-apple-darwin) echo "Building for macOS x86_64 platform" - DOCKERFILE="macos.Dockerfile" + DOCKERFILE="macos-x86_64.Dockerfile" + TARGET_STAGE="x86_64-builder" BINARY="rivet-$TARGET" ;; x86_64-pc-windows-gnu) echo "Building for Windows platform" DOCKERFILE="windows.Dockerfile" + TARGET_STAGE="" # No target stage for Windows BINARY="rivet-$TARGET.exe" ;; *) @@ -31,8 +41,12 @@ case $TARGET in ;; esac -# Build docker image -DOCKER_BUILDKIT=1 docker build -f docker/toolchain/$DOCKERFILE -t rivet-cli-builder-$TARGET . +# Build docker image with target stage (if specified) +if [ -n "$TARGET_STAGE" ]; then + DOCKER_BUILDKIT=1 docker build --target $TARGET_STAGE -f docker/toolchain/$DOCKERFILE -t rivet-cli-builder-$TARGET . +else + DOCKER_BUILDKIT=1 docker build -f docker/toolchain/$DOCKERFILE -t rivet-cli-builder-$TARGET . +fi # Extract binary CONTAINER_ID=$(docker create rivet-cli-builder-$TARGET) @@ -45,4 +59,4 @@ if [[ ! "$BINARY" == *.exe ]]; then chmod +x dist/$BINARY fi -echo "Binary saved to: dist/$BINARY" +echo "Binary saved to: dist/$BINARY" \ No newline at end of file diff --git a/docker/toolchain/linux-aarch64.Dockerfile b/docker/toolchain/linux-aarch64.Dockerfile new file mode 100644 index 0000000000..ee3af327aa --- /dev/null +++ b/docker/toolchain/linux-aarch64.Dockerfile @@ -0,0 +1,58 @@ +# syntax=docker/dockerfile:1.4 +FROM rust:1.82.0 AS base + +# Install dependencies +RUN apt-get update && apt-get install -y \ + musl-tools \ + libssl-dev \ + pkg-config \ + protobuf-compiler \ + ca-certificates \ + git-lfs \ + musl-dev \ + && rm -rf /var/lib/apt/lists/* + +# Install musl targets +RUN rustup target add aarch64-unknown-linux-musl + +# Set environment variables +ENV CARGO_INCREMENTAL=0 \ + RUSTFLAGS="--cfg tokio_unstable" \ + CARGO_NET_GIT_FETCH_WITH_CLI=true + +# Set working directory +WORKDIR /build + +# Build for aarch64 +FROM base AS aarch64-builder + +# Set up OpenSSL for aarch64 musl target +ENV SSL_VER=1.1.1w +RUN wget https://www.openssl.org/source/openssl-$SSL_VER.tar.gz \ + && tar -xzf openssl-$SSL_VER.tar.gz \ + && cd openssl-$SSL_VER \ + && ./Configure no-shared no-async --prefix=/musl-aarch64 --openssldir=/musl-aarch64/ssl linux-aarch64 \ + && make -j$(nproc) \ + && make install_sw \ + && cd .. \ + && rm -rf openssl-$SSL_VER* + +# Configure OpenSSL env vars for the build +ENV OPENSSL_DIR=/musl-aarch64 \ + OPENSSL_INCLUDE_DIR=/musl-aarch64/include \ + OPENSSL_LIB_DIR=/musl-aarch64/lib \ + PKG_CONFIG_ALLOW_CROSS=1 + +# Copy the source code +COPY . . + +# Build for Linux with musl (static binary) - aarch64 +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/usr/local/cargo/git \ + --mount=type=cache,target=/build/target \ + cargo build --bin rivet --release --target aarch64-unknown-linux-musl -v && \ + mkdir -p /artifacts && \ + cp target/aarch64-unknown-linux-musl/release/rivet /artifacts/rivet-aarch64-unknown-linux-musl + +# Default command to show help +CMD ["ls", "-la", "/artifacts"] \ No newline at end of file diff --git a/docker/toolchain/linux.Dockerfile b/docker/toolchain/linux-x86_64.Dockerfile similarity index 81% rename from docker/toolchain/linux.Dockerfile rename to docker/toolchain/linux-x86_64.Dockerfile index 29b47b7941..cabae7299f 100644 --- a/docker/toolchain/linux.Dockerfile +++ b/docker/toolchain/linux-x86_64.Dockerfile @@ -1,5 +1,5 @@ # syntax=docker/dockerfile:1.4 -FROM rust:1.82.0 +FROM rust:1.82.0 AS base # Install dependencies RUN apt-get update && apt-get install -y \ @@ -12,10 +12,21 @@ RUN apt-get update && apt-get install -y \ musl-dev \ && rm -rf /var/lib/apt/lists/* -# Install musl target +# Install musl targets RUN rustup target add x86_64-unknown-linux-musl -# Set up OpenSSL for musl target +# Set environment variables +ENV CARGO_INCREMENTAL=0 \ + RUSTFLAGS="--cfg tokio_unstable" \ + CARGO_NET_GIT_FETCH_WITH_CLI=true + +# Set working directory +WORKDIR /build + +# Build for x86_64 +FROM base AS x86_64-builder + +# Set up OpenSSL for x86_64 musl target ENV SSL_VER=1.1.1w RUN wget https://www.openssl.org/source/openssl-$SSL_VER.tar.gz \ && tar -xzf openssl-$SSL_VER.tar.gz \ @@ -32,24 +43,16 @@ ENV OPENSSL_DIR=/musl \ OPENSSL_LIB_DIR=/musl/lib \ PKG_CONFIG_ALLOW_CROSS=1 -# Set environment variables -ENV CARGO_INCREMENTAL=0 \ - RUSTFLAGS="--cfg tokio_unstable" \ - CARGO_NET_GIT_FETCH_WITH_CLI=true - -# Set working directory -WORKDIR /build - -# Build CLI instructions +# Copy the source code COPY . . -# Build for Linux with musl (static binary) +# Build for Linux with musl (static binary) - x86_64 RUN --mount=type=cache,target=/usr/local/cargo/registry \ - --mount=type=cache,target=/usr/local/cargo/git \ + --mount=type=cache,target=/usr/local/cargo/git \ --mount=type=cache,target=/build/target \ cargo build --bin rivet --release --target x86_64-unknown-linux-musl -v && \ mkdir -p /artifacts && \ cp target/x86_64-unknown-linux-musl/release/rivet /artifacts/rivet-x86_64-unknown-linux-musl # Default command to show help -CMD ["ls", "-la", "/artifacts"] +CMD ["ls", "-la", "/artifacts"] \ No newline at end of file diff --git a/docker/toolchain/macos-aarch64.Dockerfile b/docker/toolchain/macos-aarch64.Dockerfile new file mode 100644 index 0000000000..956b369d49 --- /dev/null +++ b/docker/toolchain/macos-aarch64.Dockerfile @@ -0,0 +1,71 @@ +# syntax=docker/dockerfile:1.4 +FROM rust:1.82.0 AS base + +# Install dependencies +RUN apt-get update && apt-get install -y \ + git-lfs \ + protobuf-compiler \ + clang \ + cmake \ + patch \ + libxml2-dev \ + wget \ + xz-utils \ + curl \ + && rm -rf /var/lib/apt/lists/* + +# Install osxcross +RUN git config --global --add safe.directory '*' && \ + git clone https://github.com/tpoechtrager/osxcross /root/osxcross && \ + cd /root/osxcross && \ + wget -nc https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz && \ + mv MacOSX11.3.sdk.tar.xz tarballs/ && \ + UNATTENDED=yes OSX_VERSION_MIN=10.7 ./build.sh + +# Add osxcross to PATH +ENV PATH="/root/osxcross/target/bin:$PATH" + +# Common environment variables for cross-compilation +ENV MACOSX_DEPLOYMENT_TARGET=10.7 \ + # Skip aws-lc-rs with rustls certs config when building for macOS + RUSTFLAGS="--cfg tokio_unstable --cfg rustls_native_certs --cfg aws_lc_rs" \ + CARGO_FEATURE_RUSTLS_NATIVE_CERTS=0 \ + CARGO_RUSTLS_NATIVE_CERTS=0 \ + CARGO_INCREMENTAL=0 \ + CARGO_NET_GIT_FETCH_WITH_CLI=true + +# Set working directory +WORKDIR /build + +# Build for ARM64 macOS +FROM base AS aarch64-builder + +# Install macOS ARM64 target +RUN rustup target add aarch64-apple-darwin + +# Configure Cargo for cross-compilation (ARM64) +RUN mkdir -p /root/.cargo && \ + echo '\ +[target.aarch64-apple-darwin]\n\ +linker = "aarch64-apple-darwin20.4-clang"\n\ +ar = "aarch64-apple-darwin20.4-ar"\n\ +' > /root/.cargo/config.toml + +# Set environment variables for ARM64 cross-compilation +ENV CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER=aarch64-apple-darwin20.4-clang \ + CC_aarch64_apple_darwin=aarch64-apple-darwin20.4-clang \ + CXX_aarch64_apple_darwin=aarch64-apple-darwin20.4-clang++ + +# Copy the source code +COPY . . + +# Build for ARM64 macOS +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/usr/local/cargo/git \ + --mount=type=cache,target=/build/target \ + cargo build --bin rivet --release --target aarch64-apple-darwin && \ + mkdir -p /artifacts && \ + cp target/aarch64-apple-darwin/release/rivet /artifacts/rivet-aarch64-apple-darwin + +# Default command to show help +CMD ["ls", "-la", "/artifacts"] \ No newline at end of file diff --git a/docker/toolchain/macos.Dockerfile b/docker/toolchain/macos-x86_64.Dockerfile similarity index 64% rename from docker/toolchain/macos.Dockerfile rename to docker/toolchain/macos-x86_64.Dockerfile index 644dd92f19..3fd3c25368 100644 --- a/docker/toolchain/macos.Dockerfile +++ b/docker/toolchain/macos-x86_64.Dockerfile @@ -1,5 +1,5 @@ # syntax=docker/dockerfile:1.4 -FROM rust:1.82.0 +FROM rust:1.82.0 AS base # Install dependencies RUN apt-get update && apt-get install -y \ @@ -25,38 +25,36 @@ RUN git config --global --add safe.directory '*' && \ # Add osxcross to PATH ENV PATH="/root/osxcross/target/bin:$PATH" -# Install macOS target -RUN rustup target add x86_64-apple-darwin aarch64-apple-darwin +# Common environment variables for cross-compilation +ENV MACOSX_DEPLOYMENT_TARGET=10.7 \ + # Skip aws-lc-rs with rustls certs config when building for macOS + RUSTFLAGS="--cfg tokio_unstable --cfg rustls_native_certs --cfg aws_lc_rs" \ + CARGO_FEATURE_RUSTLS_NATIVE_CERTS=0 \ + CARGO_RUSTLS_NATIVE_CERTS=0 \ + CARGO_INCREMENTAL=0 \ + CARGO_NET_GIT_FETCH_WITH_CLI=true -# Configure Cargo for cross-compilation +# Set working directory +WORKDIR /build + +# Build for x86_64 macOS +FROM base AS x86_64-builder + +# Install macOS x86_64 target +RUN rustup target add x86_64-apple-darwin + +# Configure Cargo for cross-compilation (x86_64) RUN mkdir -p /root/.cargo && \ echo '\ [target.x86_64-apple-darwin]\n\ linker = "x86_64-apple-darwin20.4-clang"\n\ ar = "x86_64-apple-darwin20.4-ar"\n\ -\n\ -[target.aarch64-apple-darwin]\n\ -linker = "aarch64-apple-darwin20.4-clang"\n\ -ar = "aarch64-apple-darwin20.4-ar"\n\ ' > /root/.cargo/config.toml -# Set environment variables for cross-compilation +# Set environment variables for x86_64 cross-compilation ENV CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER=x86_64-apple-darwin20.4-clang \ - CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER=aarch64-apple-darwin20.4-clang \ CC_x86_64_apple_darwin=x86_64-apple-darwin20.4-clang \ - CXX_x86_64_apple_darwin=x86_64-apple-darwin20.4-clang++ \ - CC_aarch64_apple_darwin=aarch64-apple-darwin20.4-clang \ - CXX_aarch64_apple_darwin=aarch64-apple-darwin20.4-clang++ \ - MACOSX_DEPLOYMENT_TARGET=10.7 \ - # Skip aws-lc-rs with rustls certs config when building for macOS - RUSTFLAGS="--cfg tokio_unstable --cfg rustls_native_certs --cfg aws_lc_rs" \ - CARGO_FEATURE_RUSTLS_NATIVE_CERTS=0 \ - CARGO_RUSTLS_NATIVE_CERTS=0 \ - CARGO_INCREMENTAL=0 \ - CARGO_NET_GIT_FETCH_WITH_CLI=true - -# Set working directory -WORKDIR /build + CXX_x86_64_apple_darwin=x86_64-apple-darwin20.4-clang++ # Copy the source code COPY . . @@ -69,12 +67,5 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \ mkdir -p /artifacts && \ cp target/x86_64-apple-darwin/release/rivet /artifacts/rivet-x86_64-apple-darwin -# Build for ARM64 macOS -RUN --mount=type=cache,target=/usr/local/cargo/registry \ - --mount=type=cache,target=/usr/local/cargo/git \ - --mount=type=cache,target=/build/target \ - cargo build --bin rivet --release --target aarch64-apple-darwin && \ - cp target/aarch64-apple-darwin/release/rivet /artifacts/rivet-aarch64-apple-darwin - # Default command to show help -CMD ["ls", "-la", "/artifacts"] +CMD ["ls", "-la", "/artifacts"] \ No newline at end of file