toolchain的定义-学习记录

  1. tensorflow 中 toolchain 定义和使用
load(":cc_toolchain_config.bzl", "cc_toolchain_config")

cc_toolchain(  // 定义了一个 cc_toolchain
    name = "cc-compiler-k8",
    all_files = ":compiler_deps",
    ar_files = ":empty",
    as_files = ":empty",
    compiler_files = ":compiler_deps",
    dwp_files = ":empty",
    linker_files = ":compiler_deps",
    objcopy_files = ":empty",
    strip_files = ":empty",
    supports_param_files = 1,
    toolchain_config = ":linux_gnu_x86",
    toolchain_identifier = "linux_gnu_x86",
)

cc_toolchain_config(  // 定义了 cc_toolchain_config
    name = "linux_gnu_x86",
    compiler = "/dt7/usr/bin/gcc",
    cpu = "k8",
)

toolchain(   // 定义了一个toolchain,包含toolchain的名字和toolchain_type
    name = "cc-toolchain-k8",
    exec_compatible_with = [
        # TODO(katre): add autodiscovered constraints for host CPU and OS.
    ],
    target_compatible_with = [
        # TODO(katre): add autodiscovered constraints for host CPU and OS.
    ],
    toolchain = ":cc-compiler-k8",
    toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)


// 通过crosstool_top 来指定这个toolchain,然后使用
cc_toolchain_suite(  // 定义了一个toolchain的集合,包含了4中类型的toolchain
    name = "toolchain",
    toolchains = {  // 具体指定了这个toolchain 集合中都有哪些toolchain
        "k8|/dt7/usr/bin/gcc": ":cc-compiler-k8",
        "k8": ":cc-compiler-k8",
        "armeabi-v7a|compiler": ":cc-compiler-armeabi-v7a",
        "armeabi-v7a": ":cc-compiler-armeabi-v7a",
    },
)


2. 如何使用配置好的toolchain

.bazelrc中,或者其他的bazel build/test/... 命令执行的时候,添加下面的参数:

--crosstool_top=//third_party/toolchains/preconfig/ubuntu16.04/gcc7_manylinux2010-nvcc-cuda10.1:toolchain

编辑于 2022-05-02 16:17