Skip to content

Commit d341e1a

Browse files
committed
chore: add standalone toolchain build scripts
1 parent 4648476 commit d341e1a

File tree

10 files changed

+422
-112
lines changed

10 files changed

+422
-112
lines changed

.github/workflows/release.yaml

Lines changed: 34 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -86,140 +86,66 @@ jobs:
8686
strategy:
8787
matrix:
8888
include:
89-
- platform: x86_64-unknown-linux-gnu
89+
- platform: linux
9090
runner: [self-hosted, Linux, X64]
9191
suffix: x86-linux
92-
# - platform: x86_64-pc-windows-gnu
92+
target: x86_64-unknown-linux-gnu
93+
# - platform: windows
9394
# runner: [self-hosted, Linux, X64]
94-
# suffix: x86-windows
95-
- platform: x86_64-apple-darwin
95+
# suffix: x86-windows.exe
96+
# target: x86_64-pc-windows-gnu
97+
- platform: macos
9698
runner: [self-hosted, Linux, X64]
9799
suffix: x86-mac
98-
- platform: aarch64-apple-darwin
100+
target: x86_64-apple-darwin
101+
- platform: macos
99102
runner: [self-hosted, Linux, ARM64]
100103
suffix: aarch64-mac
104+
target: aarch64-apple-darwin
105+
arch: arm64
101106
runs-on: ${{ matrix.runner }}
102-
container:
103-
image: rust:1.82.0
104107
steps:
105108
- uses: actions/checkout@v4
106-
107-
# Required for running in Docker
108-
- name: Git LFS Pull
109-
run: |
110-
apt-get update
111-
apt-get install git-lfs
112-
git lfs pull
113-
114-
- uses: actions/setup-node@v4
115109
with:
116-
node-version: 20
117-
118-
- run: corepack enable
110+
lfs: 'true'
119111

120-
- name: Build
121-
env:
122-
# Expose correct target since we're building cross-platform
123-
OVERRIDE_TARGET: ${{ matrix.platform }}
124-
125-
# Expose env
126-
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER: x86_64-linux-gnu-gcc
127-
CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER: x86_64-apple-darwin20.4-clang
128-
CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER: aarch64-apple-darwin20.4-clang
129-
CC_x86_64_apple_darwin: x86_64-apple-darwin20.4-clang
130-
CXX_x86_64_apple_darwin: x86_64-apple-darwin20.4-clang++
131-
CC_aarch64_apple_darwin: aarch64-apple-darwin20.4-clang
132-
CXX_aarch64_apple_darwin: aarch64-apple-darwin20.4-clang++
133-
MACOSX_DEPLOYMENT_TARGET: "10.7"
134-
# Use RUSTFLAGS to skip building aws-lc-rs when targeting macOS
135-
# CARGO_FEATURE_RUSTLS_NATIVE_CERTS: 0
136-
# CARGO_RUSTLS_NATIVE_CERTS: 0
137-
# RUSTFLAGS: "--cfg tokio_unstable ${{ contains(matrix.platform, 'apple-darwin') && '--cfg tokio_unstable --cfg rustls_native_certs --cfg aws_lc_rs' || '' }}"
138-
139-
# Expose token for pulling GH artifacts
140-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
112+
- name: Set up Docker Buildx
113+
uses: docker/setup-buildx-action@v3
141114

