10000 new libzmq and pyzmq recipe. Both require --copy-libs to work. · mixedCase/python-for-android@7bcedd3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7bcedd3

Browse files
committed
new libzmq and pyzmq recipe. Both require --copy-libs to work.
1 parent fb0e0ca commit 7bcedd3

File tree

3 files changed

+132
-3
lines changed

3 files changed

+132
-3
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from pythonforandroid.toolchain import Recipe, shprint, shutil, current_directory
2+
from pythonforandroid.util import ensure_dir
3+
from os.path import exists, join
4+
import sh
5+
6+
7+
class LibZMQRecipe(Recipe):
8+
version = '4.1.4'
9+
url = 'http://download.zeromq.org/zeromq-{version}.tar.gz'
10+
depends = ['python2']
11+
12+
def should_build(self, arch):
13+
super(LibZMQRecipe, self).should_build(arch)
14+
return True
15+
return not exists(join(self.ctx.get_libs_dir(arch.arch), 'libzmq.so'))
16+
17+
def build_arch(self, arch):
18+
super(LibZMQRecipe, self).build_arch(arch)
19+
env = self.get_recipe_env(arch)
20+
#
21+
# libsodium_recipe = Recipe.get_recipe('libsodium', self.ctx)
22+
# libsodium_dir = libsodium_recipe.get_build_dir(arch.arch)
23+
# env['sodium_CFLAGS'] = '-I{}'.format(join(
24+
# libsodium_dir, 'src'))
25+
# env['sodium_LDLAGS'] = '-L{}'.format(join(
26+
# libsodium_dir, 'src', 'libsodium', '.libs'))
27+
28+
curdir = self.get_build_dir(arch.arch)
29+
prefix = join(curdir, "install")
30+
with current_directory(curdir):
31+
bash = sh.Command('sh')
32+
shprint(
33+
bash, './configure',
34+
'--host=arm-linux-androideabi',
35+
'--without-documentation',
36+
'--prefix={}'.format(prefix),
37+
'--with-libsodium=no',
38+
_env=env)
39+
shprint(sh.make, _env=env)
40+
shprint(sh.make, 'install', _env=env)
41+
shutil.copyfile('.libs/libzmq.so', join(
42+
self.ctx.get_libs_dir(arch.arch), 'libzmq.so'))
43+
44+
bootstrap_obj_dir = join(self.ctx.bootstrap.build_dir, 'obj', 'local', arch.arch)
45+
ensure_dir(bootstrap_obj_dir)
46+
shutil.copyfile(
47+
'{}/sources/cxx-stl/gnu-libstdc++/4.8/libs/{}/libgnustl_shared.so'.format(
48+
self.ctx.ndk_dir, arch),
49+
join(bootstrap_obj_dir, 'libgnustl_shared.so'))
50+
51+
def get_recipe_env(self, arch):
52+
# XXX should stl be configuration for the toolchain itself?
53+
env = super(LibZMQRecipe, self).get_recipe_env(arch)
54+
env['CFLAGS'] += ' -Os'
55+
env['CXXFLAGS'] += ' -Os -fPIC -fvisibility=default'
56+
env['CXXFLAGS'] += ' -I{}/sources/cxx-stl/gnu-libstdc++/4.8/include'.format(self.ctx.ndk_dir)
57+
env['CXXFLAGS'] += ' -I{}/sources/cxx-stl/gnu-libstdc++/4.8/libs/{}/include'.format(
58+
self.ctx.ndk_dir, arch)
59+
env['CXXFLAGS'] += ' -L{}/sources/cxx-stl/gnu-libstdc++/4.8/libs/{}'.format(
60+
self.ctx.ndk_dir, arch)
61+
env['CXXFLAGS'] += ' -lgnustl_shared'
62+
env['LDFLAGS'] += ' -L{}/sources/cxx-stl/gnu-libstdc++/4.8/libs/{}'.format(
63+
self.ctx.ndk_dir, arch)
64+
return env
65+
66+
67+
recipe = LibZMQRecipe()
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# coding=utf-8
2+
3+
from pythonforandroid.recipe import CythonRecipe, Recipe
4+
from os.path import join
5+
from pythonforandroid.util import current_directory
6+
import sh
7+
from pythonforandroid.logger import shprint
8+
import glob
9+
10+
11+
class PyZMQRecipe(CythonRecipe):
12+
name = 'pyzmq'
13+
version = 'master'
14+
url = 'https://github.com/zeromq/pyzmq/archive/{version}.zip'
15+
site_packages_name = 'zmq'
16+
depends = ['python2', 'libzmq']
17+
cython_args = ['-Izmq/utils',
18+
'-Izmq/backend/cython',
19+
'-Izmq/devices']
20+
21+
def get_recipe_env(self, arch=None):
22+
env = super(PyZMQRecipe, self).get_recipe_env(arch)
23+
# TODO: fix hardcoded path
24+
# This is required to prevent issue with _io.so import.
25+
# hostpython = self.get_recipe('hostpython2', self.ctx)
26+
# env['PYTHONPATH'] = (
27+
# join(hostpython.get_build_dir(arch.arch), 'build',
28+
# 'lib.linux-x86_64-2.7') + ':' + env.get('PYTHONPATH', '')
29+
# )
30+
# env["LDSHARED"] = env["CC"] + ' -shared'
31+
return env
32+
33+
def build_cython_components(self, arch):
34+
libzmq_recipe = Recipe.get_recipe('libzmq', self.ctx)
35+
libzmq_prefix = join(libzmq_recipe.get_build_dir(arch.arch), "install")
36+
self.setup_extra_args = ["--zmq={}".format(libzmq_prefix)]
37+
self.build_cmd = "configure"
38+
39+
env = self.get_recipe_env(arch)
40+
setup_cfg = join(self.get_build_dir(arch.arch), "setup.cfg")
41+
with open(setup_cfg, "wb") as fd:
42+
fd.write("""
43+
[global]
44+
zmq_prefix = {}
45+
skip_check_zmq = True
46+
""".format(libzmq_prefix))
47+
48+
return super(PyZMQRecipe, self).build_cython_components(arch)
49+
50+
with current_directory(self.get_build_dir(arch.arch)):
51+
hostpython = sh.Command(self.hostpython_location)
52+
shprint(hostpython, 'setup.py', 'configure', '-v', _env=env)
53+
shprint(hostpython, 'setup.py', 'build_ext', '-v', _env=env)
54+
build_dir = glob.glob('build/lib.*')[0]
55+
shprint(sh.find, build_dir, '-name', '"*.o"', '-exec',
56+
env['STRIP'], '{}', ';', _env=env)
57+
58+
recipe = PyZMQRecipe()

pythonforandroid/tools/liblink

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ while i < len(sys.argv):
5252
if opt.startswith("-D"):
5353
continue
5454

55+
if opt.startswith("-R"):
56+
# for -rpath, not implemented yet.
57+
continue
58+
5559
if opt.startswith("-"):
5660
print(sys.argv)
5761
print("Unknown option: %s" % opt)
@@ -69,13 +73,13 @@ abs_output = join(environ.get('LIBLINK_PATH'), basename(output))
6973
if not copylibs:
7074
f = open(output, "w")
7175
f.close()
72-
76+
7377
output = abs_output
74-
78+
7579
f = open(output + ".libs", "w")
7680
f.write(" ".join(libs))
7781
f.close()
78-
82+
7983
sys.exit(subprocess.call([
8084
environ.get('LD'), '-r',
8185
'-o', output + '.o'

0 commit comments

Comments
 (0)
0