Skip to content

Implement runfiles for rlocation#374

Open
titusfortner wants to merge 1 commit into
bazel-contrib:mainfrom
titusfortner:runfiles
Open

Implement runfiles for rlocation#374
titusfortner wants to merge 1 commit into
bazel-contrib:mainfrom
titusfortner:runfiles

Conversation

@titusfortner
Copy link
Copy Markdown

Summary

Adds a Bazel runfiles library for Ruby (Bazel::Runfiles) and makes it available on the RUBYLIB of every rb_binary/rb_test so user code can resolve the runtime location of its data dependencies.

This mirrors the runfiles libraries shipped by other Bazel rulesets(rules_python, rules_go, etc.), giving Ruby targets a supported, cross-platform way to call rlocation instead of getting paths relative to the working directory.

I ran a test on Selenium fork with this branch and it worked as expected.

What's included

  • Bazel::Runfiles.create auto-detects the runfiles strategy from the environment (RUNFILES_MANIFEST_FILE / RUNFILES_DIR), falling back to discovery from $PROGRAM_NAME.

  • #rlocation(path) resolves a runfiles-relative path, with validation that rejects empty and non-normalized paths and passes absolute paths through unchanged.

  • Two strategies: ManifestBased (parses a MANIFEST, including the space/newline/backslash escaping convention and prefix-directory walking) and DirectoryBased (joins onto the runfiles root).

  • ruby/runfiles/BUILD — exposes the file via exports_files, an rb_library target (//ruby/runfiles:runfiles, public visibility), and an rb_test for the unit tests.

  • rb_binary integration (ruby/private/binary.bzl + launcher templates):

    • New private _runfiles_helper attribute pointing at the library, added to the binary's runfiles.
    • The .sh and .cmd launcher templates prepend the library's directory to RUBYLIB, so require 'bazel/runfiles' works out of the box.

Tests

This adds tests, but they are tagged manual because no Ruby toolchain is registered. They do pass manually.

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.

1 participant