Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions pythonforandroid/recipes/datoviz/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import glob
import os
import shutil
from os.path import join

import sh
from pythonforandroid.logger import info, shprint
from pythonforandroid.recipe import PyProjectRecipe, Recipe


class DatovizRecipe(PyProjectRecipe):
version = "7e1ba52513ea07f2c3a8c13b0979f1ccdb04bb11"
url = "git+https://github.com/datoviz/datoviz.git"
Comment on lines +12 to +13

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p4a uses git fetch --tags --depth 1 and this may break as soon as datoviz upstream commits on top of main.
Maybe use archive/<sha>.tar.gz instead, e.g.

url = "https://github.com/datoviz/datoviz/archive/{version}.tar.gz"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datoviz uses a lot of submodules we can't use source tar, I will request them to tag a new release.

depends = ["python3", "numpy", "libcglm"]
hostpython_prerequisites = ["pyyaml"]

def _find_glslc(self):
candidates = glob.glob(join(self.ctx.ndk_dir, "shader-tools", "*", "glslc*"))
if candidates:
return candidates[0]
return shutil.which("glslc")

def build_arch(self, arch):
self.install_hostpython_prerequisites()
build_dir = self.get_build_dir(arch.arch)
cmake_build_dir = join(build_dir, "p4a_cmake_build")
toolchain = join(self.ctx.ndk_dir, "build", "cmake", "android.toolchain.cmake")
generator = "Ninja" if shutil.which("ninja") else "Unix Makefiles"
cglm_install_dir = join(
Recipe.get_recipe("libcglm", self.ctx).get_build_dir(arch.arch),
"installation",
)

cmake_args = [
"-S",
build_dir,
"-B",
cmake_build_dir,
"-G",
generator,
f"-DCMAKE_TOOLCHAIN_FILE={toolchain}",
f"-DANDROID_ABI={arch.arch}",
f"-DANDROID_PLATFORM=android-{self.ctx.ndk_api}",
f"-DCMAKE_PREFIX_PATH={cglm_install_dir}",
f"-DCMAKE_SHARED_LINKER_FLAGS=-L{join(cglm_install_dir, 'lib')}",
"-DCMAKE_BUILD_TYPE=Release",
"-DDVZ_CGLM_SOURCE=SYSTEM",
"-DDVZ_BUILD_TESTING=OFF",
"-DDVZ_BUILD_EXAMPLES=OFF",
"-DDVZ_INSTALL=OFF",
"-DDVZ_WITH_GLFW=OFF",
"-DDVZ_BUILD_GUI=OFF",
"-DDVZ_ENABLE_CUDA=OFF",
"-DDVZ_ENABLE_QT_BRIDGE=OFF",
"-DDVZ_ENABLE_SHADERC=OFF",
"-DDVZ_WITH_FREETYPE=OFF",
"-DDVZ_WITH_MSDF_ATLAS=OFF",
"-DDVZ_KVAZAAR_SOURCE=OFF",
f"-DPython3_EXECUTABLE={self.real_hostpython_location}",
]
glslc = self._find_glslc()
if glslc:
cmake_args.append(f"-DDVZ_GLSLC_EXECUTABLE={glslc}")

info(f"Configuring datoviz CMake for {arch.arch} (android-{self.ctx.ndk_api})")
shprint(sh.cmake, *cmake_args)

nproc = str(os.cpu_count() or 4)
info(f"Building libdatoviz.so for {arch.arch}")
shprint(
sh.cmake, "--build", cmake_build_dir, "--target", "datoviz", "-j", nproc
)

built_so = join(cmake_build_dir, "src", "libdatoviz.so")
target_so = join(build_dir, "datoviz", "libdatoviz.so")
shutil.copy2(built_so, target_so)

super().build_arch(arch)


recipe = DatovizRecipe()
51 changes: 51 additions & 0 deletions pythonforandroid/recipes/libcglm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import os
import shutil
from os.path import join

import sh

from pythonforandroid.logger import info, shprint
from pythonforandroid.recipe import Recipe
from pythonforandroid.util import ensure_dir


class LibCglmRecipe(Recipe):
version = "0.9.6"
url = "https://github.com/recp/cglm/archive/refs/tags/v{version}.tar.gz"
built_libraries = {
"libcglm.so": "installation/lib",
}

def build_arch(self, arch):
source_dir = self.get_build_dir(arch.arch)
build_dir = join(source_dir, "p4a_build")
install_dir = join(source_dir, "installation")
toolchain = join(self.ctx.ndk_dir, "build", "cmake", "android.toolchain.cmake")
generator = "Ninja" if shutil.which("ninja") else "Unix Makefiles"

ensure_dir(build_dir)
cmake_args = [
"-S",
source_dir,
"-B",
build_dir,
"-G",
generator,
f"-DCMAKE_TOOLCHAIN_FILE={toolchain}",
f"-DANDROID_ABI={arch.arch}",
f"-DANDROID_PLATFORM=android-{self.ctx.ndk_api}",
f"-DCMAKE_INSTALL_PREFIX={install_dir}",
"-DCMAKE_BUILD_TYPE=Release",
"-DCMAKE_POSITION_INDEPENDENT_CODE=ON",
"-DCGLM_SHARED=ON",
"-DCGLM_STATIC=OFF",
"-DCGLM_USE_C99=ON",
"-DCGLM_USE_TEST=OFF",
]
info(f"Building cglm {self.version} for {arch.arch}")
shprint(sh.cmake, *cmake_args)
shprint(sh.cmake, "--build", build_dir, "-j", str(os.cpu_count() or 4))
shprint(sh.cmake, "--install", build_dir)


recipe = LibCglmRecipe()
Loading