Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module(
# Lower-bound dependency versions.
# These should NOT be increased unless needed, as bumping our lower-bound may change
# the versions resolved in users repositories.
bazel_dep(name = "bazel_features", version = "1.9.0")
bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "platforms", version = "0.0.5")
bazel_dep(name = "rules_cc", version = "0.0.9")
Expand Down
17 changes: 12 additions & 5 deletions ruby/extensions.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"Module extensions used by bzlmod"

load("@bazel_features//:features.bzl", "bazel_features")
load("//ruby/private:download.bzl", "RUBY_BUILD_VERSION")
load("//ruby/private:toolchain.bzl", "DEFAULT_RUBY_REPOSITORY")
load(":deps.bzl", "rb_bundle", "rb_bundle_fetch", "rb_register_toolchains")
Expand Down Expand Up @@ -105,11 +106,17 @@ def _ruby_module_extension(module_ctx):
register = False,
)

return module_ctx.extension_metadata(
reproducible = True,
root_module_direct_deps = direct_dep_names,
root_module_direct_dev_deps = direct_dev_dep_names,
)
if bazel_features.external_deps.extension_metadata_has_reproducible:
return module_ctx.extension_metadata(
reproducible = True,
root_module_direct_deps = direct_dep_names,
root_module_direct_dev_deps = direct_dev_dep_names,
)
else:
return module_ctx.extension_metadata(
root_module_direct_deps = direct_dep_names,
root_module_direct_dev_deps = direct_dev_dep_names,
)

ruby = module_extension(
implementation = _ruby_module_extension,
Expand Down
25 changes: 23 additions & 2 deletions ruby/private/bundle_fetch.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
"Implementation details for rb_bundle_fetch"

load("@bazel_skylib//lib:versions.bzl", "versions")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "get_auth")
load(
"@bazel_tools//tools/build_defs/repo:utils.bzl",
"read_netrc",
"read_user_netrc",
"use_netrc",
)
load("//ruby/private:bundler_checksums.bzl", "BUNDLER_CHECKSUMS")
load(
"//ruby/private:utils.bzl",
Expand Down Expand Up @@ -64,7 +69,7 @@ def _download_gem(repository_ctx, gem, cache_path, sha256 = None):
kwargs = {}
if sha256:
kwargs["sha256"] = sha256
download = repository_ctx.download(url = url, output = "%s/%s" % (cache_path, gem.filename), auth = get_auth(repository_ctx, [url]), **kwargs)
download = repository_ctx.download(url = url, output = "%s/%s" % (cache_path, gem.filename), auth = _get_auth(repository_ctx, [url]), **kwargs)
return download.sha256

def _get_gem_executables(repository_ctx, gem, cache_path):
Expand Down Expand Up @@ -234,6 +239,22 @@ def _rb_bundle_fetch_impl(repository_ctx):
}
return None

# The function is copied from the main branch of bazel_tools.
# It should become available there from version 7.1.0,
# We should remove this function when we upgrade minimum supported version to 7.1.0.
# https://github.com/bazelbuild/bazel/blob/d37762b494a4e122d46a5a71e3a8cc77fa15aa25/tools/build_defs/repo/utils.bzl#L424-L446
def _get_auth(ctx, urls):
if hasattr(ctx.attr, "netrc") and ctx.attr.netrc:
netrc = read_netrc(ctx, ctx.attr.netrc)
elif "NETRC" in ctx.os.environ:
netrc = read_netrc(ctx, ctx.os.environ["NETRC"])
else:
netrc = read_user_netrc(ctx)
auth_patterns = {}
if hasattr(ctx.attr, "auth_patterns") and ctx.attr.auth_patterns:
auth_patterns = ctx.attr.auth_patterns
return use_netrc(netrc, urls, auth_patterns)

rb_bundle_fetch = repository_rule(
implementation = _rb_bundle_fetch_impl,
attrs = {
Expand Down
Loading