Skip to content

Commit 263bc44

Browse files
authored
Enhance Cython integration: Add support for c++ mode, use hostpython3-provided Cython, allow pinning of specific Cython version in recipe (#957)
* Add support to build cpp files from Cython, use Cython from hostpython3, and allow configuring Cython version to be used in recipe * PEP8 (noqa as ATM we do not care why it failed to Cythonize) * Add cymunk to broken recipes * Remove cpplink, now it uses the same liblink * Remove unused import * Avoid DRY violation
1 parent 2ac3e6f commit 263bc44

File tree

22 files changed

+92
-210
lines changed

22 files changed

+92
-210
lines changed

.ci/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
BROKEN_RECIPES = set(["netifaces", "kivent_core"])
1+
BROKEN_RECIPES = set(["netifaces", "kivent_core", "cymunk"])
22

33
# recipes that were already built will be skipped
44
CORE_RECIPES = set(["kivy", "hostpython3", "python3"])

kivy_ios/recipes/audiostream/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class AudiostreamRecipe(CythonRecipe):
77
library = "libaudiostream.a"
88
depends = ["python", "sdl2", "sdl2_mixer"]
99
pre_build_ext = True
10+
hostpython_prerequisites = ["Cython==0.29.37"]
1011

1112

1213
recipe = AudiostreamRecipe()

kivy_ios/recipes/curly/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class CurlyRecipe(CythonRecipe):
77
library = "libcurly.a"
88
depends = ["python", "libcurl", "sdl2", "sdl2_image"]
99
pre_build_ext = True
10+
hostpython_prerequisites = ["Cython==0.29.37"]
1011

1112

1213
recipe = CurlyRecipe()

kivy_ios/recipes/cymunk/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class CymunkRecipe(CythonRecipe):
1212
name = 'cymunk'
1313
pre_build_ext = True
1414
library = 'libcymunk.a'
15-
15+
hostpython_prerequisites = ["Cython==0.29.37"]
1616
depends = ['python']
1717

1818
def get_recipe_env(self, arch):

kivy_ios/recipes/ffpyplayer/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class FFPyplayerRecipe(CythonRecipe):
1212
"CoreMotion"]
1313
pbx_libraries = ["libiconv"]
1414
pre_build_ext = True
15+
hostpython_prerequisites = ["Cython==0.29.37"]
1516

1617
def get_recipe_env(self, plat):
1718
env = super(FFPyplayerRecipe, self).get_recipe_env(plat)

kivy_ios/recipes/hostpython3/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,22 @@ def install(self):
100100
self.ctx.dist_dir,
101101
"hostpython3",
102102
"lib",
103-
"python3.11",
103+
f"python{self.ctx.hostpython_ver}",
104104
"site-packages",
105105
"setuptools",
106106
),
107107
)
108+
self.apply_patch(
109+
"fix-ldshared-override.patch",
110+
join(
111+
self.ctx.dist_dir,
112+
"hostpython3",
113+
"lib",
114+
f"python{self.ctx.hostpython_ver}",
115+
"site-packages",
116+
"setuptools",
117+
),
118+
)
108119

109120

110121
recipe = Hostpython3Recipe()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
diff -Naur setuptools.orig/_distutils/unixccompiler.py setuptools/_distutils/unixccompiler.py
2+
--- setuptools.orig/_distutils/unixccompiler.py 2024-02-11 18:42:58
3+
+++ setuptools/_distutils/unixccompiler.py 2024-02-11 18:45:30
4+
@@ -253,14 +253,20 @@
5+
building_exe = target_desc == CCompiler.EXECUTABLE
6+
linker = (self.linker_exe if building_exe else self.linker_so)[:]
7+
8+
- if target_lang == "c++" and self.compiler_cxx:
9+
- env, linker_ne = _split_env(linker)
10+
- aix, linker_na = _split_aix(linker_ne)
11+
- _, compiler_cxx_ne = _split_env(self.compiler_cxx)
12+
- _, linker_exe_ne = _split_env(self.linker_exe)
13+
+ # Mirko: We need our LDSHARED also for c++ things,
14+
+ # otherwise our hack to have static libs does not work
15+
+ # properly.
16+
+ # We will likely remove all these caveats once PEP 730
17+
+ # is implemented (and we will conform to it).
18+
19+
- params = _linker_params(linker_na, linker_exe_ne)
20+
- linker = env + aix + compiler_cxx_ne + params
21+
+ #if target_lang == "c++" and self.compiler_cxx:
22+
+ # env, linker_ne = _split_env(linker)
23+
+ # aix, linker_na = _split_aix(linker_ne)
24+
+ # _, compiler_cxx_ne = _split_env(self.compiler_cxx)
25+
+ # _, linker_exe_ne = _split_env(self.linker_exe)
26+
+
27+
+ # params = _linker_params(linker_na, linker_exe_ne)
28+
+ # linker = env + aix + compiler_cxx_ne + params
29+
30+
linker = compiler_fixup(linker, ld_args)
31+

kivy_ios/recipes/ios/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class IosRecipe(CythonRecipe):
77
library = "libios.a"
88
depends = ["python"]
99
pbx_frameworks = ["MessageUI", "CoreMotion", "UIKit", "WebKit", "Photos"]
10+
hostpython_prerequisites = ["Cython==0.29.37"]
1011

1112
def install(self):
1213
self.install_python_package(

kivy_ios/recipes/kivent_core/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class KiventCoreRecipe(CythonRecipe):
2121
subbuilddir = False
2222
cythonize = True
2323
pbx_frameworks = ["OpenGLES"] # note: This line may be unnecessary
24+
hostpython_prerequisites = ["Cython==0.29.37"]
2425

2526
def get_recipe_env(self, plat):
2627
env = super(KiventCoreRecipe, self).get_recipe_env(plat)

kivy_ios/recipes/kiwisolver/__init__.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22
This file is derived from the p4a recipe for kiwisolver.
33
It is a dependency of matplotlib.
44
5-
It is a C++ library, and it utilizes the cpplink script to handle
6-
creating the library files needed for inclusion in an iOS project.
7-
85
It also depends on the headers from the cppy package.
96
'''
107

118
from kivy_ios.toolchain import CythonRecipe
12-
from os.path import join
139

1410

1511
class KiwiSolverRecipe(CythonRecipe):
@@ -18,21 +14,9 @@ class KiwiSolverRecipe(CythonRecipe):
1814
version = '1.3.2'
1915
url = 'https://github.com/nucleic/kiwi/archive/{version}.zip'
2016
depends = ["python"]
21-
hostpython_prerequisites = ["cppy"]
17+
hostpython_prerequisites = ["cppy", "Cython==0.29.37"]
2218
cythonize = False
2319
library = "libkiwisolver.a"
2420

25-
def get_recipe_env(self, plat):
26-
env = super().get_recipe_env(plat)
27-
28-
# cpplink setup
29-
env['CXX_ORIG'] = env['CXX']
30-
env['CXX'] = join(self.ctx.root_dir, "tools", "cpplink")
31-
32-
# setuptools uses CC for compiling and CXX for linking
33-
env['CC'] = env['CXX']
34-
env['CFLAGS'] += ' -isysroot {}'.format(env['IOSSDKROOT'])
35-
return env
36-
3721

3822
recipe = KiwiSolverRecipe()

0 commit comments

Comments
 (0)