bazelbuild / bazelbuild/bazel

Allow starlark rules to pass `--run_under` to executables

Open
#16,232 12 comments 2 reactions 0 assignees View on GitHub
P4 team-Rules-API type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the feature request:

I would like to be able to intercept the [--run_under](https://bazel.build/reference/command-line-reference#flag--run_under) flag in a starlark rule to be able to pass it as an environment variable or argument to a test or action to have better control over when it's used. In [rules_rust](https://github.com/bazelbuild/rules_rust), executables are the compiled Rust binary which allows me to pass `--run_under` and start a debugger (see https://github.com/bazelbuild/rules_rust/issues/370#issuecomment-796592288). However, there's some interest in being able to instead generate a process wrapper that would subprocess or exec into the compiled executable (https://github.com/bazelbuild/rules_rust/issues/1303). If this were to be the case, the current use case of `--run_under` would break as the thing being executed by `--run_under` is a process wrapper. I want to be able to use process wrappers and maintain the intent of `--run_under` being run on the correct executable and not a process wrapper.

### What underlying problem are you trying to solve with this feature?

By being able to control when `--run_under` is used, rules authors would be able to more accurately translate the intent of `--run_under` to run the correct executable under the specified command while still handling ephemeral things the process may emit (coverage or profiling reports, etc).

### Which operating system are you running Bazel on?

Linux, MacOS, Windows

### What is the output of `bazel info release`?

release 5.3.0

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse master; git rev-parse HEAD` ?

_No response_

### Have you found anything relevant by searching the web?

_No response_

### Any other information, logs, or outputs that you want to share?

_No response_

Contributor guide

Open the contributing guide

Research direction

No implementation files or tests are named. Start with Bazel's --run_under command-line behavior and the Starlark rule and action entry points, then review the linked rules_rust discussions; done means rules can receive the intended value while preserving correct executable and process-wrapper behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.