Skip to content

Commit 9cd861c

Browse files
committed
[recipe-stl] Make icu a library recipe with STL support (rework)
Also done here:   - Remove hardcoded version in url   - Disable versioned shared libraries   - Make it to be build as a shared libraries (instead of static)   - Disable the build of static libraries (because we build them as shared ones, so we avoid to link with them without our consents)   - Shorten long lines to be pep8's friendly   - Remove icu from ci/constants   - Remove `RuntimeError` about the need to use NDK api <= 19 (because that is not the case anymore)   - consider host's number of cpu to perform the build
1 parent 6783b1d commit 9cd861c

File tree

3 files changed

+113
-77
lines changed

3 files changed

+113
-77
lines changed

ci/constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ class TargetPython(Enum):
6565
# IndexError: list index out of range
6666
'secp256k1',
6767
'ffpyplayer',
68-
'icu',
6968
# requires `libpq-dev` system dependency e.g. for `pg_config` binary
7069
'psycopg2',
7170
'protobuf_cpp',
Lines changed: 47 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,54 @@
11
import sh
22
import os
3-
from os.path import join, isdir
4-
from pythonforandroid.recipe import NDKRecipe
3+
from os.path import join, isdir, exists
4+
from multiprocessing import cpu_count
5+
from pythonforandroid.recipe import Recipe
56
from pythonforandroid.toolchain import shprint
67
from pythonforandroid.util import current_directory, ensure_dir
78

89

9-
class ICURecipe(NDKRecipe):
10+
class ICURecipe(Recipe):
1011
name = 'icu4c'
1112
version = '57.1'
12-
url = 'http://download.icu-project.org/files/icu4c/57.1/icu4c-57_1-src.tgz'
13+
major_version = version.split('.')[0]
14+
url = ('http://download.icu-project.org/files/icu4c/'
15+
'{version}/icu4c-{version_underscore}-src.tgz')
1316

1417
depends = [('hostpython2', 'hostpython3')] # installs in python
15-
generated_libraries = [
16-
'libicui18n.so', 'libicuuc.so', 'libicudata.so', 'libicule.so']
17-
18-
def get_lib_dir(self, arch):
19-
lib_dir = join(self.ctx.get_python_install_dir(), "lib")
20-
ensure_dir(lib_dir)
21-
return lib_dir
22-
23-
def prepare_build_dir(self, arch):
24-
if self.ctx.android_api > 19:
25-
# greater versions do not have /usr/include/sys/exec_elf.h
26-
raise RuntimeError("icu needs an android api <= 19")
27-
28-
super(ICURecipe, self).prepare_build_dir(arch)
29-
30-
def build_arch(self, arch, *extra_args):
18+
patches = ['disable-libs-version.patch']
19+
20+
built_libraries = {
21+
'libicui18n{}.so'.format(major_version): 'build_icu_android/lib',
22+
'libicuuc{}.so'.format(major_version): 'build_icu_android/lib',
23+
'libicudata{}.so'.format(major_version): 'build_icu_android/lib',
24+
'libicule{}.so'.format(major_version): 'build_icu_android/lib',
25+
'libicuio{}.so'.format(major_version): 'build_icu_android/lib',
26+
'libicutu{}.so'.format(major_version): 'build_icu_android/lib',
27+
'libiculx{}.so'.format(major_version): 'build_icu_android/lib',
28+
}
29+
need_stl_shared = True
30+
31+
@property
32+
def versioned_url(self):
33+
if self.url is None:
34+
return None
35+
return self.url.format(
36+
version=self.version,
37+
version_underscore=self.version.replace('.', '_'))
38+
39+
def get_recipe_dir(self):
40+
"""
41+
.. note:: We need to overwrite `Recipe.get_recipe_dir` due to the
42+
mismatch name between the recipe's folder (icu) and the value
43+
of `ICURecipe.name` (icu4c).
44+
"""
45+
if self.ctx.local_recipes is not None:
46+
local_recipe_dir = join(self.ctx.local_recipes, 'icu')
47+
if exists(local_recipe_dir):
48+
return local_recipe_dir
49+
return join(self.ctx.root_dir, 'recipes', 'icu')
50+
51+
def do_build_libs(self, arch):
3152
env = self.get_recipe_env(arch).copy()
3253
build_root = self.get_build_dir(arch.arch)
3354

@@ -60,74 +81,35 @@ def make_build_dest(dest):
6081
"--prefix="+icu_build,
6182
"--enable-extras=no",
6283
"--enable-strict=no",
63-
"--enable-static",
84+
"--enable-static=no",
6485
"--enable-tests=no",
6586
"--enable-samples=no",
6687
_env=host_env)
67-
shprint(sh.make, "-j5", _env=host_env)
88+
shprint(sh.make, "-j", str(cpu_count()), _env=host_env)
6889
shprint(sh.make, "install", _env=host_env)
6990

