(Bazel v0.4.5 on Windows)
Summary: If you have a custom Bazel tool written in (e.g.) C++ that needs to use a temporary directory, you currently need to explicitly manage environment vars to do so.
Detail:
/tmp is writable, but since that's not a thing on Windows, the best option is generally calling Win32 GetTempPath(), or some wrapper code that ends up calling it (e.g. posix tempdir())GetTempPath() is documented as using values from env vars $TMP, $TEMP, and $USER_PROFILE; if none of those are set, it falls back to C:\WindowsC:\Windows isn't necessarily writable by user code.Workarounds:
$TMP in the env argument to your action, taking care to add select() usage to only do this on Windows hosts. Or copy it from host_configuration.default_shell_env.use_default_shell_env=True, if you can live with non-hermetic buildsMy first thought for a reasonable fix here would be for ctx.action to ensure that a reasonable value is set for $TMP when running on Windows hosts; that might have unforeseen side-effects, though (e.g. portable code that directly calls getenv("TMP") could behave different on Windows vs non-Windows hosts).
If there was a Skylark rule to return a path to a temp directory, Workaround 1 could be done more simply, via something like env={"TMP": ctx.tmp_dir()}. (Arguably, you could do this now by using ctx.genfiles_dir(), if you're certain the tool will clean up after itself...)
This is a blocker for https://github.com/bazelbuild/bazel/issues/3264, so I'm making it P1.
Duplicate of https://github.com/bazelbuild/bazel/issues/1590
Duplicate of https://github.com/bazelbuild/bazel/issues/1590.
Duplicate of https://github.com/bazelbuild/bazel/issues/2349.
@laszlocsomor the other 2 you linked are in milestone 0.6. I'm hoping strength of numbers pulls the fix for this into 0.6 rather than this pulling them into 0.7? ;)
Hang in there, I'm working on it! :)
I wrote a design that's currently under review internally.
Design is approved, I'll start implementing it this week. Stay tuned!
Most helpful comment
Hang in there, I'm working on it! :)
I wrote a design that's currently under review internally.