Skip to content

Commit fe92d2f

Browse files
Export JRuby jar files (#13)
* Export JRuby jar to avoid pinning a version through maven downstream * Buildifier * Create a dummy jar for non-java ruby
1 parent b8f651f commit fe92d2f

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

ruby/private/providers.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ RubyRuntimeToolchainInfo = provider(
2525
"interpreter": "A label which points the Ruby interpreter",
2626
"bundler": "A label which points bundler command",
2727
"runtime": "A list of labels which points runtime libraries",
28+
"jars": "A list of labels which points to ruby jars",
2829
"headers": "A list of labels which points to the ruby headers",
2930
"rubyopt": "A list of strings which should be passed to the interpreter as command line options",
3031
},

ruby/private/runtime_alias.bzl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,30 @@ ruby_runtime_alias = rule(
1919
toolchains = [TOOLCHAIN_TYPE_NAME],
2020
)
2121

22+
def _ruby_jars_alias_impl(ctx):
23+
runtime = ctx.attr.runtime[RubyRuntimeToolchainInfo]
24+
target = runtime.jars
25+
infos = [
26+
DefaultInfo(
27+
files = target.files,
28+
runfiles = ctx.runfiles(transitive_files = target.files),
29+
),
30+
]
31+
for jar in infos[0].files.to_list():
32+
infos.append(JavaInfo(jar, jar))
33+
34+
return infos
35+
36+
ruby_jars_alias = rule(
37+
implementation = _ruby_jars_alias_impl,
38+
attrs = {
39+
"runtime": attr.label(
40+
doc = "The runtime alias to use.",
41+
mandatory = True,
42+
),
43+
},
44+
)
45+
2246
def _ruby_headers_alias_impl(ctx):
2347
runtime = ctx.attr.runtime[RubyRuntimeToolchainInfo]
2448
target = runtime.headers

ruby/private/toolchain.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def _ruby_toolchain_impl(ctx):
77
ruby_runtime = RubyRuntimeToolchainInfo(
88
interpreter = ctx.attr.interpreter,
99
runtime = ctx.files.runtime,
10+
jars = ctx.attr.jars,
1011
headers = ctx.attr.headers,
1112
rubyopt = ctx.attr.rubyopt,
1213
),
@@ -27,6 +28,11 @@ _ruby_toolchain = rule(
2728
allow_files = True,
2829
cfg = "target",
2930
),
31+
"jars": attr.label(
32+
mandatory = True,
33+
allow_files = True,
34+
cfg = "target",
35+
),
3036
"headers": attr.label(
3137
mandatory = True,
3238
allow_files = True,
@@ -42,6 +48,7 @@ def ruby_toolchain(
4248
name,
4349
interpreter,
4450
runtime,
51+
jars,
4552
headers,
4653
rubyopt = [],
4754
rules_ruby_workspace = RULES_RUBY_WORKSPACE_NAME,
@@ -51,6 +58,7 @@ def ruby_toolchain(
5158
name = impl_name,
5259
interpreter = interpreter,
5360
runtime = runtime,
61+
jars = jars,
5462
headers = headers,
5563
rubyopt = rubyopt,
5664
)

ruby/private/toolchains/ruby_runtime.bzl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ cc_library(
2929
includes = [],
3030
)
3131
32+
java_binary(
33+
name = "dummy_jar"
34+
srcs = ["Dummy.java"],
35+
)
36+
37+
filegroup(
38+
name = "jars",
39+
srcs = [":dummy_jar"],
40+
)
41+
3242
filegroup(
3343
name = "runtime",
3444
srcs = [],
@@ -46,6 +56,7 @@ ruby_toolchain(
4656
interpreter = "//:ruby_bin",
4757
rules_ruby_workspace = "{rules_ruby_workspace}",
4858
runtime = "//:runtime",
59+
jars = "//:jars",
4960
headers = "//:headers",
5061
target_settings = [
5162
"{rules_ruby_workspace}//ruby/runtime:{setting}"
@@ -74,6 +85,16 @@ cc_library(
7485
includes = {includes},
7586
)
7687
88+
java_library(
89+
name = "dummy_jar",
90+
srcs = ["Dummy.java"],
91+
)
92+
93+
filegroup(
94+
name = "jars",
95+
srcs = {jars},
96+
)
97+
7798
filegroup(
7899
name = "runtime",
79100
srcs = glob(
@@ -86,6 +107,13 @@ filegroup(
86107
)
87108
"""
88109

110+
# Define a dummy java file for creating a no-op jar when JRuby isn't selected.
111+
_dummy_jar = """
112+
public class Dummy {
113+
public static void main(String[] args) {}
114+
}
115+
"""
116+
89117
_bundle_bzl = """
90118
load("{rules_ruby_workspace}//ruby/private/bundle:def.bzl", "ruby_bundle_impl")
91119
load("{rules_ruby_workspace}//ruby/private:constants.bzl", "BUNDLE_ATTRS")
@@ -244,6 +272,8 @@ def _ruby_runtime_impl(ctx):
244272
if not interpreter_path or not interpreter_path.exists:
245273
fail("Installation of ruby version %s failed")
246274

275+
ctx.file("Dummy.java", _dummy_jar)
276+
247277
if interpreter_path and interpreter_path.exists:
248278
ruby = ruby_repository_context(ctx, interpreter_path)
249279
installed = _install_ruby(ctx, ruby)
@@ -252,6 +282,7 @@ def _ruby_runtime_impl(ctx):
252282
toolchain = _toolchain.format(
253283
includes = repr(installed.includedirs),
254284
hdrs = repr(["%s/**/*.h" % path for path in installed.includedirs]),
285+
jars = "glob([\"**/lib/jruby.jar\"])" if ruby_impl == "jruby" else [":dummy_jar"],
255286
static_library = repr(installed.static_library),
256287
shared_library = repr(installed.shared_library),
257288
rules_ruby_workspace = RULES_RUBY_WORKSPACE_NAME,

ruby/runtime/BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ load(
1111
"@rules_ruby//ruby/private:runtime_alias.bzl",
1212
_ruby_headers_alias = "ruby_headers_alias",
1313
_ruby_interpreter_alias = "ruby_interpreter_alias",
14+
_ruby_jars_alias = "ruby_jars_alias",
1415
_ruby_runtime_alias = "ruby_runtime_alias",
1516
)
1617

@@ -25,6 +26,11 @@ _ruby_runtime_alias(
2526
name = "runtime",
2627
)
2728

29+
_ruby_jars_alias(
30+
name = "jars",
31+
runtime = ":runtime",
32+
)
33+
2834
_ruby_headers_alias(
2935
name = "headers",
3036
runtime = ":runtime",

0 commit comments

Comments
 (0)