Skip to content

feat(js_run_binary): add support for path mapping - #2962

Merged
acozzette merged 21 commits into
mainfrom
path-mapping
Aug 4, 2026
Merged

feat(js_run_binary): add support for path mapping#2962
acozzette merged 21 commits into
mainfrom
path-mapping

Conversation

@acozzette

@acozzette acozzette commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

This change adds support for path mapping in js_run_binary by updating it to use the new --bazel-bindir flag instead of setting the BAZEL_BINDIR environment variable. The only mechanism Bazel provides for determining path-mapped paths is by adding inputs directly to an Args object from ctx.actions.args(). We can now compute the output Bazel bin directory that way using a special case added to run_binary() for this purpose in bazel-contrib/bazel-lib#1269.

The js_run_binary macro currently sets several other problematic environment variables: BAZEL_BUILD_FILE_PATH, BAZEL_COMPILATION_MODE, BAZEL_TARGET_CPU, BAZEL_TARGET, BAZEL_WORKSPACE, BAZEL_PACKAGE, and BAZEL_TARGET_NAME. Most of these are determined by evaluating Make variables, and run_binary conservatively assumes that path mapping is not safe if any location or Make variable expansion occurs. This change guards those variables behind a new set_legacy_environment_variables parameter (default True) so they can be disabled without a breaking change, ahead of flipping the default in a future release. To enable path mapping on a particular js_run_binary target, make sure to set this parameter to False.


Changes are visible to end-users: yes

  • Searched for relevant documentation and updated as needed: yes
  • Breaking change (forces users to change their own code or config): no
  • Suggested release notes appear below: yes

Support for path mapping in js_run_binary

Test plan

  • Covered by existing test cases
  • New test cases added

@acozzette
acozzette marked this pull request as ready for review August 1, 2026 23:27
@acozzette
acozzette requested a review from jbedard August 1, 2026 23:27
Comment thread js/private/js_run_binary.bzl
Comment thread js/private/js_run_binary.bzl Outdated
Comment thread js/private/js_run_binary.bzl
acozzette and others added 15 commits August 3, 2026 16:04
This change adds support for path mapping in `js_run_binary` by updating it to
use the new `--bazel-bindir` flag instead of setting the `BAZEL_BINDIR`
environment variable. The only mechanism Bazel provides for determining
path-mapped paths is by adding inputs directly to an `Args` object from
`ctx.actions.args()`. We can now compute the output Bazel bin directory that
way using a special case added to `run_binary()` for this purpose in
bazel-contrib/bazel-lib#1269.

The `js_run_binary` macro currently sets several other problematic environment
variables: BAZEL_BUILD_FILE_PATH, BAZEL_COMPILATION_MODE, BAZEL_TARGET_CPU,
BAZEL_TARGET, and BAZEL_WORKSPACE. These are determined by evaluating Make
variables, and `run_binary` conservatively assumes that path mapping is not
safe if any location or Make variable expansion occurs. This change deprecates
these variables and adds a `set_legacy_environment_variables` parameter
(default `True`) so they can be disabled without a breaking change, ahead of
flipping the default in a future release. To enable path mapping on a
particular `js_run_binary` target, make sure to set this parameter to `False`.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Verify these js_run_binary env vars, now computed directly in the macro
instead of via Make-variable substitution, are correct when the
js_run_binary target lives in a module other than the main one.
The expected BAZEL_TARGET value hardcoded the canonical repo name's
separator ("workspace+"), which differs across Bazel versions
("workspace~" on Bazel 7, "workspace+" on Bazel 9+), causing the test
to fail under Bazel 7.7.1. Derive it via repo_name() instead.
…t_variables

All seven js_run_binary-provided BAZEL_* env vars are now gated behind
the same flag, for consistency.
Comment thread js/private/js_run_binary.bzl
Comment thread js/private/js_run_binary.bzl Outdated
Comment thread js/private/js_run_binary.bzl Outdated
Comment thread js/private/js_run_binary.bzl
@jbedard
jbedard requested a review from thesayyn August 4, 2026 19:57
Comment thread js/private/js_run_binary.bzl
@acozzette
acozzette merged commit 90bab55 into main Aug 4, 2026
182 checks passed
@acozzette
acozzette deleted the path-mapping branch August 4, 2026 22:20
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.

3 participants