Skip to content

Commit 8702880

Browse files
committed
Add build script
1 parent 6b84f50 commit 8702880

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

build_tool.sh

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/bin/bash -e
2+
# OVERVIEW: Downloads and prepares Code Connect CLI, builds and packages figma CLI
3+
# USAGE: ./build_tool.sh [xcframework_output_path]
4+
# SIDE EFFECTS: Creates temporary directory, clones repository, installs dependencies,
5+
# builds CLI, and moves generated files to specific locations
6+
7+
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
8+
pushd "$SCRIPT_DIR" > /dev/null
9+
trap "popd > /dev/null" EXIT
10+
11+
mkdir release
12+
13+
cd cli
14+
15+
# Install dependencies and build
16+
npm install
17+
npm run bundle:cli:mac:arm64
18+
19+
# Move the generated file to the root and rename it
20+
mv bundle-cli/figma-mac-arm64 "$SCRIPT_DIR/release/figma" || echo "Warning: figma-mac-arm64 file not found"
21+
cd ..
22+
23+
echo "✅ Code Connect CLI prepared successfully"
24+
25+
echo "🔄 Building figma CLI"
26+
27+
swift build \
28+
--product figma-swift \
29+
--package-path ./swiftui/ \
30+
--configuration release \
31+
--arch arm64
32+
echo "✅ Build succeeded for figma-swift"
33+
34+
echo "🔄 Packaging CLI..."
35+
cp -f \
36+
./.build/arm64-apple-macosx/Release/figma-swift \
37+
"$SCRIPT_DIR/release/figma-swift"
38+
39+
echo "✅ Packaging succeeded for figma-swift"
40+
41+
echo "🔄 Building Figma SDK for iOS..."
42+
43+
set -x
44+
set -e
45+
46+
# Pass scheme name as the first argument to the script
47+
NAME=Figma
48+
49+
# Build the scheme for all platforms that we plan to support
50+
for PLATFORM in "iOS" "iOS Simulator"; do
51+
52+
case $PLATFORM in
53+
"iOS")
54+
RELEASE_FOLDER="Release-iphoneos"
55+
;;
56+
"iOS Simulator")
57+
RELEASE_FOLDER="Release-iphonesimulator"
58+
;;
59+
esac
60+
61+
ARCHIVE_PATH=$RELEASE_FOLDER
62+
63+
# Rewrite Package.swift so that it declaras dynamic libraries, since the approach does not work with static libraries
64+
perl -i -p0e 's/type: .static,//g' ./Package.swift
65+
perl -i -p0e 's/type: .dynamic,//g' ./Package.swift
66+
perl -i -p0e 's/(library[^,]*,)/$1 type: .dynamic,/g' ./Package.swift
67+
68+
xcodebuild archive -workspace ./ -scheme $NAME \
69+
-destination "generic/platform=$PLATFORM" \
70+
-archivePath $ARCHIVE_PATH \
71+
-derivedDataPath ".build" \
72+
SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
73+
74+
FRAMEWORK_PATH="$ARCHIVE_PATH.xcarchive/Products/usr/local/lib/$NAME.framework"
75+
MODULES_PATH="$FRAMEWORK_PATH/Modules"
76+
mkdir -p $MODULES_PATH
77+
78+
BUILD_PRODUCTS_PATH=".build/Build/Intermediates.noindex/ArchiveIntermediates/$NAME/BuildProductsPath"
79+
RELEASE_PATH="$BUILD_PRODUCTS_PATH/$RELEASE_FOLDER"
80+
SWIFT_MODULE_PATH="$RELEASE_PATH/$NAME.swiftmodule"
81+
RESOURCES_BUNDLE_PATH="$RELEASE_PATH/${NAME}_${NAME}.bundle"
82+
83+
# Copy Swift modules
84+
if [ -d $SWIFT_MODULE_PATH ]
85+
then
86+
cp -r $SWIFT_MODULE_PATH $MODULES_PATH
87+
else
88+
# In case there are no modules, assume C/ObjC library and create module map
89+
echo "module $NAME { export * }" > $MODULES_PATH/module.modulemap
90+
# Copy headers
91+
HEADERS_PATH="$RELEASE_PATH/include/$NAME"
92+
if [ -d "$HEADERS_PATH" ]; then
93+
mkdir -p "$FRAMEWORK_PATH/Headers"
94+
cp -R "$HEADERS_PATH/" "$FRAMEWORK_PATH/Headers/"
95+
else
96+
echo "Warning: No headers found at $HEADERS_PATH"
97+
fi
98+
fi
99+
100+
# Copy resources bundle, if exists
101+
if [ -e $RESOURCES_BUNDLE_PATH ]
102+
then
103+
cp -r $RESOURCES_BUNDLE_PATH $FRAMEWORK_PATH
104+
fi
105+
106+
done
107+
108+
xcodebuild -create-xcframework \
109+
-framework Release-iphoneos.xcarchive/Products/usr/local/lib/$NAME.framework \
110+
-framework Release-iphonesimulator.xcarchive/Products/usr/local/lib/$NAME.framework \
111+
-output "$SCRIPT_DIR/release/$NAME.xcframework"
112+
113+
# Move back to the root directory
114+
cd "$SCRIPT_DIR"
115+
116+
# Remove the .xcarchive files after creating the xcframework
117+
rm -rf Release-iphoneos.xcarchive Release-iphonesimulator.xcarchive
118+
119+
echo "✅ Packaging succeeded for Figma SDK for iOS"
120+
121+
echo "✅ All operations completed successfully"

0 commit comments

Comments
 (0)