7091
build_android, exists = make_build_dest("build_icu_android")
7192
if not exists:
7293

7394
configure = sh.Command(join(build_root, "source", "configure"))
7495

75-
include = (
76-
" -I{ndk}/sources/cxx-stl/gnu-libstdc++/{version}/include/"
77-
" -I{ndk}/sources/cxx-stl/gnu-libstdc++/{version}/libs/"
78-
"{arch}/include")
79-
include = include.format(ndk=self.ctx.ndk_dir,
80-
version=env["TOOLCHAIN_VERSION"],
81-
arch=arch.arch)
82-
env["CPPFLAGS"] = env["CXXFLAGS"] + " "
83-
env["CPPFLAGS"] += host_env["CPPFLAGS"]
84-
env["CPPFLAGS"] += include
85-
86-
lib = "{ndk}/sources/cxx-stl/gnu-libstdc++/{version}/libs/{arch}"
87-
lib = lib.format(ndk=self.ctx.ndk_dir,
88-
version=env["TOOLCHAIN_VERSION"],
89-
arch=arch.arch)
90-
env["LDFLAGS"] += " -lgnustl_shared -L"+lib
91-
92-
env.pop("CFLAGS", None)
93-
env.pop("CXXFLAGS", None)
94-
9596
with current_directory(build_android):
9697
shprint(
9798
configure,
9899
"--with-cross-build="+build_linux,
99100
"--enable-extras=no",
100101
"--enable-strict=no",
101-
"--enable-static",
102+
"--enable-static=no",
102103
"--enable-tests=no",
103104
"--enable-samples=no",
104105
"--host="+env["TOOLCHAIN_PREFIX"],
105106
"--prefix="+icu_build,
106107
_env=env)
107-
shprint(sh.make, "-j5", _env=env)
108+
shprint(sh.make, "-j", str(cpu_count()), _env=env)
108109
shprint(sh.make, "install", _env=env)
109110

110-
self.copy_files(arch)
111-
112-
def copy_files(self, arch):
113-
env = self.get_recipe_env(arch)
114-
115-
lib = "{ndk}/sources/cxx-stl/gnu-libstdc++/{version}/libs/{arch}"
116-
lib = lib.format(ndk=self.ctx.ndk_dir,
117-
version=env["TOOLCHAIN_VERSION"],
118-
arch=arch.arch)
119-
stl_lib = join(lib, "libgnustl_shared.so")
120-
dst_dir = join(self.ctx.get_site_packages_dir(), "..", "lib-dynload")
121-
shprint(sh.cp, stl_lib, dst_dir)
122-
123-
src_lib = join(self.get_build_dir(arch.arch), "icu_build", "lib")
124-
dst_lib = self.get_lib_dir(arch)
125-
126-
src_suffix = "." + self.version
127-
dst_suffix = "." + self.version.split(".")[0] # main version
128-
for lib in self.generated_libraries:
129-
shprint(sh.cp, join(src_lib, lib+src_suffix),
130-
join(dst_lib, lib+dst_suffix))
111+
def do_install_libs(self, arch):
112+
super(ICURecipe, self).do_install_libs(arch)
131113

132114
src_include = join(
133115
self.get_build_dir(arch.arch), "icu_build", "include")
@@ -137,16 +119,5 @@ def copy_files(self, arch):
137119
shprint(sh.cp, "-r", join(src_include, "layout"), dst_include)
138120
shprint(sh.cp, "-r", join(src_include, "unicode"), dst_include)
139121

140-
# copy stl library
141-
lib = "{ndk}/sources/cxx-stl/gnu-libstdc++/{version}/libs/{arch}"
142-
lib = lib.format(ndk=self.ctx.ndk_dir,
143-
version=env["TOOLCHAIN_VERSION"],
144-
arch=arch.arch)
145-
stl_lib = join(lib, "libgnustl_shared.so")
146-
147-
dst_dir = join(self.ctx.get_python_install_dir(), "lib")
148-
ensure_dir(dst_dir)
149-
shprint(sh.cp, stl_lib, dst_dir)
150-
151122

