【问题标题】:difficulty configuring Bazel target includes and deps难以配置 Bazel 目标包括和 deps
【发布时间】:2021-01-09 04:22:17
【问题描述】:

我正在尝试添加一些 Bazel 规则,用于构建 ICU 库构建版本的预处理数据。目前,我有一个非常 basic set of BUILD files(仍在进行中)来帮助完成 gennorm2 目标。

icu4c/source/common/BUILD 看起来像:

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 包含:

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",
    ],
)

我从构建中得到的错误如下:

$ 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
...

查询依赖似乎表明包含了正确的文件:

$  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

我的配置中缺少什么?某处目标的includes 密钥配置是否存在问题?

【问题讨论】:

    标签: c++ bazel


    【解决方案1】:

    includes 相对于packageBUILD 文件所在的文件夹)。你想在这里includes = ["."]

    如果icu4c/source/*.h 有头文件,您需要为它们创建一个带有cc_libraryicu4c/source/BUILD

    另外,为了调试,bazelisk build //icu4c/source/tools/gennorm2 --verbose_failures --sandbox_debug 将打印出完整的命令 bazel 正在运行,并保留临时文件夹以便您可以自己运行它。在让 bazel 自己运行该命令之前,我发现迭代命令以使其工作很方便。

    【讨论】:

    • 谢谢!这对让我畅通无阻非常有用。显然,我还需要为必要的标头指定一个额外的传递依赖。另外,基于一些代码库特定的细节,我还需要添加一些local_defines
    猜你喜欢
    • 2022-01-20
    • 2018-11-18
    • 2021-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多