From de90da1ca6763218e772a74c274f851118ed2726 Mon Sep 17 00:00:00 2001 From: Yancheng Zheng <103552181+anakinxc@users.noreply.github.com> Date: Thu, 19 Sep 2024 10:57:21 +0800 Subject: [PATCH] Patch upb for clang-16 (#183) --- bazel/patches/upb.patch | 29 +++++++++++++++++++++++++++++ bazel/repositories.bzl | 4 ++++ 2 files changed, 33 insertions(+) create mode 100644 bazel/patches/upb.patch diff --git a/bazel/patches/upb.patch b/bazel/patches/upb.patch new file mode 100644 index 0000000..8ffa405 --- /dev/null +++ b/bazel/patches/upb.patch @@ -0,0 +1,29 @@ +diff --git a/bazel/build_defs.bzl b/bazel/build_defs.bzl +index b5bc64f0..dc30a75f 100644 +--- a/bazel/build_defs.bzl ++++ b/bazel/build_defs.bzl +@@ -38,7 +38,7 @@ _DEFAULT_CPPOPTS.extend([ + "-Wno-long-long", + ]) + _DEFAULT_COPTS.extend([ +- "-std=c99", ++ "-std=c11", + "-pedantic", + "-Werror=pedantic", + "-Wall", +diff --git a/upb/port_def.inc b/upb/port_def.inc +index 92e4bf24..e355ace7 100644 +--- a/upb/port_def.inc ++++ b/upb/port_def.inc +@@ -92,7 +92,11 @@ + #define UPB_ALIGN_UP(size, align) (((size) + (align) - 1) / (align) * (align)) + #define UPB_ALIGN_DOWN(size, align) ((size) / (align) * (align)) + #define UPB_ALIGN_MALLOC(size) UPB_ALIGN_UP(size, UPB_MALLOC_ALIGN) ++#ifdef __clang__ ++#define UPB_ALIGN_OF(type) _Alignof(type) ++#else + #define UPB_ALIGN_OF(type) offsetof (struct { char c; type member; }, member) ++#endif + + /* Hints to the compiler about likely/unlikely branches. */ + #if defined (__GNUC__) || defined(__clang__) diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 9859748..151ef13 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -93,6 +93,10 @@ def _upb(): "https://storage.googleapis.com/grpc-bazel-mirror/github.com/protocolbuffers/upb/archive/e4635f223e7d36dfbea3b722a4ca4807a7e882e2.tar.gz", "https://github.com/protocolbuffers/upb/archive/e4635f223e7d36dfbea3b722a4ca4807a7e882e2.tar.gz", ], + patch_args = ["-p1"], + patches = [ + "@psi//bazel:patches/upb.patch", + ], ) def _com_github_emptoolkit_emp_tool():