@@ -9,7 +9,7 @@ set -euo pipefail
9
9
10
10
SOURCE_ROOT_DIR=" "
11
11
OUTPUT=" cmake-out"
12
- MODE= " Release "
12
+ MODES=()
13
13
TOOLCHAIN=" "
14
14
PYTHON=$( which python3)
15
15
FLATC=$( which flatc)
@@ -77,28 +77,38 @@ usage() {
77
77
echo
78
78
echo " Options:"
79
79
echo " --output=DIR Output directory. Default: 'cmake-out'"
80
- echo " --Debug Use Debug build mode. Default: Uses Release build mode."
81
- echo " --toolchain=FILE Cmake toolchain file. Default: '\$ SOURCE_ROOT_DIR/third-party/ios-cmake/ios.toolchain.cmake'"
82
- echo " --python=FILE Python executable path. Default: Path of python3 found in the current \$ PATH"
83
- echo " --flatc=FILE FlatBuffers Compiler executable path. Default: Path of flatc found in the current \$ PATH"
84
- echo " --coreml Include this flag to build the Core ML backend."
85
- echo " --custom Include this flag to build the Custom kernels."
86
- echo " --mps Include this flag to build the Metal Performance Shaders backend."
87
- echo " --optimized Include this flag to build the Optimized kernels."
88
- echo " --portable Include this flag to build the Portable kernels."
89
- echo " --quantized Include this flag to build the Quantized kernels."
90
- echo " --xnnpack Include this flag to build the XNNPACK backend."
80
+ echo " --Debug Build Debug version."
81
+ echo " --Release Build Release version."
82
+ echo " --toolchain=FILE CMake toolchain file. Default: '\$ SOURCE_ROOT_DIR/third-party/ios-cmake/ios.toolchain.cmake'"
83
+ echo " --python=FILE Python executable path. Default: Path of python3 in \$ PATH"
84
+ echo " --flatc=FILE FlatBuffers Compiler executable path. Default: Path of flatc in \$ PATH"
85
+ echo " --coreml Build the Core ML backend."
86
+ echo " --custom Build the Custom kernels."
87
+ echo " --mps Build the Metal Performance Shaders backend."
88
+ echo " --optimized Build the Optimized kernels."
89
+ echo " --portable Build the Portable kernels."
90
+ echo " --quantized Build the Quantized kernels."
91
+ echo " --xnnpack Build the XNNPACK backend."
91
92
echo
92
93
echo " Example:"
93
- echo " $0 /path/to/source/root --output=cmake-out --toolchain=/path/to/cmake/ toolchain --python=/path/to/python3 --coreml --mps --xnnpack"
94
+ echo " $0 /path/to/source/root --output=cmake-out --toolchain=/path/to/toolchain --python=/path/to/python3 --coreml --mps --xnnpack"
94
95
exit 0
95
96
}
96
97
97
98
for arg in " $@ " ; do
98
99
case $arg in
99
100
-h|--help) usage ;;
100
101
--output=* ) OUTPUT=" ${arg#* =} " ;;
101
- --Debug) MODE=" Debug" ;;
102
+ --Release)
103
+ if [[ ! " ${MODES[*]:- } " =~ \b Release\b ]]; then
104
+ MODES+=(" Release" )
105
+ fi
106
+ ;;
107
+ --Debug)
108
+ if [[ ! " ${MODES[*]:- } " =~ \b Debug\b ]]; then
109
+ MODES+=(" Debug" )
110
+ fi
111
+ ;;
102
112
--toolchain=* ) TOOLCHAIN=" ${arg#* =} " ;;
103
113
--python=* ) PYTHON=" ${arg#* =} " ;;
104
114
--flatc=* ) FLATC=" ${arg#* =} " ;;
@@ -120,6 +130,10 @@ for arg in "$@"; do
120
130
esac
121
131
done
122
132
133
+ if [ ${# MODES[@]} -eq 0 ]; then
134
+ MODES=(" Release" )
135
+ fi
136
+
123
137
if [[ -z " $SOURCE_ROOT_DIR " ]]; then
124
138
SOURCE_ROOT_DIR=$( pwd)
125
139
fi
@@ -146,10 +160,11 @@ cmake_build() {
146
160
local platform=$1
147
161
local platform_flag=$2
148
162
local platform_target=$3
149
- echo " Building for $platform with flag $platform_flag "
150
- mkdir " $platform " && cd " $platform " || exit 1
163
+ local mode=$4
164
+ echo " Building for $platform ($mode ) with flag $platform_flag "
165
+ mkdir -p " $platform " && cd " $platform " || exit 1
151
166
cmake " $SOURCE_ROOT_DIR " -G Xcode \
152
- -DCMAKE_BUILD_TYPE=" $MODE " \
167
+ -DCMAKE_BUILD_TYPE=" $mode " \
153
168
-DCMAKE_TOOLCHAIN_FILE=" $TOOLCHAIN " \
154
169
-DCMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD=" c++17" \
155
170
-DCMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY=" libc++" \
@@ -173,13 +188,15 @@ cmake_build() {
173
188
${platform_target: +-DDEPLOYMENT_TARGET=$platform_target } \
174
189
--log-level=VERBOSE
175
190
cmake --build . \
176
- --config $MODE \
191
+ --config " $mode " \
177
192
--verbose
178
193
cd ..
179
194
}
180
195
181
196
for index in ${! PLATFORMS[*]} ; do
182
- cmake_build " ${PLATFORMS[$index]} " " ${PLATFORM_FLAGS[$index]} " " ${PLATFORM_TARGET[$index]} "
197
+ for mode in " ${MODES[@]} " ; do
198
+ cmake_build " ${PLATFORMS[$index]} " " ${PLATFORM_FLAGS[$index]} " " ${PLATFORM_TARGET[$index]} " " $mode "
199
+ done
183
200
done
184
201
185
202
echo " Exporting headers"
@@ -206,42 +223,51 @@ check_command "$BUCK2"
206
223
# So, just patch our generated framework to do that.
207
224
sed -i ' ' ' 1i\
208
225
#define C10_USING_CUSTOM_GENERATED_MACROS
209
- ' $HEADERS_PATH /executorch/runtime/core/portable_type/c10/c10/macros/Macros.h
210
- sed -i ' ' ' 1i\
211
- #define C10_USING_CUSTOM_GENERATED_MACROS
212
- ' $HEADERS_PATH /executorch/runtime/core/portable_type/c10/c10/macros/Export.h
213
- cp -r $HEADERS_PATH /executorch/runtime/core/portable_type/c10/c10 " $HEADERS_PATH /"
226
+ ' \
227
+ " $HEADERS_PATH /executorch/runtime/core/portable_type/c10/c10/macros/Macros.h" \
228
+ " $HEADERS_PATH /executorch/runtime/core/portable_type/c10/c10/macros/Export.h"
214
229
230
+ cp -r $HEADERS_PATH /executorch/runtime/core/portable_type/c10/c10 " $HEADERS_PATH /"
215
231
216
232
cp " $SOURCE_ROOT_DIR /extension/apple/ExecuTorch/Exported/" * .h " $HEADERS_PATH /executorch"
217
233
cp " $SOURCE_ROOT_DIR /extension/apple/ExecuTorch/Exported/" * .modulemap " $HEADERS_PATH "
218
234
219
235
echo " Creating frameworks"
220
236
221
- for platform in " ${PLATFORMS[@]} " ; do
222
- echo " Directory: $platform /$MODE "
223
- FRAMEWORK_FLAGS+=(" --directory=$platform /$MODE " )
224
- done
225
-
226
237
append_framework_flag () {
227
238
local flag=" $1 "
228
239
local framework=" $2 "
240
+ local mode=" ${3:- } "
229
241
if [[ $flag == ON ]]; then
242
+ if [[ -n " $mode " && " $mode " != " Release" ]]; then
243
+ local name spec
244
+ name=$( echo " $framework " | cut -d: -f1)
245
+ spec=$( echo " $framework " | cut -d: -f2-)
246
+ framework=" ${name} _$( echo " $mode " | tr ' [:upper:]' ' [:lower:]' ) :${spec} "
247
+ fi
230
248
echo " Framework: $framework "
231
249
FRAMEWORK_FLAGS+=(" --framework=$framework " )
232
250
fi
233
251
}
234
252
235
- append_framework_flag " ON" " $FRAMEWORK_EXECUTORCH "
236
- append_framework_flag " $COREML " " $FRAMEWORK_BACKEND_COREML "
237
- append_framework_flag " $MPS " " $FRAMEWORK_BACKEND_MPS "
238
- append_framework_flag " $XNNPACK " " $FRAMEWORK_BACKEND_XNNPACK "
239
- append_framework_flag " $CUSTOM " " $FRAMEWORK_KERNELS_CUSTOM "
240
- append_framework_flag " $OPTIMIZED " " $FRAMEWORK_KERNELS_OPTIMIZED "
241
- append_framework_flag " $PORTABLE " " $FRAMEWORK_KERNELS_PORTABLE "
242
- append_framework_flag " $QUANTIZED " " $FRAMEWORK_KERNELS_QUANTIZED "
243
-
244
- " $SOURCE_ROOT_DIR " /build/create_frameworks.sh " ${FRAMEWORK_FLAGS[@]} "
253
+ for mode in " ${MODES[@]} " ; do
254
+ FRAMEWORK_FLAGS=()
255
+ for platform in " ${PLATFORMS[@]} " ; do
256
+ echo " Directory: $platform /$mode "
257
+ FRAMEWORK_FLAGS+=(" --directory=$platform /$mode " )
258
+ done
259
+
260
+ append_framework_flag " ON" " $FRAMEWORK_EXECUTORCH " " $mode "
261
+ append_framework_flag " $COREML " " $FRAMEWORK_BACKEND_COREML " " $mode "
262
+ append_framework_flag " $MPS " " $FRAMEWORK_BACKEND_MPS " " $mode "
263
+ append_framework_flag " $XNNPACK " " $FRAMEWORK_BACKEND_XNNPACK " " $mode "
264
+ append_framework_flag " $CUSTOM " " $FRAMEWORK_KERNELS_CUSTOM " " $mode "
265
+ append_framework_flag " $OPTIMIZED " " $FRAMEWORK_KERNELS_OPTIMIZED " " $mode "
266
+ append_framework_flag " $PORTABLE " " $FRAMEWORK_KERNELS_PORTABLE " " $mode "
267
+ append_framework_flag " $QUANTIZED " " $FRAMEWORK_KERNELS_QUANTIZED " " $mode "
268
+
269
+ " $SOURCE_ROOT_DIR " /build/create_frameworks.sh " ${FRAMEWORK_FLAGS[@]} "
270
+ done
245
271
246
272
echo " Cleaning up"
247
273
0 commit comments