Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactory and add support platform #28

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
108 changes: 76 additions & 32 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ else:

# Most of the settings are taken from https://github.com/BastiaanOlij/gdnative_cpp_example

opts = Variables([], ARGUMENTS)
opts = Variable([], ARGUMENTS)

# Gets the standard flags CC, CCX, etc.
env = DefaultEnvironment()

# Define our options
opts.Add(EnumVariable('platform', 'Platform build', 'iphone', ['', 'iphone', 'tvos']))
opts.Add(EnumVariable('target', "Compilation target", 'debug', ['debug', 'release', "release_debug"]))
opts.Add(EnumVariable('arch', "Compilation Architecture", '', ['', 'arm64', 'armv7', 'x86_64']))
opts.Add(BoolVariable('simulator', "Compilation platform", 'no'))
Expand All @@ -27,9 +28,15 @@ opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'bi
opts.Add(EnumVariable('plugin', 'Plugin to build', '', ['', 'apn', 'arkit', 'camera', 'icloud', 'gamecenter', 'inappstore', 'photo_picker']))
opts.Add(EnumVariable('version', 'Godot version to target', '', ['', '3.x', '4.0']))


opts.Add('sdk_version', 'SDK version ', '10.0')
# Updates the environment with the option variables.
opts.Update(env)


# Generates help for the -h scons option.
Help(opts.GenerateHelpText(env))

# Process some arguments
if env['use_llvm']:
env['CC'] = 'clang'
Expand All @@ -47,6 +54,15 @@ if env['version'] == '':
print("No valid Godot version selected.")
quit();

if env['platform'] == '':
print("No valid platform selected.")
quit();

if env['sdk_version'] == '':
print("sdk version invalid.")
quit();


# For the reference:
# - CCFLAGS are compilation flags shared between C and C++
# - CFLAGS are for C-specific compilation flags
Expand All @@ -55,20 +71,34 @@ if env['version'] == '':
# - CPPDEFINES are for pre-processor defines
# - LINKFLAGS are for linking flags


# Enable Obj-C modules
env.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])

if env['simulator']:
sdk_name = 'iphonesimulator'
env.Append(CCFLAGS=['-mios-simulator-version-min=10.0'])
env.Append(LINKFLAGS=["-mios-simulator-version-min=10.0"])
else:
sdk_name = 'iphoneos'
env.Append(CCFLAGS=['-miphoneos-version-min=10.0'])
env.Append(LINKFLAGS=["-miphoneos-version-min=10.0"])

if env['platform'] == 'iphone':
sdk_def_enable = '-DIPHONE_ENABLED'
sdk_def = 'IPHONESDK'
if env['simulator']:
sdk_name = 'iphonesimulator'
flag_version_min = '-mios-simulator-version-min='
else:
sdk_name = 'iphoneos'
flag_version_min = '-miphoneos-version-min='
elif env['platform'] == 'tvos' :
sdk_def_enable = '-DTVOS_ENABLED'
sdk_def = "TVOSSDK"
if env['simulator']:
sdk_name = 'appletvsimulator'
flag_version_min = '-mappletvsimulator-version-min='
else:
sdk_name = 'appletvos'
flag_version_min = '-mappletvos-version-min='

try:
sdk_path = decode_utf8(subprocess.check_output(['xcrun', '--sdk', sdk_name, '--show-sdk-path']).strip())
if sdk_path :
env[sdk_def] = sdk_path #SDK IPHONESDK=sdk_path
except (subprocess.CalledProcessError, OSError):
raise ValueError("Failed to find SDK path while running xcrun --sdk {} --show-sdk-path.".format(sdk_name))

Expand All @@ -82,13 +112,18 @@ env.Append(CCFLAGS=[
# '-Wextra',
])

env.Append(CCFLAGS=['-arch', env['arch'], "-isysroot", "$IPHONESDK", "-stdlib=libc++", '-isysroot', sdk_path])


env.Append(CCFLAGS=['-isysroot', sdk_path, flag_version_min + env['sdk_version']])
env.Append(LINKFLAGS=['-isysroot', sdk_path, flag_version_min + env['sdk_version'], '-F' + sdk_path])

