Skip to content
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

bazel run should run in bazel env working directory #2679

Open
cosinequanon opened this issue Mar 18, 2025 · 1 comment
Open

bazel run should run in bazel env working directory #2679

cosinequanon opened this issue Mar 18, 2025 · 1 comment

Comments

@cosinequanon
Copy link

🚀 feature request

Relevant Rules

This is meant to change the behavior of py_binary

Description

Currently if you run a binary with bazel run then the working directory will be the sandboxed bazel directory. This behavior is inconsistent with other implementations, for example in rules_go it is set like this https://github.com/bazel-contrib/rules_go/blob/b60f4475e3d97431318da1a0a81752a8884e6994/go/tools/go_bin_runner/main.go#L250

Describe the solution you'd like

bazel run should use the BUILD_WORKING_DIRECTORY environment variable to set the working directory.

Describe alternatives you've considered

You can do this hack where you add --run_under="cd $PWD &&" to the command but it only works on POSIX systems and you basically have to know the trick to have the command do what you might expect

@aignas
Copy link
Collaborator

aignas commented Mar 19, 2025

This would be a big change and one cannot make such a change easily. rules_go executable is a single file and rules_python executable needs the runfiles directory. The scope of this to change the default is potentially very large and I am not sure this will get resolved easily.

One additional workaround may be to use the excellent https://github.com/buildbuddy-io/bazel_env.bzl project that can add a binary to your path using direnv, which removes the need of --run_under, but direnv does not work on Windows.

However, having hooks to change the working directory when executing might be doable and PRs for this with tests would be welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants