keith / rules_multirun

Bazel rules for running multiple commands in parallel in a single bazel invocation
Apache License 2.0
65 stars 13 forks source link

Error running on windows #56

Open peakschris opened 2 weeks ago

peakschris commented 2 weeks ago

I'm seeing an error in latest rules_lint, which I believe uses multirun 0.9.0 for its format module:

(.venv) d:\workdir\rules_lint3\example>bazel run :format
Starting local Bazel server and connecting to it...
INFO: Analyzed target //:format (95 packages loaded, 4998 targets configured).
INFO: Found 1 target...
Target //tools/format:format_windows up-to-date:
  bazel-bin/tools/format/format_windows.bash
INFO: Elapsed time: 125.916s, Critical Path: 6.10s
INFO: 11 processes: 10 internal, 1 local.
INFO: Build completed successfully, 11 total actions
INFO: Running command line: bazel-bin/tools/format/format_windows.bash
FATAL: ExecuteProgram(D:\udu\b\l2x2bhay\execroot\_main\bazel-out\x64_windows-fastbuild\bin\tools\format\format_windows.bash) failed: ERROR: src/main/native/windows/process.cc(202): CreateProcessW("D:\b\l2x2bhay\execroot\_main\bazel-out\x64_windows-fastbuild\bin\tools\format\format_windows.bash"): %1 is not a valid Win32 application.
 (error: 193)

This surprises me because at a glance it looks like rules_multirun invokes bash scripts with the bash executable.

Do you have any hints? Thanks!

peakschris commented 2 weeks ago

I'm also seeing this in rules_multirun directly:

rules_multirun\tests>bazel run //tests:multirun_parallel

INFO: Invocation ID: e556a35b-abf7-46f2-83c7-9e666d412545
INFO: Analyzed target //tests:multirun_parallel (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //tests:multirun_parallel up-to-date:
  bazel-bin/tests/multirun_parallel.bash
INFO: Elapsed time: 14.723s, Critical Path: 14.12s
INFO: 2 processes: 1 internal, 1 local.
INFO: Build completed successfully, 2 total actions
INFO: Running command line: bazel-bin/tests/multirun_parallel.bash
FATAL: ExecuteProgram(D:\udu\b\a7g3pybb\execroot\_main\bazel-out\x64_windows-fastbuild\bin\tests\multirun_parallel.bash) failed: ERROR: src/main/native/windows/process.cc(202): CreateProcessW("D:\udu\b\a7g3pybb\execroot\_main\bazel-out\x64_windows-fastbuild\bin\tests\multirun_parallel.bash"): %1 is not a valid Win32 application.
 (error: 193)

I have an env up and running; if you can share some ideas, I can try them out

keith commented 2 weeks ago

I wonder if the issue is we need to be naming something with .exe at the end here? Or is it that we need to be calling bash.exe path/to/foo.bash?

peakschris commented 2 weeks ago

I did some digging. Seems that ctx.runfiles don't work with bash scripts on windows. There is prior art in aspect bazel-lib, which has a tool that wraps a bash in a bat. I hacked this into an fix here: https://github.com/keith/rules_multirun/compare/main...peakschris:rules_multirun:windows

But it all seems over-complex; all you are doing is launching the initial py_binary script. I wonder if there is a more modern canonical way to launch that works on all platforms?

@alexeagle, do you have any ideas?

peakschris commented 2 weeks ago

My fix isn't quite there yet, I'm still getting errors:

d:\workdir\rules_lint3\example>bazel run :format
INFO: Running command line: bazel-bin/tools/format/format_windows.bash.bat
**xargs: environment is too large for exec**
Formatted C++ in 0m0.206s
FAILED: A formatter tool exited with code 1