Skip to content

Commit 362e27d

Browse files
committed
added build script for xcframework
1 parent 92f2ff4 commit 362e27d

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ mediapipe/MediaPipe.tulsiproj/*.tulsiconf-user
44
mediapipe/provisioning_profile.mobileprovision
55
.configure.bazelrc
66
.user.bazelrc
7-
.DS_STORE
7+
.DS_STORE
8+
/frameworkbuild

BUILD_FACE_MESH_XCFRAMEWORK.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/sh
2+
3+
# Create output directories~
4+
mkdir -p ./frameworkbuild/FaceMeshIOSLibFramework/arm64
5+
mkdir -p ./frameworkbuild/FaceMeshIOSLibFramework/x86_64
6+
# XCFramework is how we're going to use it.
7+
mkdir -p ./frameworkbuild/FaceMeshIOSLibFramework/xcframework
8+
9+
# Interesting fact. Bazel `build` command stores cached files in `/private/var/tmp/...` folders
10+
# and when you run build, if it finds cached files, it kind of symlinks the files/folders
11+
# into the `bazel-bin` folder found in the project root. So don't be afraid of re-running builds
12+
# because the files are cached.
13+
14+
# build the arm64 binary framework
15+
bazel build --copt=-fembed-bitcode --apple_bitcode=embedded --config=ios_arm64 mediapipe/examples/ios/facemeshioslib:FaceMeshIOSLibFramework
16+
17+
# The arm64 framework zip will be located at //bazel-bin/mediapipe/examples/ios/facemeshioslib/FaceMeshIOSLibFramework.zip
18+
19+
# Call the framework patcher (First argument = compressed framework.zip, Second argument = header file's name(in this case FaceMeshIOSLib.h))
20+
./mediapipe/examples/ios/facemeshioslib/patch_ios_framework.sh ./bazel-bin/mediapipe/examples/ios/facemeshioslib/FaceMeshIOSLibFramework.zip FaceMeshIOSLib.h
21+
22+
# There will be a resulting patched .framework folder at the same directory, this is our arm64 one, we copy it to our arm64 folder
23+
cp -a ./bazel-bin/mediapipe/examples/ios/facemeshioslib/FaceMeshIOSLibFramework.framework ./frameworkbuild/FaceMeshIOSLibFramework/arm64
24+
25+
# Do the same for x86_64
26+
27+
# build x86_64
28+
bazel build --copt=-fembed-bitcode --apple_bitcode=embedded --config=ios_x86_64 mediapipe/examples/ios/facemeshioslib:FaceMeshIOSLibFramework
29+
30+
# Call the framework patcher
31+
./mediapipe/examples/ios/facemeshioslib/patch_ios_framework.sh ./bazel-bin/mediapipe/examples/ios/facemeshioslib/FaceMeshIOSLibFramework.zip FaceMeshIOSLib.h
32+
33+
# copy the patched framework to our folder
34+
cp -a ./bazel-bin/mediapipe/examples/ios/facemeshioslib/FaceMeshIOSLibFramework.framework ./frameworkbuild/FaceMeshIOSLibFramework/x86_64
35+
36+
# Create xcframework (because the classic lipo method with normal .framework no longer works (shows Building for iOS Simulator, but the linked and embedded framework was built for iOS + iOS Simulator))
37+
38+
xcodebuild -create-xcframework \
39+
-framework ./frameworkbuild/FaceMeshIOSLibFramework/x86_64/FaceMeshIOSLibFramework.framework \
40+
-framework ./frameworkbuild/FaceMeshIOSLibFramework/arm64/FaceMeshIOSLibFramework.framework \
41+
-output ./frameworkbuild/FaceMeshIOSLibFramework/xcframework/FaceMeshIOSLibFramework.xcframework
42+

0 commit comments

Comments
 (0)