Skip to content

Commit

Permalink
bazel_4: fix CLang 16 Werror-s on darwin
Browse files Browse the repository at this point in the history
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

(cherry picked from commit 746e394)
  • Loading branch information
boltzmannrain authored and github-actions[bot] committed Nov 30, 2023
1 parent 6b83b42 commit adc22af
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ stdenv.mkDerivation rec {
inherit src;
inherit sourceRoot;
patches = [
./upb-clang16.patch

# On Darwin, the last argument to gcc is coming up as an empty string. i.e: ''
# This is breaking the build of any C target. This patch removes the last
# argument if it's found to be an empty string.
Expand Down Expand Up @@ -399,6 +401,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 third_party/{zlib}, external/{upb} dependencies
export NIX_CFLAGS_COMPILE+=" -Wno-implicit-function-declaration -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,57 @@
diff --git a/WORKSPACE b/WORKSPACE
index 2d995f095e..55fddef663 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -1232,7 +1232,7 @@ register_toolchains("//src/main/res:empty_rc_toolchain")
http_archive(
name = "com_github_grpc_grpc",
patch_args = ["-p1"],
- patches = ["//third_party/grpc:grpc_1.33.1.patch"],
+ patches = ["//third_party/grpc:grpc_1.33.1.patch", "//:grpc-upb-clang16.patch"],
sha256 = "58eaee5c0f1bd0b92ebe1fa0606ec8f14798500620e7444726afcaf65041cb63",
strip_prefix = "grpc-1.33.1",
urls = [
diff --git a/grpc-upb-clang16.patch b/grpc-upb-clang16.patch
new file mode 100644
index 0000000000..ae6a7ad0e0
--- /dev/null
+++ b/grpc-upb-clang16.patch
@@ -0,0 +1,13 @@
+diff -r -u a/bazel/grpc_deps.bzl b/bazel/grpc_deps.bzl
+--- a/bazel/grpc_deps.bzl
++++ b/bazel/grpc_deps.bzl
+@@ -285,6 +285,8 @@
+ name = "upb",
+ sha256 = "7992217989f3156f8109931c1fc6db3434b7414957cb82371552377beaeb9d6c",
+ strip_prefix = "upb-382d5afc60e05470c23e8de19b19fc5ad231e732",
++ patches = ["//:upb-clang16.patch"],
++ patch_args = ["-p1"],
+ urls = [
+ "https://storage.googleapis.com/grpc-bazel-mirror/github.com/protocolbuffers/upb/archive/382d5afc60e05470c23e8de19b19fc5ad231e732.tar.gz",
+ "https://github.com/protocolbuffers/upb/archive/382d5afc60e05470c23e8de19b19fc5ad231e732.tar.gz",
+
diff --git a/upb-clang16.patch b/upb-clang16.patch
new file mode 100644
index 0000000000..b799737fac
--- /dev/null
+++ b/upb-clang16.patch
@@ -0,0 +1,18 @@
+--- a/BUILD
++++ b/BUILD
+@@ -34,6 +34,7 @@
+ "-Wextra",
+ # "-Wshorten-64-to-32", # not in GCC (and my Kokoro images doesn't have Clang)
+ "-Werror",
++ "-Wno-gnu-offsetof-extensions",
+ "-Wno-long-long",
+ # copybara:strip_end
+ ]
+@@ -42,6 +43,7 @@
+ # copybara:strip_for_google3_begin
+ "-pedantic",
+ "-Werror=pedantic",
++ "-Wno-gnu-offsetof-extensions",
+ "-Wstrict-prototypes",
+ # copybara:strip_end
+ ]

Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,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 and in execlog
export NIX_CFLAGS_COMPILE+=" -Wno-deprecated-builtins -Wno-gnu-offsetof-extensions -Wno-implicit-function-declaration"
# 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

0 comments on commit adc22af

Please sign in to comment.