Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added lz4 #3071

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
48 changes: 48 additions & 0 deletions pythonforandroid/recipes/liblz4/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
from os.path import join

import sh

from pythonforandroid.logger import shprint
from pythonforandroid.recipe import Recipe
from pythonforandroid.toolchain import current_directory


class LibLZ4Recipe(Recipe):
name = 'liblz4'
version = '1.9.4' # Use the desired version
Copy link
Member

Choose a reason for hiding this comment

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

We can probably drop this comment

url = 'https://github.com/lz4/lz4/archive/refs/tags/v{version}.tar.gz'
depends = []

def build_arch(self, arch):
env = self.get_recipe_env(arch)
build_dir = self.get_build_dir(arch.arch)
lib_dir = self.ctx.get_libs_dir(arch.arch)
include_dir = join(self.ctx.get_python_install_dir(), 'include', 'lz4')
Copy link
Member

Choose a reason for hiding this comment

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

CI is failing with:

Traceback (most recent call last):
  File "/home/user/app/testapps/on_device_unit_tests/setup.py", line 106, in <module>
    setup(
  File "/home/user/app/venv/lib/python3.10/site-packages/setuptools/__init__.py", line 153, in setup
    return distutils.core.setup(**attrs)
  File "/usr/lib/python3.10/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.10/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.10/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/home/user/app/pythonforandroid/bdistapk.py", line 82, in run
    main()
  File "/home/user/app/pythonforandroid/entrypoints.py", line 18, in main
    ToolchainCL()
  File "/home/user/app/pythonforandroid/toolchain.py", line 677, in __init__
    getattr(self, command)(args)
  File "/home/user/app/pythonforandroid/toolchain.py", line 104, in wrapper_func
    build_dist_from_args(ctx, dist, args)
  File "/home/user/app/pythonforandroid/toolchain.py", line 163, in build_dist_from_args
    build_recipes(build_order, python_modules, ctx,
  File "/home/user/app/pythonforandroid/build.py", line 504, in build_recipes
    recipe.build_arch(arch)
  File "/home/user/app/pythonforandroid/recipes/liblz4/__init__.py", line 21, in build_arch
    include_dir = join(self.ctx.get_python_install_dir(), 'include', 'lz4')
TypeError: Context.get_python_install_dir() missing 1 required positional argument: 'arch'

Copy link
Author

Choose a reason for hiding this comment

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

fixed

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, did you have a chance to test the recipe on-device, is it working?


# Ensure include directory exists
if not os.path.exists(include_dir):
os.makedirs(include_dir)

with current_directory(join(build_dir, 'lib')):
# Clean previous builds
shprint(sh.make, 'clean', _env=env)
# Build the static library
shprint(sh.make, 'CC={}'.format(env['CC']), 'liblz4.a', _env=env)
# Copy the static library to the libs directory
sh.cp('liblz4.a', lib_dir)
# Copy headers to the include directory
sh.cp('lz4.h', include_dir)
sh.cp('lz4frame.h', include_dir)
sh.cp('lz4hc.h', include_dir)
sh.cp('xxhash.h', include_dir)

def get_recipe_env(self, arch):
env = super().get_recipe_env(arch)
# Ensure the correct compiler is used
python_recipe = self.get_recipe('python3', self.ctx)
env['CC'] = python_recipe.get_recipe_env(arch)['CC']
return env


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

from pythonforandroid.recipe import CompiledComponentsPythonRecipe


class Lz4Recipe(CompiledComponentsPythonRecipe):
name = 'lz4'
version = '4.3.2' # Use the desired version
Copy link
Member

Choose a reason for hiding this comment

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

drop this comment too

url = 'https://pypi.python.org/packages/source/l/lz4/lz4-{version}.tar.gz'
depends = ['setuptools', 'liblz4']
call_hostpython_via_targetpython = False

def get_recipe_env(self, arch):
env = super().get_recipe_env(arch)
ctx = self.ctx

# Include the headers from liblz4
lz4_include_dir = join(ctx.get_python_install_dir(), 'include', 'lz4')
env['CFLAGS'] += f' -I{lz4_include_dir}'

# Link against the liblz4 library
lz4_lib_dir = ctx.get_libs_dir(arch.arch)
env['LDFLAGS'] += f' -L{lz4_lib_dir} -llz4'

return env


recipe = Lz4Recipe()
Loading