55# This source code is licensed under the BSD-style license found in the
66# LICENSE file in the root directory of this source tree.
77
8+ #! /bin/bash
9+ # Copyright (c) Meta Platforms, Inc. and affiliates.
10+ # All rights reserved.
11+ #
12+ # This source code is licensed under the BSD-style license found in the
13+ # LICENSE file in the root directory of this source tree.
14+
815set -euxo pipefail
916
1017MODES=()
@@ -14,23 +21,25 @@ PRESETS_RELATIVE_OUT_DIR=("ios" "simulator" "macos")
1421
1522SOURCE_ROOT_DIR=$( git rev-parse --show-toplevel)
1623OUTPUT_DIR=" ${SOURCE_ROOT_DIR} /cmake-out"
17- HEADERS_RELATIVE_PATH=" include"
18- HEADERS_ABSOLUTE_PATH=" ${OUTPUT_DIR} /${HEADERS_RELATIVE_PATH} "
1924
2025BUCK2=$( python3 " $SOURCE_ROOT_DIR /tools/cmake/resolve_buck.py" --cache_dir=" $SOURCE_ROOT_DIR /buck2-bin" )
2126if [[ " $BUCK2 " == " buck2" ]]; then
2227 BUCK2=$( command -v buck2)
2328fi
2429
25- FRAMEWORK_EXECUTORCH=" executorch:\
30+ FRAMEWORK_EXECUTORCH_NAME=" executorch"
31+ FRAMEWORK_EXECUTORCH_MODULE_NAME=" ExecuTorch"
32+ FRAMEWORK_EXECUTORCH_HEADERS_DIR=" ${FRAMEWORK_EXECUTORCH_NAME} _include"
33+ FRAMEWORK_EXECUTORCH_HEADERS_PATH=" ${OUTPUT_DIR} /${FRAMEWORK_EXECUTORCH_HEADERS_DIR} "
34+ FRAMEWORK_EXECUTORCH=" ${FRAMEWORK_EXECUTORCH_NAME} :\
2635libexecutorch.a,\
2736libexecutorch_core.a,\
2837libextension_apple.a,\
2938libextension_data_loader.a,\
3039libextension_flat_tensor.a,\
3140libextension_module.a,\
3241libextension_tensor.a,\
33- :$HEADERS_RELATIVE_PATH :ExecuTorch "
42+ :${FRAMEWORK_EXECUTORCH_HEADERS_DIR} : ${FRAMEWORK_EXECUTORCH_MODULE_NAME} "
3443
3544FRAMEWORK_THREADPOOL=" threadpool:\
3645libcpuinfo.a,\
@@ -162,19 +171,18 @@ for preset_index in "${!PRESETS[@]}"; do
162171 --preset " ${preset} "
163172
164173 cmake --build " ${preset_output_dir} " \
165- --config " ${mode} " \
166- -j$( sysctl -n hw.ncpu)
174+ --config " ${mode} "
167175 done
168176done
169177
170178echo " Exporting headers"
171179
172- mkdir -p " $HEADERS_ABSOLUTE_PATH "
180+ mkdir -p " $FRAMEWORK_EXECUTORCH_HEADERS_PATH / $FRAMEWORK_EXECUTORCH_MODULE_NAME "
173181
174182" $SOURCE_ROOT_DIR " /scripts/print_exported_headers.py --buck2=$( realpath " $BUCK2 " ) --targets \
175183 //extension/module: \
176184 //extension/tensor: \
177- | rsync -av --files-from=- " $SOURCE_ROOT_DIR " " $HEADERS_ABSOLUTE_PATH /executorch "
185+ | rsync -av --files-from=- " $SOURCE_ROOT_DIR " " $FRAMEWORK_EXECUTORCH_HEADERS_PATH / $FRAMEWORK_EXECUTORCH_MODULE_NAME "
178186
179187# HACK: XCFrameworks don't appear to support exporting any build
180188# options, but we need the following:
@@ -184,18 +192,18 @@ mkdir -p "$HEADERS_ABSOLUTE_PATH"
184192sed -i ' ' ' 1i\
185193#define C10_USING_CUSTOM_GENERATED_MACROS
186194' \
187- " $HEADERS_ABSOLUTE_PATH /executorch/runtime/core/portable_type/c10/c10/macros/Macros.h" \
188- " $HEADERS_ABSOLUTE_PATH /executorch/runtime/core/portable_type/c10/c10/macros/Export.h" \
189- " $HEADERS_ABSOLUTE_PATH /executorch/runtime/core/portable_type/c10/torch/headeronly/macros/Export.h"
195+ " $FRAMEWORK_EXECUTORCH_HEADERS_PATH /executorch/runtime/core/portable_type/c10/c10/macros/Macros.h" \
196+ " $FRAMEWORK_EXECUTORCH_HEADERS_PATH /executorch/runtime/core/portable_type/c10/c10/macros/Export.h" \
197+ " $FRAMEWORK_EXECUTORCH_HEADERS_PATH /executorch/runtime/core/portable_type/c10/torch/headeronly/macros/Export.h"
190198
191- cp -r $HEADERS_ABSOLUTE_PATH /executorch/runtime/core/portable_type/c10/c10 " $HEADERS_ABSOLUTE_PATH /"
192- cp -r $HEADERS_ABSOLUTE_PATH /executorch/runtime/core/portable_type/c10/torch " $HEADERS_ABSOLUTE_PATH /"
199+ cp -r $FRAMEWORK_EXECUTORCH_HEADERS_PATH /executorch/runtime/core/portable_type/c10/c10 " $FRAMEWORK_EXECUTORCH_HEADERS_PATH /"
200+ cp -r $FRAMEWORK_EXECUTORCH_HEADERS_PATH /executorch/runtime/core/portable_type/c10/torch " $FRAMEWORK_EXECUTORCH_HEADERS_PATH /"
193201
194- cp " $SOURCE_ROOT_DIR /extension/apple/ExecuTorch /Exported/" * .h " $HEADERS_ABSOLUTE_PATH /executorch "
202+ cp " $SOURCE_ROOT_DIR /extension/apple/$FRAMEWORK_EXECUTORCH_MODULE_NAME /Exported/" * .h " $FRAMEWORK_EXECUTORCH_HEADERS_PATH / $FRAMEWORK_EXECUTORCH_MODULE_NAME "
195203
196- cat > " $HEADERS_ABSOLUTE_PATH / module.modulemap" << ' EOF '
197- module ExecuTorch {
198- umbrella header "ExecuTorch/ExecuTorch .h"
204+ cat > " $FRAMEWORK_EXECUTORCH_HEADERS_PATH / $FRAMEWORK_EXECUTORCH_MODULE_NAME / module.modulemap" << EOF
205+ module ${FRAMEWORK_EXECUTORCH_MODULE_NAME} {
206+ umbrella header "${FRAMEWORK_EXECUTORCH_MODULE_NAME} .h"
199207 export *
200208}
201209EOF
@@ -252,7 +260,7 @@ for preset_out_dir in "${PRESETS_RELATIVE_OUT_DIR[@]}"; do
252260 rm -rf " ${OUTPUT_DIR} /${preset_out_dir} "
253261done
254262
255- rm -rf " $HEADERS_ABSOLUTE_PATH "
263+ rm -rf " $FRAMEWORK_EXECUTORCH_HEADERS_PATH "
256264
257265echo " Running tests"
258266
0 commit comments