Skip to content

Commit

Permalink
Support ARM64 Simulator + Introduce build platform concept
Browse files Browse the repository at this point in the history
  • Loading branch information
misl6 committed Sep 5, 2023
1 parent 4f91801 commit 854ac6b
Show file tree
Hide file tree
Showing 36 changed files with 448 additions and 349 deletions.
2 changes: 1 addition & 1 deletion .ci/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BROKEN_RECIPES = set(["netifaces"])
BROKEN_RECIPES = set(["netifaces", "zbarlight", "kivent_core"])

# recipes that were already built will be skipped
CORE_RECIPES = set(["kivy", "hostpython3", "python3"])
6 changes: 3 additions & 3 deletions kivy_ios/recipes/click/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class ClickRecipe(PythonRecipe):
depends = ["python"]

def install(self):
arch = list(self.filtered_archs)[0]
build_dir = self.get_build_dir(arch.arch)
plat = list(self.platforms_to_build)[0]
build_dir = self.get_build_dir(plat)
os.chdir(build_dir)
hostpython = sh.Command(self.ctx.hostpython)
build_env = arch.get_env()
build_env = plat.get_env()
dest_dir = join(self.ctx.dist_dir, "root", "python3")
build_env['PYTHONPATH'] = self.ctx.site_packages_dir
shprint(hostpython, "setup.py", "install", "--prefix", dest_dir, _env=build_env)
Expand Down
8 changes: 4 additions & 4 deletions kivy_ios/recipes/ffmpeg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class FFMpegRecipe(Recipe):
version = "n4.4.2"
url = "https://github.com/FFmpeg/FFmpeg/archive/{version}.zip"
include_per_arch = True
include_per_platform = True
include_dir = "dist/include"
optional_depends = ["openssl"]
libraries = [
Expand All @@ -21,7 +21,7 @@ class FFMpegRecipe(Recipe):
]
pbx_frameworks = ["VideoToolbox"]

def build_arch(self, arch):
def build_platform(self, plat):
options = [
"--disable-everything",
"--enable-parsers",
Expand Down Expand Up @@ -57,12 +57,12 @@ def build_arch(self, arch):
"--enable-nonfree",
"--enable-protocol=https,tls_openssl"]

build_env = arch.get_env()
build_env = plat.get_env()
build_env["VERBOSE"] = "1"
configure = sh.Command(join(self.build_dir, "configure"))
shprint(configure,
"--target-os=darwin",
"--arch={}".format(arch.arch),
"--arch={}".format(plat.arch),
"--cc={}".format(build_env["CC"]),
"--prefix={}/dist".format(self.build_dir),
"--extra-cflags={}".format(build_env["CFLAGS"]),
Expand Down
10 changes: 5 additions & 5 deletions kivy_ios/recipes/ffpyplayer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ class FFPyplayerRecipe(CythonRecipe):
pbx_libraries = ["libiconv"]
pre_build_ext = True

def get_recipe_env(self, arch):
env = super(FFPyplayerRecipe, self).get_recipe_env(arch)
def get_recipe_env(self, plat):
env = super(FFPyplayerRecipe, self).get_recipe_env(plat)
env["CC"] += " -I{}".format(
join(self.ctx.dist_dir, "include", arch.arch, "libffi"))
join(self.ctx.dist_dir, "include", plat.name, "libffi"))
env["SDL_INCLUDE_DIR"] = join(self.ctx.dist_dir, "include",
"common", "sdl2")
env["FFMPEG_INCLUDE_DIR"] = join(self.ctx.dist_dir, "include",
arch.arch, "ffmpeg")
plat.name, "ffmpeg")
env["CONFIG_POSTPROC"] = "0"
return env

def prebuild_arch(self, arch):
def prebuild_platform(self, plat):
# common to all archs
if self.has_marker("patched"):
return
Expand Down
6 changes: 3 additions & 3 deletions kivy_ios/recipes/flask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class FlaskRecipe(PythonRecipe):
depends = ["python", "jinja2", "werkzeug", "itsdangerous", "click"]

