rules_ruby icon indicating copy to clipboard operation
rules_ruby copied to clipboard

bzlmod users should get a default toolchain registration

Open alexeagle opened this issue 1 year ago • 5 comments

There's a TODO introduced, see thread: https://github.com/p0deje/rules_ruby/pull/17#discussion_r1398271819

alexeagle avatar Nov 21 '23 16:11 alexeagle

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?

p0deje avatar Jan 16 '24 18:01 p0deje

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.

alexeagle avatar Jan 29 '24 16:01 alexeagle

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 avatar Jan 30 '24 07:01 kormide

@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?

p0deje avatar Jan 31 '24 23:01 p0deje

@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.

kormide avatar Feb 01 '24 18:02 kormide