Merge pull request #15595 from dgquintas/nanopb_build_cleanup

Treat nanopb as a regular external dep
reviewable/pr15780/r1
David G. Quintas 7 years ago committed by GitHub
commit 1c6d6ba851
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 360
      CMakeLists.txt
  2. 4
      Makefile
  3. 23
      bazel/grpc_build_system.bzl
  4. 18
      bazel/grpc_deps.bzl
  5. 2
      build.yaml
  6. 15
      cmake/nanopb.cmake
  7. 8
      gRPC-C++.podspec
  8. 3
      gRPC-Core.podspec
  9. 6
      grpc.gyp
  10. 3
      setup.py
  11. 4
      src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc
  12. 2
      src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h
  13. 4
      src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h
  14. 2
      src/core/tsi/alts/handshaker/altscontext.pb.h
  15. 2
      src/core/tsi/alts/handshaker/handshaker.pb.h
  16. 2
      src/core/tsi/alts/handshaker/transport_security_common.pb.h
  17. 4
      src/core/tsi/alts/handshaker/transport_security_common_api.h
  18. 4
      src/cpp/server/health/default_health_check_service.cc
  19. 2
      src/cpp/server/health/health.pb.h
  20. 3
      templates/CMakeLists.txt.template
  21. 2
      templates/Makefile.template
  22. 8
      templates/gRPC-C++.podspec.template
  23. 3
      templates/gRPC-Core.podspec.template
  24. 19
      third_party/nanopb.BUILD
  25. 29
      third_party/nanopb/BUILD
  26. 3
      tools/codegen/core/gen_nano_proto.sh
  27. 4
      tools/run_tests/sanity/check_bazel_workspace.py

File diff suppressed because it is too large Load Diff

@ -334,12 +334,10 @@ CXXFLAGS += -std=c++11
ifeq ($(SYSTEM),Darwin)
CXXFLAGS += -stdlib=libc++
endif
CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter -DOSATOMIC_USE_INLINED=1 -Wno-deprecated-declarations
CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter -DOSATOMIC_USE_INLINED=1 -Wno-deprecated-declarations -Ithird_party/nanopb -DPB_FIELD_32BIT
COREFLAGS += -fno-rtti -fno-exceptions
LDFLAGS += -g
DEFINES += PB_FIELD_16BIT
CPPFLAGS += $(CPPFLAGS_$(CONFIG))
CFLAGS += $(CFLAGS_$(CONFIG))
CXXFLAGS += $(CXXFLAGS_$(CONFIG))

