This repository was archived by the owner on Dec 9, 2025. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·138 lines (115 loc) · 4.69 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·138 lines (115 loc) · 4.69 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/zsh
echo "iOS & macOS build script"
echo "Syntax: ./build.sh <config?>"
echo "Valid configurations: debug & release (Default: release)"
BINARY_PATH_IOS="dist/addons/apple_sign_in/ios"
BINARY_PATH_MACOS="dist/addons/apple_sign_in/macos"
BUILD_PATH_IOS=".build/arm64-apple-ios"
BUILD_PATH_MACOS=".build/x86_64-apple-macosx"
CONFIG=${1:-release}
COPY_COMMANDS=()
BOLD="$(tput bold)"
GREEN="$(tput setaf 2)"
CYAN="$(tput setaf 6)"
RED="$(tput setaf 1)"
RESET="$(tput sgr0)"
build_ios() {
xcodebuild \
-scheme "AppleSignInLibrary" \
-destination 'generic/platform=iOS' \
-derivedDataPath "$BUILD_PATH_IOS" \
-clonedSourcePackagesDirPath ".build" \
-configuration "$1" \
-skipPackagePluginValidation \
-skipMacroValidation \
-quiet
if [[ $? -gt 0 ]]; then
echo "${BOLD}${RED}Failed to build iOS library${RESET}"
return 1
fi
echo "${BOLD}${GREEN}iOS build succeeded${RESET}"
product_path="$BUILD_PATH_IOS/Build/Products/$1-iphoneos/PackageFrameworks"
for source in Sources/*; do
COPY_COMMANDS+=("cp -af \"$product_path/$source:t:r.framework\" \"$BINARY_PATH_IOS\"")
done
COPY_COMMANDS+=("cp -af \"$product_path/SwiftGodot.framework\" \"$BINARY_PATH_IOS\"")
}
build_macos() {
xcodebuild \
-scheme "AppleSignInLibrary" \
-destination 'generic/platform=macOS' \
-derivedDataPath "$BUILD_PATH_MACOS" \
-clonedSourcePackagesDirPath ".build" \
-configuration "$1" \
-skipPackagePluginValidation \
-skipMacroValidation \
-quiet
if [[ $? -gt 0 ]]; then
echo "${BOLD}${RED}Failed to build macOS library${RESET}"
return 1
fi
echo "${BOLD}${GREEN}macOS build succeeded${RESET}"
product_path="$BUILD_PATH_MACOS/Build/Products/$1-macos/PackageFrameworks"
[[ ! -d "$product_path" ]] && product_path="$BUILD_PATH_MACOS/Build/Products/$1/PackageFrameworks"
for source in Sources/*; do
COPY_COMMANDS+=("cp -af \"$product_path/$source:t:r.framework\" \"$BINARY_PATH_MACOS\"")
done
COPY_COMMANDS+=("cp -af \"$product_path/SwiftGodot.framework\" \"$BINARY_PATH_MACOS\"")
}
patch_swiftgodot_path() {
local bin="$1"
install_name_tool -change "@rpath/SwiftGodot.framework/Versions/A/SwiftGodot" "@loader_path/../../../SwiftGodot.framework/Versions/A/SwiftGodot" "$bin" 2>/dev/null || true
install_name_tool -change "@loader_path/../SwiftGodot.framework/Versions/A/SwiftGodot" "@loader_path/../../../SwiftGodot.framework/Versions/A/SwiftGodot" "$bin" 2>/dev/null || true
install_name_tool -change "@loader_path/../../SwiftGodot.framework/Versions/A/SwiftGodot" "@loader_path/../../../SwiftGodot.framework/Versions/A/SwiftGodot" "$bin" 2>/dev/null || true
}
patch_frameworks() {
local dir="$1"
[[ ! -d "$dir" ]] && return
echo "Patching macOS frameworks in $dir..."
for fw in "$dir"/*.framework; do
[[ ! -d "$fw" ]] && continue
[[ "$(basename "$fw")" = "SwiftGodot.framework" ]] && continue
local bin="$fw/$(basename "$fw" .framework)"
[[ -f "$bin" ]] && patch_swiftgodot_path "$bin"
done
}
verify_frameworks() {
local dir="$1"
[[ ! -d "$dir" ]] && return
echo "Verifying macOS binaries in $dir..."
for fw in "$dir"/*.framework; do
[[ ! -d "$fw" ]] && continue
[[ "$(basename "$fw")" = "SwiftGodot.framework" ]] && continue
local bin="$fw/$(basename "$fw" .framework)"
if [[ -f "$bin" ]] && otool -L "$bin" | grep -q "SwiftGodot.framework"; then
if ! otool -L "$bin" | grep -q "@loader_path/../../../SwiftGodot.framework/Versions/A/SwiftGodot"; then
echo "ERROR: $bin has incorrect SwiftGodot path"
exit 1
fi
fi
done
}
build_libs() {
echo "${BOLD}${CYAN}Building libraries ($1)...${RESET}"
build_ios "$1"
build_macos "$1"
if [[ ${#COPY_COMMANDS[@]} -gt 0 ]]; then
echo "${BOLD}${CYAN}Copying frameworks to dist/...${RESET}"
rm -rf "$BINARY_PATH_IOS" "$BINARY_PATH_MACOS"
mkdir -p "$BINARY_PATH_IOS" "$BINARY_PATH_MACOS"
for instruction in ${COPY_COMMANDS[@]}; do
eval $instruction
done
patch_frameworks "$BINARY_PATH_MACOS"
if [[ -d "dist/addons" && -d "demo" ]]; then
echo "Copying to demo/addons..."
mkdir -p "demo/addons"
rm -rf "demo/addons/apple_sign_in"
cp -a dist/addons/* "demo/addons/"
patch_frameworks "demo/addons/apple_sign_in/macos"
verify_frameworks "demo/addons/apple_sign_in/macos"
fi
fi
echo "${BOLD}${GREEN}Finished building $1 libraries${RESET}"
}
build_libs "$CONFIG"