Skip to content

Commit

Permalink
Merge pull request grpc#17364 from vishalpowar/generate_build
Browse files Browse the repository at this point in the history
Changes add a script for generating C code and build rule for protobuf
  • Loading branch information
vishalpowar authored Dec 12, 2018
2 parents e829a81 + 62027b7 commit 311ee1e
Show file tree
Hide file tree
Showing 26 changed files with 3,699 additions and 4 deletions.
25 changes: 25 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2274,4 +2274,29 @@ grpc_cc_library(
],
)

# TODO: Get this into build.yaml once we start using it.
grpc_cc_library(
name = "google_protobuf",
srcs = [
"src/core/ext/upb-generated/google/protobuf/any.upb.c",
"src/core/ext/upb-generated/google/protobuf/descriptor.upb.c",
"src/core/ext/upb-generated/google/protobuf/duration.upb.c",
"src/core/ext/upb-generated/google/protobuf/struct.upb.c",
"src/core/ext/upb-generated/google/protobuf/timestamp.upb.c",
"src/core/ext/upb-generated/google/protobuf/wrappers.upb.c",
],
hdrs = [
"src/core/ext/upb-generated/google/protobuf/any.upb.h",
"src/core/ext/upb-generated/google/protobuf/descriptor.upb.h",
"src/core/ext/upb-generated/google/protobuf/duration.upb.h",
"src/core/ext/upb-generated/google/protobuf/struct.upb.h",
"src/core/ext/upb-generated/google/protobuf/timestamp.upb.h",
"src/core/ext/upb-generated/google/protobuf/wrappers.upb.h",
],
language = "c++",
external_deps = [
"upb_lib",
],
)

grpc_generate_one_off_targets()
53 changes: 53 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5478,6 +5478,59 @@ endif()
endif (gRPC_BUILD_CSHARP_EXT)
if (gRPC_BUILD_TESTS)

add_library(upb
third_party/upb/google/protobuf/descriptor.upb.c
third_party/upb/upb/decode.c
third_party/upb/upb/def.c
third_party/upb/upb/encode.c
third_party/upb/upb/handlers.c
third_party/upb/upb/msg.c
third_party/upb/upb/msgfactory.c
third_party/upb/upb/refcounted.c
third_party/upb/upb/sink.c
third_party/upb/upb/table.c
third_party/upb/upb/upb.c
)

if(WIN32 AND MSVC)
set_target_properties(upb PROPERTIES COMPILE_PDB_NAME "upb"
COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
)
if (gRPC_INSTALL)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/upb.pdb
DESTINATION ${gRPC_INSTALL_LIBDIR} OPTIONAL
)
endif()
endif()


target_include_directories(upb
PUBLIC $<INSTALL_INTERFACE:${gRPC_INSTALL_INCLUDEDIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE ${_gRPC_SSL_INCLUDE_DIR}
PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR}
PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR}
PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR}
PRIVATE ${_gRPC_CARES_INCLUDE_DIR}
PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR}
PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
PRIVATE ${_gRPC_NANOPB_INCLUDE_DIR}
)
# avoid dependency on libstdc++
if (_gRPC_CORE_NOSTDCXX_FLAGS)
set_target_properties(upb PROPERTIES LINKER_LANGUAGE C)
# only use the flags for C++ source files
target_compile_options(upb PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${_gRPC_CORE_NOSTDCXX_FLAGS}>)
endif()
target_link_libraries(upb
${_gRPC_SSL_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
)


endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)

add_library(bad_client_test
test/core/bad_client/bad_client.cc
)
Expand Down
38 changes: 37 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,7 @@ plugins: $(PROTOC_PLUGINS)

privatelibs: privatelibs_c privatelibs_cxx

