加载Bazel扩展失败

时间:2019-01-10 04:32:45

标签: c++ bazel

我试图在我的bazel构建中通过存储库规则添加外部依赖项。我将规则文件放在单独的目录中,并且试图将其加载到根WORKSPACE文件中。设置如下。

[root] / WORKSPACE

load("//thirdparty:myrepo.bzl", "my_repository")

my_repository(
    name = "myrepo",
)

[root] /thirdparty/myrepo.bzl

def _repository_impl(ctxt):

my_repository = repository_rule(
    implementation = _repository_impl,
    environ = ["CC", "CXX", "LD_LIBRARY_PATH"],
    local = True,
)

[root] / src / BUILD

cc_binary(
    name = "hello",
    srcs = [
        "hello.cc",
    ],
    deps = [
        "@myrepo//:foo"
    ],
)

但是当我尝试建立hello目标时,它失败并显示以下内容。

$ bazel build -c dbg //src:*
INFO: Invocation ID: d6b14442-0558-4c07-8414-59a0766ce338
ERROR: error loading package '': Unable to load package for '//thirdparty:myrepo.bzl': BUILD file not found on package path
ERROR: error loading package '': Unable to load package for '//thirdparty:myrepo.bzl': BUILD file not found on package path
INFO: Elapsed time: 1.217s

为什么找不到扩展名(.bzl)文件?

ps:

bazel版本为0.21.0

1 个答案:

答案 0 :(得分:2)

BUILD file not found on package path表示标签说明该位置应该有一个BUILD文件(它会创建一个构建包),但没有找到。

基本上,我认为您需要做的就是在[root]/thirdparty/myrepo.bzl旁边创建一个空的BUILD文件