Skip to content

Commit

Permalink
Merge pull request grpc#15595 from dgquintas/nanopb_build_cleanup
Browse files Browse the repository at this point in the history
Treat nanopb as a regular external dep
  • Loading branch information
dgquintas authored Jun 15, 2018
2 parents 5bc31db + 39fbed3 commit 1c6d6ba
Show file tree
Hide file tree
Showing 27 changed files with 471 additions and 68 deletions.
360 changes: 360 additions & 0 deletions CMakeLists.txt

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
23 changes: 2 additions & 21 deletions bazel/grpc_build_system.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down Expand Up @@ -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(
Expand Down
18 changes: 16 additions & 2 deletions bazel/grpc_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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():
Expand All @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions cmake/nanopb.cmake
Original file line number Diff line number Diff line change
@@ -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")
8 changes: 4 additions & 4 deletions gRPC-C++.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion gRPC-Core.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions grpc.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
'-Wno-unused-parameter',
'-DOSATOMIC_USE_INLINED=1',
'-Wno-deprecated-declarations',
'-Ithird_party/nanopb',
'-DPB_FIELD_32BIT',
],
'ldflags': [
'-g',
Expand Down Expand Up @@ -137,6 +139,8 @@
'-Wno-unused-parameter',
'-DOSATOMIC_USE_INLINED=1',
'-Wno-deprecated-declarations',
'-Ithird_party/nanopb',
'-DPB_FIELD_32BIT',
],
'OTHER_CPLUSPLUSFLAGS': [
'-g',
Expand All @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
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'),)
Expand Down Expand Up @@ -181,7 +182,7 @@

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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion src/core/tsi/alts/handshaker/altscontext.pb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand Down
2 changes: 1 addition & 1 deletion src/core/tsi/alts/handshaker/handshaker.pb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/core/tsi/alts/handshaker/transport_security_common_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/server/health/default_health_check_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/server/health/health.pb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions templates/CMakeLists.txt.template
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions templates/Makefile.template
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,6 @@
% endif
% endfor

DEFINES += PB_FIELD_16BIT

CPPFLAGS += $(CPPFLAGS_$(CONFIG))
CFLAGS += $(CFLAGS_$(CONFIG))
CXXFLAGS += $(CXXFLAGS_$(CONFIG))
Expand Down
8 changes: 4 additions & 4 deletions templates/gRPC-C++.podspec.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion templates/gRPC-Core.podspec.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 19 additions & 0 deletions third_party/nanopb.BUILD
Original file line number Diff line number Diff line change
@@ -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"],
)

29 changes: 16 additions & 13 deletions third_party/nanopb/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
3 changes: 1 addition & 2 deletions tools/codegen/core/gen_nano_proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
Loading

0 comments on commit 1c6d6ba

Please sign in to comment.