privatelibs_c: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libcxxabi.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libreconnect_server.a $(LIBDIR)/$(CONFIG)/libtest_tcp_server.a $(LIBDIR)/$(CONFIG)/libz.a $(LIBDIR)/$(CONFIG)/libares.a $(LIBDIR)/$(CONFIG)/libbad_client_test.a $(LIBDIR)/$(CONFIG)/libbad_ssl_test_server.a $(LIBDIR)/$(CONFIG)/libend2end_tests.a $(LIBDIR)/$(CONFIG)/libend2end_nosec_tests.a
privatelibs_c: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libcxxabi.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libreconnect_server.a $(LIBDIR)/$(CONFIG)/libtest_tcp_server.a $(LIBDIR)/$(CONFIG)/libupb.a $(LIBDIR)/$(CONFIG)/libz.a $(LIBDIR)/$(CONFIG)/libares.a $(LIBDIR)/$(CONFIG)/libbad_client_test.a $(LIBDIR)/$(CONFIG)/libbad_ssl_test_server.a $(LIBDIR)/$(CONFIG)/libend2end_tests.a $(LIBDIR)/$(CONFIG)/libend2end_nosec_tests.a
pc_c: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc

pc_c_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc
Expand Down Expand Up @@ -10117,6 +10117,42 @@ ifneq ($(NO_DEPS),true)
endif


LIBUPB_SRC = \
third_party/upb/google/protobuf/descriptor.upb.c \
third_party/upb/upb/decode.c \
third_party/upb/upb/def.c \
third_party/upb/upb/encode.c \
third_party/upb/upb/handlers.c \
third_party/upb/upb/msg.c \
third_party/upb/upb/msgfactory.c \
third_party/upb/upb/refcounted.c \
third_party/upb/upb/sink.c \
third_party/upb/upb/table.c \
third_party/upb/upb/upb.c \

PUBLIC_HEADERS_C += \

LIBUPB_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBUPB_SRC))))

$(LIBUPB_OBJS): CFLAGS += -Ithird_party/upb -Wno-sign-conversion -Wno-shadow -Wno-conversion -Wno-implicit-fallthrough

