-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup_rust.sh
More file actions
executable file
·64 lines (52 loc) · 1.82 KB
/
setup_rust.sh
File metadata and controls
executable file
·64 lines (52 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# setup_rust.sh - Install Rust and configure for cross-compilation
# Used by both Dockerfile (local) and GitHub Actions (CI)
set -e
CARGO_HOME="${CARGO_HOME:-$HOME/.cargo}"
MACOS_SDK="${MACOS_SDK:-/opt/macos-sdk/MacOSX.sdk}"
# Install Rust if not present (minimal profile to save space)
if ! command -v rustup &> /dev/null; then
curl -fsSL https://sh.rustup.rs -o /tmp/rustup.sh
sh /tmp/rustup.sh -y --default-toolchain stable --profile minimal
rm /tmp/rustup.sh
fi
# Ensure cargo is in PATH
export PATH="$CARGO_HOME/bin:$PATH"
# Add targets
rustup target add \
x86_64-unknown-linux-gnu \
aarch64-unknown-linux-gnu \
x86_64-pc-windows-gnu \
x86_64-apple-darwin \
aarch64-apple-darwin
# Install rustfmt
rustup component add rustfmt
# Configure Cargo linkers. For macOS targets, point zig cc at the macOS SDK
# via -isysroot so the linker can resolve frameworks (CoreFoundation etc.) and
# libiconv/libSystem stubs from the SDK.
mkdir -p "$CARGO_HOME"
cat > "$CARGO_HOME/config.toml" << EOF
[target.x86_64-apple-darwin]
linker = "zcc"
rustflags = [
"-C", "link-arg=-target", "-C", "link-arg=x86_64-macos",
"-C", "link-arg=-isysroot", "-C", "link-arg=${MACOS_SDK}",
"-C", "link-arg=-L${MACOS_SDK}/usr/lib",
"-C", "link-arg=-F${MACOS_SDK}/System/Library/Frameworks",
]
[target.aarch64-apple-darwin]
linker = "zcc"
rustflags = [
"-C", "link-arg=-target", "-C", "link-arg=aarch64-macos",
"-C", "link-arg=-isysroot", "-C", "link-arg=${MACOS_SDK}",
"-C", "link-arg=-L${MACOS_SDK}/usr/lib",
"-C", "link-arg=-F${MACOS_SDK}/System/Library/Frameworks",
]
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
[target.x86_64-unknown-linux-gnu]
linker = "x86_64-linux-gnu-gcc"
EOF
echo "Rust setup complete!"