Skip to content

Commit cd48e8e

Browse files
committed
Merge pull request kivy#660 from brussee/leveldb-snappy
Added LevelDB recipe including snappy
2 parents 9e573a6 + 5eee5e1 commit cd48e8e

File tree

6 files changed

+222
-0
lines changed

6 files changed

+222
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from pythonforandroid.toolchain import Recipe, shprint, shutil, current_directory
2+
from os.path import join, exists
3+
import sh
4+
5+
class LevelDBRecipe(Recipe):
6+
version = '1.18'
7+
url = 'https://github.com/google/leveldb/archive/v{version}.tar.gz'
8+
opt_depends = ['snappy']
9+
patches = ['disable-so-version.patch', 'find-snappy.patch']
10+
11+
def should_build(self, arch):
12+
return not self.has_libs(arch, 'libleveldb.so', 'libgnustl_shared.so')
13+
14+
def build_arch(self, arch):
15+
super(LevelDBRecipe, self).build_arch(arch)
16+
env = self.get_recipe_env(arch)
17+
with current_directory(self.get_build_dir(arch.arch)):
18+
if 'snappy' in recipe.ctx.recipe_build_order:
19+
# Copy source from snappy recipe
20+
sh.cp('-rf', self.get_recipe('snappy', self.ctx).get_build_dir(arch.arch), 'snappy')
21+
# Build
22+
shprint(sh.make, _env=env)
23+
# Copy the shared library
24+
shutil.copyfile('libleveldb.so', join(self.ctx.get_libs_dir(arch.arch), 'libleveldb.so'))
25+
# Copy stl
26+
shutil.copyfile(self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/libs/' + arch.arch + '/libgnustl_shared.so',
27+
join(self.ctx.get_libs_dir(arch.arch), 'libgnustl_shared.so'))
28+
29+
def get_recipe_env(self, arch):
30+
env = super(LevelDBRecipe, self).get_recipe_env(arch)
31+
env['TARGET_OS'] = 'OS_ANDROID_CROSSCOMPILE'
32+
if 'snappy' in recipe.ctx.recipe_build_order:
33+
env['CFLAGS'] += ' -DSNAPPY' + \
34+
' -I./snappy'
35+
env['CFLAGS'] += ' -I' + self.ctx.ndk_dir + '/platforms/android-' + str(self.ctx.android_api) + '/arch-' + arch.arch.replace('eabi', '') + '/usr/include' + \
36+
' -I' + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/include' + \
37+
' -I' + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/libs/' + arch.arch + '/include'
38+
env['CXXFLAGS'] = env['CFLAGS']
39+
env['CXXFLAGS'] += ' -frtti'
40+
env['CXXFLAGS'] += ' -fexceptions'
41+
env['LDFLAGS'] += ' -L' + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/libs/' + arch.arch + \
42+
' -lgnustl_shared'
43+
return env
44+
45+
recipe = LevelDBRecipe()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--- leveldb/build_detect_platform 2014-09-16 23:19:52.000000000 +0200
2+
+++ leveldb-patch/build_detect_platform 2016-03-01 20:25:04.074484399 +0100
3+
@@ -124,6 +124,7 @@
4+
;;
5+
OS_ANDROID_CROSSCOMPILE)
6+
PLATFORM=OS_ANDROID
7+
+ PLATFORM_SHARED_VERSIONED=
8+
COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_ANDROID -DLEVELDB_PLATFORM_POSIX"
9+
PLATFORM_LDFLAGS="" # All pthread features are in the Android C library
10+
PORT_FILE=port/port_posix.cc
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- leveldb/build_detect_platform 2014-09-16 23:19:52.000000000 +0200
2+
+++ leveldb-patch/build_detect_platform 2016-03-01 21:56:04.926650079 +0100
3+
@@ -156,7 +157,7 @@
4+
# except for the test and benchmark files. By default, find will output a list
5+
# of all files matching either rule, so we need to append -print to make the
6+
# prune take effect.
7+
-DIRS="$PREFIX/db $PREFIX/util $PREFIX/table"
8+
+DIRS="$PREFIX/snappy $PREFIX/db $PREFIX/util $PREFIX/table"
9+
10+
set -f # temporarily disable globbing so that our patterns aren't expanded
11+
PRUNE_TEST="-name *test*.cc -prune"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from pythonforandroid.toolchain import PythonRecipe, shprint, shutil, current_directory
2+
from os.path import join, exists
3+
import sh
4+
5+
class PyLevelDBRecipe(PythonRecipe):
6+
version = '0.193'
7+
url = 'https://pypi.python.org/packages/source/l/leveldb/leveldb-{version}.tar.gz'
8+
depends = ['leveldb', 'hostpython2', 'python2', 'setuptools']
9+
patches = ['bindings-only.patch']
10+
call_hostpython_via_targetpython = False
11+
site_packages_name = 'leveldb'
12+
13+
def build_arch(self, arch):
14+
env = self.get_recipe_env(arch)
15+
with current_directory(self.get_build_dir(arch.arch)):
16+
# Remove source in this pypi package
17+
sh.rm('-rf', './leveldb', './leveldb.egg-info', './snappy')
18+
# Use source from leveldb recipe
19+
sh.ln('-s', self.get_recipe('leveldb', self.ctx).get_build_dir(arch.arch), 'leveldb')
20+
# Build python bindings
21+
hostpython = sh.Command(self.hostpython_location)
22+
shprint(hostpython,
23+
'setup.py',
24+
'build'
25+
, _env=env)
26+
# Install python bindings
27+
super(PyLevelDBRecipe, self).build_arch(arch)
28+
29+
def get_recipe_env(self, arch):
30+
env = super(PyLevelDBRecipe, self).get_recipe_env(arch)
31+
# Copy environment from leveldb recipe
32+
env.update(self.get_recipe('leveldb', self.ctx).get_recipe_env(arch))
33+
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
34+
env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python2.7'
35+
# Set linker to use the correct gcc
36+
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
37+
env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \
38+
' -lpython2.7' + \
39+
' -lleveldb'
40+
return env
41+
42+
recipe = PyLevelDBRecipe()
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
-
11+
from setuptools import setup, Extension
12+
13+
-system,node,release,version,machine,processor = platform.uname()
14+
-common_flags = [
15+
+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+
-
28+
-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+
-elif system == 'Linux':
36+
- extra_compile_args = common_flags + [
37+
- '-pthread',
38+
- '-Wall',
39+
- '-DOS_LINUX',
40+
- '-DLEVELDB_PLATFORM_POSIX',
41+
- ]
42+
-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+
49+
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',
60+
-
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',
100+
-
101+
# python stuff
102+
'leveldb_ext.cc',
103+
'leveldb_object.cc',
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from pythonforandroid.toolchain import Recipe
2+
3+
class SnappyRecipe(Recipe):
4+
version = '1.1.3'
5+
url = 'https://github.com/google/snappy/releases/download/{version}/snappy-{version}.tar.gz'
6+
7+
def should_build(self, arch):
8+
# Only download to use in leveldb recipe
9+
return False
10+
11+
recipe = SnappyRecipe()

0 commit comments

Comments
 (0)