$(LIBDIR)/$(CONFIG)/libupb.a: $(ZLIB_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP) $(LIBUPB_OBJS)
$(E) "[AR] Creating $@"
$(Q) mkdir -p `dirname $@`
$(Q) rm -f $(LIBDIR)/$(CONFIG)/libupb.a
$(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/libupb.a $(LIBUPB_OBJS)
ifeq ($(SYSTEM),Darwin)
$(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/libupb.a
endif




ifneq ($(NO_DEPS),true)
-include $(LIBUPB_OBJS:.o=.dep)
endif


LIBZ_SRC = \
third_party/zlib/adler32.c \
third_party/zlib/compress.c \
Expand Down
1 change: 1 addition & 0 deletions bazel/grpc_build_system.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def grpc_cc_library(
linkopts = if_not_windows(["-pthread"]),
includes = [
"include",
"src/core/ext/upb-generated",
],
alwayslink = alwayslink,
data = data,
Expand Down
6 changes: 3 additions & 3 deletions bazel/grpc_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def grpc_deps():
)

native.bind(
name = "upblib",
name = "upb_lib",
actual = "@upb//:upb",
)

Expand Down Expand Up @@ -195,8 +195,8 @@ def grpc_deps():
if "upb" not in native.existing_rules():
http_archive(
name = "upb",
strip_prefix = "upb-9ce4a77f61c134bbed28bfd5be5cd7dc0e80f5e3",
url = "https://github.com/google/upb/archive/9ce4a77f61c134bbed28bfd5be5cd7dc0e80f5e3.tar.gz",
strip_prefix = "upb-fb6f7e96895c3a9a8ae2e66516160937e7ac1779",
url = "https://github.com/google/upb/archive/fb6f7e96895c3a9a8ae2e66516160937e7ac1779.tar.gz",
)


Expand Down
2 changes: 2 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5896,6 +5896,8 @@ defaults:
-Wno-deprecated-declarations -Ithird_party/nanopb -DPB_FIELD_32BIT
CXXFLAGS: -Wnon-virtual-dtor
LDFLAGS: -g
upb:
CFLAGS: -Ithird_party/upb -Wno-sign-conversion -Wno-shadow -Wno-conversion -Wno-implicit-fallthrough
zlib:
CFLAGS: -Wno-sign-conversion -Wno-conversion -Wno-unused-value -Wno-implicit-function-declaration
-Wno-implicit-fallthrough $(W_NO_SHIFT_NEGATIVE_VALUE) -fvisibility=hidden
Expand Down
19 changes: 19 additions & 0 deletions grpc.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -2640,6 +2640,25 @@
'third_party/benchmark/src/timers.cc',
],
},
{
'target_name': 'upb',
'type': 'static_library',
'dependencies': [
],
'sources': [
'third_party/upb/google/protobuf/descriptor.upb.c',
'third_party/upb/upb/decode.c',
'third_party/upb/upb/def.c',
'third_party/upb/upb/encode.c',
'third_party/upb/upb/handlers.c',
'third_party/upb/upb/msg.c',
'third_party/upb/upb/msgfactory.c',
'third_party/upb/upb/refcounted.c',
'third_party/upb/upb/sink.c',
'third_party/upb/upb/table.c',
'third_party/upb/upb/upb.c',
],
},
{
'target_name': 'z',
'type': 'static_library',
Expand Down
24 changes: 24 additions & 0 deletions src/core/ext/upb-generated/google/protobuf/any.upb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* This file was generated by upbc (the upb compiler) from the input
* file:
*
* google/protobuf/any.proto
*
* Do not edit -- your changes will be discarded when the file is
* regenerated. */

#include "google/protobuf/any.upb.h"
#include <stddef.h>
#include "upb/msg.h"

#include "upb/port_def.inc"

static const upb_msglayout_field google_protobuf_Any__fields[2] = {
{1, UPB_SIZE(0, 0), 0, 0, 9, 1},
{2, UPB_SIZE(8, 16), 0, 0, 12, 1},
};

const upb_msglayout google_protobuf_Any_msginit = {
NULL, &google_protobuf_Any__fields[0], UPB_SIZE(16, 32), 2, false,
};

#include "upb/port_undef.inc"
63 changes: 63 additions & 0 deletions src/core/ext/upb-generated/google/protobuf/any.upb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* This file was generated by upbc (the upb compiler) from the input
* file:
*
* google/protobuf/any.proto
*
* Do not edit -- your changes will be discarded when the file is
* regenerated. */

#ifndef GOOGLE_PROTOBUF_ANY_PROTO_UPB_H_
#define GOOGLE_PROTOBUF_ANY_PROTO_UPB_H_

#include "upb/msg.h"

#include "upb/decode.h"
#include "upb/encode.h"
#include "upb/port_def.inc"
UPB_BEGIN_EXTERN_C

struct google_protobuf_Any;
typedef struct google_protobuf_Any google_protobuf_Any;

/* Enums */

/* google.protobuf.Any */

extern const upb_msglayout google_protobuf_Any_msginit;
UPB_INLINE google_protobuf_Any* google_protobuf_Any_new(upb_arena* arena) {
return upb_msg_new(&google_protobuf_Any_msginit, arena);
}
UPB_INLINE google_protobuf_Any* google_protobuf_Any_parsenew(upb_stringview buf,
upb_arena* arena) {
google_protobuf_Any* ret = google_protobuf_Any_new(arena);
return (ret && upb_decode(buf, ret, &google_protobuf_Any_msginit)) ? ret
: NULL;
}
UPB_INLINE char* google_protobuf_Any_serialize(const google_protobuf_Any* msg,
upb_arena* arena, size_t* len) {
return upb_encode(msg, &google_protobuf_Any_msginit, arena, len);
}

UPB_INLINE upb_stringview
google_protobuf_Any_type_url(const google_protobuf_Any* msg) {
return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(0, 0));
}
UPB_INLINE upb_stringview
google_protobuf_Any_value(const google_protobuf_Any* msg) {
return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16));
}

UPB_INLINE void google_protobuf_Any_set_type_url(google_protobuf_Any* msg,
upb_stringview value) {
UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(0, 0)) = value;
}
UPB_INLINE void google_protobuf_Any_set_value(google_protobuf_Any* msg,
upb_stringview value) {
UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value;
}

UPB_END_EXTERN_C

#include "upb/port_undef.inc"

#endif /* GOOGLE_PROTOBUF_ANY_PROTO_UPB_H_ */
Loading

0 comments on commit 311ee1e

Please sign in to comment.