summaryrefslogtreecommitdiff
path: root/chromium/third_party/icu/BUILD.gn
blob: b7bb4a6be926c49d90dd743c127cdbaf248d82c0 (plain)
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/host_byteorder.gni")
import("//third_party/icu/config.gni")
import("//third_party/icu/sources.gni")

if (is_android) {
  import("//build/config/android/rules.gni")
}

if (is_mac && !icu_is_in_fuchsia) {
  import("//build/config/sanitizers/sanitizers.gni")
}

assert(!icu_disable_thin_archive || !is_component_build,
       "icu_disable_thin_archive only works in static library builds")

# Meta target that includes both icuuc and icui18n. Most targets want both.
# You can depend on the individually if you need to.
group("icu") {
  public_deps = [
    ":icui18n",
    ":icuuc",
  ]
}

# Shared config used by ICU and all dependents.
config("icu_config") {
  defines = [
    # Tell ICU to not insert |using namespace icu;| into its headers,
    # so that chrome's source explicitly has to use |icu::|.
    "U_USING_ICU_NAMESPACE=0",

    # We don't use ICU plugins and dyload is only necessary for them.
    # NaCl-related builds also fail looking for dlfcn.h when it's enabled.
    "U_ENABLE_DYLOAD=0",

    # v8/Blink need to know whether Chromium's copy of ICU is used or not.
    "USE_CHROMIUM_ICU=1",

    # Enable tracing to connect to UMA but disable tracing of resource
    # to avoid performance issues.
    "U_ENABLE_TRACING=1",
    "U_ENABLE_RESOURCE_TRACING=0",
  ]

  if (!is_component_build) {
    defines += [ "U_STATIC_IMPLEMENTATION" ]
  }

  include_dirs = [
    "source/common",
    "source/i18n",
  ]

  if (icu_use_data_file) {
    defines += [ "ICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_FILE" ]
  } else {
    defines += [ "ICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_STATIC" ]
  }
}

# Config used only by ICU code.
config("icu_code") {
  cflags = []
  defines = [
    "HAVE_DLOPEN=0",

    # Only build encoding coverters and detectors necessary for HTML5.
    "UCONFIG_ONLY_HTML_CONVERSION=1",

    # TODO(jshin): do we still need this?
    "UCONFIG_USE_WINDOWS_LCID_MAPPING_API=0",

    # No dependency on the default platform encoding.
    # Will cut down the code size.
    "U_CHARSET_IS_UTF8=1",
  ]

  if (is_win) {
    # Disable some compiler warnings.
    cflags += [
      "/wd4005",  # Macro redefinition.
      "/wd4068",  # Unknown pragmas.
      "/wd4267",  # Conversion from size_t on 64-bits.
      "/utf-8",  # ICU source files are in UTF-8.
    ]
    if (!is_clang) {
      cflags += [
        # Ignore some msvc warnings here because V8 still supports msvc.
        "/wd4244",  # Conversion: possible loss of data.
      ]
      defines += [
        # https://crbug.com/1274247
        # <ctgmath> is deprecated in C++17, but ICU still uses it, so we should
        # silence the warning for now.
        "_SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING",
      ]
    }
  } else if (is_linux || is_chromeos || is_android || icu_is_in_fuchsia) {
    cflags += [ "-Wno-unused-function" ]
  }
  if (is_clang) {
    cflags += [
      # ICU has some code with the pattern:
      #   if (found = uprv_getWindowsTimeZoneInfo(...))
      "-Wno-parentheses",

      # ucnv2022.cpp contains three functions that are only used when
      # certain preprocessor defines are set.
      # unistr.cpp also has an unused function for non-component builds.
      "-Wno-unused-function",

      # putil.cpp contains unused variables when building for iOS simulators.
      "-Wno-unused-variable",

      # ICU has decided not to fix this warning as doing so would break its
      # stable API.
      "-Wno-ambiguous-reversed-operator",
    ]
  }
  if (is_clang || is_linux || is_chromeos || is_android || icu_is_in_fuchsia) {
    cflags += [
      # ICU uses its own deprecated functions.
      "-Wno-deprecated-declarations",
    ]
  }
  if (icu_is_in_fuchsia) {
    cflags += [
      # Disable spurious thread safety errors in umutex.cpp
      "-Wno-thread-safety",

      # Can probably remove the below after
      # https://unicode-org.atlassian.net/projects/ICU/issues/ICU-20869
      # is fixed.
      "-Wno-implicit-int-float-conversion",
      "-Wno-conversion",

      # Needed for C++20
      "-Wno-ambiguous-reversed-operator",
      "-Wno-rewrite-not-bool",
      "-Wno-deprecated-anon-enum-enum-conversion",
      "-Wno-deprecated-array-compare",
      "-Wno-deprecated-pragma",

      # Used for conditional changes to the compilation process that
      # are only needed for the Fuchsia toolchain.
      "-DICU_IS_IN_FUCHSIA",

      # Can be removed after
      # https://unicode-org.atlassian.net/browse/ICU-22113 is fixed.
      "-Wno-unknown-warning-option",
      "-Wno-enum-constexpr-conversion",
    ]
  }
  if (current_cpu == "wasm") {
    # Tell ICU that we are a 32 bit platform, otherwise,
    # double-conversion-utils.h doesn't know how to operate.
    defines += [ "__i386__" ]
  }
}

