Background
I'm trying to build a custom toolchain definition that references tool binaries from downloadable http_archive
package.
It seems that if tool_path.path
is relative Bazel treats it as relative to where toolchain is defined. Ex: ${execroot}/toolchain
.
http_archive
package contents on the other hand are found in ${execroot}/external/gcc12
Tool path must be canonical so you can't specify something like ../external/gcc12/bin/gcc
I looked at other custom toolchain definitions such as:
All of them use wrapper shell scripts that live under toolchain definition (so can be refernced by relative path) and call real binaries via external/gcc...
which is relative to the execroot.
While this approach works, it can cause problems with rules_foreign_cc
(See https://github.com/bazelbuild/bazel/issues/8438) and anyway seems hacky.
https://github.com/bazelbuild/bazel/pull/10967 "Add optional tool_path_origin to Tools in C++ crosstool" was merged in the May of 2020 which seems to allow relative tool paths to be evaluated relative to workspace root. However I don't quite understand how to trigger this behavior.
https://github.com/bazelbuild/bazel/issues/8438 references https://github.com/bazelbuild/bazel/pull/5809 as relevant but it was rejected in the end.
Another relevant discussion can be found at https://github.com/bazelbuild/bazel/issues/7746
Question
Is it possible to reference Bazel toolchain binaries from external package without resorting to wrapper shell scripts?