加载挡板扩展失败

Loading Bazel Extension Fails

本文关键字:失败 扩展 挡板 加载      更新时间:2023-10-16

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

[根]/工作区

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) 文件?

附言:

Bazel 版本是 0.21.0

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

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