forked from Windsander/ADI-Stable-Diffusion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_build.sh
244 lines (214 loc) · 6.96 KB
/
auto_build.sh
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/bin/bash
# Default configuration
DEFAULT_BUILD_TYPE=debug
DEFAULT_CMAKE="cmake"
DEFAULT_NINJA="ninja"
DEFAULT_JOBS=4
DEFAULT_ANDROID_VER=21 # env used
DEFAULT_CONFIRM_OPTION="-n" # Default confirmation option
# Function: Show help message
show_help() {
echo "Usage: $0 [options]"
echo "Options:"
echo " --platform PLATFORM Target platform (e.g., android, linux, macos, windows)"
echo " --arch-abi ARCH Target ABI (e.g., x86_64, aarch64, arm64, x86, arm64-v8a, armeabi-v7a)"
echo " --build-type TYPE Build type (Debug, Release, etc.)"
echo " --cmake PATH Path to CMake executable"
echo " --ninja PATH Path to Ninja executable"
echo " --jobs N Number of parallel jobs"
echo " --options OPTIONS Extra CMake options, see README.md"
# echo " --android-sdk PATH [android] Path to Android SDK"
echo " --android-ndk PATH [android] Path to Android NDK"
echo " --android-ver N [android] Android system version (default: 21)"
echo " -y/n/c Setting 'yes/no/cancel' to auto prepare sd-models"
echo " -h, --help Show this help message"
}
# Parse command line arguments
CONFIRM_OPTION=""
while [[ "$#" -gt 0 ]]; do
case $1 in
--platform) PLATFORM="$2"; shift ;;
--arch-abi) TARGET_ABI="$2"; shift ;;
--build-type) BUILD_TYPE="$2"; shift ;;
--cmake) CMAKE="$2"; shift ;;
--ninja) NINJA="$2"; shift ;;
--jobs) JOBS="$2"; shift ;;
--options) CMAKE_OPTIONS="$2"; shift ;;
# --android-sdk) ANDROID_SDK="$2"; shift ;;
--android-ndk) ANDROID_NDK="$2"; shift ;;
--android-ver) ANDROID_VER="$2"; shift ;;
-n) CONFIRM_OPTION="-n" ;;
-y) CONFIRM_OPTION="-y" ;;
-c) CONFIRM_OPTION="-c" ;;
-h|--help) show_help; exit 0 ;;
*) echo "Unknown parameter passed: $1"; show_help; exit 1 ;;
esac
shift
done
# Set default values
BUILD_TYPE=${BUILD_TYPE:-$DEFAULT_BUILD_TYPE}
JOBS=${JOBS:-$DEFAULT_JOBS}
CMAKE=${CMAKE:-$DEFAULT_CMAKE}
NINJA=${NINJA:-$DEFAULT_NINJA}
ANDROID_VER=${ANDROID_VER:-$DEFAULT_ANDROID_VER}
CMAKE_OPTIONS=${CMAKE_OPTIONS:-}
CONFIRM_OPTION=${CONFIRM_OPTION:-$DEFAULT_CONFIRM_OPTION}
# Detect platform if not specified
if [ -z "$PLATFORM" ]; then
case "$(uname -s)" in
Linux*) PLATFORM=linux ;;
Darwin*) PLATFORM=macos ;;
CYGWIN*|MINGW*|MSYS*) PLATFORM=windows ;;
Android*) PLATFORM=android ;;
*) PLATFORM=unknown ;;
esac
fi
# Detect TARGET_ABI if not specified or set to default
if [ -z "$TARGET_ABI" ] || [ "$TARGET_ABI" == "default" ]; then
case "$(uname -m)" in
x86_64)
TARGET_ABI="x86_64"
;;
aarch64 | arm64)
TARGET_ABI="aarch64"
;;
i386 | i686)
TARGET_ABI="x86"
;;
armv7l)
TARGET_ABI="armeabi-v7a"
;;
*)
echo "Unsupported current system architecture: $(uname -m)"
exit 1
;;
esac
fi
# Set project root and build directories
PROJECT_ROOT=$(dirname "$0")
BUILD_DIR=${PROJECT_ROOT}/cmake-build-${BUILD_TYPE}-${PLATFORM}-${TARGET_ABI}
# Clean old build directory
rm -rf ${BUILD_DIR}
mkdir -p ${BUILD_DIR}
# Map platform to CMAKE_SYSTEM_NAME
case "$PLATFORM" in
android)
CMAKE_SYSTEM_NAME="Android"
;;
linux)
CMAKE_SYSTEM_NAME="Linux"
;;
macos)
CMAKE_SYSTEM_NAME="Darwin"
;;
windows)
CMAKE_SYSTEM_NAME="Windows"
;;
*)
echo "Unsupported platform: $PLATFORM"
exit 1
;;
esac
# Map arch-abi to CMAKE_SYSTEM_PROCESSOR
case "$TARGET_ABI" in
x86_64)
CMAKE_SYSTEM_PROCESSOR="x86_64"
;;
aarch64)
CMAKE_SYSTEM_PROCESSOR="aarch64"
;;
arm64)
CMAKE_SYSTEM_PROCESSOR="arm64"
;;
x86)
CMAKE_SYSTEM_PROCESSOR="x86"
;;
arm64-v8a)
CMAKE_SYSTEM_PROCESSOR="arm64-v8a"
;;
armeabi-v7a)
CMAKE_SYSTEM_PROCESSOR="armeabi-v7a"
;;
*)
echo "Unsupported arch-abi: $TARGET_ABI"
echo "Please choose arch-abi from [x86_64, aarch64, arm64, x86, arm64-v8a, armeabi-v7a]"
exit 1
;;
esac
# Platform-specific configuration
case "$PLATFORM" in
android)
# CMAKE_OPTIONS="${CMAKE_OPTIONS} -DANDROID_SDK=${ANDROID_SDK}"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DANDROID_NDK=${ANDROID_NDK}"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_SYSTEM_VERSION=${ANDROID_VER}"
;;
linux)
CMAKE_OPTIONS="${CMAKE_OPTIONS}"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}"
;;
macos)
CMAKE_OPTIONS="${CMAKE_OPTIONS}"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}"
;;
windows)
CMAKE_OPTIONS="${CMAKE_OPTIONS}"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}"
;;
*)
echo "Unknown platform: $PLATFORM"
exit 1
;;
esac
# Run CMake configuration
${CMAKE} \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
${CMAKE_OPTIONS} \
-S ${PROJECT_ROOT} \
-B ${BUILD_DIR}
# Check if CMake configuration succeeded
if [ $? -ne 0 ]; then
echo "CMake configuration failed"
exit 1
fi
# Run build
${CMAKE} --build ${BUILD_DIR} --parallel ${JOBS}
# Check if build succeeded
if [ $? -ne 0 ]; then
echo "Build failed"
exit 1
fi
echo "Build succeeded"
#===================================== Prepare Resources =====================================
echo "Now, begin to prepare executing models & environment Resources!"
# Function: Safely change dir
change_directory() {
local TARGET_DIR="$1"
if [ -z "$TARGET_DIR" ]; then
echo "Usage: change_directory <target_directory>"
return 1
fi
if [ -d "$TARGET_DIR" ]; then
cd "$TARGET_DIR" || { echo "Failed to change directory to $TARGET_DIR"; return 1; }
echo "Successfully changed directory to $TARGET_DIR"
else
echo "Directory $TARGET_DIR does not exist"
return 1
fi
return 0
}
change_directory "sd/"
# Check if the directory change was successful
if [ $? -eq 0 ]; then
# Execute the auto_prepare_sd_models.sh script with the confirmation option
bash ./auto_prepare_sd_models.sh $CONFIRM_OPTION
else
echo "Failed to change directory. Exiting."
exit 1
fi
echo "clitool is under $BUILD_DIR/bin/"
echo "All Finished! ready to maneuver, sir!"