-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.sh
executable file
·132 lines (99 loc) · 2.81 KB
/
build.sh
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
#!/bin/zsh
# MARK: Help
# Syntax: ./build.sh <platform?> <config?>"
# Valid platforms are: mac, ios & all (Default: all)
# Valid configurations are: debug & release (Default: release)
# MARK: Settings
BINARY_PATH_IOS="Bin/ios"
BUILD_PATH_IOS=".build/arm64-apple-ios"
BINARY_PATH_MACOS="Bin/macos"
BUILD_PATH_MACOS=".build"
# MARK: Inputs
TARGET=$1
CONFIG=$2
if [[ ! $TARGET ]]; then
TARGET="all"
fi
if [[ ! $CONFIG ]]; then
CONFIG="release"
fi
COPY_COMMANDS=()
# MARK: Build iOS
build_ios() {
xcodebuild \
-scheme "iOS Plugins-Package" \
-destination 'generic/platform=iOS' \
-derivedDataPath "$BUILD_PATH_IOS" \
-clonedSourcePackagesDirPath ".build" \
-configuration "$1" \
-skipPackagePluginValidation \
-quiet
if [[ $? -gt 0 ]]; then
echo "${BOLD}${RED}Failed to build $target iOS library${RESET_FORMATTING}"
return 1
fi
echo "${BOLD}${GREEN}iOS build succeeded${RESET_FORMATTING}"
product_path="$BUILD_PATH_IOS/Build/Products/$1-iphoneos/PackageFrameworks"
source_path="Sources"
for source in $source_path/*; 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")
return 0
}
# MARK: Build macOS
build_macos() {
swift build \
--configuration "$1" \
--scratch-path "$BUILD_PATH_MACOS" \
--quiet
if [[ $? -gt 0 ]]; then
echo "${BOLD}${RED}Failed to build macOS library${RESET_FORMATTING}"
return 1
fi
echo "${BOLD}${GREEN}macOS build succeeded${RESET_FORMATTING}"
if [[ $(uname -m) == "x86_64" ]]; then
product_path="$BUILD_PATH_MACOS/x86_64-apple-macosx/$1"
else
product_path="$BUILD_PATH_MACOS/arm64-apple-macosx/$1"
fi
source_path="Sources"
for folder in $source_path/*
do
COPY_COMMANDS+=("cp -af $product_path/lib$folder:t:r.dylib $BINARY_PATH_MACOS")
done
COPY_COMMANDS+=("cp -af $product_path/libSwiftGodot.dylib $BINARY_PATH_MACOS")
return 0
}
# MARK: Pre & Post process
build_libs() {
echo "Building libraries..."
if [[ "$1" == "all" || "$1" == "macos" ]]; then
echo "${BOLD}${CYAN}Building macOS library ($2)...${RESET_FORMATTING}"
build_macos "$2"
fi
if [[ "$1" == "all" || "$1" == "ios" ]]; then
echo "${BOLD}${CYAN}Building iOS libraries ($2)...${RESET_FORMATTING}"
build_ios "$2"
fi
if [[ ${#COPY_COMMANDS[@]} -gt 0 ]]; then
echo "${BOLD}${CYAN}Copying binaries...${RESET_FORMATTING}"
for instruction in ${COPY_COMMANDS[@]}
do
target=${instruction##* }
if ! [[ -e "$target" ]]; then
mkdir -p "$target"
fi
eval $instruction
done
fi
echo "${BOLD}${GREEN}Finished building $2 libraries for $1 platforms${RESET_FORMATTING}"
}
# MARK: Formatting
BOLD="$(tput bold)"
GREEN="$(tput setaf 2)"
CYAN="$(tput setaf 6)"
RED="$(tput setaf 1)"
RESET_FORMATTING="$(tput sgr0)"
# MARK: Run
build_libs "$TARGET" "$CONFIG"