Skip to content

Commit

Permalink
Restructure and cleanup
Browse files Browse the repository at this point in the history
Moved plugins and scripts to different folders.
Direct usage of Godot's source instead of exported headers.
XCFramework and Static Library scripts to build final plugin library.
  • Loading branch information
naithar committed Jan 18, 2021
1 parent 401113c commit a3a4f90
Show file tree
Hide file tree
Showing 48 changed files with 129 additions and 132 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "godot"]
path = godot
url = https://github.com/godotengine/godot
21 changes: 21 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Godot Engine

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Godot iOS plugins


## Building a `.a` library

* Use submodule to pull required Godot version into `godot` folder. (`master` branch for `4.0` and `3.2` branch for `3.2` version)
Alternatively you can place a Godot's header files including generated ones at `godot` folder.
You can extract headers from Godot's source manually or by using `extract_headers.sh` script from `scripts` folder.

* Run `scons target=<debug|release|release_debug> arch=<arch> simulator=<no|yes> plugin=<plugin_name> version=<3.2|4.0>` to compile the plugin you need for specific version of Godot.
You can also use `./scripts/generate_xcframework.sh <plugin_name> <debug|release|release_debug> <godot_version>` to generate fat static library with specific configuration.

* The result `.a` binary will be stored in `bin` folder.

## Building a `.xcframework` library

* Use submodule to pull required Godot version into `godot` folder. (`master` branch for `4.0` and `3.2` branch for `3.2` version)
Alternatively you can place a Godot's header files including generated ones at `godot` folder.
You can extract headers from Godot's source manually or by using `extract_headers.sh` script from `scripts` folder.

* Run `./scripts/generate_xcframework.sh <plugin_name> <debug|release|release_debug> <godot_version>`

* The result `.xcframework` will be stored in `bin` folder as well as intermidiate `.a` binaries.
55 changes: 33 additions & 22 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'bi
opts.Add(EnumVariable('plugin', 'Plugin to build', '', ['', 'arkit', 'camera', 'icloud', 'gamecenter', 'inappstore']))
opts.Add(EnumVariable('version', 'Godot version to target', '', ['', '3.2', '4.0']))

# Local dependency paths, adapt them to your setup
godot_path = "godot/"
godot_library = "ios.fat.a"

# Updates the environment with the option variables.
opts.Update(env)

Expand Down Expand Up @@ -94,6 +90,9 @@ env.Prepend(CXXFLAGS=[
])
env.Append(LINKFLAGS=["-arch", env['arch'], '-isysroot', sdk_path, '-F' + sdk_path])

if env['arch'] == 'armv7':
env.Prepend(CXXFLAGS=['-fno-aligned-allocation'])

if env['version'] == '3.2':
env.Prepend(CFLAGS=['-std=gnu11'])
env.Prepend(CXXFLAGS=['-DGLES_ENABLED', '-std=gnu++14'])
Expand All @@ -106,16 +105,22 @@ if env['version'] == '3.2':
'-DPTRCALL_ENABLED',
])
elif env['target'] == 'release_debug':
env.Prepend(CXXFLAGS=['-O2', '-ftree-vectorize', '-fomit-frame-pointer',
env.Prepend(CXXFLAGS=['-O2', '-ftree-vectorize',
'-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1', '-DDEBUG_ENABLED',
'-DPTRCALL_ENABLED',
])

if env['arch'] != 'armv7':
env.Prepend(CXXFLAGS=['-fomit-frame-pointer'])
else:
env.Prepend(CXXFLAGS=[
'-O2', '-ftree-vectorize', '-fomit-frame-pointer',
'-O2', '-ftree-vectorize',
'-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1',
'-DPTRCALL_ENABLED',
])

if env['arch'] != 'armv7':
env.Prepend(CXXFLAGS=['-fomit-frame-pointer'])
elif env['version'] == '4.0':
env.Prepend(CFLAGS=['-std=gnu11'])
env.Prepend(CXXFLAGS=['-DVULKAN_ENABLED', '-std=gnu++17'])
Expand All @@ -128,38 +133,44 @@ elif env['version'] == '4.0':
])
elif env['target'] == 'release_debug':
env.Prepend(CXXFLAGS=[
'-O2', '-ftree-vectorize', '-fomit-frame-pointer',
'-O2', '-ftree-vectorize',
'-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1', '-DDEBUG_ENABLED',
])

