Skip to content

Commit

Permalink
ICU-21117 Use Bazel to automate generation of Unicode data files
Browse files Browse the repository at this point in the history
  • Loading branch information
echeran committed Mar 24, 2021
1 parent 29d2e85 commit 227c729
Show file tree
Hide file tree
Showing 18 changed files with 663 additions and 49 deletions.
9 changes: 9 additions & 0 deletions .bazeliskrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# © 2021 and later: Unicode, Inc. and others.
# License & terms of use: http://www.unicode.org/copyright.html

# .bazeliskrc is the configuration file for the wrapper program for the Bazel
# build system, called Bazelisk. Bazelisk can be used as a drop-in replacement
# for running Bazel commands while ensuring, through configuration, that only a
# specific version of Bazel is executed.

USE_BAZEL_VERSION=3.7.1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*.vcxproj.user
*_debug
*_release
bazel-*
cygicudata*
libicu*
libicutest*
Expand Down
5 changes: 5 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# © 2021 and later: Unicode, Inc. and others.
# License & terms of use: http://www.unicode.org/copyright.html

# This file tells Bazel where the root directory of the project is.
# "Target" and file paths in Bazel BUILD files are relative to this root directory.
356 changes: 356 additions & 0 deletions icu4c/source/common/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,356 @@
# © 2021 and later: Unicode, Inc. and others.
# License & terms of use: http://www.unicode.org/copyright.html

# This file defines Bazel targets for a subset of ICU4C "common" library header and source files.
# The configuration of dependencies among targets is strongly assisted by the
# file in depstest that maintains such information, at
# icu4c/source/test/depstest/dependencies.txt .

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")

package(
default_visibility = ["//visibility:public"],
)

# When compiling code in the `common` dir, the constant
# `U_COMMON_IMPLEMENTATION` needs to be defined. See
# https://unicode-org.github.io/icu/userguide/howtouseicu#c-with-your-own-build-system .

# If linker errors occur, then this may be a sign that the dependencies were
# not specified correctly. Use dependencies.txt in depstest for assistance. See
# https://stackoverflow.com/q/66111709/2077918 .

cc_library(
name = "headers",
hdrs = glob([
"unicode/*.h", # public
"*.h", # internal
],
# Instead of using this checked-in file, our Bazel build process
# regenerates this file and then uses the new version.
exclude = ["norm2_nfc_data.h"],
),
# We need to add includes in order to preserve existing source files'
# include directives that use traditional paths, not paths relative to
# Bazel workspace:
# https://stackoverflow.com/a/65635893/2077918
includes = ["."],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
)

cc_library(
name = "platform",
srcs = [
"cmemory.cpp",
"uobject.cpp",
"cstring.cpp",
"cwchar.cpp",
"uinvchar.cpp",
"charstr.cpp",
"unistr.cpp",
"appendable.cpp",
"stringpiece.cpp",
"ustrtrns.cpp",
"ustring.cpp",
"ustrfmt.cpp",
"utf_impl.cpp",
"putil.cpp",
"ucln_cmn.cpp",
"udataswp.cpp",
"umath.cpp",
"umutex.cpp",
"sharedobject.cpp",
"utrace.cpp",
],
deps = [
":headers",
# omit other deps b/c they are sys symbols
],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
linkopts = ["-ldl"],
)

cc_library(
name = "utrie",
srcs = ["utrie.cpp"],
deps = [":platform"],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
)

cc_library(
name = "utrie2",
srcs = ["utrie2.cpp"],
deps = [":platform"],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
)

cc_library(
name = "utrie2_builder",
srcs = ["utrie2_builder.cpp"],
deps = [
":utrie",
":utrie2",
":platform",
],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
)

cc_library(
name = "ucptrie",
srcs = ["ucptrie.cpp"],
deps = [":platform"],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
)

cc_library(
name = "umutablecptrie",
srcs = ["umutablecptrie.cpp"],
deps = [":ucptrie"],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
)

