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 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
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(arch), '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.

You probably want get_python_install_dir(arch.arch) here


# 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(arch), '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