Skip to content

Commit

Permalink
chore: explicitly provide toolchain label to rb_bundle
Browse files Browse the repository at this point in the history
This satisfies the strict-repo-deps constraint that comes with bzlmod
  • Loading branch information
alexeagle committed Nov 20, 2023
1 parent 023a679 commit 5429214
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions examples/gem/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ local_path_override(
ruby = use_extension("@rules_ruby//ruby:extensions.bzl", "ruby")

ruby.toolchain(name = "rules_ruby", version = "3.2.1")
use_repo(ruby, "rules_ruby_dist")

ruby.bundle(
name = "bundle",
srcs = [
Expand All @@ -21,6 +23,7 @@ ruby.bundle(
"BUNDLE_BUILD__FOO": "bar",
},
gemfile = "//:Gemfile",
toolchain = "@rules_ruby_dist//:BUILD",
)

use_repo(ruby, "rules_ruby_toolchains", "bundle")
Expand Down
5 changes: 4 additions & 1 deletion ruby/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
load("//ruby/private:bundle.bzl", _rb_bundle = "rb_bundle")
load("//ruby/private:download.bzl", _rb_register_toolchains = "rb_register_toolchains")

rb_bundle = _rb_bundle
def rb_bundle(toolchain = "@rules_ruby_dist//:BUILD", **kwargs):
_rb_bundle(
toolchain = toolchain,
**kwargs)
rb_register_toolchains = _rb_register_toolchains
2 changes: 2 additions & 0 deletions ruby/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ruby_bundle = tag_class(attrs = {
"srcs": attr.label_list(),
"env": attr.string_dict(),
"gemfile": attr.label(),
"toolchain": attr.label(),
})

ruby_toolchain = tag_class(attrs = {
Expand All @@ -23,6 +24,7 @@ def _ruby_module_extension(module_ctx):
srcs = bundle.srcs,
env = bundle.env,
gemfile = bundle.gemfile,
toolchain = bundle.toolchain,
)

for toolchain in mod.tags.toolchain:
Expand Down
5 changes: 4 additions & 1 deletion ruby/private/bundle.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def _rb_bundle_impl(repository_ctx):
binstubs_path = repository_ctx.path("bin")
bundle_path = repository_ctx.path(".")
gemfile_path = repository_ctx.path(repository_ctx.attr.gemfile)
toolchain_path = repository_ctx.path(Label("@rules_ruby_dist//:BUILD")).dirname
toolchain_path = repository_ctx.path(repository_ctx.attr.toolchain).dirname

if repository_ctx.os.name.startswith("windows"):
bundle = repository_ctx.path("%s/dist/bin/bundle.cmd" % toolchain_path)
Expand Down Expand Up @@ -78,6 +78,9 @@ rb_bundle = repository_rule(
List of Ruby source files used to build the library.
""",
),
"toolchain": attr.label(
mandatory = True,
),
"gemfile": attr.label(
allow_single_file = ["Gemfile"],
doc = """
Expand Down

0 comments on commit 5429214

Please sign in to comment.