From b3ff13e0e5570640d3b044bbb3c5a0e8076999d2 Mon Sep 17 00:00:00 2001 From: zhoufeng Date: Wed, 31 Mar 2021 17:35:43 +0800 Subject: [PATCH] building dependency decoupling Signed-off-by: zhoufeng --- cmake/check_requirements.cmake | 4 -- cmake/external_libs/grpc.cmake | 10 ++--- cmake/external_libs/libevent.cmake | 4 +- cmake/external_libs/openssl_stub.cmake | 18 ++++++++ cmake/mind_expression.cmake | 1 + third_party/patch/glog/glog.patch001 | 43 ++++++++++++++++--- .../patch/openssl-stub/openssl-stub.patch001 | 39 +++++++++++++++++ 7 files changed, 102 insertions(+), 17 deletions(-) create mode 100644 cmake/external_libs/openssl_stub.cmake create mode 100644 third_party/patch/openssl-stub/openssl-stub.patch001 diff --git a/cmake/check_requirements.cmake b/cmake/check_requirements.cmake index eb800456a17..075e1abe7a5 100644 --- a/cmake/check_requirements.cmake +++ b/cmake/check_requirements.cmake @@ -56,10 +56,6 @@ if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows") find_required_program(tclsh) endif() - if(MS_BUILD_GRPC) - find_required_package(OpenSSL) - endif() - ## packages used in GPU mode only if(ENABLE_GPU) find_library(gmp_LIB gmp) diff --git a/cmake/external_libs/grpc.cmake b/cmake/external_libs/grpc.cmake index dff52d8c4a3..87eed7588a1 100644 --- a/cmake/external_libs/grpc.cmake +++ b/cmake/external_libs/grpc.cmake @@ -30,9 +30,8 @@ else() endif() message("grpc using absl_DIR : " ${_FINDPACKAGE_ABSL_CONFIG_DIR}) -set(_CMAKE_ARGS_OPENSSL_ROOT_DIR "") -if(OPENSSL_ROOT_DIR) - set(_CMAKE_ARGS_OPENSSL_ROOT_DIR "-DOPENSSL_ROOT_DIR:PATH=${OPENSSL_ROOT_DIR}") +if(EXISTS ${openssl_ROOT}) + set(_CMAKE_ARGS_OPENSSL_ROOT_DIR "-DOPENSSL_ROOT_DIR:PATH=${openssl_ROOT}") endif() if(ENABLE_GITEE) @@ -77,10 +76,7 @@ target_link_libraries(grpc::grpc++ INTERFACE mindspore::z) target_link_libraries(grpc::grpc++ INTERFACE mindspore::cares) target_link_libraries(grpc::grpc++ INTERFACE mindspore::absl_strings mindspore::absl_throw_delegate mindspore::absl_raw_logging_internal mindspore::absl_int128 mindspore::absl_bad_optional_access) - -# link system openssl -find_package(OpenSSL REQUIRED) -target_link_libraries(grpc::grpc++ INTERFACE OpenSSL::SSL OpenSSL::Crypto) +target_link_libraries(grpc::grpc++ INTERFACE mindspore::ssl mindspore::crypto) function(ms_grpc_generate c_var h_var) diff --git a/cmake/external_libs/libevent.cmake b/cmake/external_libs/libevent.cmake index 719634b8e7b..e94df0f94b9 100644 --- a/cmake/external_libs/libevent.cmake +++ b/cmake/external_libs/libevent.cmake @@ -12,12 +12,14 @@ else() set(MD5 "b5333f021f880fe76490d8a799cd79f4") endif() +message("libevent using openssl stub dir: " ${openssl_ROOT}) + mindspore_add_pkg(libevent VER 2.1.12 LIBS event event_pthreads event_core URL ${REQ_URL} MD5 ${MD5} - CMAKE_OPTION -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_TESTING=OFF) + CMAKE_OPTION -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_TESTING=OFF -DOPENSSL_ROOT_DIR:PATH=${openssl_ROOT}) include_directories(${libevent_INC}) diff --git a/cmake/external_libs/openssl_stub.cmake b/cmake/external_libs/openssl_stub.cmake new file mode 100644 index 00000000000..bd3ab2d2a19 --- /dev/null +++ b/cmake/external_libs/openssl_stub.cmake @@ -0,0 +1,18 @@ +if(ENABLE_GITEE) + set(REQ_URL "https://gitee.com/mirrors/openssl/repository/archive/OpenSSL_1_1_0l.tar.gz") + set(MD5 "9d18479e0cac8ff62f7e3df3cceb69dc") +else() + set(REQ_URL "https://github.com/openssl/openssl/archive/refs/tags/OpenSSL_1_1_0l.tar.gz") + set(MD5 "46d9a2a92fd39198501503b40954e6f0") +endif() +mindspore_add_pkg(openssl + VER 1.1.0 + LIBS ssl crypto + URL ${REQ_URL} + MD5 ${MD5} + PATCHES ${CMAKE_SOURCE_DIR}/third_party/patch/openssl-stub/openssl-stub.patch001 + CONFIGURE_COMMAND ./config no-zlib) + +include_directories(${openssl_INC}) +add_library(mindspore::ssl ALIAS openssl::ssl) +add_library(mindspore::crypto ALIAS openssl::crypto) \ No newline at end of file diff --git a/cmake/mind_expression.cmake b/cmake/mind_expression.cmake index 9dee8f90961..0e168d57873 100644 --- a/cmake/mind_expression.cmake +++ b/cmake/mind_expression.cmake @@ -17,6 +17,7 @@ include(${CMAKE_SOURCE_DIR}/cmake/external_libs/protobuf.cmake) if(MS_BUILD_GRPC) # build dependencies of gRPC + include(${CMAKE_SOURCE_DIR}/cmake/external_libs/openssl_stub.cmake) include(${CMAKE_SOURCE_DIR}/cmake/external_libs/absl.cmake) include(${CMAKE_SOURCE_DIR}/cmake/external_libs/c-ares.cmake) include(${CMAKE_SOURCE_DIR}/cmake/external_libs/zlib.cmake) diff --git a/third_party/patch/glog/glog.patch001 b/third_party/patch/glog/glog.patch001 index 81a35d97e27..89ffc4068d4 100644 --- a/third_party/patch/glog/glog.patch001 +++ b/third_party/patch/glog/glog.patch001 @@ -1,11 +1,44 @@ -diff -Npur glog/CMakeLists.txt glog_modify/CMakeLists.txt +diff -Npur glog/CMakeLists.txt glog-patch/CMakeLists.txt --- glog/CMakeLists.txt 2019-03-22 10:51:46.000000000 +0800 -+++ glog_modify/CMakeLists.txt 2021-03-07 16:58:38.386879400 +0800 -@@ -470,6 +470,7 @@ add_library (glog ++++ glog-patch/CMakeLists.txt 2021-04-01 10:32:25.753140500 +0800 +@@ -64,7 +64,6 @@ check_include_file (dlfcn.h HAVE_DLFCN_H + check_include_file (execinfo.h HAVE_EXECINFO_H) + check_include_file (glob.h HAVE_GLOB_H) + check_include_file (inttypes.h HAVE_INTTYPES_H) +-check_include_file (libunwind.h HAVE_LIBUNWIND_H) + check_include_file (memory.h HAVE_MEMORY_H) + check_include_file (pwd.h HAVE_PWD_H) + check_include_file (stdint.h HAVE_STDINT_H) +@@ -80,7 +79,6 @@ check_include_file (syscall.h HAVE_SYSCA + check_include_file (syslog.h HAVE_SYSLOG_H) + check_include_file (ucontext.h HAVE_UCONTEXT_H) + check_include_file (unistd.h HAVE_UNISTD_H) +-check_include_file (unwind.h HAVE_UNWIND_H) + check_include_file (pwd.h HAVE_PWD_H) + + check_include_file_cxx ("ext/hash_map" HAVE_EXT_HASH_MAP) +@@ -116,12 +114,8 @@ check_cxx_compiler_flag (-Wunnamed-type- + # snprintf as an inline function + check_symbol_exists (snprintf stdio.h HAVE_SNPRINTF) + +-check_library_exists (unwind get_static_proc_name "" HAVE_LIB_UNWIND) + check_library_exists (dbghelp UnDecorateSymbolName "" HAVE_DBGHELP) + +-find_library (UNWIND_LIBRARY NAMES unwind DOC "unwind library") +-mark_as_advanced (UNWIND_LIBRARY) +- + check_c_source_compiles (" + #include + static void foo(void) __attribute__ ((unused)); +@@ -470,10 +464,7 @@ add_library (glog add_library(glog::glog ALIAS glog) set_target_properties (glog PROPERTIES POSITION_INDEPENDENT_CODE ON) +- +-if (UNWIND_LIBRARY) +- target_link_libraries (glog PUBLIC ${UNWIND_LIBRARY}) +-endif (UNWIND_LIBRARY) +set_target_properties (glog PROPERTIES OUTPUT_NAME mindspore_glog) - if (UNWIND_LIBRARY) - target_link_libraries (glog PUBLIC ${UNWIND_LIBRARY}) + if (HAVE_DBGHELP) + target_link_libraries (glog PUBLIC dbghelp) diff --git a/third_party/patch/openssl-stub/openssl-stub.patch001 b/third_party/patch/openssl-stub/openssl-stub.patch001 new file mode 100644 index 00000000000..5da8caac879 --- /dev/null +++ b/third_party/patch/openssl-stub/openssl-stub.patch001 @@ -0,0 +1,39 @@ +diff -Npur openssl-OpenSSL_1_1_0l/Makefile.shared openssl-OpenSSL_1_1_0l-patch/Makefile.shared +--- openssl-OpenSSL_1_1_0l/Makefile.shared 2019-09-10 21:16:54.000000000 +0800 ++++ openssl-OpenSSL_1_1_0l-patch/Makefile.shared 2021-04-01 09:26:06.018179700 +0800 +@@ -154,7 +154,7 @@ LINK_SO_SHLIB_UNPACKED= \ + DETECT_GNU_LD=($(CC) -Wl,-V /dev/null 2>&1 | grep '^GNU ld' )>/dev/null + + DO_GNU_SO_COMMON=\ +- SHAREDFLAGS='$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-Bsymbolic -Wl,-soname=$(SHLIBNAME_FULL)' ++ SHAREDFLAGS='$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-Bsymbolic -Wl,-soname=$(SHLIBNAME)' + DO_GNU_DSO=\ + $(DO_GNU_SO_COMMON) + DO_GNU_SO=\ +@@ -181,7 +181,7 @@ link_app.gnu: + link_shlib.linux-shared: + @$(PERL) $(SRCDIR)/util/mkdef.pl $(LIBNAME) linux >$(LIBNAME).map; \ + $(DO_GNU_SO); \ +- ALLSYMSFLAGS='-Wl,--whole-archive,--version-script=$(LIBNAME).map'; \ ++ ALLSYMSFLAGS='-Wl,--whole-archive'; \ + $(LINK_SO_SHLIB) + + link_dso.bsd: +@@ -380,7 +380,7 @@ link_dso.irix: + else \ + ALLSYMSFLAGS=''; \ + NOALLSYMSFLAGS=''; \ +- SHAREDFLAGS='$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-soname,$(SHLIBNAME_FULL),-B,symbolic'; \ ++ SHAREDFLAGS='$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-soname,$(SHLIBNAME),-B,symbolic'; \ + fi; \ + $(LINK_SO_DSO) + link_shlib.irix: +@@ -391,7 +391,7 @@ link_shlib.irix: + ($(CC) -v 2>&1 | grep gcc) > /dev/null && MINUSWL='-Wl,'; \ + ALLSYMSFLAGS="$${MINUSWL}-all"; \ + NOALLSYMSFLAGS="$${MINUSWL}-none"; \ +- SHAREDFLAGS='$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-soname,$(SHLIBNAME_FULL),-B,symbolic'; \ ++ SHAREDFLAGS='$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-soname,$(SHLIBNAME),-B,symbolic'; \ + fi; \ + $(LINK_SO_SHLIB) + link_app.irix: