diff --git a/BUILD b/BUILD index 67c14ca32ea..5153bf66847 100644 --- a/BUILD +++ b/BUILD @@ -1319,3 +1319,21 @@ objc_bundle_library( name = "gRPCCertificates", resources = ["etc/roots.pem"], ) + +proto_objc_rpc_path = objc_path + "/ProtoRPC" + +objc_library( + name = "proto_objc_rpc", + hdrs = glob([ + proto_objc_rpc_path + "/*.h", + ]), + srcs = glob([ + proto_objc_rpc_path + "/*.m", + ]), + includes = [objc_path], + deps = [ + ":grpc_client", + ":rx_library", + "//external:protobuf_objc", + ], +) diff --git a/Makefile b/Makefile index 1038158524e..9523e95052b 100644 --- a/Makefile +++ b/Makefile @@ -331,6 +331,8 @@ HOST_LDLIBS = $(LDLIBS) # These are automatically computed variables. # There shouldn't be any need to change anything from now on. +HAS_PKG_CONFIG = $(shell command -v pkg-config >/dev/null 2>&1 && echo true || echo false) + ifeq ($(SYSTEM),MINGW32) SHARED_EXT = dll endif @@ -355,6 +357,13 @@ ifeq ($(SYSTEM),Darwin) OPENSSL_REQUIRES_DL = true endif +ifeq ($(HAS_PKG_CONFIG),true) +OPENSSL_ALPN_CHECK_CMD = pkg-config --atleast-version=1.0.2 openssl +ZLIB_CHECK_CMD = pkg-config --exists zlib +PERFTOOLS_CHECK_CMD = pkg-config --exists profiler +PROTOBUF_CHECK_CMD = pkg-config --atleast-version=3.0.0-alpha-3 protobuf +else # HAS_PKG_CONFIG + ifeq ($(SYSTEM),MINGW32) OPENSSL_LIBS = ssl32 eay32 else @@ -365,15 +374,18 @@ OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/ope ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS) PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS) PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS) -PROTOC_CHECK_CMD = which protoc > /dev/null -PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3 -DTRACE_CHECK_CMD = which dtrace > /dev/null -SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS) ifeq ($(OPENSSL_REQUIRES_DL),true) OPENSSL_ALPN_CHECK_CMD += -ldl endif +endif # HAS_PKG_CONFIG + +PROTOC_CHECK_CMD = which protoc > /dev/null +PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3 +DTRACE_CHECK_CMD = which dtrace > /dev/null +SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS) + ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG) HAS_SYSTEM_PERFTOOLS = $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false) ifeq ($(HAS_SYSTEM_PERFTOOLS),true) @@ -442,9 +454,33 @@ LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib else DEP_MISSING += zlib endif +else +ifeq ($(HAS_PKG_CONFIG),true) +CPPFLAGS += $(shell pkg-config --cflags zlib) +LDFLAGS += $(shell pkg-config --libs-only-L zlib) +endif endif -ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),false) +OPENSSL_PKG_CONFIG = false + +ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true) +ifeq ($(HAS_PKG_CONFIG),true) +OPENSSL_PKG_CONFIG = true +CPPFLAGS := $(shell pkg-config --cflags openssl) $(CPPFLAGS) +LDFLAGS_OPENSSL_PKG_CONFIG = $(shell pkg-config --libs-only-L openssl) +ifeq ($(SYSTEM),Linux) +ifneq ($(LDFLAGS_OPENSSL_PKG_CONFIG),) +LDFLAGS_OPENSSL_PKG_CONFIG += $(shell pkg-config --libs-only-L openssl | sed s/L/Wl,-rpath,/) +endif +endif +LDFLAGS := $(LDFLAGS_OPENSSL_PKG_CONFIG) $(LDFLAGS) +else +LIBS_SECURE = $(OPENSSL_LIBS) +ifeq ($(OPENSSL_REQUIRES_DL),true) +LIBS_SECURE += dl +endif +endif +else ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true) OPENSSL_DEP = $(LIBDIR)/$(CONFIG)/openssl/libssl.a OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/openssl/libssl.a $(LIBDIR)/$(CONFIG)/openssl/libcrypto.a @@ -457,16 +493,28 @@ endif else NO_SECURE = true endif -else -LIBS_SECURE = $(OPENSSL_LIBS) -ifeq ($(OPENSSL_REQUIRES_DL),true) -LIBS_SECURE += dl -endif endif +ifeq ($(OPENSSL_PKG_CONFIG),true) +LDLIBS_SECURE += $(shell pkg-config --libs-only-l openssl) +else LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE)) +endif + +PROTOBUF_PKG_CONFIG = false -ifeq ($(HAS_SYSTEM_PROTOBUF),false) +ifeq ($(HAS_SYSTEM_PROTOBUF),true) +ifeq ($(HAS_PKG_CONFIG),true) +PROTOBUF_PKG_CONFIG = true +CPPFLAGS := $(shell pkg-config --cflags protobuf) $(CPPFLAGS) +LDFLAGS_PROTOBUF_PKG_CONFIG = $(shell pkg-config --libs-only-L protobuf) +ifeq ($(SYSTEM),Linux) +ifneq ($(LDFLAGS_PROTOBUF_PKG_CONFIG),) +LDFLAGS_PROTOBUF_PKG_CONFIG += $(shell pkg-config --libs-only-L protobuf | sed s/L/Wl,-rpath,/) +endif +endif +endif +else ifeq ($(HAS_EMBEDDED_PROTOBUF),true) PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS) @@ -475,15 +523,19 @@ PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc else NO_PROTOBUF = true endif -else endif LIBS_PROTOBUF = protobuf LIBS_PROTOC = protoc protobuf -LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF)) HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC)) +ifeq ($(PROTOBUF_PKG_CONFIG),true) +LDLIBS_PROTOBUF += $(shell pkg-config --libs-only-l protobuf) +else +LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF)) +endif + ifeq ($(MAKECMDGOALS),clean) NO_DEPS = true endif diff --git a/src/objective-c/ProtoRPC/ProtoRPC.m b/src/objective-c/ProtoRPC/ProtoRPC.m index 39120344156..4da646d7b45 100644 --- a/src/objective-c/ProtoRPC/ProtoRPC.m +++ b/src/objective-c/ProtoRPC/ProtoRPC.m @@ -33,7 +33,7 @@ #import "ProtoRPC.h" -#import +#import #import #import #import @@ -66,6 +66,8 @@ // A writer that serializes the proto messages to send. id bytesWriter = [[[GRXWriter alloc] initWithWriter:requestsWriter] map:^id(GPBMessage *proto) { + // TODO(jcanizales): Fail with an understandable error message if the requestsWriter isn't + // sending GPBMessages. return [proto data]; }]; if ((self = [super initWithHost:host method:method requestsWriter:bytesWriter])) { diff --git a/src/php/bin/determine_extension_dir.sh b/src/php/bin/determine_extension_dir.sh index 6fc392afc0a..6bbd934bf13 100755 --- a/src/php/bin/determine_extension_dir.sh +++ b/src/php/bin/determine_extension_dir.sh @@ -29,15 +29,15 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. set -e -default_extension_dir=$(php -i | grep extension_dir | sed 's/.*=> //g') +default_extension_dir=$(php-config --extension-dir) if command -v brew >/dev/null && [ -d $(brew --prefix)/opt/grpc-php ]; then # homebrew and the grpc-php formula are installed extension_dir="-d extension_dir="$(brew --prefix)/opt/grpc-php -elif [ ! -f $default_extension_dir/grpc.so ]; then +elif [ ! -e $default_extension_dir/grpc.so ]; then # the grpc extension is not found in the default PHP extension dir # try the source modules directory module_dir=../ext/grpc/modules - if [ ! -f $module_dir/grpc.so ]; then + if [ ! -e $module_dir/grpc.so ]; then echo "Please run 'phpize && ./configure && make' from ext/grpc first" exit 1 fi diff --git a/src/python/src/grpc/_adapter/_c/types.h b/src/python/src/grpc/_adapter/_c/types.h index e189ae25660..3449f0643f7 100644 --- a/src/python/src/grpc/_adapter/_c/types.h +++ b/src/python/src/grpc/_adapter/_c/types.h @@ -241,10 +241,10 @@ double pygrpc_cast_gpr_timespec_to_double(gpr_timespec timespec); gpr_timespec pygrpc_cast_double_to_gpr_timespec(double seconds); /* Returns true on success, false on failure. */ -int pygrpc_cast_pylist_to_send_metadata( - PyObject *pylist, grpc_metadata **metadata, size_t *count); +int pygrpc_cast_pyseq_to_send_metadata( + PyObject *pyseq, grpc_metadata **metadata, size_t *count); /* Returns a metadata array as a Python object on success, else NULL. */ -PyObject *pygrpc_cast_metadata_array_to_pylist(grpc_metadata_array metadata); +PyObject *pygrpc_cast_metadata_array_to_pyseq(grpc_metadata_array metadata); /* Transliterate from a list of python channel arguments (2-tuples of string and string|integer|None) to a grpc_channel_args object. The strings placed diff --git a/src/python/src/grpc/_adapter/_c/utility.c b/src/python/src/grpc/_adapter/_c/utility.c index a433f26d769..480a720c21f 100644 --- a/src/python/src/grpc/_adapter/_c/utility.c +++ b/src/python/src/grpc/_adapter/_c/utility.c @@ -32,6 +32,7 @@ */ #include +#include #define PY_SSIZE_T_CLEAN #include @@ -118,7 +119,7 @@ PyObject *pygrpc_consume_event(grpc_event event) { tag->request_call_details.method, tag->request_call_details.host, pygrpc_cast_gpr_timespec_to_double(tag->request_call_details.deadline), GRPC_OP_RECV_INITIAL_METADATA, - pygrpc_cast_metadata_array_to_pylist(tag->request_metadata), Py_None, + pygrpc_cast_metadata_array_to_pyseq(tag->request_metadata), Py_None, Py_None, Py_None, Py_None, event.success ? Py_True : Py_False); } else { @@ -172,7 +173,7 @@ int pygrpc_produce_op(PyObject *op, grpc_op *result) { c_op.flags = 0; switch (type) { case GRPC_OP_SEND_INITIAL_METADATA: - if (!pygrpc_cast_pylist_to_send_metadata( + if (!pygrpc_cast_pyseq_to_send_metadata( PyTuple_GetItem(op, INITIAL_METADATA_INDEX), &c_op.data.send_initial_metadata.metadata, &c_op.data.send_initial_metadata.count)) { @@ -190,7 +191,7 @@ int pygrpc_produce_op(PyObject *op, grpc_op *result) { /* Don't need to fill in any other fields. */ break; case GRPC_OP_SEND_STATUS_FROM_SERVER: - if (!pygrpc_cast_pylist_to_send_metadata( + if (!pygrpc_cast_pyseq_to_send_metadata( PyTuple_GetItem(op, TRAILING_METADATA_INDEX), &c_op.data.send_status_from_server.trailing_metadata, &c_op.data.send_status_from_server.trailing_metadata_count)) { @@ -247,8 +248,16 @@ int pygrpc_produce_op(PyObject *op, grpc_op *result) { } void pygrpc_discard_op(grpc_op op) { + size_t i; switch(op.op) { case GRPC_OP_SEND_INITIAL_METADATA: + /* Whenever we produce send-metadata, we allocate new strings (to handle + arbitrary sequence input as opposed to just lists or just tuples). We + thus must free those elements. */ + for (i = 0; i < op.data.send_initial_metadata.count; ++i) { + gpr_free((void *)op.data.send_initial_metadata.metadata[i].key); + gpr_free((void *)op.data.send_initial_metadata.metadata[i].value); + } gpr_free(op.data.send_initial_metadata.metadata); break; case GRPC_OP_SEND_MESSAGE: @@ -258,6 +267,16 @@ void pygrpc_discard_op(grpc_op op) { /* Don't need to free any fields. */ break; case GRPC_OP_SEND_STATUS_FROM_SERVER: + /* Whenever we produce send-metadata, we allocate new strings (to handle + arbitrary sequence input as opposed to just lists or just tuples). We + thus must free those elements. */ + for (i = 0; i < op.data.send_status_from_server.trailing_metadata_count; + ++i) { + gpr_free( + (void *)op.data.send_status_from_server.trailing_metadata[i].key); + gpr_free( + (void *)op.data.send_status_from_server.trailing_metadata[i].value); + } gpr_free(op.data.send_status_from_server.trailing_metadata); gpr_free((char *)op.data.send_status_from_server.status_details); break; @@ -419,31 +438,41 @@ void pygrpc_discard_channel_args(grpc_channel_args args) { gpr_free(args.args); } -int pygrpc_cast_pylist_to_send_metadata( - PyObject *pylist, grpc_metadata **metadata, size_t *count) { +int pygrpc_cast_pyseq_to_send_metadata( + PyObject *pyseq, grpc_metadata **metadata, size_t *count) { size_t i; Py_ssize_t value_length; - *count = PyList_Size(pylist); + char *key; + char *value; + if (!PySequence_Check(pyseq)) { + return 0; + } + *count = PySequence_Size(pyseq); *metadata = gpr_malloc(sizeof(grpc_metadata) * *count); for (i = 0; i < *count; ++i) { - if (!PyArg_ParseTuple( - PyList_GetItem(pylist, i), "ss#", - &(*metadata)[i].key, &(*metadata)[i].value, &value_length)) { + PyObject *item = PySequence_GetItem(pyseq, i); + if (!PyArg_ParseTuple(item, "ss#", &key, &value, &value_length)) { + Py_DECREF(item); gpr_free(*metadata); *count = 0; *metadata = NULL; return 0; + } else { + (*metadata)[i].key = gpr_strdup(key); + (*metadata)[i].value = gpr_malloc(value_length); + memcpy((void *)(*metadata)[i].value, value, value_length); + Py_DECREF(item); } (*metadata)[i].value_length = value_length; } return 1; } -PyObject *pygrpc_cast_metadata_array_to_pylist(grpc_metadata_array metadata) { - PyObject *result = PyList_New(metadata.count); +PyObject *pygrpc_cast_metadata_array_to_pyseq(grpc_metadata_array metadata) { + PyObject *result = PyTuple_New(metadata.count); size_t i; for (i = 0; i < metadata.count; ++i) { - PyList_SetItem( + PyTuple_SetItem( result, i, Py_BuildValue( "ss#", metadata.metadata[i].key, metadata.metadata[i].value, (Py_ssize_t)metadata.metadata[i].value_length)); diff --git a/src/python/src/grpc/_adapter/_intermediary_low.py b/src/python/src/grpc/_adapter/_intermediary_low.py index 6b96aef1d34..3c7f0a26197 100644 --- a/src/python/src/grpc/_adapter/_intermediary_low.py +++ b/src/python/src/grpc/_adapter/_intermediary_low.py @@ -144,10 +144,11 @@ class Call(object): self._metadata.append((key, value)) def premetadata(self): - return self._internal.start_batch([ + result = self._internal.start_batch([ _types.OpArgs.send_initial_metadata(self._metadata) ], _IGNORE_ME_TAG) self._metadata = [] + return result def read(self, tag): return self._internal.start_batch([ diff --git a/src/python/src/grpc/_adapter/_intermediary_low_test.py b/src/python/src/grpc/_adapter/_intermediary_low_test.py index 1a9b0c69f3c..27a5b82e9c4 100644 --- a/src/python/src/grpc/_adapter/_intermediary_low_test.py +++ b/src/python/src/grpc/_adapter/_intermediary_low_test.py @@ -282,6 +282,9 @@ class EchoTest(unittest.TestCase): self.assertIn(server_trailing_binary_metadata_key, metadata) self.assertEqual(server_trailing_binary_metadata_value, metadata[server_trailing_binary_metadata_key]) + self.assertSetEqual(set(key for key, _ in finish_accepted.metadata), + set((server_trailing_metadata_key, + server_trailing_binary_metadata_key,))) server_timeout_none_event = self.server_completion_queue.get(0) self.assertIsNone(server_timeout_none_event) diff --git a/templates/BUILD.template b/templates/BUILD.template index 4d2bf7db283..dffdc1dddde 100644 --- a/templates/BUILD.template +++ b/templates/BUILD.template @@ -205,3 +205,21 @@ objc_bundle_library( name = "gRPCCertificates", resources = ["etc/roots.pem"], ) + +proto_objc_rpc_path = objc_path + "/ProtoRPC" + +objc_library( + name = "proto_objc_rpc", + hdrs = glob([ + proto_objc_rpc_path + "/*.h", + ]), + srcs = glob([ + proto_objc_rpc_path + "/*.m", + ]), + includes = [objc_path], + deps = [ + ":grpc_client", + ":rx_library", + "//external:protobuf_objc", + ], +) diff --git a/templates/Makefile.template b/templates/Makefile.template index ebe207f1918..3b04d7d0415 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -345,6 +345,8 @@ HOST_LDLIBS = $(LDLIBS) # These are automatically computed variables. # There shouldn't be any need to change anything from now on. +HAS_PKG_CONFIG = $(shell command -v pkg-config >/dev/null 2>&1 && echo true || echo false) + ifeq ($(SYSTEM),MINGW32) SHARED_EXT = dll endif @@ -369,6 +371,13 @@ ifeq ($(SYSTEM),Darwin) OPENSSL_REQUIRES_DL = true endif +ifeq ($(HAS_PKG_CONFIG),true) +OPENSSL_ALPN_CHECK_CMD = pkg-config --atleast-version=1.0.2 openssl +ZLIB_CHECK_CMD = pkg-config --exists zlib +PERFTOOLS_CHECK_CMD = pkg-config --exists profiler +PROTOBUF_CHECK_CMD = pkg-config --atleast-version=3.0.0-alpha-3 protobuf +else # HAS_PKG_CONFIG + ifeq ($(SYSTEM),MINGW32) OPENSSL_LIBS = ssl32 eay32 else @@ -379,15 +388,18 @@ OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/ope ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS) PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS) PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS) -PROTOC_CHECK_CMD = which protoc > /dev/null -PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3 -DTRACE_CHECK_CMD = which dtrace > /dev/null -SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS) ifeq ($(OPENSSL_REQUIRES_DL),true) OPENSSL_ALPN_CHECK_CMD += -ldl endif +endif # HAS_PKG_CONFIG + +PROTOC_CHECK_CMD = which protoc > /dev/null +PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3 +DTRACE_CHECK_CMD = which dtrace > /dev/null +SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS) + ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG) HAS_SYSTEM_PERFTOOLS = $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false) ifeq ($(HAS_SYSTEM_PERFTOOLS),true) @@ -456,9 +468,33 @@ LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib else DEP_MISSING += zlib endif +else +ifeq ($(HAS_PKG_CONFIG),true) +CPPFLAGS += $(shell pkg-config --cflags zlib) +LDFLAGS += $(shell pkg-config --libs-only-L zlib) +endif endif -ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),false) +OPENSSL_PKG_CONFIG = false + +ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true) +ifeq ($(HAS_PKG_CONFIG),true) +OPENSSL_PKG_CONFIG = true +CPPFLAGS := $(shell pkg-config --cflags openssl) $(CPPFLAGS) +LDFLAGS_OPENSSL_PKG_CONFIG = $(shell pkg-config --libs-only-L openssl) +ifeq ($(SYSTEM),Linux) +ifneq ($(LDFLAGS_OPENSSL_PKG_CONFIG),) +LDFLAGS_OPENSSL_PKG_CONFIG += $(shell pkg-config --libs-only-L openssl | sed s/L/Wl,-rpath,/) +endif +endif +LDFLAGS := $(LDFLAGS_OPENSSL_PKG_CONFIG) $(LDFLAGS) +else +LIBS_SECURE = $(OPENSSL_LIBS) +ifeq ($(OPENSSL_REQUIRES_DL),true) +LIBS_SECURE += dl +endif +endif +else ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true) OPENSSL_DEP = $(LIBDIR)/$(CONFIG)/openssl/libssl.a OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/openssl/libssl.a $(LIBDIR)/$(CONFIG)/openssl/libcrypto.a @@ -471,16 +507,28 @@ endif else NO_SECURE = true endif -else -LIBS_SECURE = $(OPENSSL_LIBS) -ifeq ($(OPENSSL_REQUIRES_DL),true) -LIBS_SECURE += dl -endif endif +ifeq ($(OPENSSL_PKG_CONFIG),true) +LDLIBS_SECURE += $(shell pkg-config --libs-only-l openssl) +else LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE)) +endif + +PROTOBUF_PKG_CONFIG = false -ifeq ($(HAS_SYSTEM_PROTOBUF),false) +ifeq ($(HAS_SYSTEM_PROTOBUF),true) +ifeq ($(HAS_PKG_CONFIG),true) +PROTOBUF_PKG_CONFIG = true +CPPFLAGS := $(shell pkg-config --cflags protobuf) $(CPPFLAGS) +LDFLAGS_PROTOBUF_PKG_CONFIG = $(shell pkg-config --libs-only-L protobuf) +ifeq ($(SYSTEM),Linux) +ifneq ($(LDFLAGS_PROTOBUF_PKG_CONFIG),) +LDFLAGS_PROTOBUF_PKG_CONFIG += $(shell pkg-config --libs-only-L protobuf | sed s/L/Wl,-rpath,/) +endif +endif +endif +else ifeq ($(HAS_EMBEDDED_PROTOBUF),true) PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS) @@ -489,15 +537,19 @@ PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc else NO_PROTOBUF = true endif -else endif LIBS_PROTOBUF = protobuf LIBS_PROTOC = protoc protobuf -LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF)) HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC)) +ifeq ($(PROTOBUF_PKG_CONFIG),true) +LDLIBS_PROTOBUF += $(shell pkg-config --libs-only-l protobuf) +else +LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF)) +endif + ifeq ($(MAKECMDGOALS),clean) NO_DEPS = true endif