2

I've set up my bazel crosstool so that I can specifically select the compiler that I want: gcc9, gcc10, ..., clang12, clang13... This works great.

bazel build --compiler=clang13 //:target

I'm scratching my head wondering how I achieve this with platforms! It seems to want to select whatever compiler you specify for the given platform, and if you want to change it, you have to edit the file!

In particular, if I want my compiler to be used by dependencies, whatever I do needs to be compatible with, for example, absl, and grpc.

Is there anyway to coerce toolchain selection via --config, --define, or other flags?

# In Workspace
register_toolchains("//toolchains:gcc12",
                    "//toolchains:clang13", 
                    "//toolchains:clang14",
                    ...)                 
# But how do I tell it that I want clang13, or clang14???
bazel build --platform=linux_x86 //:target
Zendel
  • 485
  • 3
  • 14

1 Answers1

1

Here are two ideas that could help you:

  1. do not use register_toolchains() to make all toolchains known to bazel, but use https://bazel.build/reference/command-line-reference#flag--extra_toolchains (maybe based on a --config via the .bazelrc). This lets bazel only know about one compiler toolchain available for resolution. Of course with this approach you can't use different compiler toolchains for different targets.

  2. make use of the constraint_setting()s defined here. https://bazel.build/configure/windows#clang references how this is done:

platform(
    name = "x64_windows-clang-cl",
    constraint_values = [
        "@platforms//cpu:x86_64",
        "@platforms//os:windows",
        "@bazel_tools//tools/cpp:clang-cl",
    ],
)
lummax
  • 333
  • 8