Open illicitonion opened 3 years ago
/cc @katre @gregestren
This is an unfortunate wart of Bazel. The toolchains
attribute on most rules does not want a toolchain_type
: it wants something else that exposes TemplateVariableInfo
providers. This can be several other concrete toolchains (I know CC toolchains and Java toolchains provide this, I don't know about Perl toolchains).
This was named separately from the toolchain_type
and related rules, and is very annoying (I didn't name it! I promise).
In an ideal world, toolchain resolution would also consult the toolchains
attribute and add those types to the set of toolchain types needed for resolution, as you note. Unfortunately, we haven't implemented this yet.
One workaround is to add a simple rule which does declare the toolchain type of @rules_perl//:toolchain_type
, and then forwards the TemplateVariableInfo
provider from that toolchain, and use the toolchain-forwarding rule in your target that wants Perl toolchain variables. This is actually how the Java rules handle all toolchain dependencies, see https://cs.opensource.google/bazel/bazel/+/master:tools/jdk/java_toolchain_alias.bzl?ss=bazel&q=java_toolchain_alias for the implementation of java_toolchain_alias
.
Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage
) if you think this issue is still relevant or you are interested in getting the issue resolved.
@bazelbuild/triage - this is still relevant
The problem is that the genrule.toolchains
attribute isn't looking for a toolchain_type
, due to inconsistent naming. You should not be passing a toolchain type here: it wants an actual toolchain implementation.
Ideally we'd fix this to also take a toolchain type, perform toolchain resolution, and then get the make variables from the toolchain, but this is actually pretty complex (right now the set of toolchain types for a rule is static, this would make it dynamic).
Description of the problem / feature request:
As far as I can tell, there's no way for a starlark-defined toolchain to be consumed for make variable expansion.
I wanted to use
perl
from a Perl toolchain fromrules_perl
in a genrule:Unfortunately, this doesn't quite work for two reasons.
As far as I can tell, there's no way for a
toolchain_type
to expose extra providers. I can substitute in the concrete toolchain target:"@perl_darwin_amd64//:toolchain_impl"
, but this feels like it's subverting toolchain selection. Shouldn't thetoolchain_type
target proxy its providers through?tools = ["@perl_darwin_amd64//:runtime"]
to the target, and then the files are present.So this target actually works:
What operating system are you running Bazel on?
macOS
What's the output of
bazel info release
?release 4.2.1
Here's my WORKSPACE file to repro: