Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit df4e6f2

Browse files
committedApr 25, 2021
MetalANGLE support
1 parent 0e1aef4 commit df4e6f2

File tree

5 files changed

+126
-23
lines changed

5 files changed

+126
-23
lines changed
 

‎.github/workflows/kivy_ios.yml

+29
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,35 @@ jobs:
4747
run: |
4848
.ci/test_project.sh
4949
50+
build_python3_kivy_metalangle:
51+
runs-on: macos-latest
52+
steps:
53+
- name: Checkout kivy-ios
54+
uses: actions/checkout@v2
55+
- name: Set up Python 3.8
56+
uses: actions/setup-python@v2
57+
with:
58+
python-version: '3.8.x'
59+
- name: Install requirements
60+
run: |
61+
pip3 install -r requirements.txt
62+
brew install autoconf automake libtool pkg-config
63+
brew link libtool
64+
pip3 install Cython==0.29.17
65+
gem install xcpretty
66+
- name: Build Python & Kivy with MetalANGLE support
67+
run: |
68+
export KIVYIOS_USE_METALANGLE=1
69+
python toolchain.py build python3 kivy
70+
- name: Checkout kivy for tests apps
71+
uses: actions/checkout@v2
72+
with:
73+
repository: kivy/kivy
74+
path: kivy-ci-clone
75+
- name: Create & Build test project
76+
run: |
77+
.ci/test_project.sh
78+
5079
build_python3_kivy_venv:
5180
runs-on: macos-latest
5281
steps:

‎kivy_ios/recipes/kivy/__init__.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from kivy_ios.toolchain import CythonRecipe
22
from os.path import join
3+
import os
34
import logging
45
import shutil
56

@@ -17,7 +18,7 @@ class KivyRecipe(CythonRecipe):
1718
depends = ["sdl2", "sdl2_image", "sdl2_mixer", "sdl2_ttf", "ios",
1819
"pyobjus", "python", "host_setuptools3"]
1920
python_depends = ["certifi"]
20-
pbx_frameworks = ["OpenGLES", "Accelerate", "CoreMedia", "CoreVideo"]
21+
pbx_frameworks = ["Accelerate", "CoreMedia", "CoreVideo"]
2122
pre_build_ext = True
2223

2324
def get_recipe_env(self, arch):
@@ -41,9 +42,17 @@ def _remove_line(lines, pattern):
4142
for line in lines[:]:
4243
if pattern in line:
4344
lines.remove(line)
45+
46+
def _sub_pattern(lines, pattern_old, pattern_new):
47+
for i, line in enumerate(lines[:]):
48+
if pattern_old in line:
49+
lines[i] = lines[i].replace(pattern_old, pattern_new)
50+
4451
with open(pyconfig) as fd:
4552
lines = fd.readlines()
4653
_remove_line(lines, "flags['libraries'] = ['GLESv2']")
54+
if os.environ.get("KIVYIOS_USE_METALANGLE"):
55+
_sub_pattern(lines, "OpenGLES", "MetalANGLE")
4756
with open(pyconfig, "w") as fd:
4857
fd.writelines(lines)
4958

‎kivy_ios/recipes/sdl2/__init__.py

+65-17
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,84 @@
11
from kivy_ios.toolchain import Recipe, shprint
2+
from os.path import join
3+
import os
24
import sh
35

46

57
class LibSDL2Recipe(Recipe):
6-
# version = "2.0.9"
7-
# url = "https://www.libsdl.org/release/SDL2-{version}.tar.gz"
8-
version = "7cc4fc886d9e"
9-
url = "https://hg.libsdl.org/SDL/archive/{version}.tar.gz"
10-
library = "Xcode-iOS/SDL/build/Release-{arch.sdk}/libSDL2.a"
8+
version = "ios-use-metalangle"
9+
url = "https://github.com/misl6/SDL/archive/refs/heads/feature/{version}.zip"
10+
11+
metalangle_baseurl = (
12+
"https://github.com/kakashidinho/metalangle/releases/download/gles3-0.0.6"
13+
)
14+
metalangle_arch_map = dict(
15+
x86_64="MetalANGLE.framework.ios.simulator.zip",
16+
arm64="MetalANGLE.framework.ios.zip",
17+
)
18+
19+
library = "Xcode/SDL/build/Release-{arch.sdk}/libSDL2.a"
1120
include_dir = "include"
1221
pbx_frameworks = [
13-
"OpenGLES", "AudioToolbox", "QuartzCore", "CoreGraphics",
14-
"CoreMotion", "GameController", "AVFoundation", "Metal",
15-
"UIKit"]
22+
"AudioToolbox",
23+
"QuartzCore",
24+
"CoreGraphics",
25+
"CoreMotion",
26+
"GameController",
27+
"AVFoundation",
28+
"Metal",
29+
"UIKit",
30+
"CoreHaptics",
31+
]
32+
33+
def __init__(self):
34+
if os.environ.get("KIVYIOS_USE_METALANGLE"):
35+
self.frameworks = ["MetalANGLE"]
36+
self.pbx_frameworks.append("MetalANGLE")
37+
else:
38+
self.pbx_frameworks.append("OpenGLES")
1639

