Skip to content

Commit 29a6e7b

Browse files
committed
recipes: add thorvg
1 parent a9b902b commit 29a6e7b

File tree

7 files changed

+233
-104
lines changed

7 files changed

+233
-104
lines changed

pythonforandroid/recipes/jpeg/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ class JpegRecipe(Recipe):
1414
name = 'jpeg'
1515
version = '2.0.1'
1616
url = 'https://github.com/libjpeg-turbo/libjpeg-turbo/archive/{version}.tar.gz' # noqa
17-
built_libraries = {'libjpeg.a': '.', 'libturbojpeg.a': '.'}
18-
# we will require this below patch to build the shared library
19-
# patches = ['remove-version.patch']
17+
built_libraries = {'libjpeg.so': '.', 'libturbojpeg.so': '.'}
2018

2119
def build_arch(self, arch):
2220
build_dir = self.get_build_dir(arch.arch)
@@ -34,6 +32,8 @@ def build_arch(self, arch):
3432
'-DCMAKE_ANDROID_ARCH_ABI={arch}'.format(arch=arch.arch),
3533
'-DCMAKE_ANDROID_NDK=' + self.ctx.ndk_dir,
3634
'-DCMAKE_C_COMPILER={cc}'.format(cc=arch.get_clang_exe()),
35+
f'-DCMAKE_ASM_COMPILER={arch.get_clang_exe()}',
36+
f'-DCMAKE_ASM_FLAGS=--target={arch.target}',
3737
'-DCMAKE_CXX_COMPILER={cc_plus}'.format(
3838
cc_plus=arch.get_clang_exe(plus_plus=True)),
3939
'-DCMAKE_BUILD_TYPE=Release',
@@ -42,12 +42,11 @@ def build_arch(self, arch):
4242

4343
'-DANDROID_ABI={arch}'.format(arch=arch.arch),
4444
'-DANDROID_ARM_NEON=ON',
45-
'-DENABLE_NEON=ON',
46-
# '-DREQUIRE_SIMD=1',
45+
'-DWITH_SIMD=1',
46+
'-DREQUIRE_SIMD=1',
4747

4848
# Force disable shared, with the static ones is enough
49-
'-DENABLE_SHARED=0',
50-
'-DENABLE_STATIC=1',
49+
'-DENABLE_SHARED=1',
5150

5251
# Fix cmake compatibility issue
5352
'-DCMAKE_POLICY_VERSION_MINIMUM=3.5',

pythonforandroid/recipes/jpeg/build-static.patch

Lines changed: 0 additions & 85 deletions
This file was deleted.

