Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 20 additions & 6 deletions docker/toolchain/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
;;
*)
Expand All @@ -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)
Expand All @@ -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"
58 changes: 58 additions & 0 deletions docker/toolchain/linux-aarch64.Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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 \
Expand All @@ -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"]
71 changes: 71 additions & 0 deletions docker/toolchain/macos-aarch64.Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: MACOSX_DEPLOYMENT_TARGET=10.7 is very old and may not be appropriate for ARM64 builds which started with macOS 11.0

Suggested change
ENV MACOSX_DEPLOYMENT_TARGET=10.7 \
ENV MACOSX_DEPLOYMENT_TARGET=11.0 \

# 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"]
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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 . .
Expand All @@ -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"]
Loading