This repository has been archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathBUILD.icu
260 lines (242 loc) · 7.9 KB
/
BUILD.icu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
licenses(['notice'])
# TODO: Add a version attribute that takes a list of integers. For version
# 59.1, the list would be [59, 1].
# TODO: Use config_settings() and select() to build on both Linux and
# Darwin instead of using `uname -r`.
icu_src_dir = '/'.join(['.', PACKAGE_NAME, 'source'])
icu_copts = [
'-fno-exceptions',
'-I%s/common' % icu_src_dir,
'-I%s/i18n' % icu_src_dir,
'-I%s/io' % icu_src_dir,
'-I%s/tools/ctestfw' % icu_src_dir,
'-I%s/tools/toolutil' % icu_src_dir,
]
icu_linkopts = [
'-ldl',
'-lm',
]
cc_library(
name = 'icu-base',
srcs = glob([
'source/common/**/*.c',
'source/common/**/*.cpp',
'source/io/**/*.c',
'source/io/**/*.cpp',
'source/i18n/**/*.c',
'source/i18n/**/*.cpp',
# Including the layoutex directory leads to the following error:
# third_party/icu/layoutex/LXUtilities.cpp:10:28: \
# fatal error: layout/LETypes.h: No such file or directory
# #include "layout/LETypes.h"
'layoutex/**/*.c',
'layoutex/**/*.cpp',
]),
hdrs = glob([
'source/common/**/*.h',
'source/io/**/*.h',
'source/i18n/**/*.h',
'layoutex/**/*.h',
]),
includes = [
# Use this 'includes' directive to
'source/common',
'source/i18n',
'source/io',
'source/tools/ctestfw',
'source/tools/toolutil',
],
defines = [
# Officially recommended settings.
'U_USING_ICU_NAMESPACE=0',
'U_CHARSET_IS_UTF8=1',
'U_NO_DEFAULT_INCLUDE_UTF_HEADERS=1',
# TODO: The following macros are recommended by the official
# install guide to enforce explicit type in constructors.
# But they break the tests shipped with the source code.
'UNISTR_FROM_CHAR_EXPLICIT=explicit',
'UNISTR_FROM_STRING_EXPLICIT=',
# Without -DU_HAVE_ELF_H=1, the tools/toolutil/pkg_genc.c will not
# export the symbol 'writeObjectCode'. Discovered via `VERBOSE=1 make`.
'U_HAVE_ELF_H=1',
'_REENRANT=1',
#'U_HAVE_STRTOD_L=1',
],
copts = icu_copts + [
# required for building the files under common/
'-DU_COMMON_IMPLEMENTATION',
# required for building the files under io/
'-DU_IO_IMPLEMENTATION',
# required for building the files under i18n/
'-DU_I18N_IMPLEMENTATION',
],
linkopts = icu_linkopts,
)
cc_library(
name = 'stubdata',
srcs = [
'source/stubdata/stubdata.cpp',
],
deps = [
':icu-base',
],
copts = icu_copts,
)
cc_library(
name = 'icu-tools',
srcs = glob([
'source/tools/ctestfw/**/*.c',
'source/tools/ctestfw/**/*.cpp',
'source/tools/toolutil/**/*.c',
'source/tools/toolutil/**/*.cpp',
]),
hdrs = glob([
'source/tools/ctestfw/**/*.h',
'source/tools/toolutil/**/*.h',
]),
deps = [
'icu-base',
],
copts = icu_copts + [
'-DU_TOOLUTIL_IMPLEMENTATION',
]
)
# The complete list of tools is:
#
# derb genccode gencmn gendict genrb icupkg pkgdata
# genbrk gencfu gencnval gennorm2 gensprep makeconv uconv
#
# Only build icupkg and pkgdata here as they are needed for building libicudata.
#
# TODO: There is a bug in bazel that prevents the above tools to be built. The
# problem is that cc_binary treats :stubdata as a separate library. As a
# result, at linking time, the object file stubdata.pic.o separated from other
# object files by pairs of `--start-lib` and `--end-lib`, which prevents other
# object files from seeing stubdata.pic.o directly, thus leading to the
# following error:
# error: undefined reference to 'icudt59_dat'
# There is a workaround to the above described problem. That is, just build the
# :libicudata target, which depends on :icupkg and :pkgdata. After `bazel build
# :libicudata`, you can find the `icupkg` and `pkgdata` binaries in
# bazel-bin/third_party/icu/.
cc_binary(
name = 'icupkg',
srcs = [
'source/tools/icupkg/icupkg.cpp',
],
deps = [
':icu-tools',
':stubdata',
],
copts = icu_copts,
linkopts = icu_linkopts,
)
cc_binary(
name = 'pkgdata',
srcs = [
'source/tools/pkgdata/pkgdata.cpp',
'source/tools/pkgdata/pkgtypes.c',
'source/tools/pkgdata/pkgtypes.h',
],
deps = [
':icu-tools',
':stubdata',
],
copts = icu_copts,
linkopts = icu_linkopts,
)
cc_library(
name = 'icu-data',
srcs = [
'libicudata.a',
'libicudata.so',
],
)
genrule(
name = 'icupkg_inc',
srcs = glob([
'source/runConfigureICU',
# The files below are used by source/runConfigureICU.
'source/configure',
'source/common/unicode/*.h',
'source/config/*',
'source/config.sub',
'source/config.guess',
'source/install-sh',
'source/icudefs.mk.in',
'source/**/Makefile.in',
'source/**/pkgdataMakefile.in',
]),
outs = [
'icupkg.inc',
],
cmd = ' && '.join([
# Detect the ARCH used to configure the icu library.
'if [ `uname` == "Linux" ]; then ARCH=Linux; elif [ `uname` == "Darwin" ]; then ARCH=MacOSX; fi',
'CFLAGS="-DU_USING_ICU_NAMESPACE=0 -DU_CHARSET_IS_UTF8=1 -DUNISTR_FROM_CHAR_EXPLICIT=explicit -DUNISTR_FROM_STRING_EXPLICIT=explicit -DU_NO_DEFAULT_INCLUDE_UTF_HEADERS=1" $(location source/runConfigureICU) $$ARCH --with-library-bits=64 &> /dev/null',
'cd data',
'make -f pkgdataMakefile &> /dev/null',
'cd ..',
'cp data/icupkg.inc $(location icupkg.inc)',
]),
)
genrule(
name = 'libicudata',
srcs = [
'source/data/in/icudt60l.dat',
'icupkg.inc',
],
tools = [
':icupkg',
':pkgdata',
],
outs = [
'libicudata.a',
'libicudata.so',
],
cmd = ' && '.join([
# The 'out' dircectory is a temporary directory.
'mkdir -p out',
'mkdir -p out/build',
'mkdir -p out/build/icudt60l',
'mkdir -p out/build/icudt60l/curr',
'mkdir -p out/build/icudt60l/lang',
'mkdir -p out/build/icudt60l/region',
'mkdir -p out/build/icudt60l/zone',
'mkdir -p out/build/icudt60l/unit',
'mkdir -p out/build/icudt60l/brkitr',
'mkdir -p out/build/icudt60l/coll',
'mkdir -p out/build/icudt60l/rbnf',
'mkdir -p out/build/icudt60l/translit',
'mkdir -p out/tmp',
'mkdir -p out/tmp/curr',
'mkdir -p out/tmp/lang',
'mkdir -p out/tmp/region',
'mkdir -p out/tmp/zone',
'mkdir -p out/tmp/unit',
'mkdir -p out/tmp/coll',
'mkdir -p out/tmp/rbnf',
'mkdir -p out/tmp/translit',
'mkdir -p out/tmp/brkitr',
# Invoke icupkg to unpack the icu data.
'$(location :icupkg) -d out/build/icudt60l --list -x \* $(location source/data/in/icudt60l.dat) -o out/tmp/icudata.lst',
# Invoke pkgdata to package the unpacked icu data into c++ libraries
# that can be linked against.
'$(location :pkgdata) -O $(location icupkg.inc) -q -c -s out/build/icudt60l -d out -e icudt60 -T out/tmp -p icudt60l -m static -r 60.1 -L icudata out/tmp/icudata.lst &> /dev/null',
'cp out/libicudata.a $(location libicudata.a)',
'$(location :pkgdata) -O $(location icupkg.inc) -q -c -s out/build/icudt60l -d out -e icudt60 -T out/tmp -p icudt60l -m dll -r 60.1 -L icudata out/tmp/icudata.lst &> /dev/null',
# In MacOSX use .dylib; In Linux use .so.
'if [ `uname` == "Linux" ]; then DYLIB=so; elif [ `uname` == "Darwin" ]; then DYLIB=dylib; fi',
'cp -H out/libicudata.$$DYLIB $(location libicudata.so)',
'rm -rf out',
]),
)
cc_library(
name = 'icu',
visibility = ['//visibility:public'],
deps = [
':icu-base',
':icu-data',
],
copts = icu_copts,
)