cc_library(
name = "bytestrie",
srcs = ["bytestrie.cpp"],
deps = [":platform"],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
)

cc_library(
name = "bytestriebuilder",
srcs = ["bytestriebuilder.cpp"],
deps = [
":bytestrie",
":stringtriebuilder",
":sort",
],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
)

cc_library(
name = "stringtriebuilder",
srcs = ["stringtriebuilder.cpp"],
deps = [
":uhash",
],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
)

cc_library(
name = "uhash",
hdrs = [
"uhash.h",
],
srcs = [
"uhash.cpp",
],
deps = [
":headers",
],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
)

cc_library(
name = "errorcode",
hdrs = [
],
srcs = [
"errorcode.cpp",
],
includes = ["."],
deps = [
":platform",
":utypes",
],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
)

cc_library(
name = "utypes",
srcs = [
"utypes.cpp",
],
includes = ["."],
deps = [
":headers",
],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
)

cc_library(
name = "uniset",
srcs = [
"uniset.cpp",
"unifilt.cpp",
"unisetspan.cpp",
"bmpset.cpp",
"util.cpp",
"unifunct.cpp",
"usetiter.cpp",
],
includes = ["."],
deps = [
":patternprops",
":uvector",
":headers",
],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
)

cc_library(
name = "patternprops",
srcs = [
"patternprops.cpp",
],
includes = ["."],
deps = [
":headers",
],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
)

cc_library(
name = "propsvec",
srcs = [
"propsvec.cpp",
],
includes = ["."],
deps = [
":sort",
":utrie2_builder",
":headers",
],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
)

cc_library(
name = "propname",
srcs = [
"propname.cpp",
],
includes = ["."],
deps = [
":bytestrie",
":headers",
],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
)

# Note: cc_library target name "uvector32" matches dependencies.txt group name,
# but filename "uvectr32.*" differs in spelling.
cc_library(
name = "uvector32",
srcs = [
"uvectr32.cpp",
],
includes = ["."],
deps = [
":platform",
":headers",
],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
)

cc_library(
name = "sort",
srcs = [
"uarrsort.cpp",
],
includes = ["."],
deps = [
":headers",
],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
)

cc_library(
name = "uvector",
srcs = [
"uvector.cpp",
],
includes = ["."],
deps = [
":platform",
":sort",
],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
)


# Building this target will indirectly cause the creation of a header file that
# integrates normalization data. This header file is generated by a genrule
# target that invokes the gennorm2 binary.
cc_library(
name = "normalizer2",
srcs = [
"normalizer2.cpp",
"normalizer2impl.cpp",
],
includes = ["."],
hdrs = [
"normalizer2impl.h",
"norm2_nfc_data.h", # generated by gennorm2
],
deps = [
":headers",
],
local_defines = [
"U_COMMON_IMPLEMENTATION",
],
)



# Note: Bazel has chosen specifically to disallow any official support for breaking
# through constraints that would allow copying to or generating to source
# directories: https://stackoverflow.com/questions/51283183/how-to-generate-files-in-source-folder-using-bazel

genrule(
name = "gen_norm2_nfc_data_h",
srcs = [
"//icu4c/source/data/unidata/norm2:nfc.txt",
],
outs = ["norm2_nfc_data.h"],
cmd = "./$(location //icu4c/source/tools/gennorm2) -o $@ $(location //icu4c/source/data/unidata/norm2:nfc.txt) --csource && cp $@ /tmp",
tools = ["//icu4c/source/tools/gennorm2"],
)
6 changes: 6 additions & 0 deletions icu4c/source/data/unidata/changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ For new script codes see http://www.unicode.org/iso15924/codechanges.html

---------------------------------------------------------------------------- ***

Unicode 14.0 update for ICU 70

Note: running `bazelisk clean` is optional but not necessary along with running `clean.sh`.

---------------------------------------------------------------------------- ***

Unicode 13.0 update for ICU 66

https://www.unicode.org/versions/Unicode13.0.0/
Expand Down
Loading

0 comments on commit 227c729

Please sign in to comment.