-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow starlark rules to pass --run_under
to executables
#16232
Comments
@fmeum wondering if you have thoughts on this one. Could this be handled similar to the proposal for
Additionally, the |
I'm not familiar enough with Would your proposal work with both simple commands and Bazel targets passed in as |
Today I have the def _rust_test_impl(ctx):
test_binary = rust_common.compile(
ctx,
# ...
)
return DefaultInfo(
files = depset([test_binary]),
executable = test_binary,
)
rust_test(
test = True,
_implementation = _rust_test_impl,
# ...
) The way this is written, I'm able to run a similar command to the following to start the test and attach a debugger to the test binary.
This works because the argv for the test roughly looks like def _rust_test_impl(ctx):
test_binary = rust_common.compile(
ctx,
# ...
)
# Note the creation of process wrapper here.
process_wrapper = _create_rust_test_process_wrapper(
ctx,
# ...
)
return [
DefaultInfo(
files = depset([test_binary]),
runfiles = ctx.runfiles(files=[test_binary])
# Note that the process wrapper is the executable
executable = process_wrapper,
),
RunEnvironmentInfo(
arguments=[test_binary.short_path],
),
]
rust_test(
test = True,
_implementation = _rust_test_impl,
# ...
) This then breaks the use of def _rust_test_impl(ctx):
test_binary = rust_common.compile(
ctx,
# ...
)
process_wrapper = _create_rust_test_process_wrapper(
ctx,
# ...
)
# This is not the proposed way to acess --run_under, just an example to demonstrate it's use
run_under = ctx.var.get("RUN_UNDER", "")
return [
DefaultInfo(
files = depset([test_binary]),
runfiles = ctx.runfiles(files=[test_binary])
executable = process_wrapper,
),
RunEnvironmentInfo(
environment={
"RUST_TEST_RUN_UNDER": run_under,
}
arguments=[test_binary.short_path],
# Note that this prevents the command line argument for --run_under from being passed to the
# process wrapper. The process wrapper instead is aware of the uniquely named environment variable
# RUST_TEST_RUN_UNDER and would be able to use the value there to correctly invoke the `test_binary`
# created in this rule.
run_under="",
),
]
rust_test(
test = True,
_implementation = _rust_test_impl,
# ...
) Does this provide some clarity? |
Thanks for the extensive example, that definitely helped. It looks like a much simpler API may suffice for this use case: Adding a @UebelAndre Does that sound sufficient? It would get around the potentially problematic analysis time access to the |
Yeah, great idea! This particular feature would help immensely in the developer workflow story for many projects I work on. |
Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale. |
This is still desired. |
Description of the feature request:
I would like to be able to intercept the --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, executables are the compiled Rust binary which allows me to pass
--run_under
and start a debugger (see bazelbuild/rules_rust#370 (comment)). However, there's some interest in being able to instead generate a process wrapper that would subprocess or exec into the compiled executable (bazelbuild/rules_rust#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
returnsdevelopment 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
The text was updated successfully, but these errors were encountered: