Skip to content

Commit d710e2d

Browse files
authored
icu-port: build common, i18n, stubdata (#13564)
1 parent 9ef0baa commit d710e2d

File tree

1 file changed

+55
-12
lines changed

1 file changed

+55
-12
lines changed

tools/ports/icu.py

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
VERSION = '68_2'
1212
HASH = '12c3db5966c234c94e7918fb8acc8bd0838edc36a620f3faa788e7ff27b06f1aa431eb117401026e3963622b9323212f444b735d5c9dd3d0b82d772a4834b993'
1313

14+
libname_libicu_common = 'libicu_common.a'
15+
libname_libicu_stubdata = 'libicu_stubdata.a'
16+
libname_libicu_i18n = 'libicu_i18n.a'
17+
1418

1519
def needed(settings):
1620
return settings.USE_ICU
@@ -19,25 +23,64 @@ def needed(settings):
1923
def get(ports, settings, shared):
2024
url = 'https://github.com/unicode-org/icu/releases/download/%s/icu4c-%s-src.zip' % (TAG, VERSION)
2125
ports.fetch_project('icu', url, 'icu', sha512hash=HASH)
26+
icu_source_path = os.path.join(ports.get_build_dir(), 'icu', 'source')
2227

23-
def create(final):
24-
logging.info('building port: icu')
25-
26-
source_path = os.path.join(ports.get_dir(), 'icu', 'icu')
27-
dest_path = os.path.join(ports.get_build_dir(), 'icu')
28-
28+
def prepare_build():
29+
source_path = os.path.join(ports.get_dir(), 'icu', 'icu') # downloaded icu4c path
30+
dest_path = os.path.join(ports.get_build_dir(), 'icu') # icu build path
31+
logging.debug(f'preparing for icu build: {source_path} -> {dest_path}')
2932
shutil.rmtree(dest_path, ignore_errors=True)
3033
shutil.copytree(source_path, dest_path)
3134

32-
ports.build_port(os.path.join(dest_path, 'source', 'common'), final, [os.path.join(dest_path, 'source', 'common')], ['-DU_COMMON_IMPLEMENTATION=1'])
33-
34-
ports.install_header_dir(os.path.join(dest_path, 'source', 'common', 'unicode'))
35-
36-
return [shared.Cache.get_lib('libicuuc.a', create)]
35+
def build_lib(lib_output, lib_src, other_includes, build_flags):
36+
logging.debug('building port: icu- ' + lib_output)
37+
38+
additional_build_flags = [
39+
# usage of 'using namespace icu' is deprecated: icu v61
40+
'-DU_USING_ICU_NAMESPACE=0',
41+
# make explicit inclusion of utf header: ref utf.h
42+
'-DU_NO_DEFAULT_INCLUDE_UTF_HEADERS=1',
43+
# mark UnicodeString constructors explicit : ref unistr.h
44+
'-DUNISTR_FROM_CHAR_EXPLICIT=explicit',
45+
'-DUNISTR_FROM_STRING_EXPLICIT=explicit',
46+
# generate static
47+
'-DU_STATIC_IMPLEMENTATION',
48+
# CXXFLAGS
49+
'-std=c++11'
50+
]
51+
ports.build_port(lib_src, lib_output, other_includes, build_flags + additional_build_flags)
52+
53+
# creator for libicu_common
54+
def create_libicu_common(lib_output):
55+
prepare_build()
56+
lib_src = os.path.join(icu_source_path, 'common')
57+
ports.install_headers(os.path.join(lib_src, 'unicode'), target='unicode')
58+
build_lib(lib_output, lib_src, [], ['-DU_COMMON_IMPLEMENTATION=1'])
59+
60+
# creator for libicu_stubdata
61+
def create_libicu_stubdata(lib_output):
62+
lib_src = os.path.join(icu_source_path, 'stubdata')
63+
other_includes = [os.path.join(icu_source_path, 'common')]
64+
build_lib(lib_output, lib_src, other_includes, [])
65+
66+
# creator for libicu_i18n
67+
def create_libicu_i18n(lib_output):
68+
lib_src = os.path.join(icu_source_path, 'i18n')
69+
ports.install_headers(os.path.join(lib_src, 'unicode'), target='unicode')
70+
other_includes = [os.path.join(icu_source_path, 'common')]
71+
build_lib(lib_output, lib_src, other_includes, ['-DU_I18N_IMPLEMENTATION=1'])
72+
73+
return [
74+
shared.Cache.get_lib(libname_libicu_common, create_libicu_common), # this also prepares the build
75+
shared.Cache.get_lib(libname_libicu_stubdata, create_libicu_stubdata),
76+
shared.Cache.get_lib(libname_libicu_i18n, create_libicu_i18n)
77+
]
3778

3879

3980
def clear(ports, settings, shared):
40-
shared.Cache.erase_file('libicuuc.a')
81+
shared.Cache.erase_file(libname_libicu_common)
82+
shared.Cache.erase_file(libname_libicu_stubdata)
83+
shared.Cache.erase_file(libname_libicu_i18n)
4184

4285

4386
def process_args(ports):

0 commit comments

Comments
 (0)