diff --git a/Makefile b/Makefile index 0e54fb2683f..17b723a96c9 100644 --- a/Makefile +++ b/Makefile @@ -338,7 +338,9 @@ CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter -DOSAT COREFLAGS += -fno-rtti -fno-exceptions LDFLAGS += -g -DEFINES += PB_FIELD_16BIT +# nanopb tweaks +DEFINES += PB_FIELD_32BIT +CPPFLAGS += -Ithird_party/nanopb CPPFLAGS += $(CPPFLAGS_$(CONFIG)) CFLAGS += $(CFLAGS_$(CONFIG)) diff --git a/bazel/grpc_deps.bzl b/bazel/grpc_deps.bzl index 50d1d24303f..9732e27a7e3 100644 --- a/bazel/grpc_deps.bzl +++ b/bazel/grpc_deps.bzl @@ -5,7 +5,7 @@ def grpc_deps(): native.bind( name = "nanopb", - actual = "@com_github_grpc_grpc//third_party/nanopb:nanopb", + actual = "@com_github_nanopb_nanopb//:nanopb", ) native.bind( @@ -93,6 +93,14 @@ def grpc_deps(): name = "com_google_protobuf", strip_prefix = "protobuf-b5fbb742af122b565925987e65c08957739976a7", url = "https://github.com/google/protobuf/archive/b5fbb742af122b565925987e65c08957739976a7.tar.gz", + ) + + if "com_github_nanopb_nanopb" not in native.existing_rules(): + native.new_http_archive( + name = "com_github_nanopb_nanopb", + build_file = "@com_github_grpc_grpc//third_party:nanopb.BUILD", + strip_prefix = "nanopb-f8ac463766281625ad710900479130c7fcb4d63b", + url = "https://github.com/nanopb/nanopb/archive/f8ac463766281625ad710900479130c7fcb4d63b.tar.gz", ) if "com_github_google_googletest" not in native.existing_rules(): diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc index ed246273c97..8f031b0679e 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc @@ -19,8 +19,8 @@ #include #include "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h" -#include "third_party/nanopb/pb_decode.h" -#include "third_party/nanopb/pb_encode.h" +#include "pb_decode.h" +#include "pb_encode.h" #include diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h b/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h index 066c0762026..088b6f513a4 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h @@ -3,7 +3,7 @@ #ifndef PB_GRPC_LB_V1_LOAD_BALANCER_PB_H_INCLUDED #define PB_GRPC_LB_V1_LOAD_BALANCER_PB_H_INCLUDED -#include "third_party/nanopb/pb.h" +#include "pb.h" /* @@protoc_insertion_point(includes) */ #if PB_PROTO_HEADER_VERSION != 30 #error Regenerate this file with the current version of nanopb generator. diff --git a/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h b/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h index 8fe8f73f8bf..966ea45617e 100644 --- a/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h +++ b/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h @@ -21,8 +21,8 @@ #include -#include "third_party/nanopb/pb_decode.h" -#include "third_party/nanopb/pb_encode.h" +#include "pb_decode.h" +#include "pb_encode.h" #include #include diff --git a/src/core/tsi/alts/handshaker/altscontext.pb.h b/src/core/tsi/alts/handshaker/altscontext.pb.h index 3e72d7f6784..f11b2899e90 100644 --- a/src/core/tsi/alts/handshaker/altscontext.pb.h +++ b/src/core/tsi/alts/handshaker/altscontext.pb.h @@ -3,7 +3,7 @@ #ifndef PB_GRPC_GCP_ALTSCONTEXT_PB_H_INCLUDED #define PB_GRPC_GCP_ALTSCONTEXT_PB_H_INCLUDED -#include "third_party/nanopb/pb.h" +#include "pb.h" #include "src/core/tsi/alts/handshaker/transport_security_common.pb.h" /* @@protoc_insertion_point(includes) */ diff --git a/src/core/tsi/alts/handshaker/handshaker.pb.h b/src/core/tsi/alts/handshaker/handshaker.pb.h index 0805a144def..e2b193463c3 100644 --- a/src/core/tsi/alts/handshaker/handshaker.pb.h +++ b/src/core/tsi/alts/handshaker/handshaker.pb.h @@ -3,7 +3,7 @@ #ifndef PB_GRPC_GCP_HANDSHAKER_PB_H_INCLUDED #define PB_GRPC_GCP_HANDSHAKER_PB_H_INCLUDED -#include "third_party/nanopb/pb.h" +#include "pb.h" #include "src/core/tsi/alts/handshaker/transport_security_common.pb.h" /* @@protoc_insertion_point(includes) */ diff --git a/src/core/tsi/alts/handshaker/transport_security_common.pb.h b/src/core/tsi/alts/handshaker/transport_security_common.pb.h index 49096dffa30..87d9abf149f 100644 --- a/src/core/tsi/alts/handshaker/transport_security_common.pb.h +++ b/src/core/tsi/alts/handshaker/transport_security_common.pb.h @@ -3,7 +3,7 @@ #ifndef PB_GRPC_GCP_TRANSPORT_SECURITY_COMMON_PB_H_INCLUDED #define PB_GRPC_GCP_TRANSPORT_SECURITY_COMMON_PB_H_INCLUDED -#include "third_party/nanopb/pb.h" +#include "pb.h" /* @@protoc_insertion_point(includes) */ #if PB_PROTO_HEADER_VERSION != 30 #error Regenerate this file with the current version of nanopb generator. diff --git a/src/core/tsi/alts/handshaker/transport_security_common_api.h b/src/core/tsi/alts/handshaker/transport_security_common_api.h index 68228cb3b52..ec2a0b4b5e3 100644 --- a/src/core/tsi/alts/handshaker/transport_security_common_api.h +++ b/src/core/tsi/alts/handshaker/transport_security_common_api.h @@ -21,8 +21,8 @@ #include -#include "third_party/nanopb/pb_decode.h" -#include "third_party/nanopb/pb_encode.h" +#include "pb_decode.h" +#include "pb_encode.h" #include #include diff --git a/src/cpp/server/health/default_health_check_service.cc b/src/cpp/server/health/default_health_check_service.cc index 0b45a8b7140..93d0a192e0e 100644 --- a/src/cpp/server/health/default_health_check_service.cc +++ b/src/cpp/server/health/default_health_check_service.cc @@ -26,8 +26,8 @@ #include "src/cpp/server/health/default_health_check_service.h" #include "src/cpp/server/health/health.pb.h" -#include "third_party/nanopb/pb_decode.h" -#include "third_party/nanopb/pb_encode.h" +#include "pb_decode.h" +#include "pb_encode.h" namespace grpc { namespace { diff --git a/src/cpp/server/health/health.pb.h b/src/cpp/server/health/health.pb.h index 7051b3260ac..29e1f3bacb1 100644 --- a/src/cpp/server/health/health.pb.h +++ b/src/cpp/server/health/health.pb.h @@ -3,7 +3,7 @@ #ifndef PB_GRPC_HEALTH_V1_HEALTH_PB_H_INCLUDED #define PB_GRPC_HEALTH_V1_HEALTH_PB_H_INCLUDED -#include "third_party/nanopb/pb.h" +#include "pb.h" /* @@protoc_insertion_point(includes) */ #if PB_PROTO_HEADER_VERSION != 30 #error Regenerate this file with the current version of nanopb generator. diff --git a/templates/Makefile.template b/templates/Makefile.template index 901dbfc9c83..8532adf7892 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -221,7 +221,9 @@ % endif % endfor - DEFINES += PB_FIELD_16BIT + # nanopb tweaks + DEFINES += PB_FIELD_32BIT + CPPFLAGS += -Ithird_party/nanopb CPPFLAGS += $(CPPFLAGS_$(CONFIG)) CFLAGS += $(CFLAGS_$(CONFIG)) diff --git a/third_party/nanopb.BUILD b/third_party/nanopb.BUILD new file mode 100644 index 00000000000..46ca53a8fe9 --- /dev/null +++ b/third_party/nanopb.BUILD @@ -0,0 +1,19 @@ +cc_library( + name = "nanopb", + srcs = [ + "pb_common.c", + "pb_decode.c", + "pb_encode.c", + ], + hdrs = [ + "pb.h", + "pb_common.h", + "pb_decode.h", + "pb_encode.h", + ], + defines = [ + "PB_FIELD_32BIT=1", + ], + visibility = ["//visibility:public"], +) + diff --git a/tools/codegen/core/gen_nano_proto.sh b/tools/codegen/core/gen_nano_proto.sh index 6ce15178bdf..c56429a3207 100755 --- a/tools/codegen/core/gen_nano_proto.sh +++ b/tools/codegen/core/gen_nano_proto.sh @@ -74,8 +74,7 @@ pushd "$(dirname $INPUT_PROTO)" > /dev/null protoc \ --plugin=protoc-gen-nanopb="$GRPC_ROOT/third_party/nanopb/generator/protoc-gen-nanopb" \ ---nanopb_out='-T -L#include\ \"third_party/nanopb/pb.h\"'":$OUTPUT_DIR" \ -"$(basename $INPUT_PROTO)" +--nanopb_out='-T -L#include\ \"pb.h\"'":$OUTPUT_DIR" "$(basename $INPUT_PROTO)" readonly PROTO_BASENAME=$(basename $INPUT_PROTO .proto) sed -i "s:$PROTO_BASENAME.pb.h:${GRPC_OUTPUT_DIR}/$PROTO_BASENAME.pb.h:g" \