|
11 | 11 |
|
12 | 12 |
|
13 | 13 | class ProtobufCppRecipe(PythonRecipe):
|
14 |
| - name = 'protobuf_cpp' |
15 |
| - version = '3.1.0' |
16 |
| - url = 'https://github.com/google/protobuf/releases/download/v{version}/protobuf-python-{version}.tar.gz' |
17 |
| - call_hostpython_via_targetpython = False |
18 |
| - depends = ['cffi', 'setuptools'] |
19 |
| - site_packages_name = 'google/protobuf/pyext' |
20 |
| - |
21 |
| - def build_arch(self, arch): |
22 |
| - env = self.get_recipe_env(arch) |
23 |
| - |
24 |
| - # Build libproto.a |
25 |
| - with current_directory(self.get_build_dir(arch.arch)): |
26 |
| - env['HOSTARCH'] = 'arm-eabi' |
27 |
| - env['BUILDARCH'] = shprint(sh.gcc, '-dumpmachine').stdout.decode('utf-8').split('\n')[0] |
28 |
| - |
29 |
| - if not exists('configure'): |
30 |
| - shprint(sh.Command('./autogen.sh'), _env=env) |
31 |
| - |
32 |
| - shprint(sh.Command('./configure'), |
33 |
| - '--host={}'.format(env['HOSTARCH']), |
34 |
| - '--enable-shared', |
35 |
| - _env=env) |
36 |
| - |
37 |
| - with current_directory(join(self.get_build_dir(arch.arch), 'src')): |
38 |
| - shprint(sh.make, 'libprotobuf.la', '-j'+str(cpu_count()), _env=env) |
39 |
| - shprint(sh.cp, '.libs/libprotobuf.a', join(self.ctx.get_libs_dir(arch.arch), 'libprotobuf.a')) |
40 |
| - |
41 |
| - # Copy stl library |
| 14 | + name = 'protobuf_cpp' |
| 15 | + version = '3.1.0' |
| 16 | + url = 'https://github.com/google/protobuf/releases/download/v{version}/protobuf-python-{version}.tar.gz' |
| 17 | + call_hostpython_via_targetpython = False |
| 18 | + depends = ['cffi', 'setuptools'] |
| 19 | + site_packages_name = 'google/protobuf/pyext' |
| 20 | + |
| 21 | + def build_arch(self, arch): |
| 22 | + env = self.get_recipe_env(arch) |
| 23 | + |
| 24 | + # Build libproto.a |
| 25 | + with current_directory(self.get_build_dir(arch.arch)): |
| 26 | + env['HOSTARCH'] = 'arm-eabi' |
| 27 | + env['BUILDARCH'] = shprint(sh.gcc, '-dumpmachine').stdout.decode('utf-8').split('\n')[0] |
| 28 | + |
| 29 | + if not exists('configure'): |
| 30 | + shprint(sh.Command('./autogen.sh'), _env=env) |
| 31 | + |
| 32 | + shprint(sh.Command('./configure'), |
| 33 | + '--host={}'.format(env['HOSTARCH']), |
| 34 | + '--enable-shared', |
| 35 | + _env=env) |
| 36 | + |
| 37 | + with current_directory(join(self.get_build_dir(arch.arch), 'src')): |
| 38 | + shprint(sh.make, 'libprotobuf.la', '-j'+str(cpu_count()), _env=env) |
| 39 | + shprint(sh.cp, '.libs/libprotobuf.a', join(self.ctx.get_libs_dir(arch.arch), 'libprotobuf.a')) |
| 40 | + |
| 41 | + # Copy stl library |
42 | 42 | shutil.copyfile(self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/libs/' + arch.arch + '/libgnustl_shared.so',
|
43 |
| - join(self.ctx.get_libs_dir(arch.arch), 'libgnustl_shared.so')) |
44 |
| - |
45 |
| - # Build python bindings and _message.so |
46 |
| - with current_directory(join(self.get_build_dir(arch.arch), 'python')): |
47 |
| - hostpython = sh.Command(self.hostpython_location) |
48 |
| - shprint(hostpython, |
49 |
| - 'setup.py', |
50 |
| - 'build_ext', |
51 |
| - '--cpp_implementation' |
52 |
| - , _env=env) |
53 |
| - |
54 |
| - # Install python bindings |
55 |
| - self.install_python_package(arch) |
56 |
| - |
57 |
| - |
58 |
| - def install_python_package(self, arch): |
59 |
| - env = self.get_recipe_env(arch) |
60 |
| - |
61 |
| - info('Installing {} into site-packages'.format(self.name)) |
62 |
| - |
63 |
| - with current_directory(join(self.get_build_dir(arch.arch), 'python')): |
64 |
| - hostpython = sh.Command(self.hostpython_location) |
65 |
| - |
66 |
| - if self.ctx.python_recipe.from_crystax: |
67 |
| - hpenv = env.copy() |
68 |
| - shprint(hostpython, 'setup.py', 'install', '-O2', |
69 |
| - '--root={}'.format(self.ctx.get_python_install_dir()), |
70 |
| - '--install-lib=.', |
71 |
| - '--cpp_implementation', |
72 |
| - _env=hpenv, *self.setup_extra_args) |
73 |
| - else: |
74 |
| - hppath = join(dirname(self.hostpython_location), 'Lib', |
75 |
| - 'site-packages') |
76 |
| - hpenv = env.copy() |
77 |
| - if 'PYTHONPATH' in hpenv: |
78 |
| - hpenv['PYTHONPATH'] = ':'.join([hppath] + |
79 |
| - hpenv['PYTHONPATH'].split(':')) |
80 |
| - else: |
81 |
| - hpenv['PYTHONPATH'] = hppath |
82 |
| - shprint(hostpython, 'setup.py', 'install', '-O2', |
83 |
| - '--root={}'.format(self.ctx.get_python_install_dir()), |
84 |
| - '--install-lib=lib/python2.7/site-packages', |
85 |
| - '--cpp_implementation', |
86 |
| - _env=hpenv, *self.setup_extra_args) |
87 |
| - |
88 |
| - |
89 |
| - def get_recipe_env(self, arch): |
90 |
| - env = super(ProtobufCppRecipe, self).get_recipe_env(arch) |
91 |
| - env['PROTOC'] = '/home/fipo/soft/protobuf-3.1.0/src/protoc' |
92 |
| - env['PYTHON_ROOT'] = self.ctx.get_python_install_dir() |
93 |
| - env['TARGET_OS'] = 'OS_ANDROID_CROSSCOMPILE' |
94 |
| - env['CFLAGS'] += ' -I' + self.ctx.ndk_dir + '/platforms/android-' + str( |
95 |
| - self.ctx.android_api) + '/arch-' + arch.arch.replace('eabi', '') + '/usr/include' + \ |
96 |
| - ' -I' + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/include' + \ |
97 |
| - ' -I' + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/libs/' + arch.arch + '/include' + \ |
98 |
| - ' -I' + env['PYTHON_ROOT'] + '/include/python2.7' |
99 |
| - env['CXXFLAGS'] = env['CFLAGS'] |
100 |
| - env['CXXFLAGS'] += ' -frtti' |
101 |
| - env['CXXFLAGS'] += ' -fexceptions' |
102 |
| - env['LDFLAGS'] += ' -L' + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/libs/' + arch.arch + \ |
103 |
| - ' -lgnustl_shared -lpython2.7' |
104 |
| - |
105 |
| - env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions' |
106 |
| - return env |
| 43 | + join(self.ctx.get_libs_dir(arch.arch), 'libgnustl_shared.so')) |
| 44 | + |
| 45 | + # Build python bindings and _message.so |
| 46 | + with current_directory(join(self.get_build_dir(arch.arch), 'python')): |
| 47 | + hostpython = sh.Command(self.hostpython_location) |
| 48 | + shprint(hostpython, |
| 49 | + 'setup.py', |
| 50 | + 'build_ext', |
| 51 | + '--cpp_implementation' |
| 52 | + , _env=env) |
| 53 | + |
| 54 | + # Install python bindings |
| 55 | + self.install_python_package(arch) |
| 56 | + |
| 57 | + |
| 58 | + def install_python_package(self, arch): |
| 59 | + env = self.get_recipe_env(arch) |
| 60 | + |
| 61 | + info('Installing {} into site-packages'.format(self.name)) |
| 62 | + |
| 63 | + with current_directory(join(self.get_build_dir(arch.arch), 'python')): |
| 64 | + hostpython = sh.Command(self.hostpython_location) |
| 65 | + |
| 66 | + if self.ctx.python_recipe.from_crystax: |
| 67 | + hpenv = env.copy() |
| 68 | + shprint(hostpython, 'setup.py', 'install', '-O2', |
| 69 | + '--root={}'.format(self.ctx.get_python_install_dir()), |
| 70 | + '--install-lib=.', |
| 71 | + '--cpp_implementation', |
| 72 | + _env=hpenv, *self.setup_extra_args) |
| 73 | + else: |
| 74 | + hppath = join(dirname(self.hostpython_location), 'Lib', |
| 75 | + 'site-packages') |
| 76 | + hpenv = env.copy() |
| 77 | + if 'PYTHONPATH' in hpenv: |
| 78 | + hpenv['PYTHONPATH'] = ':'.join([hppath] + |
| 79 | + hpenv['PYTHONPATH'].split(':')) |
| 80 | + else: |
| 81 | + hpenv['PYTHONPATH'] = hppath |
| 82 | + shprint(hostpython, 'setup.py', 'install', '-O2', |
| 83 | + '--root={}'.format(self.ctx.get_python_install_dir()), |
| 84 | + '--install-lib=lib/python2.7/site-packages', |
| 85 | + '--cpp_implementation', |
| 86 | + _env=hpenv, *self.setup_extra_args) |
| 87 | + |
| 88 | + |
| 89 | + def get_recipe_env(self, arch): |
| 90 | + env = super(ProtobufCppRecipe, self).get_recipe_env(arch) |
| 91 | + env['PROTOC'] = '/home/fipo/soft/protobuf-3.1.0/src/protoc' |
| 92 | + env['PYTHON_ROOT'] = self.ctx.get_python_install_dir() |
| 93 | + env['TARGET_OS'] = 'OS_ANDROID_CROSSCOMPILE' |
| 94 | + env['CFLAGS'] += ' -I' + self.ctx.ndk_dir + '/platforms/android-' + str( |
| 95 | + self.ctx.android_api) + '/arch-' + arch.arch.replace('eabi', '') + '/usr/include' + \ |
| 96 | + ' -I' + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/include' + \ |
| 97 | + ' -I' + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/libs/' + arch.arch + '/include' + \ |
| 98 | + ' -I' + env['PYTHON_ROOT'] + '/include/python2.7' |
| 99 | + env['CXXFLAGS'] = env['CFLAGS'] |
| 100 | + env['CXXFLAGS'] += ' -frtti' |
| 101 | + env['CXXFLAGS'] += ' -fexceptions' |
| 102 | + env['LDFLAGS'] += ' -L' + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/libs/' + arch.arch + \ |
| 103 | + ' -lgnustl_shared -lpython2.7' |
| 104 | + |
| 105 | + env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions' |
| 106 | + return env |
107 | 107 |
|
108 | 108 |
|
109 | 109 | recipe = ProtobufCppRecipe()
|
0 commit comments