forked from SwiftedMind/GRDBCustomSQLiteBuild
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_binary.sh
More file actions
executable file
·214 lines (168 loc) · 7.26 KB
/
make_binary.sh
File metadata and controls
executable file
·214 lines (168 loc) · 7.26 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/bash
#######################################################
# PROJECT PATHS
# !! MODIFY THESE TO MATCH YOUR PROJECT HIERARCHY !!
# Paths are relative to the location of this script.
#######################################################
# The path to the folder containing GRDBCustom.xcodeproj:
GRDB_SOURCE_PATH="GRDB"
# The path to your custom "SQLiteLib-USER.xcconfig":
SQLITELIB_XCCONFIG_USER_PATH="CustomSQLiteConfig/SQLiteLib-USER.xcconfig"
# The path to your custom "GRDBCustomSQLite-USER.xcconfig":
CUSTOMSQLITE_XCCONFIG_USER_PATH="CustomSQLiteConfig/GRDBCustomSQLite-USER.xcconfig"
# The path to your custom "GRDBCustomSQLite-USER.h":
CUSTOMSQLITE_H_USER_PATH="CustomSQLiteConfig/GRDBCustomSQLite-USER.h"
# The name of the .framework output file (We usually want GRDB.framework)
FRAMEWORK_NAME="GRDB"
# The directory in which the .framework file will be placed (must be reachable for the Swift Package)
OUTPUT_PATH="Binary"
# Build configuration. Usually Release is fine.
CONFIGURATION="Release"
#######################################################
#
#######################################################
# The path to the GRDBCustom.xcodeproj file
GRDB_PROJECT_PATH="${GRDB_SOURCE_PATH}/GRDBCustom.xcodeproj"
# The scheme that builds GRDBCustom
GRDB_SCHEME_NAME="GRDBCustom"
# Create a temporary build location
BUILD_DIR="$(mktemp -d)/Build"
#######################################################
#
#######################################################
# Helper function to copy over the configuration files
copy_config_file() {
local source_file="$1"
local dest_path="$2"
local full_source="${source_file}"
local full_dest="${dest_path}"
if [ ! -f "$full_source" ]; then
echo "error: Source configuration file missing: $full_source"
exit 1
fi
echo " Copying ${source_file} to ${dest_path}"
# Create destination directory if it doesn't exist
mkdir -p "$(dirname "$full_dest")"
# Copy file preserving metadata
cp -p "$full_source" "$full_dest"
}
#######################################################
# --- Added: detect which platforms to build ----------
#######################################################
# Normalise incoming arguments to lower-case
REQUESTED_PLATFORMS=()
if [ "$#" -eq 0 ]; then
# If no args: default to *all* supported platforms
REQUESTED_PLATFORMS=(ios tvos watchos macos catalyst)
else
for arg in "$@"; do
REQUESTED_PLATFORMS+=("$(echo "$arg" | tr '[:upper:]' '[:lower:]')")
done
fi
# Helper to check whether a platform was requested
platform_requested() {
local needle="$1"
for p in "${REQUESTED_PLATFORMS[@]}"; do
if [[ "$p" == "$needle" ]]; then
return 0
fi
done
return 1
}
#######################################################
#
#######################################################
# Exit immediately if a command exits with a non-zero status.
set -e
# --- Sync Custom Config Files ---
echo "Syncing custom configuration files..."
# Define source file names and their destination paths within FRAMEWORK_PROJ_DIR
copy_config_file "${SQLITELIB_XCCONFIG_USER_PATH}" "${GRDB_SOURCE_PATH}/SQLiteCustom/src/SQLiteLib-USER.xcconfig"
copy_config_file "${CUSTOMSQLITE_XCCONFIG_USER_PATH}" "${GRDB_SOURCE_PATH}/SQLiteCustom/GRDBCustomSQLite-USER.xcconfig"
copy_config_file "${CUSTOMSQLITE_H_USER_PATH}" "${GRDB_SOURCE_PATH}/SQLiteCustom/GRDBCustomSQLite-USER.h"
echo "✓ Finished syncing configuration files."
# --- End Sync ---
echo "--- Building XCFramework for ${FRAMEWORK_NAME} ---"
echo "Framework Project: ${GRDB_PROJECT_PATH}"
echo "Output Directory: ${OUTPUT_PATH}"
echo "Build Directory: ${BUILD_DIR}"
echo "Configuration: ${CONFIGURATION}"
echo "Requested platforms: ${REQUESTED_PLATFORMS[*]}"
# Ensure output directory exists
mkdir -p "${OUTPUT_PATH}"
# Clean previous output
rm -rf "${OUTPUT_PATH}/${FRAMEWORK_NAME}.xcframework"
# Array that will collect all the -framework parameters for -create-xcframework
XCFRAMEWORK_COMPONENTS=()
#######################################################
# --- Added: platform-specific build helpers ----------
#######################################################
archive_pair() {
local device_dest="$1" # e.g. "generic/platform=iOS"
local sim_dest="$2" # e.g. "generic/platform=iOS Simulator"
local base_name="$3" # e.g. "iphoneos"
local device_path="${BUILD_DIR}/${FRAMEWORK_NAME}-${CONFIGURATION}-${base_name}.xcarchive"
local sim_path="${BUILD_DIR}/${FRAMEWORK_NAME}-${CONFIGURATION}-${base_name}sim.xcarchive"
echo "Archiving for ${base_name} Device..."
xcodebuild archive \
-project "${GRDB_PROJECT_PATH}" \
-scheme "${GRDB_SCHEME_NAME}" \
-configuration "${CONFIGURATION}" \
-destination "${device_dest}" \
-archivePath "${device_path}" \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
echo "Archiving for ${base_name} Simulator..."
xcodebuild archive \
-project "${GRDB_PROJECT_PATH}" \
-scheme "${GRDB_SCHEME_NAME}" \
-configuration "${CONFIGURATION}" \
-destination "${sim_dest}" \
-archivePath "${sim_path}" \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
XCFRAMEWORK_COMPONENTS+=("-framework" "${device_path}/Products/Library/Frameworks/${FRAMEWORK_NAME}.framework")
XCFRAMEWORK_COMPONENTS+=("-framework" "${sim_path}/Products/Library/Frameworks/${FRAMEWORK_NAME}.framework")
}
archive_single() {
local dest="$1" # e.g. "generic/platform=macOS"
local base_name="$2" # e.g. "macos"
local path="${BUILD_DIR}/${FRAMEWORK_NAME}-${CONFIGURATION}-${base_name}.xcarchive"
echo "Archiving for ${base_name}..."
xcodebuild archive \
-project "${GRDB_PROJECT_PATH}" \
-scheme "${GRDB_SCHEME_NAME}" \
-configuration "${CONFIGURATION}" \
-destination "${dest}" \
-archivePath "${path}" \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
XCFRAMEWORK_COMPONENTS+=("-framework" "${path}/Products/Library/Frameworks/${FRAMEWORK_NAME}.framework")
}
#######################################################
# --- Added: perform builds based on arguments --------
#######################################################
if platform_requested ios; then
archive_pair "generic/platform=iOS" "generic/platform=iOS Simulator" "iphoneos"
fi
if platform_requested tvos; then
archive_pair "generic/platform=tvOS" "generic/platform=tvOS Simulator" "tvos"
fi
if platform_requested watchos; then
archive_pair "generic/platform=watchOS" "generic/platform=watchOS Simulator" "watchos"
fi
if platform_requested macos; then
archive_single "generic/platform=macOS" "macos"
fi
if platform_requested catalyst; then
archive_single "generic/platform=macOS,variant=Mac Catalyst" "catalyst"
fi
#######################################################
# --- Create the XCFramework --------------------------
#######################################################
echo "Creating XCFramework..."
xcodebuild -create-xcframework \
"${XCFRAMEWORK_COMPONENTS[@]}" \
-output "${OUTPUT_PATH}/${FRAMEWORK_NAME}.xcframework"
echo "✓ XCFramework created at: ${OUTPUT_PATH}/${FRAMEWORK_NAME}.xcframework"
echo "--- XCFramework script finished ---"