|
| 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 | +from glob import glob |
| 7 | +import sh |
| 8 | + |
| 9 | + |
| 10 | +class LibThorVGRecipe(MesonRecipe): |
| 11 | + name = "libthorvg" |
| 12 | + version = "1.0.1" |
| 13 | + url = "https://github.com/thorvg/thorvg/releases/download/v{version}/thorvg.tar.gz" |
| 14 | + config_otps = [ |
| 15 | + "-Dsimd=true", |
| 16 | + "-Dbindings=capi", |
| 17 | + "-Dtools=all", |
| 18 | + "-Dengines=sw,gl", |
| 19 | + "-Dloaders=svg,png,jpg,ttf,webp", |
| 20 | + "-Dextra=opengl_es,lottie_exp,openmp", |
| 21 | + "--reconfigure", |
| 22 | + ] |
| 23 | + need_stl_shared = True |
| 24 | + skip_python = True |
| 25 | + depends = ["png", "libwebp", "jpeg"] |
| 26 | + patches = ["meson.patch"] |
| 27 | + bins = ["tvg-lottie2gif", "tvg-svg2png"] |
| 28 | + built_libraries = { |
| 29 | + "libthorvg-1.so": "install/lib", |
| 30 | + "libomp.so": "install/lib" |
| 31 | + } |
| 32 | + for bin in bins: |
| 33 | + built_libraries[f"lib{bin}bin.so"] = "install/bin" |
| 34 | + |
| 35 | + def should_build(self, arch): |
| 36 | + return Recipe.should_build(self, arch) |
| 37 | + |
| 38 | + def get_include_dir(self, arch): |
| 39 | + return join(self.get_build_dir(arch.arch), "install", "include") |
| 40 | + |
| 41 | + def build_arch(self, arch): |
| 42 | + super().build_arch(arch) |
| 43 | + build_dir = self.get_build_dir(arch.arch) |
| 44 | + install_dir = join(build_dir, "install") |
| 45 | + ensure_dir(install_dir) |
| 46 | + env = self.get_recipe_env(arch) |
| 47 | + |
| 48 | + lib_dir = self.ctx.get_libs_dir(arch.arch) |
| 49 | + png_include = self.get_recipe("png", self.ctx).get_build_dir(arch.arch) |
| 50 | + webp_include = join( |
| 51 | + self.get_recipe("libwebp", self.ctx).get_build_dir(arch.arch), "src" |
| 52 | + ) |
| 53 | + jpg_dir = self.get_recipe("jpeg", self.ctx).get_build_dir(arch.arch) |
| 54 | + |
| 55 | + with current_directory(build_dir): |
| 56 | + |
| 57 | + shprint( |
| 58 | + sh.meson, |
| 59 | + "setup", |
| 60 | + "builddir", |
| 61 | + "--cross-file", |
| 62 | + join("/tmp", "android.meson.cross"), |
| 63 | + f"--prefix={install_dir}", |
| 64 | + # config opts |
| 65 | + *self.config_otps, |
| 66 | + # deps |
| 67 | + f"-Dpng_include_dir={png_include}", |
| 68 | + f"-Dpng_lib_dir={lib_dir}", |
| 69 | + f"-Dwebp_include_dir={webp_include}", |
| 70 | + f"-Dwebp_lib_dir={lib_dir}", |
| 71 | + f"-Djpg_include_dir={jpg_dir}", |
| 72 | + f"-Djpg_lib_dir={jpg_dir}", |
| 73 | + _env=env, |
| 74 | + ) |
| 75 | + |
| 76 | + shprint(sh.ninja, "-C", "builddir", "-j", str(cpu_count()), _env=env) |
| 77 | + shprint(sh.rm, "-rf", install_dir) |
| 78 | + shprint(sh.mkdir, install_dir) |
| 79 | + shprint(sh.ninja, "-C", "builddir", "install", _env=env) |
| 80 | + |
| 81 | + # copy libomp.so |
| 82 | + arch_map = { |
| 83 | + "arm64-v8a": "aarch64", |
| 84 | + "armeabi-v7a": "arm", |
| 85 | + "x86": "i386", |
| 86 | + "x86_64": "x86_64", |
| 87 | + } |
| 88 | + lib_arch = arch_map[arch.arch] |
| 89 | + # clang version directory is variable, so glob it |
| 90 | + clang_lib_dir = glob( |
| 91 | + join(self.ctx.ndk.llvm_prebuilt_dir, "lib64/clang/*/lib/linux", lib_arch) |
| 92 | + )[0] |
| 93 | + libomp = join(clang_lib_dir, "libomp.so") |
| 94 | + shprint(sh.cp, libomp, join("install", "lib")) |
| 95 | + |
| 96 | + # setup bins |
| 97 | + bin_dir = join("install", "bin") |
| 98 | + for bin in self.bins: |
| 99 | + shprint(sh.cp, join(bin_dir, bin), join(bin_dir, f"lib{bin}bin.so")) |
| 100 | + |
| 101 | + |
| 102 | +recipe = LibThorVGRecipe() |
0 commit comments