forked from heyito/ito
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-binaries.sh
More file actions
executable file
·173 lines (142 loc) · 5.55 KB
/
build-binaries.sh
File metadata and controls
executable file
·173 lines (142 loc) · 5.55 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
# Exit immediately if a command exits with a non-zero status.
set -e
# --- Color Definitions for pretty printing ---
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# --- Function Definitions ---
print_status() {
echo -e "${GREEN}==>${NC} $1"
}
print_info() {
echo -e "${BLUE}-->${NC} $1"
}
print_error() {
echo -e "${RED}Error:${NC} $1" >&2
}
# --- Build the entire native workspace ---
build_native_workspace() {
print_status "Building native workspace..."
# Change into the native workspace directory
cd "native"
# Check if we're compiling on a Windows machine
compiling_on_windows=false
if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]] || [[ "$OS" == "Windows_NT" ]]; then
compiling_on_windows=true
fi
# Install dependencies
print_info "Installing dependencies for workspace..."
cargo fetch
# --- macOS Build ---
if [ "$BUILD_MAC" = true ]; then
# Determine target architecture (default to arm64)
local mac_target="aarch64-apple-darwin"
local arch_name="Apple Silicon (arm64)"
if [[ " ${ARGS[*]} " == *" --x64 "* ]]; then
mac_target="x86_64-apple-darwin"
arch_name="Intel (x64)"
fi
print_info "Building macOS binaries for entire workspace ($arch_name)..."
cargo build --release --workspace --target "$mac_target"
# Create symlinks for electron-builder compatibility
if [ "$mac_target" = "aarch64-apple-darwin" ]; then
print_info "Creating symlink: arm64-apple-darwin -> aarch64-apple-darwin"
ln -sfn aarch64-apple-darwin target/arm64-apple-darwin
else
print_info "Creating symlink: x64-apple-darwin -> x86_64-apple-darwin"
ln -sfn x86_64-apple-darwin target/x64-apple-darwin
fi
fi
# --- Windows Build ---
if [ "$BUILD_WINDOWS" = true ]; then
print_info "Building Windows binaries for entire workspace..."
# Use GNU target (more reliable than MSVC)
if [ "$compiling_on_windows" = true ]; then
cargo +stable-x86_64-pc-windows-gnu build --release --workspace --target x86_64-pc-windows-gnu
else
# Cross-compile from macOS/Linux using default toolchain
cargo build --release --workspace --target x86_64-pc-windows-gnu
fi
fi
# Return to the project root
cd ..
}
# --- Main Script ---
print_status "Starting native module build process..."
# Check if rustup is installed before doing anything else
if ! command -v rustup &> /dev/null; then
print_error "rustup is not installed. Please install it first: https://rustup.rs/"
exit 1
fi
# Store all script arguments in an array
ARGS=("$@")
# Determine which platforms to build for
BUILD_MAC=false
if [[ " ${ARGS[*]} " == *" --mac "* ]] || [[ " ${ARGS[*]} " == *" --all "* ]]; then
BUILD_MAC=true
fi
BUILD_WINDOWS=false
if [[ " ${ARGS[*]} " == *" --windows "* ]] || [[ " ${ARGS[*]} " == *" --all "* ]]; then
BUILD_WINDOWS=true
fi
# If no platform flags are provided, print usage and exit.
if [ "$BUILD_MAC" = false ] && [ "$BUILD_WINDOWS" = false ]; then
print_error "No platform specified. Use --mac, --windows, or --all."
echo "Usage: $0 [--mac] [--windows] [--all] [--x64]"
echo ""
echo "Options:"
echo " --mac Build for macOS (defaults to arm64, use --x64 for Intel)"
echo " --windows Build for Windows"
echo " --all Build for all platforms"
echo " --x64 Build for x64/Intel instead of arm64 (macOS only)"
exit 1
fi
# Add required Rust targets
if [ "$BUILD_MAC" = true ]; then
# Determine which macOS target to add
if [[ " ${ARGS[*]} " == *" --x64 "* ]]; then
print_status "Adding macOS x64 target..."
rustup target add x86_64-apple-darwin
else
print_status "Adding macOS arm64 target..."
rustup target add aarch64-apple-darwin
fi
fi
if [ "$BUILD_WINDOWS" = true ]; then
print_status "Adding Windows target..."
# Use GNU target (more reliable than MSVC)
rustup target add x86_64-pc-windows-gnu
# Check if MinGW-w64 is available
# Check if we're compiling on a Windows machine
compiling_on_windows=false
if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]] || [[ "$OS" == "Windows_NT" ]]; then
compiling_on_windows=true
fi
if [ "$compiling_on_windows" = true ]; then
# On Windows, use GNU toolchain
print_info "Using GNU toolchain (requires MinGW-w64)"
elif [[ "$OSTYPE" == "darwin"* ]]; then
# On macOS, check if MinGW-w64 is installed via brew or other package managers
if command -v x86_64-w64-mingw32-gcc &> /dev/null; then
print_info "Using MinGW-w64 cross-compiler for Windows builds on macOS"
elif brew list mingw-w64 &> /dev/null; then
print_info "MinGW-w64 found via Homebrew, using for Windows cross-compilation"
else
print_error "Windows GNU target requires MinGW-w64 toolchain. Install with: brew install mingw-w64"
exit 1
fi
else
# On Linux, check if MinGW-w64 is installed
if command -v x86_64-w64-mingw32-gcc &> /dev/null; then
print_info "Using MinGW-w64 cross-compiler for Windows builds on Linux"
else
print_error "Windows GNU target requires MinGW-w64 toolchain. Install with: sudo apt-get install mingw-w64"
exit 1
fi
fi
fi
# --- Build the native workspace ---
build_native_workspace
print_status "Native workspace build completed successfully!"