1740
def prebuild_arch(self, arch):
1841
if self.has_marker("patched"):
1942
return
2043
self.apply_patch("uikit-transparent.patch")
44+
if os.environ.get("KIVYIOS_USE_METALANGLE"):
45+
self.apply_patch("enable-metalangle.patch")
46+
downloaded_file = self.download_file(
47+
join(self.metalangle_baseurl, self.metalangle_arch_map[arch.arch]),
48+
self.metalangle_arch_map[arch.arch],
49+
)
50+
self.extract_file(
51+
downloaded_file,
52+
join(self.get_build_dir(arch.arch), "Xcode/SDL/third-party/frameworks"),
53+
)
54+
if arch.arch == "arm64":
55+
self.extract_file(
56+
downloaded_file,
57+
join(self.ctx.dist_dir, "frameworks"),
58+
)
2159
self.set_marker("patched")
2260

61+
def install_frameworks(self):
62+
pass
63+
2364
def build_arch(self, arch):
2465
env = arch.get_env()
25-
shprint(sh.xcodebuild, self.ctx.concurrent_xcodebuild,
26-
"ONLY_ACTIVE_ARCH=NO",
27-
"ARCHS={}".format(arch.arch),
28-
"BITCODE_GENERATION_MODE=bitcode",
29-
"CC={}".format(env['CC']),
30-
"-sdk", arch.sdk,
31-
"-project", "Xcode-iOS/SDL/SDL.xcodeproj",
32-
"-target", "libSDL-iOS",
33-
"-configuration", "Release")
66+
shprint(
67+
sh.xcodebuild,
68+
self.ctx.concurrent_xcodebuild,
69+
"ONLY_ACTIVE_ARCH=NO",
70+
"ARCHS={}".format(arch.arch),
71+
"BITCODE_GENERATION_MODE=bitcode",
72+
"CC={}".format(env["CC"]),
73+
"-sdk",
74+
arch.sdk,
75+
"-project",
76+
"Xcode/SDL/SDL.xcodeproj",
77+
"-target",
78+
"Static Library-iOS",
79+
"-configuration",
80+
"Release",
81+
)
3482

3583

3684
recipe = LibSDL2Recipe()

‎kivy_ios/toolchain.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1231,17 +1231,19 @@ def update_pbxproj(filename, pbx_frameworks=None):
12311231
group = project.get_or_create_group("Frameworks")
12321232
g_classes = project.get_or_create_group("Classes")
12331233
file_options = FileOptions(embed_framework=False, code_sign_on_copy=True)
1234+
file_options_embed = FileOptions(embed_framework=True, code_sign_on_copy=True)
12341235
for framework in pbx_frameworks:
1235-
framework_name = "{}.framework".format(framework)
1236-
if framework_name in frameworks:
1236+
if framework in frameworks:
12371237
logger.info("Ensure {} is in the project (pbx_frameworks, local)".format(framework))
1238-
f_path = join(ctx.dist_dir, "frameworks", framework_name)
1238+
f_path = join(ctx.dist_dir, "frameworks", f"{framework}.framework")
1239+
project.add_file(f_path, parent=group, tree="DEVELOPER_DIR",
1240+
force=False, file_options=file_options_embed)
12391241
else:
12401242
logger.info("Ensure {} is in the project (pbx_frameworks, system)".format(framework))
12411243
f_path = join(sysroot, "System", "Library", "Frameworks",
12421244
"{}.framework".format(framework))
1243-
project.add_file(f_path, parent=group, tree="DEVELOPER_DIR",
1244-
force=False, file_options=file_options)
1245+
project.add_file(f_path, parent=group, tree="DEVELOPER_DIR",
1246+
force=False, file_options=file_options)
12451247
for library in pbx_libraries:
12461248
logger.info("Ensure {} is in the project (pbx_libraries, dylib+tbd)".format(library))
12471249
f_path = join(sysroot, "usr", "lib",

‎kivy_ios/tools/templates/{{ cookiecutter.project_name }}-ios/{{ cookiecutter.project_name }}.xcodeproj/project.pbxproj

+15
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@
2727
59994E3B148E85C800863906 /* YourApp in Resources */ = {isa = PBXBuildFile; fileRef = 59994E3A148E85C800863906 /* YourApp */; };
2828
/* End PBXBuildFile section */
2929

30+
31+
/* Begin PBXCopyFilesBuildPhase section */
32+
EF5745029C423687AC1203A1 /* Embed Frameworks */ = {
33+
isa = PBXCopyFilesBuildPhase;
34+
buildActionMask = 2147483647;
35+
dstPath = "";
36+
dstSubfolderSpec = 10;
37+
files = (
38+
);
39+
name = "Embed Frameworks";
40+
runOnlyForDeploymentPostprocessing = 0;
41+
};
42+
/* End PBXCopyFilesBuildPhase section */
43+
3044
/* Begin PBXFileReference section */
3145
01532DA9137C099F0076F6BF /* icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = icon.png; sourceTree = "<group>"; };
3246
1D6058910D05DD3D006BFB54 /* {{ cookiecutter.project_name }}.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = {{ cookiecutter.project_name }}.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -143,6 +157,7 @@
143157
1D60588D0D05DD3D006BFB54 /* Resources */,
144158
1D60588E0D05DD3D006BFB54 /* Sources */,
145159
1D60588F0D05DD3D006BFB54 /* Frameworks */,
160+
EF5745029C423687AC1203A1 /* Embed Frameworks */,
146161
);
147162
buildRules = (
148163
);

0 commit comments

Comments
 (0)
Please sign in to comment.