Skip to content

fix: resolve portable Ruby dist path at action time and mark repo reproducible - #435

Merged
p0deje merged 4 commits into
bazel-contrib:mainfrom
TrapsterDK:fix/portable-ruby-reproducible
Nov 15, 2026
Merged

p0deje merged 4 commits into
bazel-contrib:mainfrom
TrapsterDK:fix/portable-ruby-reproducible

Conversation

@TrapsterDK

@TrapsterDK TrapsterDK commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #414.

Portable Ruby wrote BUNDLE_BUILD__PSYCH and BUNDLE_BUILD__OPENSSL with an absolute path to its dist directory. This made the repository machine-specific, embedded output_base paths in rb_binary/rb_test launchers, and did not work with remote execution (see the removed # TODO: This won't work on RBE).

Changes:

  • rb_download stores the options in a new rb_toolchain attribute, bundle_build_env, with paths relative to the repository (--with-libyaml-dir=dist).
  • rb_bundle_install and rb_gem_install make the path absolute in their scripts with $PWD/<toolchain root>/dist. This happens on the machine that runs the action, so it also works on RBE. User env still wins. Windows is unaffected.
  • For portable Ruby with an explicit platform and a sha256-pinned archive, rb_download now returns repo_metadata(reproducible = True), so Bazel 8.3+ can reuse the toolchain from the repository cache. Guarded with hasattr for older Bazel. A host-detected platform, an unpinned download, system Ruby, JRuby, TruffleRuby and Windows are not marked.
  • Regression test: examples/gem launcher_env_check_test fails if the rb_binary launcher contains BUNDLE_BUILD__PSYCH, BUNDLE_BUILD__OPENSSL or an absolute --with-*-dir=. Verified it fails on main (71164b0) and passes with this change.

Behavior change: rb_binary and rb_test no longer have BUNDLE_BUILD__PSYCH and BUNDLE_BUILD__OPENSSL in their runtime environment. Only the rules that compile native extensions set them.

Testing:

  • bazel test --ignore_dev_dependency //ruby/tests:all: 10 of 10 pass (run on the draft base 14e9863; no touched file changed upstream since). New tests: download_tests, utils_tests.
  • examples/gem: bazel test //:launcher_env_check_test passes. psych 5.3.1 built with --incompatible_strict_action_env on remote execution in the earlier run.
  • Not re-run on the final commit because the local Bazel runs timed out here: bazel run :buildifier.check, the full //ruby/tests:all, and the full examples/gem build .../test .... CI will cover them.

Assisted by Claude.

…roducible

The portable Ruby repository wrote BUNDLE_BUILD__PSYCH and
BUNDLE_BUILD__OPENSSL with an absolute path to its dist/ directory.
That made the repository machine-specific and broke on remote execution.

The repository now records the options with paths relative to the
repository (rb_toolchain.bundle_build_env). rb_bundle_install and
rb_gem_install make them absolute with $PWD when the action runs.
With no absolute path left, portable Ruby returns
repo_metadata(reproducible = True) so Bazel can reuse it from the
repository cache.
@thejesh23

Copy link
Copy Markdown

reproducible = True is set for any non-Windows portable Ruby, but the repo contents depend on the host platform and a missing sha256 isn't checked, so a cached repo from one host could be reused on another. From the diff only.

… explicit

A host-detected platform or a download without a sha256 made the
repository depend on the host or on the remote file, so it must not be
reused from the repository contents cache. is_reproducible now also
requires the platform attribute and the sha256 the archive was verified
against.

Assisted-by: Claude
@TrapsterDK

Copy link
Copy Markdown
Contributor Author

Thanks, real. A host-detected platform or a download without a sha256 could have been reused from the repo contents cache. Fixed in 46d5cea: is_reproducible now also requires the platform attribute to be set and the sha256 the archive was verified against. rb_register_toolchains sets platform for portable Ruby when the version is known, so the common case stays cacheable. Unit tests cover both new cases; //ruby/tests:all and buildifier.check pass.

Assisted by Claude.

Comment thread ruby/private/download.bzl Outdated
"""
if not portable_ruby or is_windows_target or not platform or not sha256:
return False
if version == "system" or version.startswith("jruby") or version.startswith("truffleruby"):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jruby should be reproducible as it's fully supported on RBE

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. 062a984 makes JRuby reproducible whenever its sha256 is pinned, regardless of portable_ruby or platform. It also copies the .cmd wrappers instead of symlinking them, because a symlink would point to an absolute path. I updated the unit tests, and bazel test //ruby/tests/... passes (10/10). A real JRuby download did not finish locally, so that part is untested.

Assisted by Claude.

TruffleRuby on macOS legitimately records Homebrew prefixes as
BUNDLE_BUILD__* options, which made the check fail there.

Assisted-by: Claude
JRuby's archive is the same on every platform and is verified against a
pinned sha256, so it no longer depends on portable_ruby or platform. The
Windows .cmd wrappers are copied instead of symlinked, as a symlink
points to an absolute path.

Assisted-by: Claude
@TrapsterDK

Copy link
Copy Markdown
Contributor Author

The Examples / Gem (truffleruby-40.0.0, macos-latest) failure was real. Main passes (https://github.com/bazel-contrib/rules_ruby/actions/runs/43347743666), but this PR's own launcher_env_check_test failed, because TruffleRuby legitimately embeds Homebrew prefixes. f9789de narrows that check to absolute dist/ paths. Both commits are pushed, so please check the new CI run.

Assisted by Claude.

@p0deje
p0deje merged commit 27a7c9f into bazel-contrib:main Nov 15, 2026
67 of 68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rb_binary/rb_test launchers embed output_base paths when portable_ruby = True

3 participants