Skip to content

Commit 9ba7eb9

Browse files
committed
Fixed iOS build.
1 parent 998fe33 commit 9ba7eb9

File tree

10 files changed

+232
-117
lines changed

10 files changed

+232
-117
lines changed

ios/SConstruct

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ opts.Add(EnumVariable('arch', "Compilation Architecture", '', ['', 'arm64', 'x86
2929
opts.Add(BoolVariable('simulator', "Compilation platform", 'no'))
3030
opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no'))
3131
opts.Add('target_name', 'Resulting file name.', '')
32-
opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'bin/lib/'))
32+
opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'build/lib/'))
3333
opts.Add(EnumVariable('version', 'Godot version to target', '', valid_godot_versions))
3434

3535
# Updates the environment with the option variables.
@@ -67,24 +67,19 @@ architecture_directory = ''
6767
if env['simulator']:
6868
architecture_directory = 'ios-arm64_x86_64-simulator'
6969
sdk_name = 'iphonesimulator'
70-
env.Append(CCFLAGS=['-mios-simulator-version-min=10.0'])
71-
env.Append(LINKFLAGS=["-mios-simulator-version-min=10.0"])
70+
env.Append(CCFLAGS=['-mios-simulator-version-min=14.3'])
71+
env.Append(LINKFLAGS=["-mios-simulator-version-min=14.3"])
7272
else:
7373
architecture_directory = 'ios-arm64'
7474
sdk_name = 'iphoneos'
75-
env.Append(CCFLAGS=['-miphoneos-version-min=10.0'])
76-
env.Append(LINKFLAGS=["-miphoneos-version-min=10.0"])
75+
env.Append(CCFLAGS=['-miphoneos-version-min=14.3'])
76+
env.Append(LINKFLAGS=["-miphoneos-version-min=14.3"])
7777

7878
try:
7979
sdk_path = decode_utf8(subprocess.check_output(['xcrun', '--sdk', sdk_name, '--show-sdk-path']).strip())
8080
except (subprocess.CalledProcessError, OSError):
8181
raise ValueError("Failed to find SDK path while running xcrun --sdk {} --show-sdk-path.".format(sdk_name))
8282

