Skip to content

Commit d7e0071

Browse files
committed
chore: add standalone toolchain build scripts
1 parent 39220d3 commit d7e0071

File tree

11 files changed

+2291
-1788
lines changed

11 files changed

+2291
-1788
lines changed

.github/workflows/release.yaml

Lines changed: 32 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -86,140 +86,64 @@ 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-musl
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-musl
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
179-
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 }}
117+
# Use Docker BuildKit
118+
export DOCKER_BUILDKIT=1
119+
120+
# Build the binary using our Dockerfile
121+
ARCH_ARG="${{ matrix.arch }}"
122+
docker/toolchain/build.sh ${{ matrix.target }}
123+
124+
# Make sure dist directory exists and binary is there
125+
ls -la dist/
203126
204127
- name: Upload artifacts
205128
env:
206129
AWS_ACCESS_KEY_ID: ${{ secrets.R2_RELEASES_ACCESS_KEY_ID }}
207130
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_RELEASES_SECRET_ACCESS_KEY }}
208131
run: |
132+
# Install dependencies for AWS CLI
209133
apt-get update
210-
apt-get install -y awscli
134+
apt-get install -y unzip curl
135+
136+
# Install AWS CLI
137+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
138+
unzip awscliv2.zip
139+
./aws/install
211140
212141
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
142+
BINARY_PATH="dist/rivet-${{ matrix.suffix }}"
219143
220144
aws s3 cp \
221145
"${BINARY_PATH}" \
222-
"s3://rivet/${COMMIT_SHA_SHORT}/${BINARY_NAME}" \
146+
"s3://rivet/${COMMIT_SHA_SHORT}/rivet-${{ matrix.suffix }}" \
223147
--region auto \
224148
--endpoint-url https://2a94c6a0ced8d35ea63cddc86c2681e7.r2.cloudflarestorage.com/rivet-releases
225149
@@ -253,12 +177,6 @@ jobs:
253177
apt-get install git-lfs
254178
git lfs pull
255179
256-
- uses: actions/setup-node@v4
257-
with:
258-
node-version: 20
259-
260-
- run: corepack enable
261-
262180
- name: Set outputs
263181
id: vars
264182
run: echo "sha_short=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
@@ -394,4 +312,3 @@ jobs:
394312
else
395313
./scripts/release/main.ts --version "${{ github.event.inputs.version }}" --no-latest --completeCi
396314
fi
397-

Cargo.lock

Lines changed: 18 additions & 6 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_64-unknown-linux-gnu && \
93+
cp target/x86_64-pc-windows-gnu/release/rivet.exe /artifacts/rivet-x86_64-pc-windows-gnu && \
94+
cp target/x86_64-apple-darwin/release/rivet /artifacts/rivet-x86_64-apple-darwin && \
95+
cp target/aarch64-apple-darwin/release/rivet /artifacts/rivet-aarch64-apple-darwin
96+
97+
# Default command to show help
98+
CMD ["ls", "-la", "/artifacts"]

0 commit comments

Comments
 (0)