为什么 Bazel 找不到 http_archive 下载的我的编译器工具?

Why can't Bazel find my compiler tools downloaded by http_archive?

我使用 http_archive 下载了一个编译器。在工作空间中:

http_archive(
   name = "my_compiler",
   urls = "my.org/compiler.tar.gz"],
   build_file = "//my_compiler.BUILD",
)

register_toolchains(
   "//:all",
)

my_compiler.BUILD 找到所有源并从中创建工具链:

load("@//:my_compiler.bzl", "cc_toolchain_config_my_toolchain")

package(default_visibility = ["//visibility:public"])

filegroup(
    name = "all_files",
    srcs = glob(["**/*"]),
)

filegroup(name = "empty")

cc_toolchain(
    name = "cc_my_toolchain",
    toolchain_identifier = "cc-my-toolchain",
    toolchain_config = ":my_toolchain_config",
    all_files = ":all_files",
    compiler_files = ":empty",
    dwp_files = ":empty",
    linker_files = ":empty",
    objcopy_files = ":empty",
    strip_files = ":empty",
    supports_param_files = 1,
)

cc_toolchain_config_my_compiler(
    name = "my_toolchain_config",
)

终于my_compiler.bzl:

load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "tool_path")

def _impl(ctx):
    tool_paths = [
        tool_path(
            name = "gcc",
            path = "bin/gcc",
        ),
        # more tool paths here
    ]

    return cc_common.create_cc_toolchain_config_info(
        ctx = ctx,
        toolchain_identifier = "my_toolchain",
        host_system_name = "unknown",
        target_cpu = "k8",
        target_libc = "unknown",
        target_system_name = "unknown",
        abi_libc_version = "unknown",
        abi_version = "unknown",
        compiler = "gcc",
        cxx_builtin_include_directories = [
            "include",
        ],
        tool_paths = tool_paths,
        features = [],
    )

cc_toolchain_config_my_compiler = rule(
    implementation = _impl,
    attrs = {},
    provides = [CcToolchainConfigInfo],
)

我似乎无法让工具链出现在 execroot 中。尝试构建:

src/main/tools/linux-sandbox-pid1.cc:390: "execvp(external/my_compiler/bin/gcc, 0xabc12345)": No such file or directory

然后 运行 tree 在来自 --sandbox_debug 的沙箱中没有显示 my_compiler 在外部的痕迹,只有 bazel_tools.

Bazel 不应该将编译器放在 execroot 中吗?

我做错了什么?我错过了什么?

您可能希望向 cc_toolchain 规则中的 compiler_files 提供一个空的 filegroup