feat: add extra_args passthrough to bundle install - #394
Open
DhashS wants to merge 4 commits into
Open
Conversation
Threads extra command-line arguments to `bundle install` from the
`ruby.bundle_fetch` bzlmod tag / `rb_bundle_fetch` repo rule / `rb_bundle_install`
rule down onto the install command line.
Primary use case: cross-platform bundles. With bundler's `--target-rbconfig`
(RubyGems 3.4+ / Gem::TargetRbConfig), the host ruby can install a DIFFERENT
platform's precompiled gems — e.g. assembling an x86_64-linux vendor/bundle on
an arm64-darwin host for a container image layer, without a linux executor:
ruby.bundle_fetch(
name = "bundle",
gemfile = "//:Gemfile",
gemfile_lock = "//:Gemfile.lock",
extra_args = ["--target-rbconfig", "/path/to/linux/rbconfig.rb"],
)
Covers both the bzlmod and WORKSPACE paths (shared rb_bundle_fetch repo rule)
and the standalone rb_bundle_install rule.
extra_args now supports $(location)/$(rootpath)/$(execpath) make-variable
expansion (built-in ctx.expand_location) against a new `data` label_list, which
is also threaded as inputs to the bundle install action. This lets a file-valued
flag reference a target instead of a raw path:
ruby.bundle_fetch(
name = "bundle_linux_amd64",
gemfile = "//:Gemfile",
gemfile_lock = "//:Gemfile.lock",
data = ["//image:x86_64-linux-rbconfig.rb"],
extra_args = ["--target-rbconfig", "$(location //image:x86_64-linux-rbconfig.rb)"],
)
Threaded through the bzlmod tag, repo rule, generated BUILD, and install rule.
Adds a public dist_files filegroup (glob dist/**/*) to each per-platform ruby repo, aliased on the @ruby hub. Lets you package the interpreter into a container image (portable-ruby is relocatable), e.g.: pkg_tar(name = "ruby_runtime", srcs = ["@ruby//:dist_files"], package_dir = "/usr/local", strip_prefix = "dist")
Adds the pieces needed to install a bundle for a FOREIGN platform (e.g. build a linux gems layer from a macOS host via --target-rbconfig) and package it into a container image: * env values now support $(location ...)/$(execpath ...) expansion against `data` (mirrors extra_args) — lets an env var reference a build artifact, e.g. prepend a generated cross-compiler wrapper dir onto PATH. * new `rbconfig` filegroup on the ruby dist (+ hub alias): the interpreter's own relocatable rbconfig.rb, for `gem install --target-rbconfig` cross-builds. * `binstubs` attr (default True): skip `bundle binstubs --all` for cross-platform bundles, where the host ruby can't validate the target's native extensions; the (empty) binstubs dir is still materialized. * `gems` output group: just the vendor/bundle tree (no Gemfile/binstubs), so consumers can lay the gems into a container BUNDLE_PATH with a clean strip_prefix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an
extra_argsattribute that appends extra command-line arguments to thebundle installinvocation, plumbed through all three entry points:ruby.bundle_fetchbzlmod tag (extensions.bzl)rb_bundle_fetchrepo rule (bundle_fetch.bzl, used by both bzlmod and WORKSPACE)rb_bundle_installrule (bundle_install.bzl)Why
Cross-platform bundles. Bundler 2.6 / RubyGems 3.4 added
bundle install --target-rbconfig=<rbconfig.rb>(Gem::TargetRbConfig), which lets the host Ruby install a different platform's precompiled gems. There's currently no way to pass that (or any other) flag throughrb_bundle_install— the command is hardcoded toinstall --standalone --local, theenvattr isn't consulted by bundler for--target-rbconfig(it's a Thor CLI option, not aBundler::Settingskey), andBUNDLE_IGNORE_CONFIG=1rules out.bundle/config.With
extra_args, an arm64-darwin host can assemble anx86_64-linuxvendor/bundlefor a container image layer without a Linux executor:(Today the documented cross-platform story is RBE via the multi-platform toolchains from #377 — this offers a complementary, executor-free path for precompiled gems.)
Verified
Threaded end-to-end: with
extra_argsset, the generated@bundle//:BUILDcarriesextra_args = [...]and the generated install script runs:Notes / open questions
extra_argsis a verbatimstring_list. For file-valued flags like--target-rbconfig, a natural follow-up is$(location)expansion + threading the file as an action input (hermetic). Happy to add that here or in a follow-up — whichever you prefer..cmdtemplate updated symmetrically.examples/if you'd like — guidance welcome on the preferred shape.🤖 Generated with Claude Code