Search code examples
bazelhaxe

Bazel giving "open_proc" error 21 running embedded command


I'm working on creating a Bazel extension for Haxe and while I've had some initial success in getting things to build, I've hit a roadblock and I'm not sure what the right way around it is.

In Haxe if you declare a dependency on a Haxelib in your build.hxml file, when you perform the build the Haxe compiler will go grab that Haxelib from the internet and install it locally if you don't already have it, using a program named "haxelib". It seems that this process is being blocked by the Bazel sandbox, but I haven't been able to find much documentation on how the sandboxing works, if this is expected, and if there's a way around it. I'm currently working in Windows 10; this is the error that I'm getting:

$ bazel build //:neko-lib --verbose_failures
INFO: Analyzed target //:neko-lib (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: D:/repo/validation/BUILD:3:13: HaxeCompile neko/validation.n failed (Exit 1): haxe.exe failed: error executing command
  cd C:/users/user/_bazel_user/s6xipia4/execroot/__main__
  external/haxe_windows_amd64/haxe.exe bazel-out/x64_windows-fastbuild/bin/build.hxml
Execution platform: @local_config_platform//:host
Unix.Unix_error(21, "open_proc", "haxelib path hx3compat")
Target //:neko-lib failed to build
INFO: Elapsed time: 1.705s, Critical Path: 0.62s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

hx3compat is the name of the haxelibthat I'm trying to load. Error 21 seems to be "is a directory" but I'm not exactly sure what's actually being complained about. Here's the run action that I'm using:

ctx.actions.run(
    outputs = [out],
    inputs = inputs,
    executable = haxe_cmd,
    arguments = [args],
    env = env,
    mnemonic = "HaxeCompile",
)

haxe_cmd points the haxe.exe file, while the inputs are:

  • bazel-out/x64_windows-fastbuild/bin/build.hxml (the build file I'm building)
  • external/haxe_windows_amd64/haxe.exe
  • external/haxe_windows_amd64/haxelib.exe

Any ideas on things I can try to get around this issue?

Update: I wrote a rule today that runs the command in question (haxelib path hx3compat) and that works, so I think this is an error with invoking that command - not with the command itself.


Solution

  • The particular error that I was getting - Unix error 21 - was caused by the shell that Bazel creates not having the COMSPEC environment variable: see here and here for more details. Adding that variable to the environment via the --action_env=COMSPEC command line got me past that error. However the command shell that gets spawned by the Haxe process cannot handle symlinks, and so has a lot of trouble trying to access the directories brought in by Bazel, so I think using haxe via this route will end up being a lost cause. Just for the record though, I was able to get the haxelib command itself to run through the haxe process, so the answer for this question is to ensure the COMSPEC variable is set.