bazel-toolchains icon indicating copy to clipboard operation
bazel-toolchains copied to clipboard

Can we generate a toolchain config without a hardcoded toolchain target?

Open sunjayBhatia opened this issue 4 years ago • 2 comments

bazel-toolchains generates a hard coded toolchain identifier: https://github.com/bazelbuild/bazel-toolchains/blob/e45491b49fdf48091915df04ca25540b22590b59/configs/ubuntu16_04_clang/11.0.0/bazel_3.4.1/config/BUILD#L32

This works for Linux toolchains as when the toolchain config BUILD file is always generated (from here: https://github.com/bazelbuild/bazel/blob/e4e06c0293bda20ad8c2b8db131ce821316b8d12/tools/cpp/BUILD.tpl#L47-L55) with an appropriate cpu and compiler combination only the target compiler: https://github.com/bazelbuild/bazel-toolchains/blob/e45491b49fdf48091915df04ca25540b22590b59/configs/ubuntu16_04_clang/11.0.0/bazel_3.4.1/cc/BUILD#L56

On Windows however, the BUILD file that is generated (from here: https://github.com/bazelbuild/bazel/blob/e4e06c0293bda20ad8c2b8db131ce821316b8d12/tools/cpp/BUILD.windows.tpl#L47-L59) is not structured specifically for the target compiler, rather it has a toolchain suite for all supported toolchain configs: https://github.com/envoyproxy/envoy-build-tools/blob/c4d2fe1a46a1e173c3dad245b4bbc772a75b5db7/toolchains/configs/windows/msvc-cl/bazel_3.4.1/cc/BUILD#L47-L59

It seems like this might just an issue of Bazel fixing the structure of the BUILD file template and how it is generated on Windows to match Linux, but is there anything we can do in bazel-toolchains in the mean time/instead? If we could take in the cpu and target compiler and use that to determine the toolchain config target that would help. Currently we are using the Bazel hack to set USE_CLANG_CL=1 in the environment to make the msvc-cl toolchain use clang-cl tools but we would rather use a properly named toolchain config etc.

Just looking for ideas/thoughts, and if you think we should focus on getting Bazel to structure its builtin C++ toolchain BUILD files differently

Also see: https://github.com/bazelbuild/bazel-toolchains/blob/e45491b49fdf48091915df04ca25540b22590b59/rules/rbe_repo/build_gen.bzl#L101-L127 https://github.com/bazelbuild/bazel-toolchains/blob/e45491b49fdf48091915df04ca25540b22590b59/rules/rbe_repo/build_gen.bzl#L25-L28

sunjayBhatia avatar Jul 27 '20 20:07 sunjayBhatia

cc @wrowe

sunjayBhatia avatar Jul 27 '20 20:07 sunjayBhatia

My suggestion would be to point this out to the Bazel team and see if they're interested in fixing it or accepting a contribution that restructures the Windows toolchain to look like the Linux toolchain. If Bazel refuses, I would be open to considering patching up the Windows case here but I really hope it won't be necessary.

In the meantime, does continuing to use your workaround work for you? Otherwise, maybe a Skylark macro that takes the Windows toolchain target and extracts the compiler specific toolchain target from it in your repo? I'm not sure how the compiler is auto-determined/specified on Linux so I'm not sure how this macro would look like.

smukherj1 avatar Jul 28 '20 19:07 smukherj1