env.Append(CCFLAGS=['-arch', env['arch'], '-stdlib=libc++'])
env.Append(CCFLAGS=['-DPTRCALL_ENABLED'])
env.Prepend(CXXFLAGS=[
'-DNEED_LONG_INT', '-DLIBYUV_DISABLE_NEON',
'-DIPHONE_ENABLED', '-DUNIX_ENABLED', '-DCOREAUDIO_ENABLED'
sdk_def_enable, '-DUNIX_ENABLED', '-DCOREAUDIO_ENABLED'
])
env.Append(LINKFLAGS=["-arch", env['arch'], '-isysroot', sdk_path, '-F' + sdk_path])
env.Append(LINKFLAGS=["-arch", env['arch'], '-F' + sdk_path])

if env['arch'] == 'armv7':
env.Prepend(CXXFLAGS=['-fno-aligned-allocation'])
Expand All @@ -97,6 +132,14 @@ if env['version'] == '3.x':
env.Prepend(CFLAGS=['-std=gnu11'])
env.Prepend(CXXFLAGS=['-DGLES_ENABLED', '-std=gnu++14'])

env.Prepend(
CPPPATH=[
sdk_path + "/usr/include",
sdk_path + "/System/Library/Frameworks/OpenGLES.framework/Headers",
sdk_path + "/System/Library/Frameworks/AudioUnit.framework/Headers",
]
)

