Skip to content

Commit 6f45f25

Browse files
NathanFlurryMasterPtato
authored andcommitted
chore: add Linux ARM64 and Windows build targets
1 parent 65e7c70 commit 6f45f25

File tree

6 files changed

+195
-56
lines changed

6 files changed

+195
-56
lines changed

.github/workflows/release.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,18 @@ jobs:
9292
- platform: linux
9393
runner: [self-hosted, Linux, X64]
9494
target: x86_64-unknown-linux-musl
95-
# - platform: windows
96-
# runner: [self-hosted, Linux, X64]
97-
# target: x86_64-pc-windows-musl
95+
- platform: linux
96+
runner: [self-hosted, Linux, ARM64]
97+
target: aarch64-unknown-linux-musl
98+
- platform: windows
99+
runner: [self-hosted, Linux, X64]
100+
target: x86_64-pc-windows-gnu
98101
- platform: macos
99102
runner: [self-hosted, Linux, X64]
100103
target: x86_64-apple-darwin
101104
- platform: macos
102105
runner: [self-hosted, Linux, ARM64]
103106
target: aarch64-apple-darwin
104-
arch: arm64
105107
runs-on: ${{ matrix.runner }}
106108
steps:
107109
- uses: actions/checkout@v4

docker/toolchain/build.sh

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,32 @@ TARGET=${1:-x86_64-unknown-linux-musl}
77
case $TARGET in
88
x86_64-unknown-linux-musl)
99
echo "Building for Linux x86_64 platform"
10-
DOCKERFILE="linux.Dockerfile"
10+
DOCKERFILE="linux-x86_64.Dockerfile"
11+
TARGET_STAGE="x86_64-builder"
12+
BINARY="rivet-$TARGET"
13+
;;
14+
aarch64-unknown-linux-musl)
15+
echo "Building for Linux ARM64 platform"
16+
DOCKERFILE="linux-aarch64.Dockerfile"
17+
TARGET_STAGE="aarch64-builder"
1118
BINARY="rivet-$TARGET"
1219
;;
1320
aarch64-apple-darwin)
1421
echo "Building for macOS ARM64 platform"
15-
DOCKERFILE="macos.Dockerfile"
22+
DOCKERFILE="macos-aarch64.Dockerfile"
23+
TARGET_STAGE="aarch64-builder"
1624
BINARY="rivet-$TARGET"
1725
;;
1826
x86_64-apple-darwin)
1927
echo "Building for macOS x86_64 platform"
20-
DOCKERFILE="macos.Dockerfile"
28+
DOCKERFILE="macos-x86_64.Dockerfile"
29+
TARGET_STAGE="x86_64-builder"
2130
BINARY="rivet-$TARGET"
2231
;;
2332
x86_64-pc-windows-gnu)
2433
echo "Building for Windows platform"
2534
DOCKERFILE="windows.Dockerfile"
35+
TARGET_STAGE="" # No target stage for Windows
2636
BINARY="rivet-$TARGET.exe"
2737
;;
2838
*)
@@ -31,8 +41,12 @@ case $TARGET in
3141
;;
3242
esac
3343

34-
# Build docker image
35-
DOCKER_BUILDKIT=1 docker build -f docker/toolchain/$DOCKERFILE -t rivet-cli-builder-$TARGET .
44+
# Build docker image with target stage (if specified)
45+
if [ -n "$TARGET_STAGE" ]; then
46+
DOCKER_BUILDKIT=1 docker build --target $TARGET_STAGE -f docker/toolchain/$DOCKERFILE -t rivet-cli-builder-$TARGET .
47+
else
48+
DOCKER_BUILDKIT=1 docker build -f docker/toolchain/$DOCKERFILE -t rivet-cli-builder-$TARGET .
49+
fi
3650

3751
# Extract binary
3852
CONTAINER_ID=$(docker create rivet-cli-builder-$TARGET)
@@ -45,4 +59,4 @@ if [[ ! "$BINARY" == *.exe ]]; then
4559
chmod +x dist/$BINARY
4660
fi
4761

