@@ -27,14 +27,16 @@ if [ $# -eq 0 ]; then
2727 echo " Usage: $0 <target>"
2828 echo " "
2929 echo " Available targets:"
30- echo " x86_64-unknown-linux-gnu - Linux x64"
31- echo " aarch64-unknown-linux-gnu - Linux ARM64"
32- echo " x86_64-apple-darwin - macOS x64 (Intel)"
33- echo " aarch64-apple-darwin - macOS ARM64 (Apple Silicon)"
34- echo " x86_64-pc-windows-gnu - Windows x64"
35- echo " aarch64-linux-android - Android ARM64"
36- echo " armv7-linux-androideabi - Android ARMv7"
37- echo " thumbv7em-none-eabihf - ARM Cortex-M4 (Embedded)"
30+ echo " x86_64-unknown-linux-gnu - Linux x64"
31+ echo " aarch64-unknown-linux-gnu - Linux ARM64"
32+ echo " x86_64-apple-darwin - macOS x64 (Intel)"
33+ echo " aarch64-apple-darwin - macOS ARM64 (Apple Silicon)"
34+ echo " x86_64-pc-windows-gnu - Windows x64"
35+ echo " armv7-unknown-linux-gnueabihf - Raspberry Pi ARMv7"
36+ echo " aarch64-linux-android - Android ARM64"
37+ echo " armv7-linux-androideabi - Android ARMv7"
38+ echo " xtensa-esp32-espidf - ESP32"
39+ echo " thumbv7em-none-eabihf - Arduino ARM Cortex-M4"
3840 exit 1
3941fi
4042
@@ -43,9 +45,37 @@ TARGET=$1
4345print_status " Building MetaMesh for target: $TARGET "
4446echo " =========================================="
4547
46- # Install cross tool if needed for problematic targets
48+ # Install cross tool if needed for cross-compilation targets
4749case " $TARGET " in
48- " aarch64-unknown-linux-gnu" |" aarch64-linux-android" |" armv7-linux-androideabi" |" thumbv7em-none-eabihf" )
50+ " x86_64-apple-darwin" |" aarch64-apple-darwin" )
51+ # Native macOS builds - no cross needed if on macOS
52+ if [[ " $OSTYPE " != " darwin" * ]]; then
53+ print_error " macOS targets can only be built on macOS"
54+ exit 1
55+ fi
56+ ;;
57+ " x86_64-unknown-linux-gnu" )
58+ # Native Linux build - use cross if not on Linux
59+ if [[ " $OSTYPE " != " linux-gnu" * ]]; then
60+ if ! command -v cross & > /dev/null; then
61+ print_status " Installing cross tool for cross-compilation..."
62+ cargo install cross --git https://github.com/cross-rs/cross
63+ print_success " Cross tool installed"
64+ fi
65+ fi
66+ ;;
67+ " x86_64-pc-windows-gnu" )
68+ # Windows build - use cross if not on Windows
69+ if [[ " $OSTYPE " != " msys" && " $OSTYPE " != " cygwin" ]]; then
70+ if ! command -v cross & > /dev/null; then
71+ print_status " Installing cross tool for cross-compilation..."
72+ cargo install cross --git https://github.com/cross-rs/cross
73+ print_success " Cross tool installed"
74+ fi
75+ fi
76+ ;;
77+ * )
78+ # All other targets need cross
4979 if ! command -v cross & > /dev/null; then
5080 print_status " Installing cross tool for cross-compilation..."
5181 cargo install cross --git https://github.com/cross-rs/cross
6696start_time=$( date +%s)
6797print_status " Starting build..."
6898
69- # Determine build method based on target
99+ # Determine build method based on target and host OS
70100build_success=false
71101
72102case " $TARGET " in
73- " aarch64-unknown-linux-gnu " |" aarch64-linux-android " | " armv7-linux-androideabi " | " thumbv7em-none-eabihf " )
74- # Use cross for problematic cross-compilation targets
75- print_status " Using cross tool for $TARGET "
76- if cross build --release --target " $TARGET " --bin metamesh-daemon --bin metamesh-client -v 2>&1 | while IFS= read -r line; do
77- # Filter and format cross output
103+ " x86_64-apple-darwin " |" aarch64-apple-darwin " )
104+ # Native macOS builds
105+ print_status " Using cargo for native macOS target: $TARGET "
106+ if cargo build --release --target " $TARGET " --bin metamesh-daemon --bin metamesh-client -v 2>&1 | while IFS= read -r line; do
107+ # Filter and format cargo output
78108 if [[ " $line " == * " Compiling" * ]]; then
79109 echo -e " ${YELLOW} 📦${NC} $line "
80110 elif [[ " $line " == * " Finished" * ]]; then
@@ -90,11 +120,87 @@ case "$TARGET" in
90120 build_success=true
91121 fi
92122 ;;
123+ " x86_64-unknown-linux-gnu" )
124+ # Linux build - native if on Linux, cross otherwise
125+ if [[ " $OSTYPE " == " linux-gnu" * ]]; then
126+ print_status " Using cargo for native Linux target: $TARGET "
127+ if cargo build --release --target " $TARGET " --bin metamesh-daemon --bin metamesh-client -v 2>&1 | while IFS= read -r line; do
128+ if [[ " $line " == * " Compiling" * ]]; then
129+ echo -e " ${YELLOW} 📦${NC} $line "
130+ elif [[ " $line " == * " Finished" * ]]; then
131+ echo -e " ${GREEN} ✅${NC} $line "
132+ elif [[ " $line " == * " error" * ]]; then
133+ echo -e " ${RED} ❌${NC} $line "
134+ elif [[ " $line " == * " warning" * ]]; then
135+ echo -e " ${YELLOW} ⚠️${NC} $line "
136+ else
137+ echo " $line "
138+ fi
139+ done ; then
140+ build_success=true
141+ fi
142+ else
143+ print_status " Using cross for Linux target: $TARGET "
144+ if cross build --release --target " $TARGET " --bin metamesh-daemon --bin metamesh-client -v 2>&1 | while IFS= read -r line; do
145+ if [[ " $line " == * " Compiling" * ]]; then
146+ echo -e " ${YELLOW} 📦${NC} $line "
147+ elif [[ " $line " == * " Finished" * ]]; then
148+ echo -e " ${GREEN} ✅${NC} $line "
149+ elif [[ " $line " == * " error" * ]]; then
150+ echo -e " ${RED} ❌${NC} $line "
151+ elif [[ " $line " == * " warning" * ]]; then
152+ echo -e " ${YELLOW} ⚠️${NC} $line "
153+ else
154+ echo " $line "
155+ fi
156+ done ; then
157+ build_success=true
158+ fi
159+ fi
160+ ;;
161+ " x86_64-pc-windows-gnu" )
162+ # Windows build - native if on Windows, cross otherwise
163+ if [[ " $OSTYPE " == " msys" || " $OSTYPE " == " cygwin" ]]; then
164+ print_status " Using cargo for native Windows target: $TARGET "
165+ if cargo build --release --target " $TARGET " --bin metamesh-daemon --bin metamesh-client -v 2>&1 | while IFS= read -r line; do
166+ if [[ " $line " == * " Compiling" * ]]; then
167+ echo -e " ${YELLOW} 📦${NC} $line "
168+ elif [[ " $line " == * " Finished" * ]]; then
169+ echo -e " ${GREEN} ✅${NC} $line "
170+ elif [[ " $line " == * " error" * ]]; then
171+ echo -e " ${RED} ❌${NC} $line "
172+ elif [[ " $line " == * " warning" * ]]; then
173+ echo -e " ${YELLOW} ⚠️${NC} $line "
174+ else
175+ echo " $line "
176+ fi
177+ done ; then
178+ build_success=true
179+ fi
180+ else
181+ print_status " Using cross for Windows target: $TARGET "
182+ if cross build --release --target " $TARGET " --bin metamesh-daemon --bin metamesh-client -v 2>&1 | while IFS= read -r line; do
183+ if [[ " $line " == * " Compiling" * ]]; then
184+ echo -e " ${YELLOW} 📦${NC} $line "
185+ elif [[ " $line " == * " Finished" * ]]; then
186+ echo -e " ${GREEN} ✅${NC} $line "
187+ elif [[ " $line " == * " error" * ]]; then
188+ echo -e " ${RED} ❌${NC} $line "
189+ elif [[ " $line " == * " warning" * ]]; then
190+ echo -e " ${YELLOW} ⚠️${NC} $line "
191+ else
192+ echo " $line "
193+ fi
194+ done ; then
195+ build_success=true
196+ fi
197+ fi
198+ ;;
93199 * )
94- # Use regular cargo for native and simple targets
95- print_status " Using cargo for $TARGET "
96- if cargo build --release --target " $TARGET " --bin metamesh-daemon --bin metamesh-client -v 2>&1 | while IFS= read -r line; do
97- # Filter and format cargo output
200+ # Use cross for all other cross-compilation targets
201+ print_status " Using cross tool for $TARGET "
202+ if cross build --release --target " $TARGET " --bin metamesh-daemon --bin metamesh-client -v 2>&1 | while IFS= read -r line; do
203+ # Filter and format cross output
98204 if [[ " $line " == * " Compiling" * ]]; then
99205 echo -e " ${YELLOW} 📦${NC} $line "
100206 elif [[ " $line " == * " Finished" * ]]; then
0 commit comments