Building gRPC with Autotools. This patch enables building gRPC through Autotools under Linux with opetion `--enable-grpc`. Additionally, another option `--enable-grpc` is added to let the user specify the path to a custom gRPC library. This option depends on `--with-protobuf` to avoid using conflicting versions of Protobuf libraries.
For OpenSSL and unbundled Protobuf, we introduce new variables `<lib>_CPPFLAGS` and `<lib>_LINKERFLAGS` for building gRPC. Review: https://reviews.apache.org/r/61159 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/90f7a7e1 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/90f7a7e1 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/90f7a7e1 Branch: refs/heads/master Commit: 90f7a7e140d4dbee53a0edc2ab225a4ea83db3a5 Parents: fa0494e Author: Chun-Hung Hsiao <chhs...@mesosphere.io> Authored: Tue May 23 10:49:00 2017 -0700 Committer: Jie Yu <yujie....@gmail.com> Committed: Thu Aug 10 16:55:06 2017 -0700 ---------------------------------------------------------------------- 3rdparty/Makefile.am | 50 +++++++++++++++++++ 3rdparty/versions.am | 1 + configure.ac | 123 ++++++++++++++++++++++++++++++++++++++++++++-- src/Makefile.am | 15 ++++++ 4 files changed, 185 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/90f7a7e1/3rdparty/Makefile.am ---------------------------------------------------------------------- diff --git a/3rdparty/Makefile.am b/3rdparty/Makefile.am index 742b8bf..2182837 100644 --- a/3rdparty/Makefile.am +++ b/3rdparty/Makefile.am @@ -38,6 +38,8 @@ CONFIGURE_ARGS = @CONFIGURE_ARGS@ --enable-shared=no --with-pic --srcdir=. CONFIGURE_ARGS += --prefix=/ # Set up building flags for non-bundled libraries. +SSL_INCLUDE_FLAGS = @SSL_CPPFLAGS@ +SSL_LINKER_FLAGS = @SSL_LINKERFLAGS@ ZLIB_INCLUDE_FLAGS = @ZLIB_CPPFLAGS@ ZLIB_LINKER_FLAGS = @ZLIB_LINKERFLAGS@ @@ -53,6 +55,7 @@ GLOG = glog-$(GLOG_VERSION) GOOGLETEST = googletest-release-$(GOOGLETEST_VERSION) GMOCK = $(GOOGLETEST)/googlemock GPERFTOOLS = gperftools-$(GPERFTOOLS_VERSION) +GRPC = grpc-$(GRPC_VERSION) GTEST = $(GOOGLETEST)/googletest HTTP_PARSER = http-parser-$(HTTP_PARSER_VERSION) LEVELDB = leveldb-$(LEVELDB_VERSION) @@ -72,6 +75,7 @@ EXTRA_DIST = \ $(GLOG).tar.gz \ $(GOOGLETEST).tar.gz \ $(GPERFTOOLS).tar.gz \ + $(GRPC).tar.gz \ $(HTTP_PARSER).tar.gz \ $(LEVELDB).tar.gz \ $(LIBEV).tar.gz \ @@ -88,6 +92,10 @@ EXTRA_DIST = \ EXTRA_DIST += \ $(GLOG).patch +# We patch grpc for CMake compilation issues. +EXTRA_DIST += \ + $(GRPC).patch + # We need to patch leveldb to prevent it from linking to snappy and # tcmalloc; see MESOS-1054, MESOS-1624. EXTRA_DIST += \ @@ -108,6 +116,7 @@ CLEAN_EXTRACTED = \ $(GLOG) \ $(GOOGLETEST) \ $(GPERFTOOLS) \ + $(GRPC) \ $(HTTP_PARSER) \ $(LEVELDB) \ $(LIBEV) \ @@ -280,6 +289,47 @@ $(PROTOBUF)-build-stamp: $(PROTOBUF)-stamp touch $@ ALL_LOCAL += $(PROTOBUF)/src/libprotobuf.la ALL_LOCAL += $(PROTOBUF)/src/protoc + +PROTOBUF_INCLUDE_FLAGS = -I$(abs_builddir)/$(PROTOBUF)/src +PROTOBUF_LINKER_FLAGS = -L$(abs_builddir)/$(PROTOBUF)/src/.libs +PROTOC = $(abs_builddir)/$(PROTOBUF)/src/protoc +else +$(PROTOBUF)-build-stamp: + touch $@ + +PROTOBUF_INCLUDE_FLAGS = @PROTOBUF_CPPFLAGS@ +PROTOBUF_LINKER_FLAGS = @PROTOBUF_LINKERFLAGS@ +PROTOC = @PROTOCOMPILER@ +endif + +if ENABLE_GRPC +if WITH_BUNDLED_GRPC +LIB_GRPC = $(GRPC)/libs/opt/libgrpc++.a \ + $(GRPC)/libs/opt/libgrpc.a \ + $(GRPC)/libs/opt/libgpr.a + +$(LIB_GRPC): $(GRPC)-build-stamp + +$(GRPC)-build-stamp: $(GRPC)-stamp \ + $(PROTOBUF)-build-stamp + cd $(GRPC) && \ + CPPFLAGS="$(PROTOBUF_INCLUDE_FLAGS) \ + $(SSL_INCLUDE_FLAGS) \ + $(ZLIB_INCLUDE_FLAGS)" \ + LDFLAGS="$(PROTOBUF_LINKER_FLAGS) \ + $(SSL_LINKER_FLAGS) \ + $(ZLIB_LINKER_FLAGS)" \ + $(MAKE) $(AM_MAKEFLAGS) \ + HAS_PKG_CONFIG=false \ + NO_PROTOC=false \ + PROTOC=$(PROTOC) + touch $@ + +ALL_LOCAL += $(LIB_GRPC) +else +$(GRPC)-build-stamp: + touch $@ +endif endif # Convenience library for gmock/gtest. http://git-wip-us.apache.org/repos/asf/mesos/blob/90f7a7e1/3rdparty/versions.am ---------------------------------------------------------------------- diff --git a/3rdparty/versions.am b/3rdparty/versions.am index 0893572..82d66be 100644 --- a/3rdparty/versions.am +++ b/3rdparty/versions.am @@ -25,6 +25,7 @@ ELFIO_VERSION = 3.2 GLOG_VERSION = 0.3.3 GOOGLETEST_VERSION = 1.8.0 GPERFTOOLS_VERSION = 2.5 +GRPC_VERSION = 1.4.2 HTTP_PARSER_VERSION = 2.6.2 LEVELDB_VERSION = 1.19 LIBEV_VERSION = 4.22 http://git-wip-us.apache.org/repos/asf/mesos/blob/90f7a7e1/configure.ac ---------------------------------------------------------------------- diff --git a/configure.ac b/configure.ac index b6a6deb..ee3818d 100644 --- a/configure.ac +++ b/configure.ac @@ -205,6 +205,11 @@ AC_ARG_ENABLE([debug], option won't change them]), [], [enable_debug=no]) +AC_ARG_ENABLE([grpc], + AS_HELP_STRING([--enable-grpc], + [enable grpc support]), + [], [enable_grpc=no]) + AC_ARG_ENABLE([port-mapping-isolator], AS_HELP_STRING([--enable-port-mapping-isolator], [enable port mapping network isolator]), @@ -331,6 +336,13 @@ AC_ARG_WITH([gmock], location prefixed by the given path]), [without_bundled_gmock=yes], []) +AC_ARG_WITH([grpc], + AS_HELP_STRING([--with-grpc@<:@=DIR@:>@], + [excludes building and using the bundled grpc + package in lieu of an installed version at a + location prefixed by the given path]), + [without_bundled_grpc=yes], []) + AC_ARG_WITH([http-parser], AS_HELP_STRING([--with-http-parser@<:@=DIR@:>@], [excludes building and using the bundled http-parser @@ -1463,8 +1475,11 @@ AM_CONDITIONAL([WITH_BUNDLED_NVML], # CPPFLAGS while extending it by /include and to LDFLAGS while # extending it by /lib. if test -n "`echo $with_protobuf`"; then - CPPFLAGS="$CPPFLAGS -isystem ${with_protobuf}/include" - LDFLAGS="$LDFLAGS -L${with_protobuf}/lib" + PROTOBUF_CPPFLAGS="-isystem ${with_protobuf}/include" + PROTOBUF_LINKERFLAGS="-L${with_protobuf}/lib" + + CPPFLAGS="$PROTOBUF_CPPFLAGS $CPPFLAGS" + LDFLAGS="$PROTOBUF_LINKERFLAGS $LDFLAGS" fi # Check if user has asked us to use a preinstalled protobuf, or if @@ -1541,9 +1556,12 @@ fi AM_CONDITIONAL([WITH_BUNDLED_PROTOBUF], [test "x$with_bundled_protobuf" = "xyes"]) +AC_SUBST([PROTOBUF_CPPFLAGS]) AC_SUBST([PROTOBUF_JAR]) +AC_SUBST([PROTOBUF_LINKERFLAGS]) AC_SUBST([PROTOCOMPILER]) + if test -n "`echo $with_libev`"; then CPPFLAGS="$CPPFLAGS -isystem ${with_libev}/include" LDFLAGS="$LDFLAGS -L${with_libev}/lib" @@ -1728,8 +1746,11 @@ if test -z "`echo $with_ssl`" && fi if test -n "`echo $with_ssl`"; then - CPPFLAGS="-isystem ${with_ssl}/include $CPPFLAGS" - LDFLAGS="-L${with_ssl}/lib $LDFLAGS" + SSL_CPPFLAGS="-isystem ${with_ssl}/include" + SSL_LINKERFLAGS="-L${with_ssl}/lib" + + CPPFLAGS="$SSL_CPPFLAGS $CPPFLAGS" + LDFLAGS="$SSL_LINKERFLAGS $LDFLAGS" fi AC_CHECK_LIB([crypto], [RAND_poll], [found_crypto=yes]) @@ -1783,6 +1804,9 @@ fi AM_CONDITIONAL([ENABLE_SSL], [test x"$enable_ssl" = "xyes"]) +AC_SUBST([SSL_CPPFLAGS]) +AC_SUBST([SSL_LINKERFLAGS]) + # Check if user has asked us to use a preinstalled stout, or if # they asked us to ignore all bundled libraries while compiling and @@ -1930,6 +1954,97 @@ AC_SUBST([ZLIB_CPPFLAGS]) AC_SUBST([ZLIB_LINKERFLAGS]) +# Check if grpc prefix path was supplied and if so, add it to the +# CPPFLAGS and LDFLAGS with respective /include and /lib path suffixes. +if test -n "`echo $with_grpc`"; then + if test "x$without_bundled_protobuf" != "xyes"; then + AC_MSG_ERROR([protobuf not specified +------------------------------------------------------------------- +You have requested the use of a non-bundled grpc without specifying +the protobuf library it uses. This is prohibited to avoid using +conflicting versions of protobuf libraries. Please specify the +location of protobuf used by grpc by providing a prefix path via +--with-protobuf=DIR. +------------------------------------------------------------------- + ]) + fi + + CPPFLAGS="$CPPFLAGS -isystem ${with_grpc}/include" + LDFLAGS="$LDFLAGS -L${with_grpc}/lib" +fi + +if test "x$enable_grpc" = "xyes"; then + # Check if user has asked us to use a preinstalled grpc, or if they + # asked us to ignore all bundled libraries while compiling and linking. + if test "x$without_bundled_grpc" = "xyes" || \ + test "x$enable_bundled" != "xyes"; then + # Use the system default prefix if not specified. + if test -n "`echo $with_grpc`"; then + GRPCPREFIX="${with_grpc}" + elif test "x$enable_bundled" != "xyes"; then + GRPCPREFIX="/usr" + fi + + # Check if headers and library were located. + saved_LIBS="$LIBS" + LIBS="-lgrpc++ -lgrpc -lgpr $LIBS" + AC_LANG_PUSH([C++]) + AC_CHECK_HEADERS([grpc++/grpc++.h], + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM([#include <grpc++/grpc++.h>], + [grpc::Version();])], + [found_grpc=yes], + [found_grpc=no])], + [found_grpc=no]) + AC_LANG_POP() + LIBS="$saved_LIBS" + + if test "x$found_grpc" = "xyes"; then + with_bundled_grpc=no + + AC_CHECK_TOOL([GRPC_CXX_PLUGIN_TEST], + [grpc_cpp_plugin], + [], + [$GRPCPREFIX/bin]) + + if test -z "`echo $GRPC_CXX_PLUGIN_TEST`"; then + AC_MSG_ERROR([grpc_cpp_plugin not found in PATH]) + fi + + GRPC_CXX_PLUGIN="$GRPCPREFIX/bin/grpc_cpp_plugin" + + else + AC_MSG_ERROR([cannot find grpc +------------------------------------------------------------------- +You have requested the use of a non-bundled grpc but no suitable +grpc could be found. + +You may want specify the location of grpc by providing a prefix +path via --with-grpc=DIR, or check that the path you provided is +correct if you are already doing this. +------------------------------------------------------------------- + ]) + fi + else + if test "x$found_ssl" != "xyes"; then + AC_MSG_ERROR([cannot find libssl +------------------------------------------------------------------- +libssl is required for gRPC to build. +------------------------------------------------------------------- + ]) + fi + + with_bundled_grpc=yes + fi +fi + +AM_CONDITIONAL([ENABLE_GRPC], [test "x$enable_grpc" = "xyes"]) +AM_CONDITIONAL([WITH_BUNDLED_GRPC], + [test "x$with_bundled_grpc" = "xyes"]) + +AC_SUBST([GRPC_CXX_PLUGIN]) + + # Check if ZooKeeper prefix path was supplied and if so, add it to # CPPFLAGS while extending it by /include/zookeeper and to LDFLAGS # while extending it by /lib. http://git-wip-us.apache.org/repos/asf/mesos/blob/90f7a7e1/src/Makefile.am ---------------------------------------------------------------------- diff --git a/src/Makefile.am b/src/Makefile.am index 4cf3535..68fff14 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -39,6 +39,7 @@ GLOG = 3rdparty/glog-$(GLOG_VERSION) GOOGLETEST = 3rdparty/googletest-release-$(GOOGLETEST_VERSION) GMOCK = $(GOOGLETEST)/googlemock GTEST = $(GOOGLETEST)/googletest +GRPC = 3rdparty/grpc-$(GRPC_VERSION) PROTOBUF = 3rdparty/protobuf-$(PROTOBUF_VERSION) PICOJSON = 3rdparty/picojson-$(PICOJSON_VERSION) NVML = 3rdparty/nvml-$(NVML_VERSION) @@ -173,6 +174,19 @@ LIB_GLOG = -lglog LDADD += -lglog endif +if ENABLE_GRPC +if WITH_BUNDLED_GRPC +LIB_GRPC = ../$(GRPC)/libs/opt/libgrpc++.a \ + ../$(GRPC)/libs/opt/libgrpc.a \ + ../$(GRPC)/libs/opt/libgpr.a \ + -lssl -lcrypto +GRPC_CPP_PLUGIN = ../$(GRPC)/bins/opt/grpc_cpp_plugin +else +LIB_GRPC = -lgrpc++ -lgrpc -lgpr -lssl -lcrypto +GRPC_CPP_PLUGIN = @GRPC_CXX_PLUGIN@ +endif +endif + if WITH_BUNDLED_LEVELDB MESOS_CPPFLAGS += -I../$(LEVELDB)/include @@ -1509,6 +1523,7 @@ libmesos_la_LIBTOOLFLAGS = --tag=CXX libmesos_la_LIBADD = \ libmesos_no_3rdparty.la \ $(LIB_GLOG) \ + $(LIB_GRPC) \ $(LIB_LEVELDB) \ $(LIB_PROCESS) \ $(LIB_PROTOBUF) \