48-
echo "Binary saved to: dist/$BINARY"
62+
echo "Binary saved to: dist/$BINARY"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# syntax=docker/dockerfile:1.4
2+
FROM rust:1.82.0 AS base
3+
4+
# Install dependencies
5+
RUN apt-get update && apt-get install -y \
6+
musl-tools \
7+
libssl-dev \
8+
pkg-config \
9+
protobuf-compiler \
10+
ca-certificates \
11+
git-lfs \
12+
musl-dev \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
# Install musl targets
16+
RUN rustup target add aarch64-unknown-linux-musl
17+
18+
# Set environment variables
19+
ENV CARGO_INCREMENTAL=0 \
20+
RUSTFLAGS="--cfg tokio_unstable" \
21+
CARGO_NET_GIT_FETCH_WITH_CLI=true
22+
23+
# Set working directory
24+
WORKDIR /build
25+
26+
# Build for aarch64
27+
FROM base AS aarch64-builder
28+
29+
# Set up OpenSSL for aarch64 musl target
30+
ENV SSL_VER=1.1.1w
31+
RUN wget https://www.openssl.org/source/openssl-$SSL_VER.tar.gz \
32+
&& tar -xzf openssl-$SSL_VER.tar.gz \
33+
&& cd openssl-$SSL_VER \
34+
&& ./Configure no-shared no-async --prefix=/musl-aarch64 --openssldir=/musl-aarch64/ssl linux-aarch64 \
35+
&& make -j$(nproc) \
36+
&& make install_sw \
37+
&& cd .. \
38+
&& rm -rf openssl-$SSL_VER*
39+
40+
# Configure OpenSSL env vars for the build
41+
ENV OPENSSL_DIR=/musl-aarch64 \
42+
OPENSSL_INCLUDE_DIR=/musl-aarch64/include \
43+
OPENSSL_LIB_DIR=/musl-aarch64/lib \
44+
PKG_CONFIG_ALLOW_CROSS=1
45+
46+
# Copy the source code
47+
COPY . .
48+
49+
# Build for Linux with musl (static binary) - aarch64
50+
RUN --mount=type=cache,target=/usr/local/cargo/registry \
51+
--mount=type=cache,target=/usr/local/cargo/git \
52+
--mount=type=cache,target=/build/target \
53+
cargo build --bin rivet --release --target aarch64-unknown-linux-musl -v && \
54+
mkdir -p /artifacts && \
55+
cp target/aarch64-unknown-linux-musl/release/rivet /artifacts/rivet-aarch64-unknown-linux-musl
56+
57+
# Default command to show help
58+
CMD ["ls", "-la", "/artifacts"]
Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# syntax=docker/dockerfile:1.4
2-
FROM rust:1.82.0
2+
FROM rust:1.82.0 AS base
33