if env['target'] == 'debug':
env.Prepend(CXXFLAGS=[
'-gdwarf-2', '-O0',
Expand Down Expand Up @@ -151,33 +194,34 @@ else:
print("No valid version to set flags for.")
quit();

# Adding header files
env.Append(CPPPATH=[
'.',
'godot',
'godot/main',
'godot/core',
'godot/core/os',
'godot/core/platform',
'godot/platform/iphone',
'godot/modules',
'godot/scene',
'godot/servers',
'godot/drivers',
'godot/thirdparty',
])
if env['platform'] == 'iphone' :

# Adding header files
env.Append(CPPPATH=[
'.',
'godot',
'godot/platform/iphone',
])

elif env['platform'] == 'tvos' :
# Adding header files
env.Append(CPPPATH=[
'.',
'godot',
'godot/platform/tvos',
])


# tweak this if you want to use different folders, or more folders, to store your source code in.
sources = Glob('plugins/' + env['plugin'] + '/*.cpp')
sources.append(Glob('plugins/' + env['plugin'] + '/*.mm'))
sources.append(Glob('plugins/' + env['plugin'] + '/*.m'))

# lib<plugin>.<arch>-<simulator|iphone>.<release|debug|release_debug>.a
library_platform = env["arch"] + "-" + ("simulator" if env["simulator"] else "iphone")
library_name = env['plugin'] + "." + library_platform + "." + env["target"] + ".a"
# lib<plugin>.<arch>-<platform>.<simulator>.<release|debug|release_debug>.a
# lib<plugin>.<arch>-<platform>.<release|debug|release_debug>.a
library_platform = env['arch'] + '-' + env['platform'] + ('.simulator' if env['simulator'] else '')
library_name = env['plugin'] + "." + library_platform + "." + env['target'] + '.a'
library = env.StaticLibrary(target=env['target_path'] + library_name, source=sources)

Default(library)

# Generates help for the -h scons option.
Help(opts.GenerateHelpText(env))
2 changes: 1 addition & 1 deletion godot
Submodule godot updated 4448 files
9 changes: 9 additions & 0 deletions plugins/inappstore/in_app_store.mm
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@ - (void)finishTransactionWithProductID:(NSString *)productID {
self.pendingTransactions[productID] = nil;
}

- (BOOL)paymentQueue:(SKPaymentQueue *)queue shouldAddStorePayment:(SKPayment *)payment forProduct:(SKProduct *)product {
Copy link
Author

@Valeryn4 Valeryn4 Jan 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops...
Accidentally sent this development. Its deferred purchase.

The event is used when a purchase has been initiated outside of the app.

Dictionary ret;
ret["type"] = "purchase_deferred";
ret["result"] = "ok";
ret["product_id"] = String::utf8([payment.productIdentifier UTF8String]);
InAppStore::get_singleton()->_post_event(ret);
return false;
}

- (void)reset {
[self.pendingTransactions removeAllObjects];
}
Expand Down
33 changes: 21 additions & 12 deletions scripts/generate_static_library.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
#!/bin/bash
set -e

# Compile static libraries

# ARM64 Device
scons target=$2 arch=arm64 plugin=$1 version=$3
# ARM7 Device
scons target=$2 arch=armv7 plugin=$1 version=$3
scons platform=$4 target=$2 arch=arm64 plugin=$1 version=$3
if [[$4 == "iphone"]] then;
#ARMv7 Device
scons platform=$4 target=$2 arch=arm7 plugin=$1 version=$3
fi

# x86_64 Simulator
scons target=$2 arch=x86_64 simulator=yes plugin=$1 version=$3
scons platform=$4 target=$2 arch=x86_64 simulator=yes plugin=$1 version=$3
# ARM64 Simulator
scons platform=$4 target=$2 arch=arm64 simulator=yes plugin=$1 version=$3

# Creating a fat libraries for device and simulator
# lib<plugin>.<arch>-<simulator|iphone>.<release|debug|release_debug>.a
lipo -create "./bin/lib$1.x86_64-simulator.$2.a" \
"./bin/lib$1.armv7-iphone.$2.a" \
"./bin/lib$1.arm64-iphone.$2.a" \
-output "./bin/$1.$2.a"
if [[$4 == "iphone"]] then;
lipo -create "./bin/lib$1.x86_64-$4.simulator.$2.a" \
"./bin/lib$1.arm64-$4.simulator.$2.a" \
"./bin/lib$1.arm64-$4.$2.a" \
"./bin/lib$1.armv7-$4.$2.a" \
-output "./bin/$1.$4-$2.a"
elif [[$4 == "tvos"]] then;
lipo -create "./bin/lib$1.x86_64-$4.simulator.$2.a" \
"./bin/lib$1.arm64-$4.simulator.$2.a" \
"./bin/lib$1.arm64-$4.$2.a" \
-output "./bin/$1.$4-$2.a"
fi
30 changes: 18 additions & 12 deletions scripts/generate_xcframework.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@ set -e
# Compile static libraries

# ARM64 Device
scons target=$2 arch=arm64 plugin=$1 version=$3
# ARM7 Device
scons target=$2 arch=armv7 plugin=$1 version=$3
scons platform=$4 target=$2 arch=arm64 plugin=$1 version=$3
if [[$4 == "iphone"]] then;
# ARMv7 Device
scons platform=$4 target=$2 arch=arm7 plugin=$1 version=$3
fi

# x86_64 Simulator
scons target=$2 arch=x86_64 simulator=yes plugin=$1 version=$3
scons platform=$4 target=$2 arch=x86_64 simulator=yes plugin=$1 version=$3
# ARM64 Simulator
scons target=$2 arch=arm64 simulator=yes plugin=$1 version=$3
scons platform=$4 target=$2 arch=arm64 simulator=yes plugin=$1 version=$3

# Creating a fat libraries for device and simulator
# lib<plugin>.<arch>-<simulator|iphone>.<release|debug|release_debug>.a
lipo -create "./bin/lib$1.x86_64-simulator.$2.a" "./bin/lib$1.arm64-simulator.$2.a" -output "./bin/$1-simulator.$2.a"
lipo -create "./bin/lib$1.armv7-iphone.$2.a" "./bin/lib$1.arm64-iphone.$2.a" -output "./bin/$1-device.$2.a"

# lib<plugin>.<arch>-<platform>.<simulator>.<release|debug|release_debug>.a
lipo -create "./bin/lib$1.x86_64-$4.simulator.$2.a" "./bin/lib$1.arm64-$4.simulator.$2.a" -output "./bin/$4/$1-simulator.$2.a"
if [[$4 == "iphone"]] then;
lipo -create "./bin/lib$1.arm64-$4.$2.a" "./bin/lib$1.armv7-$4.$2.a" -output "./bin/$4/$1-device.$2.a"
else
lipo -create "./bin/lib$1.arm64-$4.$2.a" -output "./bin/$4/$1-device.$2.a"
fi
# Creating a xcframework
xcodebuild -create-xcframework \
-library "./bin/$1-device.$2.a" \
-library "./bin/$1-simulator.$2.a" \
-output "./bin/$1.$2.xcframework"
-library "./bin/$4/$1-device.$2.a" \
-library "./bin/$4/$1-simulator.$2.a" \
-output "./bin/$4/$1.$2.xcframework"
25 changes: 16 additions & 9 deletions scripts/release_static_library.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
#!/bin/bash

GODOT_PLUGINS="gamecenter inappstore icloud camera arkit apn photo_picker"
if [[$1 == "tvos"]] then;
GODOT_PLUGINS="inappstore icloud"
elif [[$1 == "iphone"]] then;
GODOT_PLUGINS="gamecenter inappstore icloud camera arkit apn photo_picker"
fi

# Compile Plugin
rm -rf ./bin/$1
mkdir ./bin/$1

# Compile Plugin
for lib in $GODOT_PLUGINS; do
./scripts/generate_static_library.sh $lib release $1
./scripts/generate_static_library.sh $lib release_debug $1
mv ./bin/${lib}.release_debug.a ./bin/${lib}.debug.a
./scripts/generate_static_library.sh $lib release $2
./scripts/generate_static_library.sh $lib release_debug $2
mv ./bin/$1/${lib}.release_debug.a ./bin/$1/${lib}.debug.a
done

# Move to release folder

rm -rf ./bin/release
mkdir ./bin/release

mkdir ./bin/$1/release

# Move Plugin
for lib in $GODOT_PLUGINS; do
mkdir ./bin/release/${lib}
mv ./bin/${lib}.{release,debug}.a ./bin/release/${lib}
mkdir ./bin/$1/release/${lib}
mv ./bin/$1/${lib}.{release,debug}.a ./bin/$1/release/${lib}
done
34 changes: 23 additions & 11 deletions scripts/release_xcframework.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
#!/bin/bash
set -e

GODOT_PLUGINS="gamecenter inappstore icloud camera arkit apn photo_picker"
#call ./scripts/releasexcframework.sh iphone 3.x
#call ./scripts/releasexcframework.sh tvos 3.x
#call ./scripts/releasexcframework.sh iphone 4.0
#call ./scripts/releasexcframework.sh tvos 4.0

# Compile Plugin
if [[$1 == "tvos"]] then;
GODOT_PLUGINS="inappstore icloud"
elif [[$1 == "iphone"]] then;
GODOT_PLUGINS="gamecenter inappstore icloud camera arkit apn photo_picker"
fi

rm -rf ./bin/$1
mkdir ./bin/$1

# Compile Plugin
for lib in $GODOT_PLUGINS; do
./scripts/generate_xcframework.sh $lib release $1
./scripts/generate_xcframework.sh $lib release_debug $1
mv ./bin/${lib}.release_debug.xcframework ./bin/${lib}.debug.xcframework
./scripts/generate_xcframework_$1.sh $lib release $2
./scripts/generate_xcframework_$1.sh $lib release_debug $2
mv ./bin/$1/${lib}.release_debug.xcframework ./bin/$1/${lib}.debug.xcframework
done

# Move to release folder

rm -rf ./bin/release
mkdir ./bin/release

mkdir ./bin/$1/release

# Move Plugin
for lib in $GODOT_PLUGINS; do
mkdir ./bin/release/${lib}
mv ./bin/${lib}.{release,debug}.xcframework ./bin/release/${lib}
cp ./plugins/${lib}/${lib}.gdip ./bin/release/${lib}
done
mkdir ./bin/$1/release/${lib}
mv ./bin/$1/${lib}.{release,debug}.xcframework ./bin/$1/release/${lib}
cp ./plugins/${lib}/${lib}.gdip ./bin/$1/release/${lib}/${lib}.gdatvp
done