# Config used to set default visibility to hidden.
config("visibility_hidden") {
  cflags = []
  if (is_mac || is_linux || is_chromeos || is_android || is_fuchsia) {
    cflags += [ "-fvisibility=hidden" ]
  }
}

template("generate_icu_component") {
  if (icu_is_in_fuchsia) {
    target(default_library_type, target_name) {
      forward_variables_from(invoker,
                             "*",
                             [
                               "testonly",
                               "visibility",
                             ])
      assert(fuchsia_output_name_postfix == "")

      # ICU uses RTTI, replace the default "no rtti" config (if applied).
      configs += [
        "//build/config:no_rtti",
        "//build/config:symbol_visibility_hidden",
      ]
      configs -= [
        "//build/config:no_rtti",
        "//build/config:symbol_visibility_hidden",
      ]

      configs += [ "//build/config:rtti" ]

      # These need to be applied after the main configs so the "-Wno-*" options
      # take effect.
      configs += [ ":icu_code" ]
      configs += extra_configs
      public_configs = [ ":icu_config" ]
    }
  } else {
    component(target_name) {
      forward_variables_from(invoker,
                             "*",
                             [
                               "testonly",
                               "visibility",
                             ])
      if (is_fuchsia) {
        base_output_name = target_name
        if (defined(invoker.output_name)) {
          base_output_name = invoker.output_name
        }

        # Fuchsia puts its own libicu*.so in /system/lib where we need to put our
        # .so when doing component builds, so we need to give this a different name.
        output_name = "${base_output_name}_cr${fuchsia_output_name_postfix}"
      } else {
        assert(fuchsia_output_name_postfix == "")
      }

      # ICU uses RTTI, replace the default "no rtti" config (if applied).
      configs += [
        "//build/config/compiler:no_rtti",
        "//build/config/compiler:chromium_code",
      ]
      configs -= [
        "//build/config/compiler:no_rtti",
        "//build/config/compiler:chromium_code",
      ]
      configs += [
        "//build/config/compiler:rtti",
        "//build/config/compiler:no_chromium_code",
      ]

      # These need to be applied after the main configs so the "-Wno-*" options
      # take effect.
      configs += [ ":icu_code" ]
      configs += extra_configs
      public_configs = [ ":icu_config" ]

      # Make icu into a standalone static library. Currently This is only useful
      # on Chrome OS.
      if (icu_disable_thin_archive) {
        configs -= [ "//build/config/compiler:thin_archive" ]
        complete_static_lib = true
      }
    }
  }
}

template("generate_icui18n") {
  generate_icu_component(target_name) {
    assert(defined(invoker.icuuc_deps), "Need the 'icuuc_deps' parameter.")
    icuuc_deps = invoker.icuuc_deps

    fuchsia_output_name_postfix = ""
    if (defined(invoker.fuchsia_output_name_postfix)) {
      fuchsia_output_name_postfix = invoker.fuchsia_output_name_postfix
    }

    forward_variables_from(invoker,
                           "*",
                           [
                             "testonly",
                             "visibility",
                           ])

    sources = icu18n_sources
    public = icu18n_public

    defines = [ "U_I18N_IMPLEMENTATION" ]
    deps = icuuc_deps

    # TODO(fxbug.dev/98632): workaround for toolchain issues, see bug
    if (icu_is_in_fuchsia && is_fuchsia) {
      deps += [ "//build/config/fuchsia:uses-outline-atomics-fxbug98632" ]
    }
  }
}

generate_icui18n("icui18n") {
  extra_configs = []
  icuuc_deps = [ ":icuuc_private" ]
}

generate_icui18n("icui18n_hidden_visibility") {
  extra_configs = [ ":visibility_hidden" ]
  icuuc_deps = [ ":icuuc_private_hidden_visibility" ]
  if (is_fuchsia && !icu_is_in_fuchsia) {
    fuchsia_output_name_postfix = "_hidden_visibility"
  }
}

template("generate_icuuc") {
  generate_icu_component(target_name) {
    fuchsia_output_name_postfix = ""
    if (defined(invoker.fuchsia_output_name_postfix)) {
      fuchsia_output_name_postfix = invoker.fuchsia_output_name_postfix
    }

    forward_variables_from(invoker,
                           "*",
                           [
                             "testonly",
                             "visibility",
                           ])

    sources = icuuc_sources
    public_deps = [ ":icuuc_public" ]

    defines = [ "U_COMMON_IMPLEMENTATION" ]
    deps = [ ":icudata" ]

    if (is_chromeos) {
      deps += [ ":icudata_hash" ]
    }

    if (icu_use_data_file && icu_use_stub_data) {
      sources += [ "source/stubdata/stubdata.cpp" ]
    }

    defines += [ "U_ICUDATAENTRY_IN_COMMON" ]

    # TODO(fxbug.dev/98632): workaround for toolchain issues, see bug
    if (icu_is_in_fuchsia && is_fuchsia) {
      deps += [ "//build/config/fuchsia:uses-outline-atomics-fxbug98632" ]
    }
  }
}

