Skip to content

Commit 71e855a

Browse files
committed
Update the openssl libs to version 1.1.1 (LTS)
This openssl version is an LTS (supported until 11th September 2023). To compile this libraries we are using the clang feature introduced in c7edf85. Doing it this way, allow us to successfully compile and link with python (which also is compiled using the clang compiler), and moreover: - The openssl recipe has been enhanced by introducing a couple of methods (include_flags and link_flags) which should help us to link other recipes with the openssl libs. - New variable introduced `url_version`, used to download our recipe (in the subclassed method versioned_url). This has been done this way to keep the name of the generated libraries short, to match with python libs naming (<major.minor>) and to avoid touching all the openssl dependant recipes.
1 parent c7edf85 commit 71e855a

File tree

2 files changed

+75
-31
lines changed

2 files changed

+75
-31
lines changed

pythonforandroid/recipes/openssl/__init__.py

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,64 @@
1+
import time
2+
from os.path import join
13
from functools import partial
24

35
from pythonforandroid.toolchain import Recipe, shprint, current_directory
46
import sh
57

68

79
class OpenSSLRecipe(Recipe):
8-
version = '1.0.2h'
9-
url = 'https://www.openssl.org/source/openssl-{version}.tar.gz'
10+
'''
11+
The OpenSSL libraries for python-for-android. This recipe will generate the
12+
following libraries as shared libraries (*.so):
13+
14+
- crypto
15+
- ssl
16+
17+
The generated openssl libraries are versioned, where the version is the
18+
recipe attribute :attr:`version` e.g.: ``libcrypto1.1.so``,
19+
``libssl1.1.so``...so...to link your recipe with the openssl libs,
20+
remember to add the version at the end, e.g.:
21+
``-lcrypto1.1 -lssl1.1``. Or better, you could do it dynamically
22+
using the methods: :meth:`include_flags` and :meth:`link_flags`.
23+
24+
.. versionchanged:: 0.6.0
25+
26+
- The gcc compiler has been deprecated in favour of clang and libraries
27+
updated to version 1.1.1 (LTS - supported until 11th September 2023)
28+
- Added two new methods to make easier to link with openssl:
29+
:meth:`include_flags` and :meth:`link_flags`
30+
- subclassed versioned_url
31+
- Adapted method :meth:`select_build_arch` to API 21+
32+
33+
'''
34+
35+
version = '1.1'
36+
'''the major minor version used to link our recipes'''
37+
38+
url_version = '1.1.1'
39+
'''the version used to download our libraries'''
40+
41+
url = 'https://www.openssl.org/source/openssl-{url_version}.tar.gz'
42+
43+
@property
44+
def versioned_url(self):
45+
if self.url is None:
46+
return None
47+
return self.url.format(url_version=self.url_version)
48+
49+
def include_flags(self, arch):
50+
'''Returns a string with the include folders'''
51+
openssl_includes = join(self.get_build_dir(arch.arch), 'include')
52+
return ' -I' + openssl_includes + \
53+
' -I' + join(openssl_includes, 'internal') + \
54+
' -I' + join(openssl_includes, 'openssl')
55+
56+
def link_flags(self, arch):
57+
'''Returns a string with the right link flags to compile against the
58+
openssl libraries'''
59+
build_dir = self.get_build_dir(arch.arch)
60+
return ' -L' + build_dir + \
61+
' -lcrypto{version} -lssl{version}'.format(version=self.version)
1062