def install(self):
arch = list(self.filtered_archs)[0]
build_dir = self.get_build_dir(arch.arch)
plat = list(self.platforms_to_build)[0]
build_dir = self.get_build_dir(plat)
os.chdir(build_dir)
hostpython = sh.Command(self.ctx.hostpython)
build_env = arch.get_env()
build_env = plat.get_env()
dest_dir = join(self.ctx.dist_dir, "root", "python")
build_env['PYTHONPATH'] = self.ctx.site_packages_dir
shprint(hostpython, "setup.py", "install", "--prefix", dest_dir, _env=build_env)
Expand Down
8 changes: 4 additions & 4 deletions kivy_ios/recipes/freetype/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ class FreetypeRecipe(Recipe):
url = "https://download.savannah.gnu.org/releases/freetype/freetype-old/freetype-{version}.tar.bz2"
library = "objs/.libs/libfreetype.a"
include_dir = ["include", ("builds/unix/ftconfig.h", "config/ftconfig.h")]
include_per_arch = True
include_per_platform = True

def build_arch(self, arch):
build_env = arch.get_env()
def build_platform(self, plat):
build_env = plat.get_env()
configure = sh.Command(join(self.build_dir, "configure"))
shprint(configure,
"CC={}".format(build_env["CC"]),
"LD={}".format(build_env["LD"]),
"CFLAGS={}".format(build_env["CFLAGS"]),
"LDFLAGS={}".format(build_env["LDFLAGS"]),
"--prefix=/",
"--host={}".format(arch.triple),
"--host={}".format(plat.triple),
"--without-png",
"--without-bzip2",
"--without-fsspec",
Expand Down
12 changes: 6 additions & 6 deletions kivy_ios/recipes/hostopenssl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ def get_build_env(self):
self.build_env = build_env
return build_env

def build_arch(self, arch):
def build_platform(self, plat):
build_env = self.get_build_env()
configure = sh.Command(join(self.build_dir, "Configure"))
shprint(configure,
arch_mapper[arch.arch],
arch_mapper[plat.arch],
_env=build_env)
shprint(sh.make, "clean")
shprint(sh.make, self.ctx.concurrent_make, "build_libs")

def install(self):
arch = self.archs[0]
plat = list(self.platforms_to_build)[0]
sh.mkdir('-p', join(self.ctx.dist_dir, 'hostopenssl'))
sh.cp('-r', join(self.get_build_dir(arch), 'include'),
sh.cp('-r', join(self.get_build_dir(plat), 'include'),
join(self.ctx.dist_dir, 'hostopenssl', 'include'))
sh.mkdir('-p', join(self.ctx.dist_dir, 'hostopenssl', 'lib'))
sh.cp(join(self.get_build_dir(arch), 'libssl.a'),
sh.cp(join(self.get_build_dir(plat), 'libssl.a'),
join(self.ctx.dist_dir, 'hostopenssl', 'lib'))
sh.cp(join(self.get_build_dir(arch), 'libcrypto.a'),
sh.cp(join(self.get_build_dir(plat), 'libcrypto.a'),
join(self.ctx.dist_dir, 'hostopenssl', 'lib'))


Expand Down
16 changes: 8 additions & 8 deletions kivy_ios/recipes/hostpython3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ def init_with_ctx(self, ctx):
logger.info("Global: hostpython located at {}".format(self.ctx.hostpython))
logger.info("Global: hostpgen located at {}".format(self.ctx.hostpgen))

def get_build_subdir(self, arch):
return join(self.get_build_dir(arch), self.build_subdir)
def get_build_subdir(self, plat):
return join(self.get_build_dir(plat), self.build_subdir)

def prebuild_arch(self, arch):
def prebuild_platform(self, plat):
if self.has_marker("patched"):
return
self.apply_patch("disable_sysconfig_cflags.patch")
self.copy_file("ModulesSetup", "Modules/Setup.local")
self.set_marker("patched")

def postbuild_arch(self, arch):
def postbuild_platform(self, plat):
return

def get_build_env(self):
Expand All @@ -55,12 +55,12 @@ def get_build_env(self):
])
return build_env

def build_arch(self, arch):
def build_platform(self, plat):
build_env = self.get_build_env()

configure = sh.Command(join(self.build_dir, "configure"))

build_subdir = self.get_build_subdir(arch.arch)
build_subdir = self.get_build_subdir(plat)
os.makedirs(build_subdir, exist_ok=True)

with cd(build_subdir):
Expand All @@ -75,9 +75,9 @@ def build_arch(self, arch):
_env=build_env)

def install(self):
arch = list(self.filtered_archs)[0]
plat = list(self.platforms_to_build)[0]
build_env = self.get_build_env()
build_subdir = self.get_build_subdir(arch.arch)
build_subdir = self.get_build_subdir(plat)
build_env["PATH"] = os.environ["PATH"]
shprint(sh.make, self.ctx.concurrent_make,
"-C", build_subdir,
Expand Down
6 changes: 3 additions & 3 deletions kivy_ios/recipes/itsdangerous/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class ItsDangerousRecipe(PythonRecipe):
depends = ["python"]

def install(self):
arch = list(self.filtered_archs)[0]
build_dir = self.get_build_dir(arch.arch)
plat = list(self.platforms_to_build)[0]
build_dir = self.get_build_dir(plat)
hostpython = sh.Command(self.ctx.hostpython)
build_env = arch.get_env()
build_env = plat.get_env()
dest_dir = join(self.ctx.dist_dir, "root", "python3")
build_env['PYTHONPATH'] = self.ctx.site_packages_dir
with cd(build_dir):
Expand Down
6 changes: 3 additions & 3 deletions kivy_ios/recipes/jinja2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class Jinja2Recipe(PythonRecipe):
depends = ["python", "markupsafe"]

def install(self):
arch = list(self.filtered_archs)[0]
build_dir = self.get_build_dir(arch.arch)
plat = list(self.platforms_to_build)[0]
build_dir = self.get_build_dir(plat)
os.chdir(build_dir)
hostpython = sh.Command(self.ctx.hostpython)
build_env = arch.get_env()
build_env = plat.get_env()
dest_dir = join(self.ctx.dist_dir, "root", "python3")
build_env['PYTHONPATH'] = self.ctx.site_packages_dir
shprint(hostpython, "setup.py", "install", "--prefix", dest_dir, _env=build_env)
Expand Down
28 changes: 14 additions & 14 deletions kivy_ios/recipes/kivent_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ class KiventCoreRecipe(CythonRecipe):
cythonize = True
pbx_frameworks = ["OpenGLES"] # note: This line may be unnecessary

def get_recipe_env(self, arch):
env = super(KiventCoreRecipe, self).get_recipe_env(arch)
def get_recipe_env(self, plat):
env = super(KiventCoreRecipe, self).get_recipe_env(plat)
env['CYTHONPATH'] = self.get_recipe(
'kivy', self.ctx).get_build_dir(arch.arch)
'kivy', self.ctx).get_build_dir(plat)
return env

def get_build_dir(self, arch, sub=False):
def get_build_dir(self, plat, sub=False):
"""
Call this to get the correct build_dir, where setup.py is located which is
actually under modules/core/setup.py
"""
builddir = super(KiventCoreRecipe, self).get_build_dir(str(arch))
builddir = super(KiventCoreRecipe, self).get_build_dir(plat)
if sub or self.subbuilddir:
core_build_dir = join(builddir, 'modules', 'core')
logger.info("Core build directory is located at {}".format(core_build_dir))
Expand All @@ -42,7 +42,7 @@ def get_build_dir(self, arch, sub=False):
logger.info("Building in {}".format(builddir))
return builddir

def build_arch(self, arch):
def build_platform(self, plat):
"""
Override build.arch to avoid calling setup.py here (Call it in
install() instead).
Expand All @@ -66,26 +66,26 @@ def install(self):
Note: This method is called by build_all() in toolchain.py
"""
arch = list(self.filtered_archs)[0]
plat = list(self.platforms_to_build)[0]

build_dir = self.get_build_dir(arch.arch, sub=True)
logger.info("Building kivent_core {} in {}".format(arch.arch, build_dir))
build_dir = self.get_build_dir(plat, sub=True)
logger.info("Building kivent_core {} in {}".format(plat.arch, build_dir))
chdir(build_dir)
hostpython = sh.Command(self.ctx.hostpython)

# Get the appropriate environment for this recipe (including CYTHONPATH)
# build_env = arch.get_env()
build_env = self.get_recipe_env(arch)
# build_env = plat.get_env()
build_env = self.get_recipe_env(plat)

dest_dir = join(self.ctx.dist_dir, "root", "python")
build_env['PYTHONPATH'] = join(dest_dir, 'lib', 'python3.7', 'site-packages')

# Add Architecture specific kivy path for 'import kivy' to PYTHONPATH
arch_kivy_path = self.get_recipe('kivy', self.ctx).get_build_dir(arch.arch)
arch_kivy_path = self.get_recipe('kivy', self.ctx).get_build_dir(plat)
build_env['PYTHONPATH'] = join(build_env['PYTHONPATH'], ':', arch_kivy_path)

# Make sure you call kivent_core/modules/core/setup.py
subdir_path = self.get_build_dir(str(arch), sub=True)
subdir_path = self.get_build_dir(plat, sub=True)
setup_path = join(subdir_path, "setup.py")

# Print out directories for sanity check
Expand All @@ -94,7 +94,7 @@ def install(self):
logger.info("BUILD", self.ctx.build_dir)
logger.info("INCLUDE", self.ctx.include_dir)
logger.info("DISTDIR", self.ctx.dist_dir)
logger.info("ARCH KIVY LOC", self.get_recipe('kivy', self.ctx).get_build_dir(arch.arch))
logger.info("ARCH KIVY LOC", self.get_recipe('kivy', self.ctx).get_build_dir(plat))

shprint(hostpython, setup_path, "build_ext", "install", _env=build_env)

Expand Down
8 changes: 4 additions & 4 deletions kivy_ios/recipes/kivy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ class KivyRecipe(CythonRecipe):
pbx_frameworks = ["OpenGLES", "Accelerate", "CoreMedia", "CoreVideo"]
pre_build_ext = True

def get_recipe_env(self, arch):
env = super().get_recipe_env(arch)
def get_recipe_env(self, plat):
env = super().get_recipe_env(plat)
env["KIVY_SDL2_PATH"] = ":".join([
join(self.ctx.dist_dir, "include", "common", "sdl2"),
join(self.ctx.dist_dir, "include", "common", "sdl2_image"),
join(self.ctx.dist_dir, "include", "common", "sdl2_ttf"),
join(self.ctx.dist_dir, "include", "common", "sdl2_mixer")])
return env

def build_arch(self, arch):
def build_platform(self, plat):
self._patch_setup()
super().build_arch(arch)
super().build_platform(plat)

def _patch_setup(self):
# patch setup to remove some functionnalities
Expand Down
14 changes: 9 additions & 5 deletions kivy_ios/recipes/libcurl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@


class CurlRecipe(Recipe):
version = "7.65.3"
version = "7.88.1"
url = "https://curl.haxx.se/download/curl-{version}.tar.gz"
library = "lib/.libs/libcurl.a"
include_dir = "include"
depends = ["openssl"]

def build_arch(self, arch):
build_env = arch.get_env()
def build_platform(self, plat):
build_env = plat.get_env()
configure = sh.Command(join(self.build_dir, "configure"))
shprint(configure,
"CC={}".format(build_env["CC"]),
"LD={}".format(build_env["LD"]),
"CFLAGS={}".format(build_env["CFLAGS"]),
"LDFLAGS={}".format(build_env["LDFLAGS"]),
"PKG_CONFIG=ios-pkg-config",
# ios-pkg-config does not exists,
# is needed to disable the pkg-config usage.
"--prefix=/",
"--host={}".format(arch.triple),
"--host={}".format(plat.triple),
"--disable-shared",
"--without-libidn2")
"--without-libidn2",
"--with-openssl")
shprint(sh.make, "clean")
shprint(sh.make, self.ctx.concurrent_make)

