-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Windows: Bash-less alternative for genrule #7503
Comments
To avoid repeating the same mistake we did with Bash about assuming that certain tools are always installed with Bash (e.g. zip, grep, tar, perl), (#5265), the rule should:
I don't know PowerShell enough to draw are constraints about what the rule could assume is available and what isn't. Maybe someone with more expertise could chime in on this. |
This rule runs a cmd.exe or Bash command. See bazelbuild/bazel#7503
The macro select()s the 'shell' (and more) attributes on host platform. Example use: shell_actions( name = "foo", cmd_cmd = "copy /Y %SA_IN% %SA_OUT%", bash_cmd = "cp -f $SA_IN $SA_OUT", ... ) See bazelbuild/bazel#7503
We can provide a simple rule in skylib: exec_cmd(
name = "x",
tool = "//pkg:binary_to_run",
args = ["-a", "-o", "$(location output_file)"],
outputs = ["output_file", "logs"],
stdout = "file_that_will_contain_stdout",
stderr = "file_that_will_contain_stderr",
] It executes a command, we can specify arguments, and we can save stdout and/or stderr to an output file. This should be able to replace many basic uses of genrule, right? And we can support this on all platforms. |
Yes, that's a great idea! I'm also planning to add |
Progress!
Still missing: some genrule-like Starlark rule that (a) needs no Bash, and (b) can run something in cmd.exe or PowerShell |
We can also consider Buck's solution: They have |
@meteorcloudy : Interesting idea (and nice documentation!) but do you know the reason for a common fallback attribute? Bash and Cmd syntax is so different, there's hardly any command that works exactly the same for both. (The only example I can think of is |
The clear priority of |
How about we have only two attributes, |
Interesting. WDYT about |
The logic sounds ideal to me, but do we want to add |
It is the same. It's just a question of naming. "cmd" might mean either "command" or "cmd.exe", so calling a bash command "cmd" next to a cmd.exe command called "cmd_exe" would be more confusing than calling the bash command "cmd_bash". |
Yeah, that makes sense. I guess that's why Buck has both |
Removing "Bazel 1.0" label:
|
Hmm, I prefer to keep the 1.0 label. I already have a change to add |
Oh OK! |
Is it really important to add them to genrule? I wonder if we can steer users away from genrule instead, and promote simpler, Stalark-based alternatives. |
I think adding them to genrule will make it easier for users to migrate away from Bash. Because
Why would a Starlark based "genrule" be better than the native genrule? |
We're moving the native rules to Starlark. As genrule is complex (it also has differences between its version inside Google and outside), I wonder if we should add more features to it. For example, Laszló wrote run_binary. This is simpler and cross-platform, although it addresses only the most simple cases. Creating a new rule can allow us to simplify the design. We can also rename No strong feelings, go ahead if it's better for you. |
Thanks for explaining! I think the Starlark rules like run_binary is very useful under certain situations, but they still cannot replace genrule in many cases and they have a very different interface compared to genrule. So I think, in order to provide a nicer experiences for our users, I'm willing to add a bit complexity to the existing rule and take on any maintenance or migration work when nedded. :) |
Extract language specific functions to an interface. Working towards: bazelbuild#7503
Related #7503 RELNOTES[NEW]: Genrule now supports `cmd_bash`, `cmd_ps`, `cmd_bat` attributes. More details at https://docs.bazel.build/versions/master/be/general.html#genrule.cmd PiperOrigin-RevId: 261660849
Extract language specific functions to an interface. Working towards: bazelbuild/bazel#7503 Closes #9022. PiperOrigin-RevId: 260910470
Description of the problem / feature request:
Provide a genrule implementation (or a similar rule) that does not use Bash, but uses Cmd or PowerShell instead.
Feature requests: what underlying problem are you trying to solve with this feature?
Goal: a genrule-like rule that supports simple shell actions (e.g. copy files, run programs on inputs to produce outputs, etc.) without having to install any extra shell (i.e. should work on a clean Win10 installation).
This is part of the effort to cut Bazel's Bash dependency (#4319).
What operating system are you running Bazel on?
Windows 10
What's the output of
bazel info release
?0.22.0
Have you found anything relevant by searching the web?
maprule() contains most of the necessary logic for this: https://github.com/bazelbuild/bazel-skylib/blob/master/rules/maprule.bzl
The text was updated successfully, but these errors were encountered: