Repository navigation
Conversation
The `env` tag attribute only accepts static strings, and `load()` is not allowed in MODULE.bazel, so machine-resolved values (e.g. a toolchain selected via a generated repository) cannot reach the generated rb_bundle_install action. Add an optional `env_bzl` label whose exported `bundle_env` dict is loaded into the generated BUILD and merged with `env`, resolved at BUILD-evaluation time so values participate in the action cache key. Upstream: bazel-contrib#432
acecilia
force-pushed
the
feat/bundle-fetch-env-bzl
branch
from
October 27, 2026 20:30
6def310 to
3f9e477
Compare
acecilia
marked this pull request as draft
October 27, 2026 20:43
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.
Problem
rb_bundle_installcompiles native gem extensions (json, prism, ffi, ...) with toolchains resolved from the environment (e.g. on macOSmkmfresolves clang and the SDK throughxcrun). Consumers that need to control that selection face two dead ends:MODULE.bazelvalues must be static strings, andload()is not allowed inMODULE.bazel, so machine-resolved env (e.g.DEVELOPER_DIRpointing at the Xcode a project pins, or values exposed by a generated repository) cannot reach the install action.Solution
Optional
env_bzllabel attr on thebundle_fetchtag. The generatedBUILDof the bundle repository loads it as a dict namedbundle_envand merges it with the staticenv:Real-world example of the referenced
//Bazel/dependencies:ruby_bundle_env.bzl, from a large consumer repo. The@developer_dirrepository is generated by a repository rule that resolves the Xcode pinned by the project (same mechanism the repo uses to select the Xcode for all its Apple builds), so the bundle install compiles native extensions with the project's Xcode:Because the load happens at BUILD-evaluation time:
rb_bundle_installaction, so a change of e.g. toolchain selection re-runs the install (and per-machine values keep remote caches from sharing entries across differently-provisioned hosts).This intentionally does not couple rules_ruby to any platform toolchain (e.g. apple_support): each consumer injects its own policy.
Testing
Validated end-to-end in the consumer repo above:
DEVELOPER_DIR(resolved from a repository that picks the pinned Xcode) is present in the generatedbundle_install_*.sh(verified viabazel aquery), and changing the value invalidates and re-runs the bundle install action.