142-
# Pull via Git CLI to improve reliability in CI
143-
ENV CARGO_NET_GIT_FETCH_WITH_CLI: "true"
115+
- name: Build using toolchain Dockerfile
144116
run: |
145-
# Install required components for each platform
146-
apt-get update
147-
if [[ "${{ matrix.platform }}" == "x86_64-pc-windows-gnu" ]]; then
148-
echo "Installing Windows components"
149-
150-
apt-get install -y gcc-mingw-w64-x86-64
151-
elif [[ "${{ matrix.platform }}" == "x86_64-unknown-linux-gnu" ]]; then
152-
echo "Installing Linux components"
153-
154-
apt-get install -y gcc-x86-64-linux-gnu libc6-dev-amd64-cross
155-
elif [[ "${{ matrix.platform }}" == "x86_64-apple-darwin" || "${{ matrix.platform }}" == "aarch64-apple-darwin" ]]; then
156-
echo "Installing macOS components"
157-
158-
apt-get install -y clang cmake patch libxml2-dev wget xz-utils curl
159-
160-
# Install osxcross
161-
git config --global --add safe.directory '*'
162-
git clone https://github.com/tpoechtrager/osxcross /root/osxcross
163-
(
164-
cd /root/osxcross
165-
wget -nc https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz
166-
mv MacOSX11.3.sdk.tar.xz tarballs/
167-
UNATTENDED=yes OSX_VERSION_MIN=10.7 ./build.sh
168-
)
169-
170-
# Add osxcross to PATH permanently
171-
echo 'export PATH="/root/osxcross/target/bin:$PATH"' >> ~/.bashrc
172-
export PATH="/root/osxcross/target/bin:$PATH"
173-
174-
# Verify compiler installation
175-
echo 'clang path:'
176-
which x86_64-apple-darwin20.4-clang
177-
echo 'clang version:'
178-
x86_64-apple-darwin20.4-clang --version
117+
# Use Docker BuildKit
118+
export DOCKER_BUILDKIT=1
119+
120+
# Build the binary using our Dockerfile
121+
ARCH_ARG="${{ matrix.arch }}"
122+
if [ -n "$ARCH_ARG" ]; then
123+
# For ARM64 macOS
124+
docker/toolchain/build.sh ${{ matrix.platform }} $ARCH_ARG
125+
else
126+
# For other platforms
127+
docker/toolchain/build.sh ${{ matrix.platform }}
179128
fi
180-
181-
# Install targets
182-
rustup target add ${{ matrix.platform }}
183-
184-
mkdir -p /root/.cargo && \
185-
echo '\
186-
[target.x86_64-unknown-linux-gnu]\n\
187-
linker = "x86_64-linux-gnu-gcc"\n\
188-
\n\
189-
[target.x86_64-pc-windows-gnu]\n\
190-
linker = "x86_64-w64-mingw32-gcc"\n\
191-
\n\
192-
[target.x86_64-apple-darwin]\n\
193-
linker = "x86_64-apple-darwin20.4-clang"\n\
194-
ar = "x86_64-apple-darwin20.4-ar"\n\
195-
\n\
196-
[target.aarch64-apple-darwin]\n\
197-
linker = "aarch64-apple-darwin20.4-clang"\n\
198-
ar = "aarch64-apple-darwin20.4-ar"\n\
199-
' > /root/.cargo/config.toml
200-
201-
# Build
202-
cargo build --bin rivet --release --target ${{ matrix.platform }}
129+
130+
# Make sure dist directory exists and binary is there
131+
ls -la dist/
203132
204133
- name: Upload artifacts
205134
env:
206135
AWS_ACCESS_KEY_ID: ${{ secrets.R2_RELEASES_ACCESS_KEY_ID }}
207136
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_RELEASES_SECRET_ACCESS_KEY }}
208137
run: |
209-
apt-get update
210-
apt-get install -y awscli
138+
# Install AWS CLI
139+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
140+
unzip awscliv2.zip
141+
./aws/install
211142
212143
COMMIT_SHA_SHORT="${GITHUB_SHA::7}"
213-
BINARY_PATH="target/${{ matrix.platform }}/release/rivet"
214-
BINARY_NAME="rivet-${{ matrix.suffix }}"
215-
if [[ "${{ matrix.platform }}" == "x86_64-pc-windows-gnu" ]]; then
216-
BINARY_PATH="${BINARY_PATH}.exe"
217-
BINARY_NAME="${BINARY_NAME}.exe"
218-
fi
144+
BINARY_PATH="dist/rivet-${{ matrix.suffix }}"
219145
220146
aws s3 cp \
221147
"${BINARY_PATH}" \
222-
"s3://rivet/${COMMIT_SHA_SHORT}/${BINARY_NAME}" \
148+
"s3://rivet/${COMMIT_SHA_SHORT}/rivet-${{ matrix.suffix }}" \
223149
--region auto \
224150
--endpoint-url https://2a94c6a0ced8d35ea63cddc86c2681e7.r2.cloudflarestorage.com/rivet-releases
225151
@@ -394,4 +320,3 @@ jobs:
394320
else
395321
./scripts/release/main.ts --version "${{ github.event.inputs.version }}" --no-latest --completeCi
396322
fi
397-

