Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/tools/ports/icu.py
4130 views
1
# Copyright 2018 The Emscripten Authors. All rights reserved.
2
# Emscripten is available under two separate licenses, the MIT license and the
3
# University of Illinois/NCSA Open Source License. Both these licenses can be
4
# found in the LICENSE file.
5
6
import os
7
8
TAG = 'release-68-2'
9
VERSION = '68_2'
10
HASH = '12c3db5966c234c94e7918fb8acc8bd0838edc36a620f3faa788e7ff27b06f1aa431eb117401026e3963622b9323212f444b735d5c9dd3d0b82d772a4834b993'
11
12
variants = {'icu-mt': {'PTHREADS': 1}}
13
14
libname_libicu_common = 'libicu_common'
15
libname_libicu_stubdata = 'libicu_stubdata'
16
libname_libicu_i18n = 'libicu_i18n'
17
libname_libicu_io = 'libicu_io'
18
19
20
def needed(settings):
21
return settings.USE_ICU
22
23
24
def get_lib_name(base_name, settings):
25
return base_name + ('-mt' if settings.PTHREADS else '') + '.a'
26
27
28
def get(ports, settings, shared):
29
ports.fetch_project('icu', f'https://github.com/unicode-org/icu/releases/download/{TAG}/icu4c-{VERSION}-src.zip', sha512hash=HASH)
30
icu_source_path = None
31
32
def prepare_build():
33
nonlocal icu_source_path
34
source_path = ports.get_dir('icu', 'icu') # downloaded icu4c path
35
icu_source_path = os.path.join(source_path, 'source')
36
37
def build_lib(lib_output, lib_src, other_includes, build_flags):
38
additional_build_flags = [
39
# TODO: investigate why this is needed and remove
40
'-Wno-macro-redefined',
41
'-Wno-deprecated-declarations',
42
'-Wno-array-compare',
43
'-Wno-unknown-warning-option',
44
'-Wno-unnecessary-virtual-specifier',
45
# usage of 'using namespace icu' is deprecated: icu v61
46
'-DU_USING_ICU_NAMESPACE=0',
47
# make explicit inclusion of utf header: ref utf.h
48
'-DU_NO_DEFAULT_INCLUDE_UTF_HEADERS=1',
49
# mark UnicodeString constructors explicit : ref unistr.h
50
'-DUNISTR_FROM_CHAR_EXPLICIT=explicit',
51
'-DUNISTR_FROM_STRING_EXPLICIT=explicit',
52
# generate static
53
'-DU_STATIC_IMPLEMENTATION',
54
# CXXFLAGS
55
'-std=c++11',
56
]
57
if settings.PTHREADS:
58
additional_build_flags.append('-pthread')
59
60
ports.build_port(lib_src, lib_output, 'icu', includes=other_includes, flags=build_flags + additional_build_flags)
61
62
# creator for libicu_common
63
def create_libicu_common(lib_output):
64
prepare_build()
65
lib_src = os.path.join(icu_source_path, 'common')
66
ports.install_headers(os.path.join(lib_src, 'unicode'), target='unicode')
67
ports.make_pkg_config('ici', VERSION, '-sUSE_ICU')
68
build_lib(lib_output, lib_src, [], ['-DU_COMMON_IMPLEMENTATION=1'])
69
70
# creator for libicu_stubdata
71
def create_libicu_stubdata(lib_output):
72
lib_src = os.path.join(icu_source_path, 'stubdata')
73
other_includes = [os.path.join(icu_source_path, 'common')]
74
build_lib(lib_output, lib_src, other_includes, [])
75
76
# creator for libicu_i18n
77
def create_libicu_i18n(lib_output):
78
lib_src = os.path.join(icu_source_path, 'i18n')
79
ports.install_headers(os.path.join(lib_src, 'unicode'), target='unicode')
80
other_includes = [os.path.join(icu_source_path, 'common')]
81
build_lib(lib_output, lib_src, other_includes, ['-DU_I18N_IMPLEMENTATION=1'])
82
83
# creator for libicu_io
84
def create_libicu_io(lib_output):
85
prepare_build()
86
lib_src = os.path.join(icu_source_path, 'io')
87
ports.install_headers(os.path.join(lib_src, 'unicode'), target='unicode')
88
other_includes = [os.path.join(icu_source_path, 'common'), os.path.join(icu_source_path, 'i18n')]
89
build_lib(lib_output, lib_src, other_includes, ['-DU_IO_IMPLEMENTATION=1'])
90
91
return [
92
shared.cache.get_lib(get_lib_name(libname_libicu_common, settings), create_libicu_common), # this also prepares the build
93
shared.cache.get_lib(get_lib_name(libname_libicu_stubdata, settings), create_libicu_stubdata),
94
shared.cache.get_lib(get_lib_name(libname_libicu_i18n, settings), create_libicu_i18n),
95
shared.cache.get_lib(get_lib_name(libname_libicu_io, settings), create_libicu_io),
96
]
97
98
99
def clear(ports, settings, shared):
100
shared.cache.erase_lib(get_lib_name(libname_libicu_common, settings))
101
shared.cache.erase_lib(get_lib_name(libname_libicu_stubdata, settings))
102
shared.cache.erase_lib(get_lib_name(libname_libicu_i18n, settings))
103
shared.cache.erase_lib(get_lib_name(libname_libicu_io, settings))
104
105
106
def show():
107
return 'icu (-sUSE_ICU or --use-port=icu; Unicode License)'
108
109