Skip to content

Commit 129601c

Browse files
opacaminclement
authored andcommitted
[WIP][LIBS - PART III] Rework of pyleveldb, leveldb and snappy (#1966)
* [recipe-lib] Make snappy a library recipe * [recipe-stl] Make leveldb a library recipe and... make it work with the reworked snappy recipe * [recipe-stl] Fix pyleveldb for reworked leveldb/snappy
1 parent 7ec64aa commit 129601c

File tree

6 files changed

+180
-157
lines changed

6 files changed

+180
-157
lines changed
Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,46 @@
1-
from pythonforandroid.toolchain import Recipe, shprint, shutil, current_directory
1+
from pythonforandroid.logger import shprint
2+
from pythonforandroid.util import current_directory
3+
from pythonforandroid.recipe import Recipe
4+
from multiprocessing import cpu_count
25
from os.path import join
36
import sh
47

58

69
class LevelDBRecipe(Recipe):
7-
version = '1.18'
8-
url = 'https://github.com/google/leveldb/archive/v{version}.tar.gz'
9-
opt_depends = ['snappy']
10-
patches = ['disable-so-version.patch', 'find-snappy.patch']
11-
12-
def should_build(self, arch):
13-
return not self.has_libs(arch, 'libleveldb.so', 'libgnustl_shared.so')
10+
version = '1.22'
11+
url = 'https://github.com/google/leveldb/archive/{version}.tar.gz'
12+
depends = ['snappy']
13+
built_libraries = {'libleveldb.so': '.'}
14+
need_stl_shared = True
1415

1516
def build_arch(self, arch):
16-
super(LevelDBRecipe, self).build_arch(arch)
1717
env = self.get_recipe_env(arch)
18-
with current_directory(self.get_build_dir(arch.arch)):
19-
if 'snappy' in recipe.ctx.recipe_build_order:
20-
# Copy source from snappy recipe
21-
sh.cp('-rf', self.get_recipe('snappy', self.ctx).get_build_dir(arch.arch), 'snappy')
22-
# Build
23-
shprint(sh.make, _env=env)
24-
# Copy the shared library
25-
shutil.copyfile('libleveldb.so', join(self.ctx.get_libs_dir(arch.arch), 'libleveldb.so'))
26-
# Copy stl
27-
shutil.copyfile(self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/libs/' + arch.arch + '/libgnustl_shared.so',
28-
join(self.ctx.get_libs_dir(arch.arch), 'libgnustl_shared.so'))
29-
30-
def get_recipe_env(self, arch):
31-
env = super(LevelDBRecipe, self).get_recipe_env(arch)
32-
env['TARGET_OS'] = 'OS_ANDROID_CROSSCOMPILE'
33-
if 'snappy' in recipe.ctx.recipe_build_order:
34-
env['CFLAGS'] += ' -DSNAPPY' + \
35-
' -I./snappy'
36-
env['CFLAGS'] += ' -I' + self.ctx.ndk_dir + '/platforms/android-' + str(self.ctx.android_api) + '/arch-' + arch.arch.replace('eabi', '') + '/usr/include' + \
37-
' -I' + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/include' + \
38-
' -I' + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/libs/' + arch.arch + '/include'
39-
env['CXXFLAGS'] = env['CFLAGS']
40-
env['CXXFLAGS'] += ' -frtti'
41-
env['CXXFLAGS'] += ' -fexceptions'
42-
env['LDFLAGS'] += ' -L' + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/libs/' + arch.arch + \
43-
' -lgnustl_shared'
44-
return env
18+
source_dir = self.get_build_dir(arch.arch)
19+
with current_directory(source_dir):
20+
snappy_recipe = self.get_recipe('snappy', self.ctx)
21+
snappy_build = snappy_recipe.get_build_dir(arch.arch)
22+
23+
shprint(sh.cmake, source_dir,
24+
'-DANDROID_ABI={}'.format(arch.arch),
25+
'-DANDROID_NATIVE_API_LEVEL={}'.format(self.ctx.ndk_api),
26+
'-DANDROID_STL=' + self.stl_lib_name,
27+
28+
'-DCMAKE_TOOLCHAIN_FILE={}'.format(
29+
join(self.ctx.ndk_dir, 'build', 'cmake',
30+
'android.toolchain.cmake')),
31+
'-DCMAKE_BUILD_TYPE=Release',
32+
33+
'-DBUILD_SHARED_LIBS=1',
34+
35+
'-DHAVE_SNAPPY=1',
36+
'-DCMAKE_CXX_FLAGS=-I{path}'.format(path=snappy_build),
37+
'-DCMAKE_SHARED_LINKER_FLAGS=-L{path} -lsnappy'.format(
38+
path=snappy_build),
39+
'-DCMAKE_EXE_LINKER_FLAGS=-L{path} -lsnappy'.format(
40+
path=snappy_build),
41+
42+
_env=env)
43+
shprint(sh.make, '-j' + str(cpu_count()), _env=env)
4544

4645

4746
recipe = LevelDBRecipe()

pythonforandroid/recipes/leveldb/disable-so-version.patch

Lines changed: 0 additions & 10 deletions
This file was deleted.

pythonforandroid/recipes/leveldb/find-snappy.patch

Lines changed: 0 additions & 11 deletions
This file was deleted.

pythonforandroid/recipes/pyleveldb/__init__.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,26 @@
22

33

44
class PyLevelDBRecipe(CppCompiledComponentsPythonRecipe):
5-
version = '0.193'
6-
url = 'https://pypi.python.org/packages/source/l/leveldb/leveldb-{version}.tar.gz'
7-
depends = ['snappy', 'leveldb', ('hostpython2', 'hostpython3'), 'setuptools']
5+
version = '0.194'
6+
url = ('https://pypi.python.org/packages/source/l/leveldb/'
7+
'leveldb-{version}.tar.gz')
8+
depends = ['snappy', 'leveldb', 'setuptools']
89
patches = ['bindings-only.patch']
9-
call_hostpython_via_targetpython = False # Due to setuptools
1010
site_packages_name = 'leveldb'
1111

12+
def get_recipe_env(self, arch):
13+
env = super(PyLevelDBRecipe, self).get_recipe_env(arch)
14+
15+
snappy_recipe = self.get_recipe('snappy', self.ctx)
16+
leveldb_recipe = self.get_recipe('leveldb', self.ctx)
17+
18+
env["LDFLAGS"] += " -L" + snappy_recipe.get_build_dir(arch.arch)
19+
env["LDFLAGS"] += " -L" + leveldb_recipe.get_build_dir(arch.arch)
20+
21+
env["SNAPPY_BUILD_PATH"] = snappy_recipe.get_build_dir(arch.arch)
22+
env["LEVELDB_BUILD_PATH"] = leveldb_recipe.get_build_dir(arch.arch)
23+
24+
return env
25+
1226

1327
recipe = PyLevelDBRecipe()
Lines changed: 106 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,119 @@
1-
--- pyleveldb/setup.py 2014-03-28 02:51:24.000000000 +0100
2-
+++ pyleveldb-patch/setup.py 2016-03-02 11:52:13.780678586 +0100
3-
@@ -7,41 +7,22 @@
4-
#
5-
# See LICENSE for details.
6-
7-
-import glob
8-
-import platform
9-
-import sys
10-
-
1+
This patch force to only build the python bindings, and to do so, we modify
2+
the setup.py file in oder that finds our compiled libraries (libleveldb.so and
3+
libsnappy.so)
4+
--- leveldb-0.194/setup.py.orig 2016-09-17 02:05:55.000000000 +0200
5+
+++ leveldb-0.194/setup.py 2019-02-26 16:57:40.997435911 +0100
6+
@@ -11,44 +11,25 @@ import platform
7+
import sys
8+
119
from setuptools import setup, Extension
12-
13-
-system,node,release,version,machine,processor = platform.uname()
10+
+from os import environ
11+
12+
system, node, release, version, machine, processor = platform.uname()
1413
-common_flags = [
14+
- '-I./leveldb/include',
15+
- '-I./leveldb',
16+
- '-I./snappy',
1517
+extra_compile_args = [
16-
'-I./leveldb/include',
17-
'-I./leveldb',
18-
- '-I./snappy',
19-
+ '-I./leveldb/snappy',
20-
'-I.',
21-
- '-fno-builtin-memcmp',
22-
'-O2',
23-
'-fPIC',
24-
'-DNDEBUG',
25-
'-DSNAPPY',
26-
-]
27-
-
18+
+ '-I{}/include'.format(environ.get('LEVELDB_BUILD_PATH')),
19+
+ '-I{}'.format(environ.get('LEVELDB_BUILD_PATH')),
20+
+ '-I{}'.format(environ.get('SNAPPY_BUILD_PATH')),
21+
+ '-I.',
22+
'-I.',
23+
- '-fno-builtin-memcmp',
24+
'-O2',
25+
'-fPIC',
26+
'-DNDEBUG',
27+
'-DSNAPPY',
28+
+ '-pthread',
29+
+ '-Wall',
30+
+ '-D_REENTRANT',
31+
+ '-DOS_ANDROID',
32+
]
33+
2834
-if system == 'Darwin':
29-
- extra_compile_args = common_flags + [
30-
- '-DOS_MACOSX',
31-
+ '-Wall',
32-
'-DLEVELDB_PLATFORM_POSIX',
33-
- '-Wno-error=unused-command-line-argument-hard-error-in-future',
34-
- ]
35+
- extra_compile_args = common_flags + [
36+
- '-DOS_MACOSX',
37+
- '-DLEVELDB_PLATFORM_POSIX',
38+
- '-Wno-error=unused-command-line-argument-hard-error-in-future',
39+
- ]
3540
-elif system == 'Linux':
41+
- extra_compile_args = common_flags + [
42+
- '-pthread',
43+
- '-Wall',
44+
- '-DOS_LINUX',
45+
- '-DLEVELDB_PLATFORM_POSIX',
46+
- ]
47+
-elif system == 'SunOS':
3648
- extra_compile_args = common_flags + [
3749
- '-pthread',
38-
- '-Wall',
39-
- '-DOS_LINUX',
50+
- '-Wall',
51+
- '-DOS_SOLARIS',
4052
- '-DLEVELDB_PLATFORM_POSIX',
4153
- ]
4254
-else:
43-
- print >>sys.stderr, "Don't know how to compile leveldb for %s!" % system
44-
- sys.exit(0)
45-
+ '-D_REENTRANT',
46-
+ '-DOS_ANDROID',
47-
+]
48-
55+
- sys.stderr.write("Don't know how to compile leveldb for %s!\n" % system)
56+
- sys.exit(1)
57+
-
4958
setup(
50-
name = 'leveldb',
51-
@@ -75,52 +56,6 @@
52-
ext_modules = [
53-
Extension('leveldb',
54-
sources = [
55-
- # snappy
56-
- './snappy/snappy.cc',
57-
- './snappy/snappy-stubs-internal.cc',
58-
- './snappy/snappy-sinksource.cc',
59-
- './snappy/snappy-c.cc',
59+
name = 'leveldb',
60+
version = '0.194',
61+
@@ -81,57 +62,11 @@ setup(
62+
ext_modules = [
63+
Extension('leveldb',
64+
sources = [
65+
- # snappy
66+
- './snappy/snappy.cc',
67+
- './snappy/snappy-stubs-internal.cc',
68+
- './snappy/snappy-sinksource.cc',
69+
- './snappy/snappy-c.cc',
6070
-
61-
- #leveldb
62-
- 'leveldb/db/builder.cc',
63-
- 'leveldb/db/c.cc',
64-
- 'leveldb/db/db_impl.cc',
65-
- 'leveldb/db/db_iter.cc',
66-
- 'leveldb/db/dbformat.cc',
67-
- 'leveldb/db/filename.cc',
68-
- 'leveldb/db/log_reader.cc',
69-
- 'leveldb/db/log_writer.cc',
70-
- 'leveldb/db/memtable.cc',
71-
- 'leveldb/db/repair.cc',
72-
- 'leveldb/db/table_cache.cc',
73-
- 'leveldb/db/version_edit.cc',
74-
- 'leveldb/db/version_set.cc',
75-
- 'leveldb/db/write_batch.cc',
76-
- 'leveldb/table/block.cc',
77-
- 'leveldb/table/block_builder.cc',
78-
- 'leveldb/table/filter_block.cc',
79-
- 'leveldb/table/format.cc',
80-
- 'leveldb/table/iterator.cc',
81-
- 'leveldb/table/merger.cc',
82-
- 'leveldb/table/table.cc',
83-
- 'leveldb/table/table_builder.cc',
84-
- 'leveldb/table/two_level_iterator.cc',
85-
- 'leveldb/util/arena.cc',
86-
- 'leveldb/util/bloom.cc',
87-
- 'leveldb/util/cache.cc',
88-
- 'leveldb/util/coding.cc',
89-
- 'leveldb/util/comparator.cc',
90-
- 'leveldb/util/crc32c.cc',
91-
- 'leveldb/util/env.cc',
92-
- 'leveldb/util/env_posix.cc',
93-
- 'leveldb/util/filter_policy.cc',
94-
- 'leveldb/util/hash.cc',
95-
- 'leveldb/util/histogram.cc',
96-
- 'leveldb/util/logging.cc',
97-
- 'leveldb/util/options.cc',
98-
- 'leveldb/util/status.cc',
99-
- 'leveldb/port/port_posix.cc',
71+
- #leveldb
72+
- 'leveldb/db/builder.cc',
73+
- 'leveldb/db/c.cc',
74+
- 'leveldb/db/db_impl.cc',
75+
- 'leveldb/db/db_iter.cc',
76+
- 'leveldb/db/dbformat.cc',
77+
- 'leveldb/db/filename.cc',
78+
- 'leveldb/db/log_reader.cc',
79+
- 'leveldb/db/log_writer.cc',
80+
- 'leveldb/db/memtable.cc',
81+
- 'leveldb/db/repair.cc',
82+
- 'leveldb/db/table_cache.cc',
83+
- 'leveldb/db/version_edit.cc',
84+
- 'leveldb/db/version_set.cc',
85+
- 'leveldb/db/write_batch.cc',
86+
- 'leveldb/table/block.cc',
87+
- 'leveldb/table/block_builder.cc',
88+
- 'leveldb/table/filter_block.cc',
89+
- 'leveldb/table/format.cc',
90+
- 'leveldb/table/iterator.cc',
91+
- 'leveldb/table/merger.cc',
92+
- 'leveldb/table/table.cc',
93+
- 'leveldb/table/table_builder.cc',
94+
- 'leveldb/table/two_level_iterator.cc',
95+
- 'leveldb/util/arena.cc',
96+
- 'leveldb/util/bloom.cc',
97+
- 'leveldb/util/cache.cc',
98+
- 'leveldb/util/coding.cc',
99+
- 'leveldb/util/comparator.cc',
100+
- 'leveldb/util/crc32c.cc',
101+
- 'leveldb/util/env.cc',
102+
- 'leveldb/util/env_posix.cc',
103+
- 'leveldb/util/filter_policy.cc',
104+
- 'leveldb/util/hash.cc',
105+
- 'leveldb/util/histogram.cc',
106+
- 'leveldb/util/logging.cc',
107+
- 'leveldb/util/options.cc',
108+
- 'leveldb/util/status.cc',
109+
- 'leveldb/port/port_posix.cc',
100110
-
101-
# python stuff
102-
'leveldb_ext.cc',
103-
'leveldb_object.cc',
111+
# python stuff
112+
'leveldb_ext.cc',
113+
'leveldb_object.cc',
114+
],
115+
- libraries = ['stdc++'],
116+
+ libraries = ['snappy', 'leveldb', 'stdc++', 'c++_shared'],
117+
extra_compile_args = extra_compile_args,
118+
)
119+
]
Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1-
from pythonforandroid.toolchain import Recipe
1+
from pythonforandroid.recipe import Recipe
2+
from pythonforandroid.logger import shprint
3+
from pythonforandroid.util import current_directory
4+
from os.path import join
5+
import sh
26

37

48
class SnappyRecipe(Recipe):
5-
version = '1.1.3'
6-
url = 'https://github.com/google/snappy/releases/download/{version}/snappy-{version}.tar.gz'
9+
version = '1.1.7'
10+
url = 'https://github.com/google/snappy/archive/{version}.tar.gz'
11+
built_libraries = {'libsnappy.so': '.'}
712

8-
def should_build(self, arch):
9-
# Only download to use in leveldb recipe
10-
return False
13+
def build_arch(self, arch):
14+
env = self.get_recipe_env(arch)
15+
source_dir = self.get_build_dir(arch.arch)
16+
with current_directory(source_dir):
17+
shprint(sh.cmake, source_dir,
18+
'-DANDROID_ABI={}'.format(arch.arch),
19+
'-DANDROID_NATIVE_API_LEVEL={}'.format(self.ctx.ndk_api),
20+
'-DCMAKE_TOOLCHAIN_FILE={}'.format(
21+
join(self.ctx.ndk_dir, 'build', 'cmake',
22+
'android.toolchain.cmake')),
23+
'-DBUILD_SHARED_LIBS=1',
24+
_env=env)
25+
shprint(sh.make, _env=env)
1126

1227

1328
recipe = SnappyRecipe()

0 commit comments

Comments
 (0)