Unable to find toolchain

1,216 views
Skip to first unread message

Austin Schuh

unread,
Jan 11, 2019, 8:10:45 PM1/11/19
to bazel-discuss, Marcel Hlopko
Hi Marcel (or anyone else),

I'm working on upgrading to bazel 0.21.0.  It's a monster.  On the plus side, rules_go seems to work with our CROSSTOOL out of the box, so that's good news.

Target toolchain suite:
cc_toolchain_suite(
    name = "toolchain",
    toolchains = { 
        "k8|clang": ":cc-compiler-k8-clang",
        "k8|gcc": ":cc-compiler-k8-gcc",
        "armhf-debian|clang": ":cc-compiler-armhf-clang",
        "armhf-debian|gcc": ":cc-compiler-armhf-gcc",
        "darwin|clang": ":cc-compiler-darwin",
        "arm64-debian|gcc": "cc-compiler-arm64-gcc",
    },  
    visibility = ["//visibility:public"],
)

Host toolchain suite:

# This is the entry point for --host_crosstool_top.
cc_toolchain_suite(
    name = "toolchain",
    toolchains = { 
        # The error below triggers both with and without this
        "k8": ":cc-compiler-k8-clang",
        "k8|clang": ":cc-compiler-k8-clang",
    },  
    visibility = ["//visibility:public"],
)

I'm getting the following 3 errors:
1)
ERROR: /home/austin/local/peloton-tech/tools/host_cpp/BUILD:7:1: in cc_toolchain_suite rule //tools/host_cpp:toolchain: Error while selecting cc_toolchain: No toolchain found for cpu 'k8'. Valid toolchains are: [
  local_linux_k8: --cpu='k8' --compiler='clang',
  local_linux_gcc: --cpu='k8' --compiler='gcc',
  clang_linux_armhf: --cpu='armhf-debian' --compiler='clang',
  linaro_linux_armhf: --cpu='armhf-debian' --compiler='gcc',
  local_darwin: --cpu='darwin' --compiler='clang',
  linaro_linux_aarch64_gcc_2018_05: --cpu='arm64-debian' --compiler='gcc',
]
2)
ERROR: /home/austin/local/peloton-tech/tools/cpp/BUILD:67:1: in cc_toolchain_suite rule //tools/cpp:toolchain: cc_toolchain_suite '//tools/cpp:toolchain' does not contain a toolchain for cpu 'k8'

And:
3)
ERROR: /home/austin/.cache/bazel/_bazel_austin/dd758a6cc6943296d5c6a65e2c252c63/external/com_google_protobuf/BUILD:1131:13: Configurable attribute "copts" doesn't match this configuration (would a default condition help?).
Conditions checked:
 //tools:compiler_gcc
 //tools:compiler_clang

Where compiler_gcc and compiler_clang are:
config_setting(
    name = "compiler_clang",
    values = {"compiler": "clang"},
)

config_setting(
    name = "compiler_gcc",
    values = {"compiler": "gcc"},
)

I can get rid of error 1 and 2 by adding a k8 entry without a compiler specified, but that doesn't fix it.  I'd really like to set it up so clang is the default compiler (and my selects work properly to catch it).  How would you recommend setting the default compiler and detecting compiler type for selecting flags?  We've got a macro set up right now to wrap the specifics up, but I need to update it to use the new 0.21.0 methodology.

Austin

Marcel Hlopko

unread,
Jan 14, 2019, 2:06:48 AM1/14/19
to Austin Schuh, bazel-discuss
Hi Austin,

well, 0.22 won't be smaller :) And 0.23-0.24 will have https://github.com/bazelbuild/bazel/issues/6861 :) Be sure to test flipping incompatible flags in 0.21 to detect problems early, and to benefit from migration instructions. 

For 1 and 2, after you fixed cc_toolchain_suite, it can be that bazel cannot find the CROSSTOOL.toolchain, the simplest way is to use cc_toolchain.toolchain_identifier to map cc_toolchain to CROSSTOOL.toolchain.

For 3, we added compiler_flag.bzl which allows you to select on the compiler field value from the CROSSTOOL.toolchain. That will solve your usecase (if I understand it correctly).

Hope this helps
--
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891
Reply all
Reply to author
Forward
0 new messages