-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_macos_crosscompile.sh
More file actions
executable file
·84 lines (71 loc) · 2.3 KB
/
setup_macos_crosscompile.sh
File metadata and controls
executable file
·84 lines (71 loc) · 2.3 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# Setup macOS cross-compilation on Linux
# This script sets up osxcross for building macOS binaries from Linux
set -e
echo "🍎 Setting up macOS cross-compilation environment..."
echo ""
# 1. Install dependencies
echo "📦 Installing dependencies..."
if command -v apt &> /dev/null; then
sudo apt install -y clang cmake libxml2-dev libssl-dev zlib1g-dev
elif command -v dnf &> /dev/null; then
sudo dnf install -y clang cmake libxml2-devel openssl-devel zlib-devel
elif command -v pacman &> /dev/null; then
sudo pacman -S --needed clang cmake libxml2 openssl zlib
fi
# 2. Clone osxcross
if [ ! -d "$HOME/osxcross" ]; then
echo "📥 Cloning osxcross..."
cd ~
git clone https://github.com/tpoechtrager/osxcross.git
else
echo "✓ osxcross already cloned"
fi
cd ~/osxcross
# 3. Download macOS SDK
echo ""
echo "⚠️ IMPORTANT: You need a macOS SDK!"
echo "Download MacOSX SDK from:"
echo " https://github.com/joseluisq/macosx-sdks/releases"
echo ""
echo "Recommended: MacOSX12.3.sdk.tar.xz or MacOSX13.3.sdk.tar.xz"
echo ""
echo "Place the SDK file in: ~/osxcross/tarballs/"
echo ""
read -p "Have you downloaded and placed the SDK? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Please download the SDK first, then run this script again."
exit 1
fi
# 4. Build osxcross
echo "🔨 Building osxcross toolchain..."
./build.sh
# 5. Add to PATH (add to ~/.bashrc or ~/.zshrc)
echo ""
echo "✅ osxcross built successfully!"
echo ""
echo "Add this to your ~/.bashrc or ~/.zshrc:"
echo 'export PATH="$HOME/osxcross/target/bin:$PATH"'
echo ""
# 6. Setup Cargo config for macOS targets
echo "📝 Creating Cargo config for macOS cross-compilation..."
mkdir -p ~/.cargo
cat >> ~/.cargo/config.toml << 'EOF'
# macOS cross-compilation (osxcross)
[target.x86_64-apple-darwin]
linker = "x86_64-apple-darwin20.4-clang"
ar = "x86_64-apple-darwin20.4-ar"
[target.aarch64-apple-darwin]
linker = "aarch64-apple-darwin20.4-clang"
ar = "aarch64-apple-darwin20.4-ar"
EOF
echo ""
echo "✨ Setup complete!"
echo ""
echo "Next steps:"
echo " 1. Add osxcross to PATH (see above)"
echo " 2. Restart your terminal or run: source ~/.bashrc"
echo " 3. Add Rust targets: rustup target add x86_64-apple-darwin aarch64-apple-darwin"
echo " 4. Build: cargo build --release --target x86_64-apple-darwin"
echo ""