From 19b8aaf20ebc90c77452802aead21aa0d8bfbb1c Mon Sep 17 00:00:00 2001 From: Ansh Dadwal Date: Thu, 28 Mar 2024 16:55:04 +0530 Subject: [PATCH] recipes: add new `uvloop` recipe --- .../recipes/libpthread/__init__.py | 51 +++++++++++++++++++ pythonforandroid/recipes/uvloop/__init__.py | 18 +++++++ 2 files changed, 69 insertions(+) create mode 100644 pythonforandroid/recipes/libpthread/__init__.py create mode 100644 pythonforandroid/recipes/uvloop/__init__.py diff --git a/pythonforandroid/recipes/libpthread/__init__.py b/pythonforandroid/recipes/libpthread/__init__.py new file mode 100644 index 0000000000..10feca475a --- /dev/null +++ b/pythonforandroid/recipes/libpthread/__init__.py @@ -0,0 +1,51 @@ +from os import makedirs, remove +from os.path import exists, join +import sh + +from pythonforandroid.recipe import Recipe +from pythonforandroid.logger import shprint + + +class LibPthread(Recipe): + ''' + This is a dumb recipe. We may need this because some recipes inserted some + flags `-lpthread` without our control, case of: + + - :class:`~pythonforandroid.recipes.uvloop.UvloopRecipe` + + .. note:: the libpthread doesn't exist in android but it is integrated into + libc, so we create a symbolic link which we will remove when our build + finishes''' + + def build_arch(self, arch): + libc_path = join(arch.ndk_lib_dir_versioned, 'libc') + # Create a temporary folder to add to link path with a fake libpthread.so: + fake_libpthread_temp_folder = join( + self.get_build_dir(arch.arch), + "p4a-libpthread-recipe-tempdir" + ) + if not exists(fake_libpthread_temp_folder): + makedirs(fake_libpthread_temp_folder) + + # Set symlinks, and make sure to update them on every build run: + if exists(join(fake_libpthread_temp_folder, "libpthread.so")): + remove(join(fake_libpthread_temp_folder, "libpthread.so")) + shprint(sh.ln, '-sf', + libc_path + '.so', + join(fake_libpthread_temp_folder, "libpthread.so"), + ) + if exists(join(fake_libpthread_temp_folder, "libpthread.a")): + remove(join(fake_libpthread_temp_folder, "libpthread.a")) + shprint(sh.ln, '-sf', + libc_path + '.a', + join(fake_libpthread_temp_folder, "libpthread.a"), + ) + + # Add folder as -L link option for all recipes if not done yet: + if fake_libpthread_temp_folder not in arch.extra_global_link_paths: + arch.extra_global_link_paths.append( + fake_libpthread_temp_folder + ) + + +recipe = LibPthread() diff --git a/pythonforandroid/recipes/uvloop/__init__.py b/pythonforandroid/recipes/uvloop/__init__.py new file mode 100644 index 0000000000..c1363bb4cd --- /dev/null +++ b/pythonforandroid/recipes/uvloop/__init__.py @@ -0,0 +1,18 @@ +from pythonforandroid.recipe import PythonRecipe + + +class UvloopRecipe(PythonRecipe): + # 0.19.0 + version = '6c770dc3fbdd281d15c2ad46588c139696f9269c' + url = 'git+https://github.com/MagicStack/uvloop' + depends = ['cython', 'setuptools', 'librt', 'libpthread'] + call_hostpython_via_targetpython = False + + def get_recipe_env(self, arch): + env = super().get_recipe_env(arch) + env["LIBUV_CONFIGURE_HOST"] = arch.command_prefix + env["PLATFORM"] = "android" + return env + + +recipe = UvloopRecipe()