-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathbuild-xcframework.sh
More file actions
executable file
·58 lines (47 loc) · 2.22 KB
/
Copy pathbuild-xcframework.sh
File metadata and controls
executable file
·58 lines (47 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
set -e
# Build universal static library for Apple platforms
# Outputs: NemoTextProcessing.xcframework
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
BUILD_DIR="$SCRIPT_DIR/build"
OUTPUT_DIR="$SCRIPT_DIR/output"
rm -rf "$BUILD_DIR" "$OUTPUT_DIR"
mkdir -p "$BUILD_DIR" "$OUTPUT_DIR"
echo "Building for macOS (arm64)..."
cargo build --release --features "ffi,fst-engine" --target aarch64-apple-darwin
echo "Building for macOS (x86_64)..."
cargo build --release --features "ffi,fst-engine" --target x86_64-apple-darwin
echo "Building for iOS (arm64)..."
cargo build --release --features "ffi,fst-engine" --target aarch64-apple-ios
echo "Building for iOS Simulator (arm64)..."
cargo build --release --features "ffi,fst-engine" --target aarch64-apple-ios-sim
echo "Creating universal macOS library..."
mkdir -p "$BUILD_DIR/macos"
lipo -create \
target/aarch64-apple-darwin/release/libtext_processing_rs.a \
target/x86_64-apple-darwin/release/libtext_processing_rs.a \
-output "$BUILD_DIR/macos/libtext_processing_rs.a"
echo "Creating XCFramework..."
# NOTE: headers live in swift/include/CNemoTextProcessing/ so each slice gets
# Headers/CNemoTextProcessing/module.modulemap. Xcode's ProcessXCFramework copies
# each xcframework's Headers/ into the SHARED $BUILT_PRODUCTS_DIR/include, so a
# top-level include/module.modulemap collides with any other xcframework that
# ships one ("Multiple commands produce .../include/module.modulemap"). Clang
# still resolves `import CNemoTextProcessing` because it looks for a module map
# in a subdirectory named after the module. Keep the directory name == module name.
xcodebuild -create-xcframework \
-library "$BUILD_DIR/macos/libtext_processing_rs.a" \
-headers swift/include \
-library target/aarch64-apple-ios/release/libtext_processing_rs.a \
-headers swift/include \
-library target/aarch64-apple-ios-sim/release/libtext_processing_rs.a \
-headers swift/include \
-output "$OUTPUT_DIR/NemoTextProcessing.xcframework"
echo "Copying Swift wrapper..."
cp swift/NemoTextProcessing.swift "$OUTPUT_DIR/"
echo ""
echo "Done! Output:"
echo " $OUTPUT_DIR/NemoTextProcessing.xcframework"
echo " $OUTPUT_DIR/NemoTextProcessing.swift"
echo ""
echo "Add both to your Xcode project."