rules_ruby
rules_ruby copied to clipboard
bzlmod users should get a default toolchain registration
There's a TODO introduced, see thread: https://github.com/p0deje/rules_ruby/pull/17#discussion_r1398271819
I've tried adding the default toolchain by adding the following to MODULE.bazel
ruby = use_extension("@rules_ruby//ruby:extensions.bzl", "ruby")
ruby.toolchain(
name = "ruby",
version = "jruby-9.4.5.0",
)
use_repo(ruby, "ruby", "ruby_toolchains")
register_toolchains("@ruby_toolchains//:all")
However, this fails as now there are multiple toolchains called ruby:
Error in fail: Multiple conflicting toolchains declared for name ruby (jruby-9.4.5.0, None) and ("", Label("//:.ruby-version"), ["libyaml"])
How multiple toolchain registrations should actually work? Is there any good example of this?
That error is our own, in extensions.bzl doing logic that looks at the global view of all calls to the extension and decide what to do. I think it's just a logic bug that we should figure out how to disambiguate this case.
@kormide has been doing these fixes in our other rules lately and probably has some details easily recalled.
You can follow what we do with toolchain registration in bazel-lib: https://github.com/aspect-build/bazel-lib/blob/main/lib/extensions.bzl#L110.
We use this private toolchain_repos_bfs utility to do the work.
@kormide Thank you for sharing, but the code in is quite similar to what ruby_rules already do and produce the same error. How would a user define a custom toolchain with a custom yq
version in their MODULE? Do they need to use a different toolchain name?
@kormide Thank you for sharing, but the code in is quite similar to what ruby_rules already do and produce the same error. How would a user define a custom toolchain with a custom
yq
version in their MODULE? Do they need to use a different toolchain name?
We write the toolchain module extension so that whatever version is specified in the root module overrides versions from other invocations in the dependency graph, as long as the repo "name" is the same.