Workaround for #166205 similar to
51451ac406
And warning fix similar to `bazel_6` fix for
```
external/upb~0.0.0-20220923-a547704/upb/mini_table.c:634:14: error: defining a type within '__builtin_offsetof' is a Clang extension [-Werror,-Wgnu-offsetof-extensions]
UPB_ASSERT(UPB_ALIGN_OF(upb_StringView) ==
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
Fixing `bazel_4` after #234710
Error example
https://hydra.nixos.org/build/241174862/nixlog/1
```
Execution platform: //:default_host_platform
third_party/zlib/gzwrite.c:89:20: error: call to undeclared function 'write'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
writ = write(state->fd, strm->next_in, put);
^
```
Similar to #269481 and #269297
Fixing `bazel_5` after #234710
Error example
https://hydra.nixos.org/build/241240612/nixlog/1
```
external/com_google_absl/absl/meta/type_traits.h:560:8: error: builtin __has_trivial_assign is deprecated; use __is_trivially_assignable instead [-Werror,-Wdeprecated-builtins]
(__has_trivial_assign(ExtentsRemoved) || !kIsCopyOrMoveAssignable) &&
```
Similar to #269297, and remaining `bazel_4` is WIP for another PR
bazel_6 https://hydra.nixos.org/build/241090720/nixlog/1
```
external/upb/upb/upb.c:228:25: error: defining a type within '__builtin_offsetof' is a Clang extension [-Werror,-Wgnu-offsetof-extensions]
n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_Arena));
^~~~~~~~~~~~~~~~~~~~~~~
```
bazel_6 https://hydra.nixos.org/build/241127779/nixlog/1
```
In file included from external/com_google_absl/absl/algorithm/container.h:55:
external/com_google_absl/absl/meta/type_traits.h:560:8: error: builtin __has_trivial_assign is deprecated; use __is_trivially_assignable instead [-Werror,-Wdeprecated-builtins]
(__has_trivial_assign(ExtentsRemoved) || !kIsCopyOrMoveAssignable) &&
^
```
Note: `bazel_5` and `bazel_4` require more work, for some reason extra
`-Wall` in combination with `-Werror` sneaks in and overrides `-Wno-`
settings, haven't managed yet to debug where exactly are the last
flags (last one wins) come from there.
ZHF: #265948
https://hydra.nixos.org/build/240805256/nixlog/1https://hydra.nixos.org/build/240805170/nixlog/2
Failure is a bit obscured but long story short, a script within
bazel gets custom nixpkgs shebang which in turn makes shell run
in POSIX-compatible mode. Bazel expects bash in non-POSIX mode
and osx-specific script starts to fail due to `set -e` and subshell
interaction differences in those modes (sub-shells and functions
suddently start inheriting `set -e` and fail to produce desired
output). More debug info is available in #267670
Shell scripts aren't guaranteed to work as interpreters in shebang.
In particular thin shell wrappers aren't shebang-ready on MacOS.
It may work sometimes depending on what exactly would try to execute
a script with such shebang, but generally it's not guaranteed to work.
See #124556
Bash wrapper was introduced in #266847 and so far seems like the
issue only affects darwin builds: hydra failure is in osx-specific
script, also shebang issue is usually darwin-specific.
Let's wrap it as a native binary to make it shebang-compatible.
The wrapper is only currently added to `bazel_6` so no need for
changes in other versions.
ZHF: #265948
The tests started to fail after the repo-wide python 3.10 -> 3.11 update.
This is caused by Bazel's py_binary rule setting the [`PYTHONSAFEPATH`][1]
environment variable, which only has an effect for Python >= 3.11.
Setting this variable avoids prepending the current working directory and the
script's directory. The current test code relied on this behavior and thus
failed with:
```
Traceback (most recent call last):
File "/build/.cache/bazel/_bazel_build/8bcfff1c77854f2a2b07d1413b0fc106/execroot/our_workspace/bazel-out/k8-fastbuild/bin/python/bin.runfiles/our_workspace/python/bin.py", line 6, in <module>
from lib import foo
ModuleNotFoundError: No module named 'lib'
```
See also [bazelbuild/bazel#7091][2]
[1]: https://docs.python.org/3.11/using/cmdline.html#envvar-PYTHONSAFEPATH
[2]: https://github.com/bazelbuild/bazel/issues/7091
Nix's version of bazel has custom patches to make bazel more hermetic when used with nix. One of those is limiting the default
environment of Bash. However, this default environment is insufficient because lots of programs rely on diff being in the path like buildifier, golangci-lint, and other things since golang diff implementations aren't very good.
Ideally we'd include "diffutils" as part of this list for rules that assume the presence of "diff" and don't allow nice knobs to configure otherwise.
Furthermore, bazel has a lot of internal facilities that utilize patch (like when downloading workspaces, we have the option of patching them), so include gnupatch as well.
Fixes#249846