Skip to content

Commit

Permalink
bazel_6: fix CLang 16 Werror-s on darwin
Browse files Browse the repository at this point in the history
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
  • Loading branch information
boltzmannrain committed Nov 22, 2023
1 parent 2858c28 commit ed175a6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ stdenv.mkDerivation rec {
inherit src;
inherit sourceRoot;
patches = [
# upb definition inside bazel sets its own copts that take precedence
# over flags we set externally, so need to patch them at the source
./upb-clang16.patch

# Force usage of the _non_ prebuilt java toolchain.
# the prebuilt one does not work in nix world.
./java_toolchain.patch
Expand Down Expand Up @@ -403,6 +407,8 @@ stdenv.mkDerivation rec {
# libcxx includes aren't added by libcxx hook
# https://github.com/NixOS/nixpkgs/pull/41589
export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem ${lib.getDev libcxx}/include/c++/v1"
# for CLang 16 compatibility in external/{absl,upb} dependencies
export NIX_CFLAGS_COMPILE+=" -Wno-deprecated-builtins -Wno-gnu-offsetof-extensions"
# don't use system installed Xcode to run clang, use Nix clang instead
sed -i -E "s;/usr/bin/xcrun (--sdk macosx )?clang;${stdenv.cc}/bin/clang $NIX_CFLAGS_COMPILE $(bazelLinkFlags) -framework CoreFoundation;g" \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
diff --git a/distdir_deps.bzl b/distdir_deps.bzl
index c7fc4588e4..01e6966fca 100644
--- a/distdir_deps.bzl
+++ b/distdir_deps.bzl
@@ -192,6 +192,8@@ DIST_DEPS = {
"archive": "a5477045acaa34586420942098f5fecd3570f577.tar.gz",
"sha256": "cf7f71eaff90b24c1a28b49645a9ff03a9a6c1e7134291ce70901cb63e7364b5",
"strip_prefix": "upb-a5477045acaa34586420942098f5fecd3570f577",
+ "patches": ["//:upb-clang16.patch"],
+ "patch_args": ["-p1"],
"urls": [
"https://mirror.bazel.build/github.com/protocolbuffers/upb/archive/a5477045acaa34586420942098f5fecd3570f577.tar.gz",
"https://github.com/protocolbuffers/upb/archive/a5477045acaa34586420942098f5fecd3570f577.tar.gz",
diff --git a/upb-clang16.patch b/upb-clang16.patch
new file mode 100644
index 0000000000..f81855181f
--- /dev/null
+++ upb-clang16.patch
@@ -0,0 +1,10 @@
+--- a/bazel/build_defs.bzl
++++ b/bazel/build_defs.bzl
+@@ -43,6 +43,7 @@
+ "-Werror=pedantic",
+ "-Wall",
+ "-Wstrict-prototypes",
++ "-Wno-gnu-offsetof-extensions",
+ # GCC (at least) emits spurious warnings for this that cannot be fixed
+ # without introducing redundant initialization (with runtime cost):
+ # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635

0 comments on commit ed175a6

Please sign in to comment.