我想在 bazel 中为我的 genrule 创建一个工具链。我创建了一个名为 toolchain.bzl 的文件,该文件中的源代码是这样的:
BarInfo = provider(
fields = {
"bar": "path to bar executable",
},
doc = "Defines a Bar toolchain based on an SDK",
)
def _bar_toolchain_impl(ctx):
bar_info = ctx.attr.path
platform_bar_info = platform_common.ToolchainInfo(
bar_info = BarInfo(bar = bar_info),
)
return [platform_bar_info]
bar_toolchain = rule(
implementation = _bar_toolchain_impl,
attrs = {
"path": attr.string(
doc = "path to bar executable",
mandatory = False,
),
},
)
Run Code Online (Sandbox Code Playgroud)
我把这个写在 BUILD 文件中。
load(":toolchain.bzl", "bar_toolchain")
toolchain_type(
name = "toolchain_type",
visibility = ["//visibility:public"],
)
bar_toolchain(
name = "bar_toolchain",
path = "/usr/local/bin/bar",
visibility = ["//visibility:public"],
)
toolchain(
name = "bar_linux",
target_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
toolchain = "//:bar_toolchain",
toolchain_type = "//:toolchain_type",
visibility = ["//visibility:public"],
)
genrule(
name = "build_bar",
srcs = glob(["**/*.bar"]),
outs = ["a.sh"],
cmd = """
touch a.sh
""",
toolchains = ["//:toolchain_type"],
)
Run Code Online (Sandbox Code Playgroud)
但当我跑步时
巴泽尔构建 //:build_bar
我收到这个错误
'//:toolchain_type' 没有强制提供程序:'TemplateVariableInfo'。
我可以做什么来解决这个问题?
genrule的toolchains属性只能用于访问特定于工具链的“make 变量”,这些变量被替换到 的genrule命令字符串中。由于您的工具链未声明任何 make 变量,因此 Bazel 会出错。make 变量文档中描述了定义工具链make 变量。
| 归档时间: |
|
| 查看次数: |
5658 次 |
| 最近记录: |