152123
recipe = ICURecipe()
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
diff -aur icu4c-org/source/config/Makefile.inc.in icu4c/source/config/Makefile.inc.in
2+
--- icu/source/config/Makefile.inc.in.orig 2016-03-23 21:50:50.000000000 +0100
3+
+++ icu/source/config/Makefile.inc.in 2019-02-15 17:59:28.331749766 +0100
4+
@@ -142,8 +142,8 @@
5+
LDLIBRARYPATH_ENVVAR = LD_LIBRARY_PATH
6+
7+
# Versioned target for a shared library
8+
-FINAL_SO_TARGET = $(SO_TARGET).$(SO_TARGET_VERSION)
9+
-MIDDLE_SO_TARGET = $(SO_TARGET).$(SO_TARGET_VERSION_MAJOR)
10+
+FINAL_SO_TARGET = $(SO_TARGET).$(SO_TARGET_VERSION)
11+
+MIDDLE_SO_TARGET = $(SO_TARGET)
12+
13+
# Access to important ICU tools.
14+
# Use as follows: $(INVOKE) $(GENRB) arguments ..
15+
diff -aur icu4c-org/source/config/mh-linux icu4c/source/config/mh-linux
16+
--- icu4c-org/source/config/mh-linux 2017-07-05 13:23:06.000000000 +0200
17+
+++ icu4c/source/config/mh-linux 2017-07-06 14:02:52.275016858 +0200
18+
@@ -24,9 +24,17 @@
19+
20+
## Compiler switch to embed a library name
21+
# The initial tab in the next line is to prevent icu-config from reading it.
22+
- LD_SONAME = -Wl,-soname -Wl,$(notdir $(MIDDLE_SO_TARGET))
23+
+ LD_SONAME = -Wl,-soname -Wl,$(notdir $(SO_TARGET))
24+
+ DATA_STUBNAME = data$(SO_TARGET_VERSION_MAJOR)
25+
+ COMMON_STUBNAME = uc$(SO_TARGET_VERSION_MAJOR)
26+
+ I18N_STUBNAME = i18n$(SO_TARGET_VERSION_MAJOR)
27+
+ LAYOUT_STUBNAME = le$(SO_TARGET_VERSION_MAJOR)
28+
+ LAYOUTEX_STUBNAME = lx$(SO_TARGET_VERSION_MAJOR)
29+
+ IO_STUBNAME = io$(SO_TARGET_VERSION_MAJOR)
30+
+ TOOLUTIL_STUBNAME = tu$(SO_TARGET_VERSION_MAJOR)
31+
+ CTESTFW_STUBNAME = test$(SO_TARGET_VERSION_MAJOR)
32+
#SH# # We can't depend on MIDDLE_SO_TARGET being set.
33+
-#SH# LD_SONAME=
34+
+#SH# LD_SONAME=$(SO_TARGET)
35+
36+
## Shared library options
37+
LD_SOOPTIONS= -Wl,-Bsymbolic
38+
@@ -64,10 +64,10 @@
39+
40+
## Versioned libraries rules
41+
42+
-%.$(SO).$(SO_TARGET_VERSION_MAJOR): %.$(SO).$(SO_TARGET_VERSION)
43+
- $(RM) $@ && ln -s ${<F} $@
44+
-%.$(SO): %.$(SO).$(SO_TARGET_VERSION_MAJOR)
45+
- $(RM) $@ && ln -s ${*F}.$(SO).$(SO_TARGET_VERSION) $@
46+
+%.$(SO).$(SO_TARGET_VERSION_MAJOR): %.$(SO).$(SO_TARGET_VERSION)
47+
+ $(RM) $@ && ln -s ${<F} $@
48+
+%.$(SO): %.$(SO).$(SO_TARGET_VERSION_MAJOR)
49+
+ $(RM) $@ && ln -s ${*F}.$(SO).$(SO_TARGET_VERSION) $@
50+
51+
## Bind internal references
52+
53+
diff -aur icu4c-org/source/data/Makefile.in icu4c/source/data/Makefile.in
54+
--- icu4c-org/source/data/Makefile.in 2017-07-05 13:23:06.000000000 +0200
55+
+++ icu4c/source/data/Makefile.in 2017-07-06 14:05:31.607995855 +0200
56+
@@ -24,9 +24,9 @@
57+
ifeq ($(PKGDATA_OPTS),)
58+
PKGDATA_OPTS = -O $(top_builddir)/data/icupkg.inc
59+
endif
60+
-ifeq ($(PKGDATA_VERSIONING),)
61+
-PKGDATA_VERSIONING = -r $(SO_TARGET_VERSION)
62+
-endif
63+
+#ifeq ($(PKGDATA_VERSIONING),)
64+
+#PKGDATA_VERSIONING = -r $(SO_TARGET_VERSION)
65+
+#endif
66+

0 commit comments

Comments
 (0)