@ -36,9 +36,7 @@ def if_not_windows(a):
def _get_external_deps(external_deps):
ret = []
for dep in external_deps:
if dep == "nanopb":
ret += ["grpc_nanopb"]
elif dep == "address_sorting":
if dep == "address_sorting":
ret += ["//third_party/address_sorting"]
elif dep == "cares":
ret += select({"//:grpc_no_ares": [],
@ -161,24 +159,7 @@ def grpc_cc_binary(name, srcs = [], deps = [], external_deps = [], args = [], da
linkopts = if_not_windows(["-pthread"]) + linkopts,
)
def grpc_generate_one_off_targets():
native.cc_library(
name = "grpc_nanopb",
hdrs = [
"//third_party/nanopb:pb.h",
"//third_party/nanopb:pb_common.h",
"//third_party/nanopb:pb_decode.h",
"//third_party/nanopb:pb_encode.h",
],
srcs = [
"//third_party/nanopb:pb_common.c",
"//third_party/nanopb:pb_decode.c",
"//third_party/nanopb:pb_encode.c",
],
defines = [
"PB_FIELD_16BIT=1",
],
)
def grpc_generate_one_off_targets(): pass
def grpc_sh_test(name, srcs, args = [], data = []):
native.sh_test(

@ -2,6 +2,12 @@
def grpc_deps():
"""Loads dependencies need to compile and test the grpc library."""
native.bind(
name = "nanopb",
actual = "@com_github_nanopb_nanopb//:nanopb",
)
native.bind(
name = "libssl",
actual = "@boringssl//:ssl",
@ -59,12 +65,12 @@ def grpc_deps():
native.bind(
name = "grpc_cpp_plugin",
actual = "@com_github_grpc_grpc//:grpc_cpp_plugin"
actual = "@com_github_grpc_grpc//:grpc_cpp_plugin",
)
native.bind(
name = "grpc++_codegen_proto",
actual = "@com_github_grpc_grpc//:grpc++_codegen_proto"
actual = "@com_github_grpc_grpc//:grpc++_codegen_proto",
)
if "boringssl" not in native.existing_rules():
@ -87,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():

@ -5625,7 +5625,7 @@ defaults:
global:
COREFLAGS: -fno-rtti -fno-exceptions
CPPFLAGS: -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter -DOSATOMIC_USE_INLINED=1
-Wno-deprecated-declarations
-Wno-deprecated-declarations -Ithird_party/nanopb -DPB_FIELD_32BIT
LDFLAGS: -g
zlib:
CFLAGS: -Wno-sign-conversion -Wno-conversion -Wno-unused-value -Wno-implicit-function-declaration

@ -0,0 +1,15 @@
# Copyright 2018 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set(_gRPC_NANOPB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/nanopb")

@ -663,9 +663,9 @@ Pod::Spec.new do |s|
end
s.prepare_command = <<-END_OF_COMMAND
find src/cpp/ -type f -exec sed -E -i'.back' 's;#include "third_party/nanopb/(.*)";#include <nanopb/\\1>;g' {} \\\;
find src/cpp/ -name "*.back" -type f -delete
find src/core/ -regex ".*\.h" -type f -exec sed -E -i'.back' 's;#include "third_party/nanopb/(.*)";#include <nanopb/\\1>;g' {} \\\;
find src/core/ -name "*.back" -type f -delete
find src/cpp/ -type f ! -path '*.grpc_back' -print0 | xargs -0 -L1 sed -E -i'.grpc_back' 's;#include "(pb(_.*)?\\.h)";#include <nanopb/\\1>;g'
find src/cpp/ -type f -path '*.grpc_back' -print0 | xargs -0 rm
find src/core/ -type f ! -path '*.grpc_back' -print0 | xargs -0 -L1 sed -E -i'.grpc_back' 's;#include "(pb(_.*)?\\.h)";#include <nanopb/\\1>;g'
find src/core/ -type f -path '*.grpc_back' -print0 | xargs -0 rm
END_OF_COMMAND
end

@ -1264,6 +1264,7 @@ Pod::Spec.new do |s|
# TODO (mxyan): Instead of this hack, add include path "third_party" to C core's include path?
s.prepare_command = <<-END_OF_COMMAND
find src/core/ -type f ! -path '*.back*' -exec sed -E -i'.back' 's;#include "third_party/nanopb/(.*)";#include <nanopb/\\1>;g' {} \\\;
find src/core/ -type f ! -path '*.grpc_back' -print0 | xargs -0 -L1 sed -E -i'.grpc_back' 's;#include "(pb(_.*)?\\.h)";#include <nanopb/\\1>;g'
find src/core/ -type f -path '*.grpc_back' -print0 | xargs -0 rm
END_OF_COMMAND
end

@ -59,6 +59,8 @@
'-Wno-unused-parameter',
'-DOSATOMIC_USE_INLINED=1',
'-Wno-deprecated-declarations',
'-Ithird_party/nanopb',
'-DPB_FIELD_32BIT',
],
'ldflags': [
'-g',
@ -137,6 +139,8 @@
'-Wno-unused-parameter',
'-DOSATOMIC_USE_INLINED=1',
'-Wno-deprecated-declarations',
'-Ithird_party/nanopb',
'-DPB_FIELD_32BIT',
],
'OTHER_CPLUSPLUSFLAGS': [
'-g',
@ -147,6 +151,8 @@
'-Wno-unused-parameter',
'-DOSATOMIC_USE_INLINED=1',
'-Wno-deprecated-declarations',
'-Ithird_party/nanopb',
'-DPB_FIELD_32BIT',
'-stdlib=libc++',
'-std=c++11',
'-Wno-error=deprecated-declarations',

@ -37,6 +37,7 @@ PYTHON_STEM = os.path.join('src', 'python', 'grpcio')
CORE_INCLUDE = ('include', '.',)
SSL_INCLUDE = (os.path.join('third_party', 'boringssl', 'include'),)
ZLIB_INCLUDE = (os.path.join('third_party', 'zlib'),)
NANOPB_INCLUDE = (os.path.join('third_party', 'nanopb'),)
CARES_INCLUDE = (
os.path.join('third_party', 'cares'),
os.path.join('third_party', 'cares', 'cares'),)
@ -181,7 +182,7 @@ if BUILD_WITH_SYSTEM_CARES:
EXTENSION_INCLUDE_DIRECTORIES = (
(PYTHON_STEM,) + CORE_INCLUDE + SSL_INCLUDE + ZLIB_INCLUDE +
CARES_INCLUDE + ADDRESS_SORTING_INCLUDE)
NANOPB_INCLUDE + CARES_INCLUDE + ADDRESS_SORTING_INCLUDE)
EXTENSION_LIBRARIES = ()
if "linux" in sys.platform:

@ -18,9 +18,9 @@
#include <grpc/support/port_platform.h>
#include "pb_decode.h"
#include "pb_encode.h"
#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 <grpc/support/alloc.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.

@ -21,8 +21,8 @@
#include <grpc/support/port_platform.h>
#include "third_party/nanopb/pb_decode.h"
#include "third_party/nanopb/pb_encode.h"
#include "pb_decode.h"
#include "pb_encode.h"
#include <grpc/slice.h>
#include <grpc/slice_buffer.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) */

@ -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) */

@ -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.

@ -21,8 +21,8 @@
#include <grpc/support/port_platform.h>
#include "third_party/nanopb/pb_decode.h"
#include "third_party/nanopb/pb_encode.h"
#include "pb_decode.h"
#include "pb_encode.h"
#include <grpc/slice.h>
#include <grpc/slice_buffer.h>

@ -24,10 +24,10 @@
#include <grpc/support/log.h>
#include <grpcpp/impl/codegen/method_handler_impl.h>
#include "pb_decode.h"
#include "pb_encode.h"
#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"
namespace grpc {
namespace {

@ -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.

@ -168,6 +168,7 @@
include(cmake/gflags.cmake)
include(cmake/benchmark.cmake)
include(cmake/address_sorting.cmake)
include(cmake/nanopb.cmake)
if(NOT MSVC)
set(CMAKE_C_FLAGS "<%text>${CMAKE_C_FLAGS}</%text> -std=c99")
@ -383,6 +384,7 @@
PRIVATE <%text>${_gRPC_CARES_INCLUDE_DIR}</%text>
PRIVATE <%text>${_gRPC_GFLAGS_INCLUDE_DIR}</%text>
PRIVATE <%text>${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}</%text>
PRIVATE <%text>${_gRPC_NANOPB_INCLUDE_DIR}</%text>
% if lib.build in ['test', 'private'] and lib.language == 'c++':
PRIVATE third_party/googletest/googletest/include
PRIVATE third_party/googletest/googletest
@ -464,6 +466,7 @@
PRIVATE <%text>${_gRPC_CARES_INCLUDE_DIR}</%text>
PRIVATE <%text>${_gRPC_GFLAGS_INCLUDE_DIR}</%text>
PRIVATE <%text>${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}</%text>
PRIVATE <%text>${_gRPC_NANOPB_INCLUDE_DIR}</%text>
% if tgt.build in ['test', 'private'] and tgt.language == 'c++':
PRIVATE third_party/googletest/googletest/include
PRIVATE third_party/googletest/googletest

@ -221,8 +221,6 @@
% endif
% endfor
DEFINES += PB_FIELD_16BIT
CPPFLAGS += $(CPPFLAGS_$(CONFIG))
CFLAGS += $(CFLAGS_$(CONFIG))
CXXFLAGS += $(CXXFLAGS_$(CONFIG))

@ -196,9 +196,9 @@
end
s.prepare_command = <<-END_OF_COMMAND
find src/cpp/ -type f -exec sed -E -i'.back' 's;#include "third_party/nanopb/(.*)";#include <nanopb/\\1>;g' {} \\\;
find src/cpp/ -name "*.back" -type f -delete
find src/core/ -regex ".*\.h" -type f -exec sed -E -i'.back' 's;#include "third_party/nanopb/(.*)";#include <nanopb/\\1>;g' {} \\\;
find src/core/ -name "*.back" -type f -delete
find src/cpp/ -type f ! -path '*.grpc_back' -print0 | xargs -0 -L1 sed -E -i'.grpc_back' 's;#include "(pb(_.*)?\\.h)";#include <nanopb/\\1>;g'
find src/cpp/ -type f -path '*.grpc_back' -print0 | xargs -0 rm
find src/core/ -type f ! -path '*.grpc_back' -print0 | xargs -0 -L1 sed -E -i'.grpc_back' 's;#include "(pb(_.*)?\\.h)";#include <nanopb/\\1>;g'
find src/core/ -type f -path '*.grpc_back' -print0 | xargs -0 rm
END_OF_COMMAND
end

@ -220,6 +220,7 @@
# TODO (mxyan): Instead of this hack, add include path "third_party" to C core's include path?
s.prepare_command = <<-END_OF_COMMAND
find src/core/ -type f ! -path '*.back*' -exec sed -E -i'.back' 's;#include "third_party/nanopb/(.*)";#include <nanopb/\\1>;g' {} \\\;
find src/core/ -type f ! -path '*.grpc_back' -print0 | xargs -0 -L1 sed -E -i'.grpc_back' 's;#include "(pb(_.*)?\\.h)";#include <nanopb/\\1>;g'
find src/core/ -type f -path '*.grpc_back' -print0 | xargs -0 rm
END_OF_COMMAND
end

@ -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"],
)

@ -5,17 +5,20 @@ exports_files(["LICENSE.txt"])
package(default_visibility = ["//visibility:public"])
cc_library(
name = "nanopb",
visibility = ["//visibility:public"],
hdrs = [
"pb.h",
"pb_common.h",
"pb_decode.h",
"pb_encode.h",
],
srcs = [
"pb_common.c",
"pb_decode.c",
"pb_encode.c",
],
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"],
)

@ -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" \

@ -47,6 +47,7 @@ _GRPC_DEP_NAMES = [
'com_google_protobuf',
'com_github_google_googletest',
'com_github_gflags_gflags',
'com_github_nanopb_nanopb',
'com_github_google_benchmark',
'com_github_cares_cares',
'com_google_absl',
@ -120,9 +121,12 @@ names_without_bazel_only_deps = names_and_urls.keys()
for dep_name in _GRPC_BAZEL_ONLY_DEPS:
names_without_bazel_only_deps.remove(dep_name)
archive_urls = [names_and_urls[name] for name in names_without_bazel_only_deps]
# Exclude nanopb from the check: it's not a submodule for distribution reasons,
# but it's a workspace dependency to enable users to use their own version.
workspace_git_hashes = {
re.search(git_hash_pattern, url).group()
for url in archive_urls
if 'nanopb' not in url
}
if len(workspace_git_hashes) == 0:
print("(Likely) parse error, did not find any bazel git dependencies.")

Loading…
Cancel
Save