Skip to content

Commit 1461b61

Browse files
committed
recipes: add new uvloop recipe
1 parent 8110faf commit 1461b61

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from os import makedirs, remove
2+
from os.path import exists, join
3+
import sh
4+
5+
from pythonforandroid.recipe import Recipe
6+
from pythonforandroid.logger import shprint
7+
8+
9+
class LibPthread(Recipe):
10+
'''
11+
This is a dumb recipe. We may need this because some recipes inserted some
12+
flags `-lpthread` without our control, case of:
13+
14+
- :class:`~pythonforandroid.recipes.uvloop.UvloopRecipe`
15+
16+
.. note:: the libpthread doesn't exist in android but it is integrated into
17+
libc, so we create a symbolic link which we will remove when our build
18+
finishes'''
19+
20+
def build_arch(self, arch):
21+
libc_path = join(arch.ndk_lib_dir_versioned, 'libc')
22+
# Create a temporary folder to add to link path with a fake libpthread.so:
23+
fake_libpthread_temp_folder = join(
24+
self.get_build_dir(arch.arch),
25+
"p4a-libpthread-recipe-tempdir"
26+
)
27+
if not exists(fake_libpthread_temp_folder):
28+
makedirs(fake_libpthread_temp_folder)
29+
30+
# Set symlinks, and make sure to update them on every build run:
31+
if exists(join(fake_libpthread_temp_folder, "libpthread.so")):
32+
remove(join(fake_libpthread_temp_folder, "libpthread.so"))
33+
shprint(sh.ln, '-sf',
34+
libc_path + '.so',
35+
join(fake_libpthread_temp_folder, "libpthread.so"),
36+
)
37+
if exists(join(fake_libpthread_temp_folder, "libpthread.a")):
38+
remove(join(fake_libpthread_temp_folder, "libpthread.a"))
39+
shprint(sh.ln, '-sf',
40+
libc_path + '.a',
41+
join(fake_libpthread_temp_folder, "libpthread.a"),
42+
)
43+
44+
# Add folder as -L link option for all recipes if not done yet:
45+
if fake_libpthread_temp_folder not in arch.extra_global_link_paths:
46+
arch.extra_global_link_paths.append(
47+
fake_libpthread_temp_folder
48+
)
49+
50+
51+
recipe = LibPthread()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from pythonforandroid.recipe import PyProjectRecipe
2+
3+
4+
class UvloopRecipe(PyProjectRecipe):
5+
version = 'v0.19.0'
6+
url = 'git+https://github.com/MagicStack/uvloop'
7+
depends = ['librt', 'libpthread']
8+
9+
def get_recipe_env(self, arch, **kwargs):
10+
env = super().get_recipe_env(arch, **kwargs)
11+
env["LIBUV_CONFIGURE_HOST"] = arch.command_prefix
12+
env["PLATFORM"] = "android"
13+
return env
14+
15+
16+
recipe = UvloopRecipe()

0 commit comments

Comments
 (0)