Skip to content

Commit ae130f3

Browse files
committed
fix(executorch): iOS xcframework single-platform + wire sccache
iOS: the build now completes (preset + --config Release), but the bundle swept in the flatc/flatcc HOST-tool archives (built for macOS to run the schema compiler) — mixing macOS + iphoneos objects, so xcframework rejected the slice ("binaries with multiple platforms are not supported"). Exclude the flatc_ep/flatcc_ep host EPs from the per-slice merge (they're not part of the shipped runtime). Perf: wire sccache as the compiler launcher for executorch's build AND the intel-mac PyTorch-from-source build (non-Windows; Windows skipped for the MSVC /Fd pdb issue). The shared stage-build action only wired sccache for tflite, so executorch — especially the ~95-min from-source PyTorch leg — compiled uncached every run. Warm re-runs should now be much faster.
1 parent 66a5751 commit ae130f3

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

engines/executorch/build-executorch.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ if [ "$PLATFORM" = "macos" ] && [ "$ARCH" = "x86_64" ]; then
9393
[ -f "$PT/requirements-build.txt" ] && python -m pip install -r "$PT/requirements-build.txt"
9494
python -m pip install pyyaml typing_extensions setuptools numpy
9595
rm -f "$PT/build/CMakeCache.txt" # sticky cache vars from a prior config (see build-libtorch.sh)
96+
# Route PyTorch's compiles through sccache too — this from-source build is the slowest leg by
97+
# far, so caching it across runs is the biggest win. PyTorch forwards CMAKE_*_COMPILER_LAUNCHER.
98+
PT_SCCACHE=""
99+
command -v sccache >/dev/null 2>&1 && \
100+
PT_SCCACHE="CMAKE_C_COMPILER_LAUNCHER=sccache CMAKE_CXX_COMPILER_LAUNCHER=sccache"
96101
# Env scoped to the subshell so PyTorch's BUILD_* / USE_* don't leak into ExecuTorch's
97102
# own cmake below. CMAKE_POLICY_VERSION_MINIMUM: old vendored protobuf needs the <3.5
98103
# policy floor under CMake 4.x. USE_NATIVE_ARCH=0: avoid Apple-Clang-rejected -mavx512fp16.
@@ -105,6 +110,7 @@ if [ "$PLATFORM" = "macos" ] && [ "$ARCH" = "x86_64" ]; then
105110
BUILD_TEST=0 BUILD_PYTHON=0 BUILD_SHARED_LIBS=1 \
106111
USE_MKLDNN=1 USE_NATIVE_ARCH=0 \
107112
CMAKE_OSX_ARCHITECTURES=x86_64 MACOSX_DEPLOYMENT_TARGET=12.0 \
113+
${PT_SCCACHE} \
108114
python tools/build_libtorch.py )
109115
[ -d "$PT/torch/include" ] || \
110116
{ echo "ERROR: pytorch source build produced no torch/include headers under $PT"; exit 1; }
@@ -231,6 +237,14 @@ case "$PLATFORM" in
231237
*) echo "ERROR: unknown platform '$PLATFORM'"; exit 1 ;;
232238
esac
233239

240+
# Route compiles through sccache (the CI sets it up) so warm re-runs are fast. The shared
241+
# stage-build action only wires this for tflite, so executorch compiled uncached — the big
242+
# intel-mac PyTorch-from-source + ExecuTorch builds rebuilt from scratch every run. Skip on
243+
# Windows: MSVC /Fd (pdb) trips sccache (same reason the shared action limits it to tflite).
244+
if [ "$PLATFORM" != "windows" ] && command -v sccache >/dev/null 2>&1; then
245+
ET_FLAGS+=(-DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache)
246+
fi
247+
234248
# A restored/cached build tree pins CMake cache vars from the PRIOR config; drop the cache
235249
# so cmake re-detects against the current flags (objects + any compiler cache keep the
236250
# rebuild incremental). No-op on a cold build. Mirrors build-libtorch.sh.

engines/executorch/ios.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ build_slice ios-simulator "$SRC/cmake-out-ios-sim"
6666

6767
# Merge each slice's transitive static archives (executorch + kernels + xnnpack/coreml/_deps
6868
# CMake scatters across the build tree) into one self-contained fat libexecutorch.a per slice.
69+
# EXCLUDE the flatc/flatcc host-tool ExternalProjects: those build for the macOS HOST (to run
70+
# the schema compiler during the build), so their libs are macOS-platform Mach-O. Sweeping them
71+
# into the iOS bundle makes the archive "multiple platforms" and xcframework rejects it. The
72+
# host tools aren't part of the shipped runtime, so dropping them is correct.
73+
export BUNDLE_EXCLUDE_REGEX='/flatc_ep/|/flatcc_ep/'
6974
rm -rf dev sim && mkdir -p dev sim
7075
bash "$ROOT/scripts/bundle-static.sh" "$SRC/cmake-out-ios" "$PWD/dev/libexecutorch.a"
7176
bash "$ROOT/scripts/bundle-static.sh" "$SRC/cmake-out-ios-sim" "$PWD/sim/libexecutorch.a"

0 commit comments

Comments
 (0)