1163
def should_build(self, arch):
1264
return not self.has_libs(arch, 'libssl' + self.version + '.so',
@@ -21,20 +73,20 @@ def check_symbol(self, env, sofile, symbol):
2173
print('{} missing symbol {}; rebuilding'.format(sofile, symbol))
2274
return False
2375

24-
def get_recipe_env(self, arch=None):
25-
env = super(OpenSSLRecipe, self).get_recipe_env(arch)
76+
def get_recipe_env(self, arch=None, with_flags_in_cc=True, clang=True):
77+
env = super(OpenSSLRecipe, self).get_recipe_env(
78+
arch, with_flags_in_cc=True, clang=True)
2679
env['OPENSSL_VERSION'] = self.version
27-
env['CFLAGS'] += ' ' + env['LDFLAGS']
28-
env['CC'] += ' ' + env['LDFLAGS']
2980
env['MAKE'] = 'make' # This removes the '-j5', which isn't safe
81+
env['ANDROID_NDK'] = self.ctx.ndk_dir
3082
return env
3183

3284
def select_build_arch(self, arch):
3385
aname = arch.arch
3486
if 'arm64' in aname:
3587
return 'linux-aarch64'
3688
if 'v7a' in aname:
37-
return 'android-armv7'
89+
return 'android-arm'
3890
if 'arm' in aname:
3991
return 'android'
4092
if 'x86' in aname:
@@ -48,16 +100,17 @@ def build_arch(self, arch):
48100
# so instead we manually run perl passing in Configure
49101
perl = sh.Command('perl')
50102
buildarch = self.select_build_arch(arch)
51-
shprint(perl, 'Configure', 'shared', 'no-dso', 'no-krb5', buildarch, _env=env)
103+
shprint(perl, 'Configure', 'shared', 'no-dso', 'no-asm', buildarch,
104+
'-D__ANDROID_API__={}'.format(self.ctx.ndk_api),
105+
_env=env)
52106
self.apply_patch('disable-sover.patch', arch.arch)
53-
self.apply_patch('rename-shared-lib.patch', arch.arch)
54107

55-
# check_ssl = partial(self.check_symbol, env, 'libssl' + self.version + '.so')
56108
check_crypto = partial(self.check_symbol, env, 'libcrypto' + self.version + '.so')
57109
while True:
58110
shprint(sh.make, 'build_libs', _env=env)
59-
if all(map(check_crypto, ('SSLeay', 'MD5_Transform', 'MD4_Init'))):
111+
if all(map(check_crypto, ('MD5_Transform', 'MD4_Init'))):
60112
break
113+
time.sleep(3)
61114
shprint(sh.make, 'clean', _env=env)
62115

63116
self.install_libs(arch, 'libssl' + self.version + '.so',
Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
--- openssl/Makefile 2016-01-28 17:26:49.159522273 +0100
2-
+++ b/Makefile 2016-01-28 17:26:54.358438402 +0100
3-
@@ -342,7 +342,7 @@
4-
link-shared:
5-
@ set -e; for i in $(SHLIBDIRS); do \
6-
$(MAKE) -f $(HERE)/Makefile.shared -e $(BUILDENV) \
7-
- LIBNAME=$$i LIBVERSION=$(SHLIB_MAJOR).$(SHLIB_MINOR) \
8-
+ LIBNAME=$$i LIBVERSION= \
9-
LIBCOMPATVERSIONS=";$(SHLIB_VERSION_HISTORY)" \
10-
symlink.$(SHLIB_TARGET); \
11-
libs="$$libs -l$$i"; \
12-
@@ -356,7 +356,7 @@
13-
libs="$(LIBKRB5) $$libs"; \
14-
fi; \
15-
$(CLEARENV) && $(MAKE) -f Makefile.shared -e $(BUILDENV) \
16-
- LIBNAME=$$i LIBVERSION=$(SHLIB_MAJOR).$(SHLIB_MINOR) \
17-
+ LIBNAME=$$i LIBVERSION= \
18-
LIBCOMPATVERSIONS=";$(SHLIB_VERSION_HISTORY)" \
19-
LIBDEPS="$$libs $(EX_LIBS)" \
20-
link_a.$(SHLIB_TARGET); \
1+
--- openssl/Makefile.orig 2018-10-20 22:49:40.418310423 +0200
2+
+++ openssl/Makefile 2018-10-20 22:50:23.347322403 +0200
3+
@@ -19,7 +19,7 @@
4+
SHLIB_MAJOR=1
5+
SHLIB_MINOR=1
6+
SHLIB_TARGET=linux-shared
7+
-SHLIB_EXT=.so.$(SHLIB_VERSION_NUMBER)
8+
+SHLIB_EXT=$(SHLIB_VERSION_NUMBER).so
9+
SHLIB_EXT_SIMPLE=.so
10+
SHLIB_EXT_IMPORT=
11+

0 commit comments

Comments
 (0)