Skip to content

Commit f05ce10

Browse files
authored
Put module.modulemap inside Headers/{ModuleName} for Apple frameworks
That's needed to avoid collisions when several frameworks are linked in Xcode, when two or more have module.modulemap in their Headers
1 parent 4456407 commit f05ce10

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

scripts/build_apple_frameworks.sh

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
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+
815
set -euxo pipefail
916

1017
MODES=()
@@ -14,23 +21,25 @@ PRESETS_RELATIVE_OUT_DIR=("ios" "simulator" "macos")
1421

1522
SOURCE_ROOT_DIR=$(git rev-parse --show-toplevel)
1623
OUTPUT_DIR="${SOURCE_ROOT_DIR}/cmake-out"
17-
HEADERS_RELATIVE_PATH="include"
18-
HEADERS_ABSOLUTE_PATH="${OUTPUT_DIR}/${HEADERS_RELATIVE_PATH}"
1924

2025
BUCK2=$(python3 "$SOURCE_ROOT_DIR/tools/cmake/resolve_buck.py" --cache_dir="$SOURCE_ROOT_DIR/buck2-bin")
2126
if [[ "$BUCK2" == "buck2" ]]; then
2227
BUCK2=$(command -v buck2)
2328
fi
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}:\
2635
libexecutorch.a,\
2736
libexecutorch_core.a,\
2837
libextension_apple.a,\
2938
libextension_data_loader.a,\
3039
libextension_flat_tensor.a,\
3140
libextension_module.a,\
3241
libextension_tensor.a,\
33-
:$HEADERS_RELATIVE_PATH:ExecuTorch"
42+
:${FRAMEWORK_EXECUTORCH_HEADERS_DIR}:${FRAMEWORK_EXECUTORCH_MODULE_NAME}"
3443

3544
FRAMEWORK_THREADPOOL="threadpool:\
3645
libcpuinfo.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
168176
done
169177

170178
echo "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"
184192
sed -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
}
201209
EOF
@@ -252,7 +260,7 @@ for preset_out_dir in "${PRESETS_RELATIVE_OUT_DIR[@]}"; do
252260
rm -rf "${OUTPUT_DIR}/${preset_out_dir}"
253261
done
254262

255-
rm -rf "$HEADERS_ABSOLUTE_PATH"
263+
rm -rf "$FRAMEWORK_EXECUTORCH_HEADERS_PATH"
256264

257265
echo "Running tests"
258266

0 commit comments

Comments
 (0)