10000 add openssl support · kived/python-for-android@e190e99 · GitHub
[go: up one dir, main page]

Skip to content

Commit e190e99

Browse files
committed
add openssl support
1 parent fdb2b5f commit e190e99

19 files changed

+480
-40
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
2+
3+
4+
class CffiRecipe(CompiledComponentsPythonRecipe):
5+
name = 'cffi'
6+
version = '1.4.2'
7+
url = 'https://pypi.python.org/packages/source/c/cffi/cffi-{version}.tar.gz'
8+
9+
depends = [('python2', 'python3'), 'setuptools', 'pycparser', 'libffi']
10+
11+
patches = ['disable-pkg-config.patch']
12+
13+
# call_hostpython_via_targetpython = False
14+
install_in_hostpython = True
15+
16+
def get_recipe_env(self, arch=None):
17+
env = super(CffiRecipe, self).get_recipe_env(arch)
18+
libffi = self.get_recipe('libffi', self.ctx)
19+
includes = libffi.get_include_dirs(arch)
20+
env['CFLAGS'] = ' -I'.join([env.get('CFLAGS', '')] + includes)
21+
env['LDFLAGS'] = (env.get('CFLAGS', '') + ' -L' +
22+
self.ctx.get_libs_dir(arch.arch))
23+
env['PYTHONPATH'] = ':'.join([
24+
self.ctx.get_site_packages_dir(),
25+
env['BUILDLIB_PATH'],
26+
])
27+
return env
28+
29+
30+
recipe = CffiRecipe()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
diff -Naur cffi-1.4.2/setup.py b/setup.py
2+
--- cffi-1.4.2/setup.py 2015-12-21 12:09:47.000000000 -0600
3+
+++ b/setup.py 2015-12-23 10:20:40.590622524 -0600
4+
@@ -5,8 +5,7 @@
5+
6+
sources = ['c/_cffi_backend.c']
7+
libraries = ['ffi']
8+
-include_dirs = ['/usr/include/ffi',
9+
- '/usr/include/libffi'] # may be changed by pkg-config
10+
+include_dirs = []
11+
define_macros = []
12+
library_dirs = []
13+
extra_compile_args = []
14+
@@ -67,14 +66,7 @@
15+
sys.stderr.write("The above error message can be safely ignored\n")
16+
17+
def use_pkg_config():
18+
- if sys.platform == 'darwin' and os.path.exists('/usr/local/bin/brew'):
19+
- use_homebrew_for_libffi()
20+
-
21+
- _ask_pkg_config(include_dirs, '--cflags-only-I', '-I', sysroot=True)
22+
- _ask_pkg_config(extra_compile_args, '--cflags-only-other')
23+
- _ask_pkg_config(library_dirs, '--libs-only-L', '-L', sysroot=True)
< F438 /td>
24+
- _ask_pkg_config(extra_link_args, '--libs-only-other')
25+
- _ask_pkg_config(libraries, '--libs-only-l', '-l')
26+
+ pass
27+
28+
def use_homebrew_for_libffi():
29+
# We can build by setting:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from os.path import dirname, join
2+
3+
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
4+
5+
6+
class CryptographyRecipe(CompiledComponentsPythonRecipe):
7+
name = 'cryptography'
8+
version = '1.1.2'
9+
url = 'https://pypi.python.org/packages/source/c/cryptography/cryptography-{version}.tar.gz'
10+
11+
depends = [('python2', 'python3'), 'cffi', 'enum34', 'openssl', 'ipaddress', 'idna']
12+
13+
patches = ['fix-cffi-path.patch',
14+
'link-static.patch']
15+
16+
# call_hostpython_via_targetpython = False
17+
18+
def get_recipe_env(self, arch=None):
19+
env = super(CryptographyRecipe, self).get_recipe_env(arch)
20+
# # libffi = self.get_recipe('libffi', self.ctx)
21+
# # includes = libffi.get_include_dirs(arch)
22+
# # env['CFLAGS'] = ' -I'.join([env.get('CFLAGS', '')] + includes)
23+
# # env['LDFLAGS'] = (env.get('CFLAGS', '') + ' -L' +
24+
# # self.ctx.get_libs_dir(arch.arch))
25+
openssl = self.get_recipe('openssl', self.ctx)
26+
openssl_dir = openssl.get_build_dir(arch.arch)
27+
env['CFLAGS'] = env.get('CFLAGS', '') + ' -I' + join(openssl_dir, 'include')
28+
# env['LDFLAGS'] = env.get('LDFLAGS', '') + ' -L' + openssl.get_build_dir(arch.arch)
29+
env['LIBSSL'] = join(openssl_dir, 'libssl.a')
30+
env['LIBCRYPTO'] = join(openssl_dir, 'libcrypto.a')
31+
env['PYTHONPATH'] = ':'.join([
32+
join(dirname(self.real_hostpython_location), 'Lib'),
33+
join(dirname(self.real_hostpython_location), 'Lib', 'site-packages'),
34+
env['BUILDLIB_PATH'],
35+
])
36+
print env
37+
return env
38+
39+
40+
recipe = CryptographyRecipe()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
diff -Naur cryptography/setup.py b/setup.py
2+
--- cryptography/setup.py 2015-12-10 13:53:28.000000000 -0600
3+
+++ b/setup.py 2015-12-23 12:12:22.830287138 -0600
4+
@@ -18,6 +18,10 @@
5+
from setuptools.command.install import install
6+
from setuptools.command.test import test
7+
8+
+import sys
9+
+for d in sys.path[:]:
10+
+ if 'python-installs' in d:
11+
+ sys.path.remove(d)
12+
13+
base_dir = os.path.dirname(__file__)
14+
src_dir = os.path.join(base_dir, "src")
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
--- cryptography/src/_cffi_src/build_openssl.py 2015-12-10 13:53:28.000000000 -0600
2+
+++ b/src/_cffi_src/build_openssl.py 2016-01-06 14:58:59.735728893 -0600
3+
@@ -10,50 +10,6 @@
4+
from _cffi_src.utils import build_ffi_for_binding, extra_link_args
5+
6+
7+
-def _get_openssl_libraries(platform):
8+
- # OpenSSL goes by a different library name on different operating systems.
9+
- if platform == "darwin":
10+
- return _osx_libraries(
11+
- os.environ.get("CRYPTOGRAPHY_OSX_NO_LINK_FLAGS")
12+
- )
13+
- elif platform == "win32":
14+
- return ["libeay32", "ssleay32", "advapi32",
15+
- "crypt32", "gdi32", "user32", "ws2_32"]
16+
- else:
17+
- # In some circumstances, the order in which these libs are
18+
- # specified on the linker command-line is significant;
19+
- # libssl must come before libcrypto
20+
- # (http://marc.info/?l=openssl-users&m=135361825921871)
21+
- return ["ssl", "crypto"]
22+
-
23+
-
24+
-def _osx_libraries(build_static):
25+
- # For building statically we don't want to pass the -lssl or -lcrypto flags
26+
- if build_static == "1":
27+
- return []
28+
- else:
29+
- return ["ssl", "crypto"]
30+
-
31+
-
32+
-_OSX_PRE_INCLUDE = """
33+
-#ifdef __APPLE__
34+
-#include <AvailabilityMacros.h>
35+
-#define __ORIG_DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER \
36+
- DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER
37+
-#undef DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER
38+
-#define DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER
39+
-#endif
40+
-"""
41+
-
42+
-_OSX_POST_INCLUDE = """
43+
-#ifdef __APPLE__
44+
-#undef DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER
45+
-#define DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER \
46+
- __ORIG_DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER
47+
-#endif
48+
-"""
49+
-
50+
-
51+
ffi = build_ffi_for_binding(
52+
module_name="_openssl",
53+
module_prefix="_cffi_src.openssl.",
54+
@@ -89,8 +45,6 @@
55+
"x509_vfy",
56+
"pkcs7",
57+
],
58+
- pre_include=_OSX_PRE_INCLUDE,
59+
- post_include=_OSX_POST_INCLUDE,
60+
- libraries=_get_openssl_libraries(sys.platform),
61+
- extra_link_args=extra_link_args(sys.platform),
62+
+ libraries=[],
63+
+ extra_link_args=[os.environ['LIBSSL'], os.environ['LIBCRYPTO']],
64+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from pythonforandroid.recipe import PythonRecipe
2+
3+
4+
class IdnaRecipe(PythonRecipe):
5+
name = 'idna'
6+
version = '2.0'
7+
url = 'https://pypi.python.org/packages/source/i/idna/idna-{version}.tar.gz'
8+
9+
depends = [('python2', 'python3'), 'setuptools']
10+
11+
call_hostpython_via_targetpython = False
12+
13+
14+
recipe = IdnaRecipe()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from pythonforandroid.recipe import PythonRecipe
2+
3+
4+
class IpaddressRecipe(PythonRecipe):
5+
name = 'ipaddress'
6+
version = '1.0.15'
7+
url = 'https://pypi.python.org/packages/source/i/ipaddress/ipaddress-{version}.tar.gz'
8+
9+
depends = ['python2']
10+
11+
12+
recipe = IpaddressRecipe()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
APP_OPTIM := release
2+
APP_ABI := all # or armeabi
3+
APP_MODULES := libffi
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from pythonforandroid.recipe import Recipe
2+
from pythonforandroid.logger import shprint
3+
from pythonforandroid.util import current_directory
4+
from os.path import exists, join
5+
import sh
6+
import glob
7+
8+
9+
class LibffiRecipe(Recipe):
10+
name = 'libffi'
11+
version = 'v3.2.1'
12+
url = 'https://github.com/atgreen/libffi/archive/{version}.zip'
13+
14+
patches = ['remove-version-info.patch']
15+
16+
host = 'arm-unknown-linux-androideabi'
17+
18+
def should_build(self, arch):
19+
# return not bool(glob.glob(join(self.ctx.get_libs_dir(arch.arch),
20+
# 'libffi.so*')))
21+
return not exists(join(self.ctx.get_libs_dir(arch.arch), 'libffi.so'))
22+
# return not exists(join(self.ctx.get_python_install_dir(), 'lib',
23+
# 'libffi.so'))
24+
25+
def build_arch(self, arch):
26+
env = self.get_recipe_env(arch)
27+
with current_directory(self.get_build_dir(arch.arch)):
28+
if not exists('configure'):
29+
shprint(sh.Command('./autogen.sh'), _env=env)
30+
shprint(sh.Command('./configure'), '--host=arm-linux-androideabi',
31+
'--prefix=' + self.ctx.get_python_install_dir(),
32+
'--enable-shared', _env=env)
33+
shprint(sh.make, '-j5', 'libffi.la', _env=env)
34+
35+
host = None
36+
with open('Makefile') as f:
37+
for line in f:
38+
if line.startswith('host = '):
39+
host = line.strip()[7:]
40+
break
41+
42+
if not host or not exists(host):
43+
raise RuntimeError('failed to find build output! ({})'
44+
.format(host))
45+
46+
self.host = host
47+
48+
# dlname = None
49+
# with open(join(host, 'libffi.la')) as f:
50+
# for line in f:
51+
# if line.startswith('dlname='):
52+
# dlname = line.strip()[8:-1]
53+
# break
54+
#
55+
# if not dlname or not exists(join(host, '.libs', dlname)):
56+
# raise RuntimeError('failed to locate shared object! ({})'
57+
# .format(dlname))
58+
59+
# shprint(sh.sed, '-i', 's/^dlname=.*$/dlname=\'libffi.so\'/', join(host, 'libffi.la'))
60+
61+
shprint(sh.cp, '-t', self.ctx.get_libs_dir(arch.arch),
62+
join(host, '.libs', 'libffi.so')) #,
63+
# join(host, 'libffi.la'))
64+
65+
def get_include_dirs(self, arch):
66+
return [join(self.get_build_dir(arch.arch), self.host, 'include')]
67+
68+
69+
recipe = LibffiRecipe()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
diff -Naur libffi/Android.mk b/Android.mk
2+
--- libffi/Android.mk 2015-12-22 17:00:48.025478556 -0600
3+
+++ b/Android.mk 2015-12-22 17:02:23.999249390 -0600
4+
@@ -23,23 +23,20 @@
5+
# Build rules for the target.
6+
#
7+
8+
-# We only build ffi for mips.
9+
-ifeq ($(TARGET_ARCH),mips)
10+
11+
- include $(CLEAR_VARS)
12+
+include $(CLEAR_VARS)
13+
14+
- ffi_arch := $(TARGET_ARCH)
15+
- ffi_os := $(TARGET_OS)
16+
+ffi_arch := $(TARGET_ARCH)
17+
+ffi_os := $(TARGET_OS)
18+
19+
- # This include just keeps the nesting a bit saner.
20+
- include $(LOCAL_PATH)/Libffi.mk
21+
+# This include just keeps the nesting a bit saner.
22+
+include $(LOCAL_PATH)/Libffi.mk
23+
24+
- LOCAL_MODULE_TAGS := optional
25+
- LOCAL_MODULE := libffi
26+
+LOCAL_MODULE_TAGS := optional
27+
+LOCAL_MODULE := libffi
28+
29+
- include $(BUILD_SHARED_LIBRARY)
30+
+include $(BUILD_SHARED_LIBRARY)
31+
32+
-endif
33+
34+
# Also include the rules for the test suite.
35+
include external/libffi/testsuite/Android.mk

0 commit comments

Comments
 (0)
0