Expand Down
17 changes: 8 additions & 9 deletions kivy_ios/recipes/libffi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@


class LibffiRecipe(Recipe):
version = "3.4.2"
version = "3.4.4"
url = "https://github.com/libffi/libffi/releases/download/v{version}/libffi-{version}.tar.gz"
library = "build/Release-{arch.sdk}/libffi.a"
include_per_arch = True
include_dir = "build_{arch.sdk}-{arch.arch}/include"
library = "build/Release-{plat.sdk}/libffi.a"
include_per_platform = True
include_dir = "build_{plat.name}/include"
include_name = "ffi"
archs = ["x86_64", "arm64"]

def prebuild_arch(self, arch):
def prebuild_platform(self, plat):
if self.has_marker("patched"):
return
self.apply_patch("enable-tramp-build.patch")
Expand All @@ -26,7 +25,7 @@ def prebuild_arch(self, arch):
"generate-darwin-source-and-headers.py")
self.set_marker("patched")

def build_arch(self, arch):
def build_platform(self, plat):
if exists("generate-darwin-source-and-headers.py"):
shprint(
sh.mv,
Expand All @@ -37,9 +36,9 @@ def build_arch(self, arch):
shprint(python3, "_generate-darwin-source-and-headers.py", "--only-ios")
shprint(sh.xcodebuild, self.ctx.concurrent_xcodebuild,
"ONLY_ACTIVE_ARCH=NO",
"ARCHS={}".format(arch.arch),
"ARCHS={}".format(plat.arch),
"BITCODE_GENERATION_MODE=bitcode",
"-sdk", arch.sdk,
"-sdk", plat.sdk,
"-project", "libffi.xcodeproj",
"-target", "libffi-iOS",
"-configuration", "Release")
Expand Down
Loading

0 comments on commit 854ac6b

Please sign in to comment.