Cargo.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker/toolchain/Dockerfile

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
FROM rust:1.82.0
2+
3+
# Install dependencies for cross-compilation
4+
RUN apt-get update && apt-get install -y \
5+
gcc-x86_64-linux-gnu \
6+
libc6-dev-amd64-cross \
7+
gcc-mingw-w64-x86-64 \
8+
clang \
9+
cmake \
10+
patch \
11+
libxml2-dev \
12+
wget \
13+
xz-utils \
14+
curl \
15+
git-lfs \
16+
awscli \
17+
libssl-dev \
18+
pkg-config \
19+
protobuf-compiler \
20+
ca-certificates \
21+
&& rm -rf /var/lib/apt/lists/*
22+
23+
# Install FoundationDB client
24+
RUN curl -Lf -o /usr/lib/libfdb_c.so "https://github.com/apple/foundationdb/releases/download/7.1.60/libfdb_c.x86_64.so"
25+
26+
# Install macOS cross-compilation tools (osxcross)
27+
RUN git config --global --add safe.directory '*' && \
28+
git clone https://github.com/tpoechtrager/osxcross /root/osxcross && \
29+
cd /root/osxcross && \
30+
wget -nc https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz && \
31+
mv MacOSX11.3.sdk.tar.xz tarballs/ && \
32+
UNATTENDED=yes OSX_VERSION_MIN=10.7 ./build.sh && \
33+
echo 'export PATH="/root/osxcross/target/bin:$PATH"' >> ~/.bashrc
34+
35+
# Add osxcross to PATH
36+
ENV PATH="/root/osxcross/target/bin:$PATH"
37+
38+
# Install Rust targets
39+
RUN rustup target add x86_64-unknown-linux-gnu && \
40+
rustup target add x86_64-pc-windows-gnu && \
41+
rustup target add x86_64-apple-darwin && \
42+
rustup target add aarch64-apple-darwin
43+
44+
# Configure Cargo for cross-compilation
45+
RUN mkdir -p /root/.cargo && \
46+
echo '\
47+
[target.x86_64-unknown-linux-gnu]\n\
48+
linker = "x86_64-linux-gnu-gcc"\n\
49+
\n\
50+
[target.x86_64-pc-windows-gnu]\n\
51+
linker = "x86_64-w64-mingw32-gcc"\n\
52+
\n\
53+
[target.x86_64-apple-darwin]\n\
54+
linker = "x86_64-apple-darwin20.4-clang"\n\
55+
ar = "x86_64-apple-darwin20.4-ar"\n\
56+
\n\
57+
[target.aarch64-apple-darwin]\n\
58+
linker = "aarch64-apple-darwin20.4-clang"\n\
59+
ar = "aarch64-apple-darwin20.4-ar"\n\
60+
' > /root/.cargo/config.toml
61+
62+
# Set environment variables for cross-compilation
63+
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc \
64+
CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER=x86_64-apple-darwin20.4-clang \
65+
CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER=aarch64-apple-darwin20.4-clang \
66+
CC_x86_64_apple_darwin=x86_64-apple-darwin20.4-clang \
67+
CXX_x86_64_apple_darwin=x86_64-apple-darwin20.4-clang++ \
68+
CC_aarch64_apple_darwin=aarch64-apple-darwin20.4-clang \
69+
CXX_aarch64_apple_darwin=aarch64-apple-darwin20.4-clang++ \
70+
MACOSX_DEPLOYMENT_TARGET=10.7 \
71+
CARGO_INCREMENTAL=0 \
72+
RUSTFLAGS="--cfg tokio_unstable" \
73+
CARGO_NET_GIT_FETCH_WITH_CLI=true
74+
75+
# Set working directory
76+
WORKDIR /build
77+
78+
# Build CLI instructions
79+
COPY . .
80+
81+
# Build for all platforms by default
82+
ARG PLATFORMS="x86_64-unknown-linux-gnu x86_64-pc-windows-gnu x86_64-apple-darwin aarch64-apple-darwin"
83+
84+
# Build the CLI for all platforms
85+
RUN for platform in ${PLATFORMS}; do \
86+
echo "Building for $platform..." && \
87+
cargo build --bin rivet --release --target $platform; \
88+
done
89+
90+
# Create directory for finished binaries
91+
RUN mkdir -p /artifacts && \
92+
cp target/x86_64-unknown-linux-gnu/release/rivet /artifacts/rivet-x86-linux && \
93+
cp target/x86_64-pc-windows-gnu/release/rivet.exe /artifacts/rivet-x86-windows.exe && \
94+
cp target/x86_64-apple-darwin/release/rivet /artifacts/rivet-x86-mac && \
95+
cp target/aarch64-apple-darwin/release/rivet /artifacts/rivet-aarch64-mac
96+
97+
# Default command to show help
98+
CMD ["ls", "-la", "/artifacts"]

docker/toolchain/build.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Default to Linux if no platform specified
5+
PLATFORM=${1:-linux}
6+
ARCH=${2:-}
7+
8+
case $PLATFORM in
9+
linux)
10+
echo "Building for Linux platform"
11+
DOCKERFILE="linux.Dockerfile"
12+
BINARY="rivet-x86-linux"
13+
;;
14+
macos)
15+
if [ "$ARCH" == "arm64" ] || [ "$ARCH" == "aarch64" ]; then
16+
echo "Building for macOS ARM64 platform"
17+
DOCKERFILE="macos.Dockerfile"
18+
BINARY="rivet-aarch64-mac"
19+
else
20+
echo "Building for macOS x86_64 platform"
21+
DOCKERFILE="macos.Dockerfile"
22+
BINARY="rivet-x86-mac"
23+
fi
24+
;;
25+
windows)
26+
echo "Building for Windows platform"
27+
DOCKERFILE="windows.Dockerfile"
28+
BINARY="rivet-x86-windows.exe"
29+
;;
30+
*)
31+
echo "Unsupported platform: $PLATFORM"
32+
echo "Usage: $0 [linux|macos|windows] [arch]"
33+
echo " For macOS, specify 'arm64' as second parameter for ARM64 build"
34+
exit 1
35+
;;
36+
esac
37+
38+
# Build docker image
39+
DOCKER_BUILDKIT=1 docker build -f docker/toolchain/$DOCKERFILE -t rivet-cli-builder-$PLATFORM .
40+
41+
# Extract binary
42+
CONTAINER_ID=$(docker create rivet-cli-builder-$PLATFORM)
43+
mkdir -p dist
44+
docker cp "$CONTAINER_ID:/artifacts/$BINARY" dist/
45+
docker rm "$CONTAINER_ID"
46+
47+
# Make binary executable (skip for Windows .exe files)
48+
if [[ ! "$BINARY" == *.exe ]]; then
49+
chmod +x dist/$BINARY
50+
fi
51+
52+
echo "Binary saved to: dist/$BINARY"

0 commit comments

Comments
 (0)