44
# Install dependencies
55
RUN apt-get update && apt-get install -y \
@@ -12,10 +12,21 @@ RUN apt-get update && apt-get install -y \
1212
musl-dev \
1313
&& rm -rf /var/lib/apt/lists/*
1414

15-
# Install musl target
15+
# Install musl targets
1616
RUN rustup target add x86_64-unknown-linux-musl
1717

18-
# Set up OpenSSL for musl target
18+
# Set environment variables
19+
ENV CARGO_INCREMENTAL=0 \
20+
RUSTFLAGS="--cfg tokio_unstable" \
21+
CARGO_NET_GIT_FETCH_WITH_CLI=true
22+
23+
# Set working directory
24+
WORKDIR /build
25+
26+
# Build for x86_64
27+
FROM base AS x86_64-builder
28+
29+
# Set up OpenSSL for x86_64 musl target
1930
ENV SSL_VER=1.1.1w
2031
RUN wget https://www.openssl.org/source/openssl-$SSL_VER.tar.gz \
2132
&& tar -xzf openssl-$SSL_VER.tar.gz \
@@ -32,24 +43,16 @@ ENV OPENSSL_DIR=/musl \
3243
OPENSSL_LIB_DIR=/musl/lib \
3344
PKG_CONFIG_ALLOW_CROSS=1
3445

35-
# Set environment variables
36-
ENV CARGO_INCREMENTAL=0 \
37-
RUSTFLAGS="--cfg tokio_unstable" \
38-
CARGO_NET_GIT_FETCH_WITH_CLI=true
39-
40-
# Set working directory
41-
WORKDIR /build
42-
43-
# Build CLI instructions
46+
# Copy the source code
4447
COPY . .
4548

46-
# Build for Linux with musl (static binary)
49+
# Build for Linux with musl (static binary) - x86_64
4750
RUN --mount=type=cache,target=/usr/local/cargo/registry \
48-
--mount=type=cache,target=/usr/local/cargo/git \
51+
--mount=type=cache,target=/usr/local/cargo/git \
4952
--mount=type=cache,target=/build/target \
5053
cargo build --bin rivet --release --target x86_64-unknown-linux-musl -v && \
5154
mkdir -p /artifacts && \
5255
cp target/x86_64-unknown-linux-musl/release/rivet /artifacts/rivet-x86_64-unknown-linux-musl
5356

5457
# Default command to show help
55-
CMD ["ls", "-la", "/artifacts"]
58+
CMD ["ls", "-la", "/artifacts"]
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# syntax=docker/dockerfile:1.4
2+
FROM rust:1.82.0 AS base
3+
4+
# Install dependencies
5+
RUN apt-get update && apt-get install -y \
6+
git-lfs \
7+
protobuf-compiler \
8+
clang \
9+
cmake \
10+
patch \
11+
libxml2-dev \
12+
wget \
13+
xz-utils \
14+
curl \
15+
&& rm -rf /var/lib/apt/lists/*
16+
17+
# Install osxcross
18+
RUN git config --global --add safe.directory '*' && \
19+
git clone https://github.com/tpoechtrager/osxcross /root/osxcross && \
20+
cd /root/osxcross && \
21+
wget -nc https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz && \
22+
mv MacOSX11.3.sdk.tar.xz tarballs/ && \
23+
UNATTENDED=yes OSX_VERSION_MIN=10.7 ./build.sh
24+
25+
# Add osxcross to PATH
26+
ENV PATH="/root/osxcross/target/bin:$PATH"
27+
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
36+
37+
# Set working directory
38+
WORKDIR /build
39+
40+
# Build for ARM64 macOS
41+
FROM base AS aarch64-builder
42+
43+
# Install macOS ARM64 target
44+
RUN rustup target add aarch64-apple-darwin
45+
46+
# Configure Cargo for cross-compilation (ARM64)
47+
RUN mkdir -p /root/.cargo && \
48+
echo '\
49+
[target.aarch64-apple-darwin]\n\
50+
linker = "aarch64-apple-darwin20.4-clang"\n\
51+
ar = "aarch64-apple-darwin20.4-ar"\n\
52+
' > /root/.cargo/config.toml
53+
54+
# Set environment variables for ARM64 cross-compilation
55+
ENV CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER=aarch64-apple-darwin20.4-clang \
56+
CC_aarch64_apple_darwin=aarch64-apple-darwin20.4-clang \
57+
CXX_aarch64_apple_darwin=aarch64-apple-darwin20.4-clang++
58+
59+
# Copy the source code
60+
COPY . .
61+
62+
# Build for ARM64 macOS
63+
RUN --mount=type=cache,target=/usr/local/cargo/registry \
64+
--mount=type=cache,target=/usr/local/cargo/git \
65+
--mount=type=cache,target=/build/target \
66+
cargo build --bin rivet --release --target aarch64-apple-darwin && \
67+
mkdir -p /artifacts && \
68+
cp target/aarch64-apple-darwin/release/rivet /artifacts/rivet-aarch64-apple-darwin
69+
70+
# Default command to show help
71+
CMD ["ls", "-la", "/artifacts"]
Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# syntax=docker/dockerfile:1.4
2-
FROM rust:1.82.0
2+
FROM rust:1.82.0 AS base
33

44
# Install dependencies
55
RUN apt-get update && apt-get install -y \
@@ -25,38 +25,36 @@ RUN git config --global --add safe.directory '*' && \
2525
# Add osxcross to PATH
2626
ENV 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)
3247
RUN mkdir -p /root/.cargo && \
3348
echo '\
3449
[target.x86_64-apple-darwin]\n\
3550
linker = "x86_64-apple-darwin20.4-clang"\n\
3651
ar = "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
4455
ENV 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
6260
COPY . .
@@ -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

Comments
 (0)