Skip to content

Commit

Permalink
Pillow recipe rework + upgrade to version 8.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
misl6 committed Apr 6, 2021
1 parent e38cd58 commit af61ccc
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 44 deletions.
2 changes: 1 addition & 1 deletion kivy_ios/recipes/libjpeg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class JpegRecipe(Recipe):
version = "v9a"
version = "v9d"
url = "http://www.ijg.org/files/jpegsrc.{version}.tar.gz"
library = ".libs/libjpeg.a"
include_dir = [
Expand Down
92 changes: 49 additions & 43 deletions kivy_ios/recipes/pillow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,67 @@
from kivy_ios.toolchain import Recipe, shprint
from kivy_ios.toolchain import CythonRecipe, shprint
from os.path import join
import sh
import os
import fnmatch


class PillowRecipe(Recipe):
version = "6.1.0"
class PillowRecipe(CythonRecipe):
version = "8.2.0"
url = "https://pypi.python.org/packages/source/P/Pillow/Pillow-{version}.tar.gz"
library = "libpillow.a"
depends = ["hostpython3", "host_setuptools3", "freetype", "libjpeg", "python3", "ios"]
depends = [
"hostpython3",
"host_setuptools3",
"freetype",
"libjpeg",
"python3",
"ios",
]
python_depends = ["setuptools"]
pbx_libraries = ["libz", "libbz2"]
include_per_arch = True
cythonize = False

def get_pil_env(self, arch):
build_env = arch.get_env()
build_env["IOSROOT"] = self.ctx.root_dir
build_env["IOSSDKROOT"] = arch.sysroot
build_env["LDSHARED"] = join(self.ctx.root_dir, "tools", "liblink")
build_env["ARM_LD"] = build_env["LD"]
build_env["ARCH"] = arch.arch
build_env["C_INCLUDE_PATH"] = join(arch.sysroot, "usr", "include")
build_env["LIBRARY_PATH"] = join(arch.sysroot, "usr", "lib")
build_env["CFLAGS"] += " ".join([
"-I{}".format(join(self.ctx.dist_dir, "include", arch.arch, "freetype")) +
" -I{}".format(join(self.ctx.dist_dir, "include", arch.arch, "libjpeg")) +
" -arch {}".format(arch.arch)
])
build_env['PATH'] = os.environ['PATH']
return build_env
def prebuild_arch(self, arch):
if self.has_marker("patched"):
return
self.apply_patch("bypass-find-library.patch")
self.set_marker("patched")

def get_recipe_env(self, arch):
env = super().get_recipe_env(arch)
env["C_INCLUDE_PATH"] = join(arch.sysroot, "usr", "include")
env["LIBRARY_PATH"] = join(arch.sysroot, "usr", "lib")
env["CFLAGS"] += " ".join(
[
"-I{}".format(join(self.ctx.dist_dir, "include", arch.arch, "freetype"))
+ " -I{}".format(
join(self.ctx.dist_dir, "include", arch.arch, "libjpeg")
)
+ " -arch {}".format(arch.arch)
]
)
env["PATH"] = os.environ["PATH"]
env[
"PKG_CONFIG"
] = "ios-pkg-config" # ios-pkg-config does not exists, is needed to disable the pkg-config usage.
return env

def build_arch(self, arch):
build_env = self.get_pil_env(arch)
build_env = self.get_recipe_env(arch)
hostpython3 = sh.Command(self.ctx.hostpython)
shprint(hostpython3, "setup.py", "build_ext", "--disable-tiff",
"--disable-webp", "-g", _env=build_env)
shprint(
hostpython3,
"setup.py",
"build_ext",
"--disable-tiff",
"--disable-webp",
"--disable-jpeg2000",
"--disable-lcms",
"--disable-platform-guessing",
"-g",
_env=build_env,
)
self.biglink()

def install(self):
arch = list(self.filtered_archs)[0]
build_dir = self.get_build_dir(arch.arch)
os.chdir(build_dir)
hostpython3 = sh.Command(self.ctx.hostpython)
build_env = self.get_pil_env(arch)
dest_dir = join(self.ctx.dist_dir, "root", "python3")
build_env['PYTHONPATH'] = self.ctx.site_packages_dir
shprint(hostpython3, "setup.py", "install", "--prefix", dest_dir,
_env=build_env)

def biglink(self):
dirs = []
for root, dirnames, filenames in os.walk(self.build_dir):
if fnmatch.filter(filenames, "*.so.libs"):
dirs.append(root)
cmd = sh.Command(join(self.ctx.root_dir, "tools", "biglink"))
shprint(cmd, join(self.build_dir, "libpillow.a"), *dirs)


recipe = PillowRecipe()
19 changes: 19 additions & 0 deletions kivy_ios/recipes/pillow/bypass-find-library.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff -Naur Pillow-8.2.0.orig/setup.py Pillow-8.2.0/setup.py
--- Pillow-8.2.0.orig/setup.py 2021-04-05 11:11:26.000000000 +0200
+++ Pillow-8.2.0/setup.py 2021-04-05 11:16:12.000000000 +0200
@@ -222,12 +222,9 @@


def _find_library_file(self, library):
- ret = self.compiler.find_library_file(self.compiler.library_dirs, library)
- if ret:
- _dbg("Found library %s at %s", (library, ret))
- else:
- _dbg("Couldn't find library %s in %s", (library, self.compiler.library_dirs))
- return ret
+ # The provided find method is broken on our implementation.
+ # We will select by --disable flags what is actually disabled.
+ return True


def _find_include_dir(self, dirname, include):

0 comments on commit af61ccc

Please sign in to comment.