group("icuuc") {
  public_deps = [ ":icuuc_private" ]
}

group("icuuc_hidden_visibility") {
  public_deps = [ ":icuuc_private_hidden_visibility" ]
}

source_set("icuuc_public") {
  sources = icuuc_public
}

generate_icuuc("icuuc_private") {
  extra_configs = []
  output_name = "icuuc"
  visibility = [
    ":icui18n",
    ":icuuc",
  ]
}

generate_icuuc("icuuc_private_hidden_visibility") {
  extra_configs = [ ":visibility_hidden" ]
  output_name = "icuuc_hidden_visibility"
  visibility = [
    ":icui18n_hidden_visibility",
    ":icuuc_hidden_visibility",
  ]
  if (is_fuchsia && !icu_is_in_fuchsia) {
    fuchsia_output_name_postfix = "_hidden_visibility"
  }
}

if (is_android && enable_java_templates) {
  android_assets("icu_assets") {
    if (icu_use_data_file) {
      sources = [ "$root_out_dir/icudtl.dat" ]
      deps = [ ":icudata" ]
      disable_compression = true
    }
  }
}

if (is_android) {
  data_dir = "android"
} else if (is_ios) {
  data_dir = "ios"
} else if (is_chromeos) {
  data_dir = "chromeos"
} else if (current_cpu == "wasm") {
  data_dir = "flutter"
} else if (icu_is_in_fuchsia && icu_fuchsia_override_data_dir != "") {
  # See //config.gni for details.
  data_dir = icu_fuchsia_override_data_dir
} else {
  data_dir = "common"
}

if (current_cpu == "mips" || current_cpu == "mips64" ||
    host_byteorder == "big") {
  data_bundle_prefix = "icudtb"
} else {
  data_bundle_prefix = "icudtl"
}
data_bundle = "${data_bundle_prefix}.dat"

if (icu_use_data_file) {
  if (is_ios) {
    bundle_data("icudata") {
      sources = [ "$data_dir/$data_bundle" ]
      outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
    }
  } else {
    copy("icudata") {
      sources = [ "$data_dir/$data_bundle" ]
      outputs = [ "$root_out_dir/$data_bundle" ]
      data = [ "$root_out_dir/$data_bundle" ]
    }
  }

  if (is_chromeos) {
    copy("icudata_hash") {
      sources = [ "//third_party/icu/chromeos/icudtl.dat.hash" ]
      outputs = [ "$root_out_dir/icudtl.dat.hash" ]
    }
  }
} else {
  if (current_cpu == "wasm") {
    data_assembly = "$target_gen_dir/${data_bundle_prefix}_dat.cpp"
  } else {
    data_assembly = "$target_gen_dir/${data_bundle_prefix}_dat.S"
  }
  inline_data_assembly = "$target_gen_dir/${data_bundle_prefix}_dat.cc"
  action("make_data_assembly") {
    if (current_cpu == "wasm") {
      # See scripts/make_data_cpp.py for details on building ICU for wasm.
      script = "scripts/make_data_cpp.py"
      inputs = [ "$data_dir/$data_bundle" ]
      outputs = [ data_assembly ]
      args = [
        rebase_path(inputs[0], root_build_dir),
        rebase_path(data_assembly, root_build_dir),
      ]
    } else {
      script = "scripts/make_data_assembly.py"
      inputs = [ "$data_dir/$data_bundle" ]
      outputs = [ data_assembly ]
      args = [
        rebase_path(inputs[0], root_build_dir),
        rebase_path(data_assembly, root_build_dir),
      ]
      if (is_mac || is_ios) {
        args += [ "--mac" ]
      } else if (is_win) {
        args += [ "--win" ]
      }
    }
  }

  if (is_win) {
    action("make_inline_data_assembly") {
      deps = [ ":make_data_assembly" ]
      script = "scripts/asm_to_inline_asm.py"
      inputs = [ data_assembly ]
      outputs = [ inline_data_assembly ]
      args = rebase_path([
                           data_assembly,
                           inline_data_assembly,
                         ],
                         root_build_dir)
    }
  } else {
    not_needed([ "inline_data_assembly" ])
  }

  source_set("icudata") {
    defines = [ "U_HIDE_DATA_SYMBOL" ]
    if (is_win) {
      sources = [ inline_data_assembly ]
      deps = [ ":make_inline_data_assembly" ]
    } else {
      sources = [ data_assembly ]
      deps = [ ":make_data_assembly" ]
    }
  }
}