Skip to content

Commit 04eeb22

Browse files
committed
Stop bundling unnecessary host runtime into container images
1 parent 031b30e commit 04eeb22

4 files changed

Lines changed: 16 additions & 12 deletions

File tree

ruby/private/BUILD.host_runtime.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ruby_toolchain(
1414
"-I$(RUNFILES_DIR)/org_ruby_lang_ruby_host/bundler/lib",
1515
],
1616
runtime = "//:runtime",
17+
is_host = True,
1718
rules_ruby_workspace = "{rules_ruby_workspace}",
1819
# TODO(yugui) Extract platform info from RbConfig
1920
# exec_compatible_with = [],

ruby/private/binary.bzl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,18 @@ def _ruby_binary_impl(ctx):
2929
"main",
3030
)
3131

32+
if sdk.is_host:
33+
interpreter_file_deps = []
34+
interpreter_trans_deps = []
35+
else:
36+
interpreter_file_deps = [interpreter]
37+
interpreter_trans_deps = [sdk.interpreter]
38+
3239
executable = ctx.actions.declare_file(ctx.attr.name)
3340
deps = _transitive_deps(
3441
ctx,
35-
extra_files = [interpreter, executable],
36-
extra_deps = [sdk.interpreter],
42+
extra_files = interpreter_file_deps + [executable],
43+
extra_deps = interpreter_trans_deps,
3744
)
3845

3946
rubyopt = reversed(deps.rubyopt.to_list())

ruby/private/host_runtime.bzl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ def _install_host_ruby(ctx, ruby):
5252
},
5353
)
5454

55-
# Install lib
56-
paths, rel_paths = _list_libdirs(ruby)
57-
for i, (path, rel_path) in enumerate(zip(paths, rel_paths)):
58-
if not _is_subpath(rel_path, rel_paths[:i]):
59-
ctx.symlink(path, rel_path)
60-
6155
# Install libruby
6256
static_library = ruby.expand_rbconfig(ruby, "${libdir}/${LIBRUBY_A}")
6357
if ctx.path(static_library).exists:
@@ -73,7 +67,6 @@ def _install_host_ruby(ctx, ruby):
7367

7468
return struct(
7569
includedirs = _install_dirs(ctx, ruby, "rubyarchhdrdir", "rubyhdrdir"),
76-
libdirs = rel_paths,
7770
static_library = _relativate(static_library),
7871
shared_library = _relativate(shared_library),
7972
)
@@ -104,8 +97,6 @@ def _ruby_host_runtime_impl(ctx):
10497
"BUILD.bazel",
10598
ctx.attr._buildfile_template,
10699
substitutions = {
107-
"{ruby_path}": repr(ruby.rel_interpreter_path),
108-
"{ruby_basename}": repr(ruby.interpreter_name),
109100
"{includes}": repr(installed.includedirs),
110101
"{hdrs}": repr(["%s/**/*.h" % path for path in installed.includedirs]),
111102
"{static_library}": repr(installed.static_library),

ruby/private/toolchain.bzl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ RubyRuntimeInfo = provider(
77
"bundler": "A label which points bundler command",
88
"runtime": "A list of labels which points runtime libraries",
99
"rubyopt": "A list of strings which should be passed to the interpreter as command line options",
10+
"is_host": "True only if the runtime is the host ruby ",
1011
},
1112
)
1213

@@ -17,6 +18,7 @@ def _ruby_toolchain_impl(ctx):
1718
bundler = ctx.attr.bundler,
1819
runtime = ctx.files.runtime,
1920
rubyopt = ctx.attr.rubyopt,
21+
is_host = ctx.attr.is_host,
2022
),
2123
)]
2224

@@ -43,6 +45,7 @@ _ruby_toolchain = rule(
4345
"rubyopt": attr.string_list(
4446
default = [],
4547
),
48+
"is_host": attr.bool(default = False),
4649
},
4750
)
4851

@@ -52,15 +55,17 @@ def ruby_toolchain(
5255
bundler,
5356
runtime,
5457
rubyopt = [],
58+
is_host = False,
5559
rules_ruby_workspace = RULES_RUBY_WORKSPACE_NAME,
5660
**kwargs):
5761
impl_name = name + "_sdk"
5862
_ruby_toolchain(
5963
name = impl_name,
6064
interpreter = interpreter,
6165
bundler = bundler,
62-
rubyopt = rubyopt,
6366
runtime = runtime,
67+
rubyopt = rubyopt,
68+
is_host = is_host,
6469
)
6570

6671
native.toolchain(

0 commit comments

Comments
 (0)