if env['arch'] != 'armv7':
env.Prepend(CXXFLAGS=['-fomit-frame-pointer'])
else:
env.Prepend(CXXFLAGS=[
'-O2', '-ftree-vectorize', '-fomit-frame-pointer',
'-O2', '-ftree-vectorize',
'-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1',
])

if env['arch'] != 'armv7':
env.Prepend(CXXFLAGS=['-fomit-frame-pointer'])
else:
print("No valid version to set flags for.")
quit();

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

# tweak this if you want to use different folders, or more folders, to store your source code in.
sources = Glob(env['plugin'] + '/*.cpp')
sources.append(Glob(env['plugin'] + '/*.mm'))
sources.append(Glob(env['plugin'] + '/*.m'))
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")
Expand Down
15 changes: 0 additions & 15 deletions arkit/SCsub

This file was deleted.

6 changes: 0 additions & 6 deletions arkit/config.py

This file was deleted.

15 changes: 0 additions & 15 deletions camera/SCsub

This file was deleted.

6 changes: 0 additions & 6 deletions camera/config.py

This file was deleted.

15 changes: 0 additions & 15 deletions gamecenter/SCsub

This file was deleted.

6 changes: 0 additions & 6 deletions gamecenter/config.py

This file was deleted.

1 change: 1 addition & 0 deletions godot
Submodule godot added at 40b354
Empty file removed godot_headers/dummy
Empty file.
15 changes: 0 additions & 15 deletions icloud/SCsub

This file was deleted.

6 changes: 0 additions & 6 deletions icloud/config.py

This file was deleted.

15 changes: 0 additions & 15 deletions inappstore/SCsub

This file was deleted.

6 changes: 0 additions & 6 deletions inappstore/config.py

This file was deleted.

2 changes: 1 addition & 1 deletion arkit/arkit.gdip → plugins/arkit/arkit.gdip
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[config]
name="ARKit"
binary="arkit_lib.a"
binary="arkit.a"

initialization="register_arkit_types"
deinitialization="unregister_arkit_types"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion camera/camera.gdip → plugins/camera/camera.gdip
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[config]
name="Camera"
binary="camera_lib.a"
binary="camera.a"

initialization="register_camera_types"
deinitialization="unregister_camera_types"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[config]
name="GameCenter"
binary="gamecenter_lib.a"
binary="gamecenter.a"

initialization="register_gamecenter_types"
deinitialization="unregister_gamecenter_types"
Expand Down
2 changes: 1 addition & 1 deletion icloud/icloud.gdip → plugins/icloud/icloud.gdip
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[config]
name="iCloud"
binary="icloud_lib.a"
binary="icloud.a"

initialization="register_icloud_types"
deinitialization="unregister_icloud_types"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[config]
name="InAppStore"
binary="inappstore_lib.a"
binary="inappstore.a"

initialization="register_inappstore_types"
deinitialization="unregister_inappstore_types"
Expand Down
3 changes: 3 additions & 0 deletions scripts/extract_headers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

rsync -a -m -R --include '*/' --include '*.h' --include '*.inc' --exclude '*' ./ extracted_headers
17 changes: 17 additions & 0 deletions scripts/generate_static_library.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# 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
# x86_64 Simulator
scons target=$2 arch=x86_64 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"
23 changes: 23 additions & 0 deletions scripts/generate_xcframework.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# 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
# x86_64 Simulator
scons target=$2 arch=x86_64 simulator=yes plugin=$1 version=$3
# ARM64 Simulator
scons 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"

# Creating a xcframework
xcodebuild -create-xcframework \
-library "./bin/$1-device.$2.a" \
-library "./bin/$1-simulator.$2.a" \
-output "./bin/$1.$2.xcframework"

0 comments on commit a3a4f90

Please sign in to comment.