Skip to content

Commit 6bae07f

Browse files
Upgrade ruby-build and add jruby support
1 parent 9d82554 commit 6bae07f

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

ruby/private/sdk.bzl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,23 @@ def rules_ruby_select_sdk(version = "host"):
2828
"3.0.3",
2929
"3.1.0",
3030
"3.1.1",
31+
"jruby-9.2.21.0",
32+
"jruby-9.3.6.0",
3133
]
3234

33-
if version in supported_versions:
34-
_ruby_runtime(
35-
name = "org_ruby_lang_ruby_toolchain",
36-
version = version,
37-
)
38-
else:
35+
for v in sorted(supported_versions, reverse=True):
36+
if v.startswith(version):
37+
supported_version = v
38+
break
39+
40+
if not supported_version:
3941
fail("rules_ruby_select_sdk: unsupported ruby version '%s' not in '%s'" % (version, supported_versions))
4042

43+
_ruby_runtime(
44+
name = "org_ruby_lang_ruby_toolchain",
45+
version = supported_version,
46+
)
47+
4148
native.register_toolchains(
4249
"@org_ruby_lang_ruby_toolchain//:toolchain",
4350
)

ruby/private/toolchains/ruby_runtime.bzl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ load("//ruby/private/toolchains:repository_context.bzl", "ruby_repository_contex
33

44
def _install_ruby_version(ctx, version):
55
ctx.download_and_extract(
6-
url = "https://github.com/rbenv/ruby-build/archive/refs/tags/v20220218.tar.gz",
7-
sha256 = "35c82b13b7bc3713eee5615b0145c79fbbac32873f55f2ab796620d76970d8e3",
8-
stripPrefix = "ruby-build-20220218",
6+
url = "https://github.com/rbenv/ruby-build/archive/refs/tags/v20220825.tar.gz",
7+
sha256 = "55d9363a27486e4ec9623985d7764c5cf8e59cafe58afcf666e81fa148dea2f0",
8+
stripPrefix = "ruby-build-20220825",
99
)
1010

1111
install_path = "./build"
12-
ctx.execute(
12+
result = ctx.execute(
1313
["./bin/ruby-build", "--verbose", version, install_path],
1414
quiet = False,
1515
timeout = 1600, # massive timeout because this does a lot and is a beast
1616
)
17+
if result.return_code:
18+
fail("Ruby build failed: %s %s" % (result.stdout, result.stderr))
1719

1820
def _is_subpath(path, ancestors):
1921
"""Determines if path is a subdirectory of one of the ancestors"""
@@ -107,6 +109,9 @@ def host_ruby_is_correct_version(ctx, version):
107109
return False
108110

109111
ruby_version = ctx.execute(["ruby", "-e", "print RUBY_VERSION"]).stdout
112+
ruby_platform = ctx.execute(["ruby", "-e", "print RUBY_PLATFORM"]).stdout
113+
if ruby_platform == "java":
114+
ruby_version = "jruby-" + ruby_version
110115

111116
have_ruby_version = (version == ruby_version)
112117

@@ -124,7 +129,7 @@ def _ruby_runtime_impl(ctx):
124129
_install_ruby_version(ctx, version)
125130
interpreter_path = ctx.path("./build/bin/ruby")
126131

127-
if not interpreter_path:
132+
if not interpreter_path or not interpreter_path.exists:
128133
fail(
129134
"Command 'ruby' not found. Set $PATH or specify interpreter_path",
130135
"interpreter_path",

0 commit comments

Comments
 (0)