83-
84-
env.Append(FRAMEWORKPATH=[f'#Pods/Google-Mobile-Ads-SDK/Frameworks/GoogleMobileAdsFramework/GoogleMobileAds.xcframework/{architecture_directory}'])
85-
env.Append(FRAMEWORKPATH=[f'#Pods/GoogleUserMessagingPlatform/Frameworks/Release/UserMessagingPlatform.xcframework/{architecture_directory}'])
86-
87-
8883
env.Append(CCFLAGS=[
8984
'-fobjc-arc',
9085
'-fmessage-length=0', '-fno-strict-aliasing', '-fdiagnostics-print-source-range-info',

ios/script/build.sh

100644100755
Lines changed: 75 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,30 @@ set -e
77
trap "sleep 1; echo" EXIT
88

99
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
10+
GODOT_DIR=$(realpath $SCRIPT_DIR/..)/godot
1011
ANDROID_DIR=$(realpath $SCRIPT_DIR/../../android)
12+
BUILD_DIR=$(realpath $SCRIPT_DIR/..)/build
13+
CONFIG_DIR=$(realpath $SCRIPT_DIR/../config)
1114

1215
PLUGIN_NODE_TYPE="Share"
1316
PLUGIN_NAME="${PLUGIN_NODE_TYPE}Plugin"
1417
PLUGIN_VERSION=''
1518
PLUGIN_PACKAGE_NAME=$($SCRIPT_DIR/get_gradle_property.sh pluginPackageName $ANDROID_DIR/config.gradle.kts)
1619
ANDROID_DEPENDENCIES=$($SCRIPT_DIR/get_android_dependencies.sh)
17-
readarray -t IOS_FRAMEWORKS <<< "$($SCRIPT_DIR/get_config_property.sh -qas frameworks)"
18-
readarray -t IOS_LINKER_FLAGS <<< "$($SCRIPT_DIR/get_config_property.sh -qas flags)"
20+
IOS_FRAMEWORKS=()
21+
while IFS= read -r line; do
22+
IOS_FRAMEWORKS+=("$line")
23+
done < <($SCRIPT_DIR/get_config_property.sh -qas frameworks)
24+
IOS_LINKER_FLAGS=()
25+
while IFS= read -r line; do
26+
IOS_LINKER_FLAGS+=("$line")
27+
done < <($SCRIPT_DIR/get_config_property.sh -qas flags)
1928
SUPPORTED_GODOT_VERSIONS=("4.2" "4.3" "4.4" "4.5")
2029
BUILD_TIMEOUT=40 # increase this value using -t option if device is not able to generate all headers before godot build is killed
2130

22-
DEST_DIRECTORY="./bin/release"
23-
FRAMEWORKDIR="./bin/framework"
24-
LIB_DIRECTORY="./bin/lib"
25-
CONFIG_DIRECTORY="./config"
31+
DEST_DIR=$BUILD_DIR/release
32+
FRAMEWORKDIR=$BUILD_DIR/framework
33+
LIB_DIR=$BUILD_DIR/lib
2634

2735
do_clean=false
2836
do_remove_pod_trunk=false
@@ -120,20 +128,26 @@ function display_error()
120128

121129
function remove_godot_directory()
122130
{
123-
if [[ -d "godot" ]]
131+
if [[ -d "$GODOT_DIR" ]]
124132
then
125-
display_status "removing 'godot' directory..."
126-
rm -rf "godot"
133+
display_status "removing '$GODOT_DIR' directory..."
134+
rm -rf $GODOT_DIR
127135
else
128-
display_warning "'godot' directory not found..."
136+
display_warning "'$GODOT_DIR' directory not found!"
129137
fi
130138
}
131139

132140

133141
function clean_plugin_build()
134142
{
135-
display_status "cleaning existing build directories and generated files..."
136-
rm -rf ./bin/*
143+
if [[ -d "$BUILD_DIR" ]]
144+
then
145+
display_status "removing '$BUILD_DIR' directory..."
146+
rm -rf $BUILD_DIR
147+
else
148+
display_warning "'$BUILD_DIR' directory not found!"
149+
fi
150+
display_status "cleaning generated files..."
137151
find . -name "*.d" -type f -delete
138152
find . -name "*.o" -type f -delete
139153
}
@@ -158,25 +172,21 @@ function download_godot()
158172
exit 1
159173
fi
160174

161-
if [[ -d "godot" ]]
175+
if [[ -d "$GODOT_DIR" ]]
162176
then
163-
display_error "Error: godot directory already exists. Won't download."
177+
display_error "Error: $GODOT_DIR directory already exists. Won't download."
164178
exit 1
165179
fi
166180

167181
SELECTED_GODOT_VERSION=$1
168182
display_status "downloading godot version $SELECTED_GODOT_VERSION..."
169183

170-
godot_directory="godot-${SELECTED_GODOT_VERSION}-stable"
171-
godot_archive_file_name="${godot_directory}.tar.xz"
184+
$SCRIPT_DIR/fetch_git_repo.sh -t ${SELECTED_GODOT_VERSION}-stable https://github.com/godotengine/godot.git $GODOT_DIR
172185

173-
curl -LO "https://github.com/godotengine/godot/releases/download/${SELECTED_GODOT_VERSION}-stable/${godot_archive_file_name}"
174-
tar -xf "$godot_archive_file_name"
175-
176-
mv "$godot_directory" godot
177-
rm $godot_archive_file_name
178-
179-
echo "$SELECTED_GODOT_VERSION" > godot/GODOT_VERSION
186+
if [[ -d "$GODOT_DIR" ]]
187+
then
188+
echo "$SELECTED_GODOT_VERSION" > $GODOT_DIR/GODOT_VERSION
189+
fi
180190
}
181191

182192

@@ -198,13 +208,13 @@ function generate_godot_headers()
198208

199209
function generate_static_library()
200210
{
201-
if [[ ! -f "./godot/GODOT_VERSION" ]]
211+
if [[ ! -f "$GODOT_DIR/GODOT_VERSION" ]]
202212
then
203213
display_error "Error: godot wasn't downloaded properly. Can't generate static library."
204214
exit 1
205215
fi
206216

207-
GODOT_VERSION=$(cat ./godot/GODOT_VERSION)
217+
GODOT_VERSION=$(cat $GODOT_DIR/GODOT_VERSION)
208218

209219
TARGET_TYPE="$1"
210220
lib_directory="$2"
@@ -232,45 +242,63 @@ function install_pods()
232242

233243
function build_plugin()
234244
{
235-
if [[ ! -f "./godot/GODOT_VERSION" ]]
245+
if [[ ! -f "$GODOT_DIR/GODOT_VERSION" ]]
236246
then
237247
display_error "Error: godot wasn't downloaded properly. Can't build plugin."
238248
exit 1
239249
fi
240250

241-
GODOT_VERSION=$(cat ./godot/GODOT_VERSION)
251+
GODOT_VERSION=$(cat $GODOT_DIR/GODOT_VERSION)
242252

243253
# Clear target directories
244-
rm -rf "$DEST_DIRECTORY"
245-
rm -rf "$LIB_DIRECTORY"
254+
rm -rf "$DEST_DIR"
255+
rm -rf "$LIB_DIR"
246256

247257
# Create target directories
248-
mkdir -p "$DEST_DIRECTORY"
249-
mkdir -p "$LIB_DIRECTORY"
258+
mkdir -p "$DEST_DIR"
259+
mkdir -p "$LIB_DIR"
250260

251261
display_status "building plugin library with godot version $GODOT_VERSION ..."
252262

253263
# Compile library
254-
generate_static_library release $LIB_DIRECTORY
255-
generate_static_library release_debug $LIB_DIRECTORY
256-
mv $LIB_DIRECTORY/$PLUGIN_NAME.release_debug.a $LIB_DIRECTORY/$PLUGIN_NAME.debug.a
264+
generate_static_library release $LIB_DIR
265+
generate_static_library release_debug $LIB_DIR
266+
mv $LIB_DIR/$PLUGIN_NAME.release_debug.a $LIB_DIR/$PLUGIN_NAME.debug.a
257267

258268
# Move library
259-
cp $LIB_DIRECTORY/$PLUGIN_NAME.{release,debug}.a "$DEST_DIRECTORY"
269+
cp $LIB_DIR/$PLUGIN_NAME.{release,debug}.a "$DEST_DIR"
270+
271+
cp "$CONFIG_DIR"/*.gdip "$DEST_DIR"
272+
}
273+
274+
275+
function merge_string_array() {
276+
local arr=("$@") # Accept array as input
277+
local result=""
278+
local first=true
279+
280+
for str in "${arr[@]}"; do
281+
if [ "$first" = true ]; then
282+
result="$str"
283+
first=false
284+
else
285+
result="$result, $str"
286+
fi
287+
done
260288

261-
cp "$CONFIG_DIRECTORY"/*.gdip "$DEST_DIRECTORY"
289+
echo "$result"
262290
}
263291

264292

265293
function create_zip_archive()
266294
{
267-
if [[ ! -f "./godot/GODOT_VERSION" ]]
295+
if [[ ! -f "$GODOT_DIR/GODOT_VERSION" ]]
268296
then
269297
display_error "Error: godot wasn't downloaded properly. Can't create zip archive."
270298
exit 1
271299
fi
272300

273-
GODOT_VERSION=$(cat ./godot/GODOT_VERSION)
301+
GODOT_VERSION=$(cat $GODOT_DIR/GODOT_VERSION)
274302

275303
if [[ -z $PLUGIN_VERSION ]]
276304
then
@@ -281,13 +309,13 @@ function create_zip_archive()
281309

282310
file_name="$PLUGIN_NAME-$godot_version_suffix.zip"
283311

284-
if [[ -e "./bin/release/$file_name" ]]
312+
if [[ -e "$BUILD_DIR/release/$file_name" ]]
285313
then
286314
display_warning "deleting existing $file_name file..."
287-
rm ./bin/release/$file_name
315+
rm $BUILD_DIR/release/$file_name
288316
fi
289317

290-
tmp_directory=$(realpath $SCRIPT_DIR/../bin/.tmp_zip)
318+
tmp_directory=$BUILD_DIR/.tmp_zip
291319
addon_directory=$(realpath $SCRIPT_DIR/../../addon)
292320

293321
if [[ -d "$tmp_directory" ]]
@@ -321,8 +349,8 @@ function create_zip_archive()
321349
s/@pluginNodeName@/$PLUGIN_NODE_TYPE/g;
322350
s/@pluginPackageName@/$PLUGIN_PACKAGE_NAME/g;
323351
s/@pluginDependencies@/$ANDROID_DEPENDENCIES/g;
324-
s/@iosFrameworks@/$IOS_FRAMEWORKS/g;
325-
s/@iosLinkerFlags@/$IOS_LINKER_FLAGS/g
352+
s/@iosFrameworks@/$(merge_string_array $IOS_FRAMEWORKS)/g;
353+
s/@iosLinkerFlags@/$(merge_string_array $IOS_LINKER_FLAGS)/g
326354
" "$file"
327355
done
328356
fi
@@ -331,10 +359,10 @@ function create_zip_archive()
331359
find $(realpath $SCRIPT_DIR/../Pods) -iname '*.xcframework' -type d -exec cp -r {} $tmp_directory/ios/framework \;
332360

333361
mkdir -p $tmp_directory/ios/plugins
334-
cp $CONFIG_DIRECTORY/*.gdip $tmp_directory/ios/plugins
335-
cp $LIB_DIRECTORY/$PLUGIN_NAME.{release,debug}.a $tmp_directory/ios/plugins
362+
cp $CONFIG_DIR/*.gdip $tmp_directory/ios/plugins
363+
cp $LIB_DIR/$PLUGIN_NAME.{release,debug}.a $tmp_directory/ios/plugins
336364

337-
mkdir -p $DEST_DIRECTORY
365+
mkdir -p $DEST_DIR
338366

339367
display_status "creating $file_name file..."
340368
cd $tmp_directory; zip -yr ../release/$file_name ./*; cd -
@@ -412,7 +440,7 @@ while getopts "aA:bcgG:hHipPt:z:" option; do
412440
esac
413441
done
414442

415-
if ! [[ " ${SUPPORTED_GODOT_VERSIONS[*]} " =~ [[:space:]]${GODOT_VERSION}[[:space:]] ]]
443+
if ! [[ " ${SUPPORTED_GODOT_VERSIONS[*]} " =~ [[:space:]]${GODOT_VERSION}[[:space:]] ]] && [[ "$do_build" == true ]]
416444
then
417445
if [[ "$do_download_godot" == false ]]
418446
then

ios/script/fetch_git_repo.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
#
3+
# © 2024-present https://github.com/cengiz-pz
4+
#
5+
6+
# Function to show usage
7+
usage() {
8+
echo "Usage: $0 [-t <tag>] <repo_url> <target_directory>"
9+
exit 1
10+
}
11+
12+
# Parse options
13+
TAG=""
14+
while getopts ":t:" opt; do
15+
case $opt in
16+
t)
17+
TAG="$OPTARG"
18+
;;
19+
\?)
20+
echo "Invalid option: -$OPTARG" >&2
21+
usage
22+
;;
23+
:)
24+
echo "Option -$OPTARG requires an argument." >&2
25+
usage
26+
;;
27+
esac
28+
done
29+
30+
shift $((OPTIND -1))
31+
32+
# Validate positional arguments
33+
if [ $# -ne 2 ]; then
34+
usage
35+
fi
36+
37+
REPO_URL="$1"
38+
TARGET_DIR="$2"
39+
40+
# Function to check if a remote tag exists
41+
tag_exists() {
42+
git ls-remote --tags "$1" | grep -q "refs/tags/$2$"
43+
}
44+
45+
# Determine cloning strategy
46+
if [ -n "$TAG" ]; then
47+
echo "Checking if tag '$TAG' exists in the repository..."
48+
49+
if tag_exists "$REPO_URL" "$TAG"; then
50+
echo "Tag '$TAG' found. Cloning..."
51+
git clone --branch "$TAG" --depth 1 "$REPO_URL" "$TARGET_DIR"
52+
else
53+
echo "Warning: Tag '$TAG' not found. Falling back to latest commit on 'master' branch..."
54+
git clone --branch master --depth 1 "$REPO_URL" "$TARGET_DIR"
55+
fi
56+
else
57+
echo "No tag specified. Cloning latest commit from 'master'..."
58+
git clone --branch master --depth 1 "$REPO_URL" "$TARGET_DIR"
59+
fi
60+
61+
# Check for success
62+
if [ $? -ne 0 ]; then
63+
echo "Failed to clone repository."
64+
exit 1
65+
fi
66+
67+
echo "Repository successfully cloned into '$TARGET_DIR'."

0 commit comments

Comments
 (0)