Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

c++ - difficulty configuring Bazel target includes and deps

I'm trying to add some Bazel rules for building pre-processed data for build releases of the ICU library. Currently, I have a very basic set of BUILD files (still work-in-progress) to help complete the gennorm2 target.

icu4c/source/common/BUILD looks something like:

cc_library(
    name = "headers",
    hdrs = glob([
        "unicode/*.h", # public
        "*.h",         # internal
    ]),
    includes = [
        "icu4c/source",
        "icu4c/source/common",
    ],
    local_defines = [
        "U_COMMON_IMPLEMENTATION",
    ],
)
...
cc_library(
    name = "normalizer2",
    srcs = [
        "normalizer2.cpp",
        "normalizer2impl.cpp",
    ],
    hdrs = [
        "normalizer2impl.h",
    ],
)
...

icu4c/source/tools/gennorm2/BUILD contains:

cc_binary(
    name = "gennorm2",
    srcs = glob([
        "*.c",
        "*.cpp",
        "*.h",   # cannot have hdrs section in cc_binary
    ]),
    deps = [
        "//icu4c/source/common:hash",
        "//icu4c/source/common:normalizer2",
        "//icu4c/source/common:umutablecptrie",
        "//icu4c/source/common:ucptrie",
        "//icu4c/source/common:platform",
        "//icu4c/source/common:headers",
    ],
)

The error that I get from building looks like:

$ bazelisk build //icu4c/source/tools/gennorm2
...
In file included from icu4c/source/tools/gennorm2/gennorm2.cpp:23:
icu4c/source/tools/gennorm2/n2builder.h:29:10: fatal error: normalizer2impl.h: No such file or directory
   29 | #include "normalizer2impl.h"  // for IX_COUNT
      |          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
Target //icu4c/source/tools/gennorm2:gennorm2 failed to build
...

Querying for the dependencies seems to indicate that the correct files are included:

$  bazel query 'deps(//icu4c/source/tools/gennorm2)' --nohost_deps --noimplicit_deps | grep normalizer
Loading: 0 packages loaded
//icu4c/source/common:normalizer2
Loading: 0 packages loaded
//icu4c/source/common:normalizer2impl.cpp
//icu4c/source/common:normalizer2.cpp
//icu4c/source/common:unicode/normalizer2.h
//icu4c/source/common:normalizer2impl.h
Loading: 0 packages loaded

What am I missing in my configurations? Is it a problem in an includes key config for a target somewhere?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

includes is relative to the package (folder where the BUILD file is). You want includes = ["."] here.

If there are header files at icu4c/source/*.h, you will need to create a icu4c/source/BUILD with a cc_library for them.

Also, for debugging, bazelisk build //icu4c/source/tools/gennorm2 --verbose_failures --sandbox_debug will print out the full command bazel is running and leave the temporary folder around so you can run it yourself. I find that handy for iterating on a command to make it work, before getting bazel to run that command itself.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...