pythonforandroid/recipes/jpeg/remove-version.patch

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
from pythonforandroid.recipe import Recipe, MesonRecipe
2+
from os.path import join
3+
from pythonforandroid.util import ensure_dir, current_directory
4+
from pythonforandroid.logger import shprint
5+
from multiprocessing import cpu_count
6+
import sh
7+
8+
9+
class LibThorVGRecipe(MesonRecipe):
10+
name = "libthorvg"
11+
version = "1.0.1"
12+
url = "https://github.com/thorvg/thorvg/releases/download/v{version}/thorvg.tar.gz"
13+
config_otps = [
14+
"-Dsimd=true",
15+
"-Dbindings=capi",
16+
"-Dtools=all",
17+
"-Dengines=sw,gl",
18+
"-Dloaders=svg,png,jpg,ttf,webp",
19+
"-Dextra=opengl_es,lottie_exp,openmp",
20+
"--reconfigure",
21+
]
22+
need_stl_shared = True
23+
skip_python = True
24+
depends = ["png", "libwebp", "jpeg"]
25+
patches = ["meson.patch"]
26+
bins = ["tvg-lottie2gif", "tvg-svg2png"]
27+
built_libraries = {
28+
"libthorvg-1.so": "install/lib"
29+
}
30+
for bin in bins:
31+
built_libraries[f"lib{bin}bin.so"] = "install/bin"
32+
33+
def should_build(self, arch):
34+
return Recipe.should_build(self, arch)
35+
36+
def get_include_dir(self, arch):
37+
return join(self.get_build_dir(arch.arch), "install", "include")
38+
39+
def build_arch(self, arch):
40+
super().build_arch(arch)
41+
build_dir = self.get_build_dir(arch.arch)
42+
install_dir = join(build_dir, "install")
43+
ensure_dir(install_dir)
44+
env = self.get_recipe_env(arch)
45+
46+
lib_dir = self.ctx.get_libs_dir(arch.arch)
47+
png_include = self.get_recipe("png", self.ctx).get_build_dir(arch.arch)
48+
webp_include = join(
49+
self.get_recipe("libwebp", self.ctx).get_build_dir(arch.arch), "src"
50+
)
51+
jpg_dir = self.get_recipe("jpeg", self.ctx).get_build_dir(arch.arch)
52+
53+
with current_directory(build_dir):
54+
55+
shprint(
56+
sh.meson,
57+
"setup",
58+
"builddir",
59+
"--cross-file",
60+
join("/tmp", "android.meson.cross"),
61+
f"--prefix={install_dir}",
62+
# config opts
63+
*self.config_otps,
64+
# deps
65+
f"-Dpng_include_dir={png_include}",
66+
f"-Dpng_lib_dir={lib_dir}",
67+
f"-Dwebp_include_dir={webp_include}",
68+
f"-Dwebp_lib_dir={lib_dir}",
69+
f"-Djpg_include_dir={jpg_dir}",
70+
f"-Djpg_lib_dir={jpg_dir}",
71+
_env=env,
72+
)
73+
74+
shprint(sh.ninja, "-C", "builddir", "-j", str(cpu_count()), _env=env)
75+
shprint(sh.rm, "-rf", install_dir)
76+
shprint(sh.mkdir, install_dir)
77+
shprint(sh.ninja, "-C", "builddir", "install", _env=env)
78+
79+
# setup bins
80+
bin_dir = join("install", "bin")
81+
for bin in self.bins:
82+
shprint(sh.cp, join(bin_dir, bin), join(bin_dir, f"lib{bin}bin.so"))
83+
84+
85+
recipe = LibThorVGRecipe()
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
diff '--color=auto' -uNr thorvg/meson_options.txt thorvg.mod/meson_options.txt
2+
--- thorvg/meson_options.txt 2026-02-12 21:02:13.000000000 +0530
3+
+++ thorvg.mod/meson_options.txt 2026-03-06 11:11:43.111722092 +0530
4+
@@ -68,3 +68,11 @@
5+
choices: ['', 'opengl_es', 'lottie_exp', 'openmp'],
6+
value: ['lottie_exp', 'openmp'],
7+
description: 'Enable support for extra options')
8+
+
9+
+
10+
+option('png_include_dir', type: 'string', value: '', description: 'Path to PNG headers')
11+
+option('png_lib_dir', type: 'string', value: '', description: 'Path to PNG library')
12+
+option('webp_include_dir', type: 'string', value: '', description: 'Path to WEBP headers')
13+
+option('webp_lib_dir', type: 'string', value: '', description: 'Path to WEBP library')
14+
+option('jpg_include_dir', type: 'string', value: '', description: 'Path to JPG headers')
15+
+option('jpg_lib_dir', type: 'string', value: '', description: 'Path to JPG library')
16+
diff '--color=auto' -uNr thorvg/src/loaders/external_jpg/meson.build thorvg.mod/src/loaders/external_jpg/meson.build
17+
--- thorvg/src/loaders/external_jpg/meson.build 2026-02-12 21:02:13.000000000 +0530
18+
+++ thorvg.mod/src/loaders/external_jpg/meson.build 2026-03-06 11:16:26.360504907 +0530
19+
@@ -3,11 +3,12 @@
20+
'tvgJpgLoader.cpp',
21+
]
22+
23+
-jpg_dep = dependency('libturbojpeg', required: false)
24+
-
25+
-if not jpg_dep.found()
26+
- jpg_dep = cc.find_library('turbojpeg', required: false)
27+
-endif
28+
+jpg_inc = include_directories(get_option('jpg_include_dir'))
29+
+jpg_lib = cc.find_library('turbojpeg', dirs: [get_option('jpg_lib_dir')], required: true)
30+
+jpg_dep = declare_dependency(
31+
+ include_directories: jpg_inc,
32+
+ dependencies: [jpg_lib]
33+
+)
34+
35+
if jpg_dep.found()
36+
subloader_dep += [declare_dependency(
37+
diff '--color=auto' -uNr thorvg/src/loaders/external_png/meson.build thorvg.mod/src/loaders/external_png/meson.build
38+
--- thorvg/src/loaders/external_png/meson.build 2026-02-12 21:02:13.000000000 +0530
39+
+++ thorvg.mod/src/loaders/external_png/meson.build 2026-03-06 10:59:38.966203768 +0530
40+
@@ -3,7 +3,12 @@
41+
'tvgPngLoader.cpp',
42+
]
43+
44+
-png_dep = dependency('libpng', required: false)
45+
+png_inc = include_directories(get_option('png_include_dir'))
46+
+png_lib = cc.find_library('png16', dirs: [get_option('png_lib_dir')], required: true)
47+
+png_dep = declare_dependency(
48+
+ include_directories: png_inc,
49+
+ dependencies: [png_lib]
50+
+)
51+
52+
if png_dep.found()
53+
subloader_dep += [declare_dependency(
54+
diff '--color=auto' -uNr thorvg/src/loaders/external_webp/meson.build thorvg.mod/src/loaders/external_webp/meson.build
55+
--- thorvg/src/loaders/external_webp/meson.build 2026-02-12 21:02:13.000000000 +0530
56+
+++ thorvg.mod/src/loaders/external_webp/meson.build 2026-03-06 11:03:55.626148453 +0530
57+
@@ -3,7 +3,12 @@
58+
'tvgWebpLoader.cpp',
59+
]
60+
61+
-webp_dep = dependency('libwebp', required: false)
62+
+webp_inc = include_directories(get_option('webp_include_dir'))
63+
+webp_lib = cc.find_library('webp', dirs: [get_option('webp_lib_dir')], required: true)
64+
+webp_dep = declare_dependency(
65+
+ include_directories: webp_inc,
66+
+ dependencies: [webp_lib]
67+
+)
68+
69+
if webp_dep.found()
70+
subloader_dep += [declare_dependency(
71+
@@ -11,4 +16,4 @@
72+
dependencies : webp_dep,
73+
sources : source_file
74+
)]
75+
-endif
76+
\ No newline at end of file
77+
+endif
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from pythonforandroid.recipe import PyProjectRecipe
2+
3+
4+
class ThorVGPythonRecipe(PyProjectRecipe):
5+
site_packages_name = "thorvg_python"
6+
version = "1.1.1"
7+
url = "https://github.com/laggykiller/thorvg-python/archive/refs/tags/v{version}.tar.gz"
8+
depends = ["libthorvg"]
9+
patches = ["sharedlib.patch"]
10+
11+
12+
recipe = ThorVGPythonRecipe()
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
diff '--color=auto' -uNr thorvg-python-1.1.1/pyproject.toml thorvg-python-1.1.1.mod/pyproject.toml
2+
--- thorvg-python-1.1.1/pyproject.toml 2026-02-28 01:45:23.000000000 +0530
3+
+++ thorvg-python-1.1.1.mod/pyproject.toml 2026-03-06 13:36:02.822762758 +0530
4+
@@ -34,7 +34,6 @@
5+
6+
[build-system]
7+
requires = [
8+
- "conan>=2.0",
9+
"setuptools>=45"
10+
]
11+
build-backend = "setuptools.build_meta"
12+
@@ -45,4 +44,4 @@
13+
14+
[tool.mypy]
15+
python_version = "3.9"
16+
-files = ["src", "tests"]
17+
\ No newline at end of file
18+
+files = ["src", "tests"]
19+
diff '--color=auto' -uNr thorvg-python-1.1.1/setup.py thorvg-python-1.1.1.mod/setup.py
20+
--- thorvg-python-1.1.1/setup.py 2026-02-28 01:45:23.000000000 +0530
21+
+++ thorvg-python-1.1.1.mod/setup.py 2026-03-06 13:32:56.878441668 +0530
22+
@@ -213,10 +213,4 @@
23+
packages=find_packages(where="src"),
24+
package_dir={"": "src"},
25+
include_package_data=True,
26+
- package_data={
27+
- "thorvg_python": ["*.dll", "*.dylib", "*.so"],
28+
- },
29+
- cmdclass={
30+
- "build_py": build_py_custom,
31+
- },
32+
)
33+
diff '--color=auto' -uNr thorvg-python-1.1.1/src/thorvg_python/engine.py thorvg-python-1.1.1.mod/src/thorvg_python/engine.py
34+
--- thorvg-python-1.1.1/src/thorvg_python/engine.py 2026-02-28 01:45:23.000000000 +0530
35+
+++ thorvg-python-1.1.1.mod/src/thorvg_python/engine.py 2026-03-06 13:34:47.097440103 +0530
36+
@@ -7,7 +7,7 @@
37+
from typing import List, Optional, Tuple, Type
38+
39+
from .base import Result
40+
-
41+
+from ctypes.utils import find_library
42+
43+
def _load_lib_with_prefix_suffix(
44+
lib_prefix: str, lib_suffix: str
45+
@@ -67,7 +67,7 @@
46+
return None
47+
48+
49+
-THORVG_LIB = _load_lib()
50+
+THORVG_LIB = find_library("libthorvg-1.so")
51+
52+
53+
class Engine:

0 commit comments

Comments
 (0)