Skip to content

Commit a4e34e0

Browse files
committed
feat: switch to bazel-contrib/portable-ruby
1 parent 3d1af0b commit a4e34e0

16 files changed

Lines changed: 404 additions & 239 deletions

docs/repository_rules.md

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ruby/extensions.bzl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,19 @@ ruby_toolchain = tag_class(attrs = {
3333
"msys2_packages": attr.string_list(doc = "Extra MSYS2 packages to install.", default = ["libyaml"]),
3434
"portable_ruby": attr.bool(
3535
doc = """\
36-
When True, downloads portable Ruby from jdx/ruby instead of compiling via \
36+
When True, downloads portable Ruby from bazel-contrib/portable-ruby instead of compiling via \
3737
ruby-build. Has no effect on JRuby, TruffleRuby, or Windows.\
3838
""",
3939
default = False,
4040
),
41+
"portable_ruby_release_suffix": attr.string(
42+
doc = """\
43+
Release suffix for portable Ruby downloads. When empty (default), uses the built-in \
44+
PORTABLE_RUBY_DEFAULT_SUFFIXES mapping. Set explicitly to pin to a specific rebuild, \
45+
e.g. "2" downloads version X.Y.Z-2.\
46+
""",
47+
default = "",
48+
),
4149
"portable_ruby_checksums": attr.string_dict(
4250
doc = """\
4351
Platform checksums for portable Ruby downloads, overriding built-in checksums. \
@@ -105,6 +113,7 @@ def _ruby_module_extension(module_ctx):
105113
toolchain.msys2_packages,
106114
toolchain.ruby_build_version,
107115
toolchain.portable_ruby,
116+
toolchain.portable_ruby_release_suffix,
108117
toolchain.portable_ruby_checksums,
109118
)
110119
if module_ctx.is_dev_dependency(toolchain):
@@ -121,6 +130,7 @@ def _ruby_module_extension(module_ctx):
121130
msys2_packages,
122131
ruby_build_version,
123132
portable_ruby,
133+
portable_ruby_release_suffix,
124134
portable_ruby_checksums,
125135
) = config
126136
rb_register_toolchains(
@@ -130,6 +140,7 @@ def _ruby_module_extension(module_ctx):
130140
msys2_packages = msys2_packages,
131141
ruby_build_version = ruby_build_version,
132142
portable_ruby = portable_ruby,
143+
portable_ruby_release_suffix = portable_ruby_release_suffix,
133144
portable_ruby_checksums = portable_ruby_checksums,
134145
register = False,
135146
)

ruby/private/download.bzl

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"Repository rule for fetching Ruby interpreters"
22

3-
load("//ruby/private:portable_ruby_checksums.bzl", "PORTABLE_RUBY_CHECKSUMS")
3+
load("//ruby/private:portable_ruby_checksums.bzl", "PORTABLE_RUBY_CHECKSUMS", "PORTABLE_RUBY_DEFAULT_SUFFIXES")
44

55
RUBY_BUILD_VERSION = "20260114"
66

77
_JRUBY_BINARY_URL = "https://repo1.maven.org/maven2/org/jruby/jruby-dist/{version}/jruby-dist-{version}-bin.tar.gz"
88
_RUBY_BUILD_URL = "https://github.com/rbenv/ruby-build/archive/refs/tags/v{version}.tar.gz"
99
_RUBY_INSTALLER_URL = "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-{version}-1/rubyinstaller-devkit-{version}-1-x64.exe"
1010
_PORTABLE_RUBY_NAME = "ruby-{version}.{platform}.tar.gz"
11-
_MISE_RUBY_URL = "https://github.com/jdx/ruby/releases/download/{release}/{name}"
11+
_PORTABLE_RUBY_URL = "https://github.com/bazel-contrib/portable-ruby/releases/download/{release}/{name}"
1212

1313
# Maintained JRuby versions integrity from https://repo1.maven.org/maven2/org/jruby/jruby-dist.
1414
# Run the following script to update the list:
@@ -280,7 +280,7 @@ def _install_via_ruby_build(repository_ctx, version):
280280
repository_ctx.delete("ruby-build")
281281

282282
def _install_portable_ruby(repository_ctx, ruby_version, checksums):
283-
"""Install portable Ruby from jdx/ruby project.
283+
"""Install portable Ruby from bazel-contrib/portable-ruby project.
284284
285285
Args:
286286
repository_ctx: Repository context
@@ -291,7 +291,7 @@ def _install_portable_ruby(repository_ctx, ruby_version, checksums):
291291
# Detect platform
292292
os_name = repository_ctx.os.name
293293
if os_name.startswith("mac"):
294-
os_key = "macos"
294+
os_key = "darwin"
295295
elif os_name.startswith("linux"):
296296
os_key = "linux"
297297
else:
@@ -306,16 +306,13 @@ def _install_portable_ruby(repository_ctx, ruby_version, checksums):
306306
else:
307307
arch_key = arch
308308

309-
if os_key == "macos" and arch_key == "x86_64":
310-
print("Warning: Portable Ruby does not support macOS on x86_64, falling back to compiling from source.") # buildifier: disable=print
311-
_install_via_ruby_build(repository_ctx, ruby_version)
312-
return
309+
# Combine to form platform key
310+
platform_key = arch_key + "_" + os_key
313311

314-
if os_key == "macos":
315-
# Intel is not supported
316-
platform_key = "macos"
317-
else:
318-
platform_key = arch_key + "_" + os_key
312+
# Determine release suffix: explicit attr overrides built-in default
313+
suffix = repository_ctx.attr.portable_ruby_release_suffix
314+
if not suffix:
315+
suffix = PORTABLE_RUBY_DEFAULT_SUFFIXES.get(ruby_version, "1")
319316

320317
artifact_name = _PORTABLE_RUBY_NAME.format(
321318
version = ruby_version,
@@ -326,15 +323,15 @@ def _install_portable_ruby(repository_ctx, ruby_version, checksums):
326323
kwargs = {}
327324
if artifact_name in checksums:
328325
kwargs["sha256"] = checksums[artifact_name]
329-
elif artifact_name in PORTABLE_RUBY_CHECKSUMS:
330-
kwargs["sha256"] = PORTABLE_RUBY_CHECKSUMS[artifact_name]
326+
elif suffix in PORTABLE_RUBY_CHECKSUMS and artifact_name in PORTABLE_RUBY_CHECKSUMS[suffix]:
327+
kwargs["sha256"] = PORTABLE_RUBY_CHECKSUMS[suffix][artifact_name]
331328

332329
repository_ctx.report_progress(
333-
"Downloading portable Ruby %s for %s" % (ruby_version, platform_key),
330+
"Downloading portable Ruby %s (suffix %s) for %s" % (ruby_version, suffix, platform_key),
334331
)
335332
repository_ctx.download_and_extract(
336-
url = _MISE_RUBY_URL.format(
337-
release = ruby_version,
333+
url = _PORTABLE_RUBY_URL.format(
334+
release = ruby_version + "-" + suffix,
338335
name = artifact_name,
339336
),
340337
output = "dist/",
@@ -399,16 +396,25 @@ which isn't available in this ruby-build yet.
399396
"portable_ruby": attr.bool(
400397
default = False,
401398
doc = """
402-
When set to True, downloads portable Ruby from jdx/ruby instead of compiling via ruby-build.
399+
When set to True, downloads portable Ruby from bazel-contrib/portable-ruby instead of compiling via ruby-build.
403400
Has no effect on JRuby, TruffleRuby, or Windows (which use their own installation methods).
401+
""",
402+
),
403+
"portable_ruby_release_suffix": attr.string(
404+
default = "",
405+
doc = """
406+
Release suffix for portable Ruby downloads from bazel-contrib/portable-ruby.
407+
The release tag is constructed as `{version}-{suffix}` (e.g. `4.0.2-1`).
408+
When empty (default), the built-in PORTABLE_RUBY_DEFAULT_SUFFIXES mapping is used.
409+
Set explicitly to pin to a specific rebuild (e.g. `"2"` for `4.0.2-2`).
404410
""",
405411
),
406412
"portable_ruby_checksums": attr.string_dict(
407413
default = {},
408414
doc = """
409415
Platform checksums for portable Ruby downloads, overriding built-in checksums. Can be generated by running `bazel run @rules_ruby//tools/generate_portable_ruby_checksums`.
410416
411-
Keys: artifact names (e.g., ruby-3.4.8.x86_64_linux.tar.gz, ruby-3.4.8.macos.tar.gz).
417+
Keys: artifact names (e.g., ruby-3.4.8.x86_64_linux.tar.gz, ruby-3.4.8.arm64_darwin.tar.gz).
412418
Values: SHA256 checksums for the corresponding platform.
413419
""",
414420
),

0 commit comments

Comments
 (0)