From 317ec86d31d2726852d1341f7b31cfde10a3cb38 Mon Sep 17 00:00:00 2001 From: XuanYang-cn <51370125+XuanYang-cn@users.noreply.github.com> Date: Mon, 17 Aug 2020 15:23:54 +0800 Subject: [PATCH] Optimize download&compilation of opentracing (#3276) * opentracing runable Signed-off-by: yangxuan * optimize opentracing Signed-off-by: yangxuan * rm opentracing from Thirdpartypackages.cmake Signed-off-by: yangxuan * rm dup links Signed-off-by: yangxuan * fit unittest cann't compile bug Signed-off-by: yangxuan * fix format Signed-off-by: yangxuan Co-authored-by: yangxuan --- core/cmake/ThirdPartyPackages.cmake | 62 -------------------- core/src/CMakeLists.txt | 3 +- core/src/db/CMakeLists.txt | 1 + core/src/tracing/CMakeLists.txt | 6 +- core/thirdparty/CMakeLists.txt | 5 ++ core/thirdparty/opentracing/CMakeLists.txt | 67 ++++++++++++++++++++++ core/unittest/CMakeLists.txt | 4 +- 7 files changed, 79 insertions(+), 69 deletions(-) create mode 100644 core/thirdparty/opentracing/CMakeLists.txt diff --git a/core/cmake/ThirdPartyPackages.cmake b/core/cmake/ThirdPartyPackages.cmake index b70592f45f..659033cc55 100644 --- a/core/cmake/ThirdPartyPackages.cmake +++ b/core/cmake/ThirdPartyPackages.cmake @@ -16,7 +16,6 @@ set(MILVUS_THIRDPARTY_DEPENDENCIES SQLite libunwind gperftools - Opentracing fiu AWS oatpp) @@ -41,8 +40,6 @@ macro(build_dependency DEPENDENCY_NAME) build_libunwind() elseif ("${DEPENDENCY_NAME}" STREQUAL "gperftools") build_gperftools() - elseif ("${DEPENDENCY_NAME}" STREQUAL "Opentracing") - build_opentracing() elseif ("${DEPENDENCY_NAME}" STREQUAL "fiu") build_fiu() elseif ("${DEPENDENCY_NAME}" STREQUAL "oatpp") @@ -253,13 +250,6 @@ else () "https://github.com/gperftools/gperftools/releases/download/gperftools-${GPERFTOOLS_VERSION}/gperftools-${GPERFTOOLS_VERSION}.tar.gz") endif () -if (DEFINED ENV{MILVUS_OPENTRACING_URL}) - set(OPENTRACING_SOURCE_URL "$ENV{MILVUS_OPENTRACING_URL}") -else () - set(OPENTRACING_SOURCE_URL "https://github.com/opentracing/opentracing-cpp/archive/${OPENTRACING_VERSION}.tar.gz" - "https://gitee.com/quicksilver/opentracing-cpp/repository/archive/${OPENTRACING_VERSION}.zip") -endif () - if (DEFINED ENV{MILVUS_FIU_URL}) set(FIU_SOURCE_URL "$ENV{MILVUS_FIU_URL}") else () @@ -564,58 +554,6 @@ if (MILVUS_WITH_GPERFTOOLS) link_directories(SYSTEM ${GPERFTOOLS_PREFIX}/lib) endif () -# ---------------------------------------------------------------------- -# opentracing - -macro(build_opentracing) - message(STATUS "Building OPENTRACING-${OPENTRACING_VERSION} from source") - set(OPENTRACING_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/opentracing_ep-prefix/src/opentracing_ep") - set(OPENTRACING_STATIC_LIB "${OPENTRACING_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentracing${CMAKE_STATIC_LIBRARY_SUFFIX}") - set(OPENTRACING_MOCK_TRACER_STATIC_LIB "${OPENTRACING_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentracing_mocktracer${CMAKE_STATIC_LIBRARY_SUFFIX}") - set(OPENTRACING_INCLUDE_DIR "${OPENTRACING_PREFIX}/include") - set(OPENTRACING_CMAKE_ARGS - ${EP_COMMON_CMAKE_ARGS} - "-DCMAKE_INSTALL_PREFIX=${OPENTRACING_PREFIX}" - -DBUILD_SHARED_LIBS=OFF) - - ExternalProject_Add(opentracing_ep - URL - ${OPENTRACING_SOURCE_URL} - ${EP_LOG_OPTIONS} - URL_MD5 - "e598ba4b81ae8e1ceed8cd8bbf86f2fd" - CMAKE_ARGS - ${OPENTRACING_CMAKE_ARGS} - BUILD_COMMAND - ${MAKE} - ${MAKE_BUILD_ARGS} - BUILD_BYPRODUCTS - ${OPENTRACING_STATIC_LIB} - ${OPENTRACING_MOCK_TRACER_STATIC_LIB} - ) - - file(MAKE_DIRECTORY "${OPENTRACING_INCLUDE_DIR}") - add_library(opentracing STATIC IMPORTED) - set_target_properties(opentracing - PROPERTIES IMPORTED_LOCATION "${OPENTRACING_STATIC_LIB}" - INTERFACE_INCLUDE_DIRECTORIES "${OPENTRACING_INCLUDE_DIR}") - - add_library(opentracing_mocktracer STATIC IMPORTED) - set_target_properties(opentracing_mocktracer - PROPERTIES IMPORTED_LOCATION "${OPENTRACING_MOCK_TRACER_STATIC_LIB}" - INTERFACE_INCLUDE_DIRECTORIES "${OPENTRACING_INCLUDE_DIR}") - - add_dependencies(opentracing opentracing_ep) - add_dependencies(opentracing_mocktracer opentracing_ep) -endmacro() - -if (MILVUS_WITH_OPENTRACING) - resolve_dependency(Opentracing) - - get_target_property(OPENTRACING_INCLUDE_DIR opentracing INTERFACE_INCLUDE_DIRECTORIES) - include_directories(SYSTEM ${OPENTRACING_INCLUDE_DIR}) -endif () - # ---------------------------------------------------------------------- # fiu macro(build_fiu) diff --git a/core/src/CMakeLists.txt b/core/src/CMakeLists.txt index dc65c3eb75..1a38fbce65 100644 --- a/core/src/CMakeLists.txt +++ b/core/src/CMakeLists.txt @@ -48,11 +48,11 @@ add_subdirectory( storage ) add_subdirectory( cache ) add_subdirectory( codecs ) add_subdirectory( segment ) +add_subdirectory( tracing ) add_subdirectory( utils ) add_subdirectory( metrics ) add_subdirectory( config ) -add_subdirectory( tracing ) add_subdirectory( query ) add_subdirectory( db ) # target milvus_engine add_subdirectory( log ) @@ -62,7 +62,6 @@ set(link_lib milvus_engine config metrics - tracing log oatpp query diff --git a/core/src/db/CMakeLists.txt b/core/src/db/CMakeLists.txt index 754389c7fe..2ec945a8ac 100644 --- a/core/src/db/CMakeLists.txt +++ b/core/src/db/CMakeLists.txt @@ -145,6 +145,7 @@ target_link_libraries( milvus_engine cache storage codecs + tracing ${THIRD_PARTY_LIBS} ${ENGINE_LIBS} ) diff --git a/core/src/tracing/CMakeLists.txt b/core/src/tracing/CMakeLists.txt index fa30deb01c..60ffb59a57 100644 --- a/core/src/tracing/CMakeLists.txt +++ b/core/src/tracing/CMakeLists.txt @@ -15,11 +15,11 @@ aux_source_directory( ${MILVUS_ENGINE_SRC}/tracing TRACING_FILES ) add_library( tracing STATIC ${TRACING_FILES} ) -set( TRACING_LIB opentracing - opentracing_mocktracer +set( TRACING_LIB opentracing::opentracing + opentracing::mocktracer pthread z dl ) -target_link_libraries( tracing ${TRACING_LIB} ) +target_link_libraries( tracing PUBLIC ${TRACING_LIB} ) diff --git a/core/thirdparty/CMakeLists.txt b/core/thirdparty/CMakeLists.txt index a89129b881..ebc7911e62 100644 --- a/core/thirdparty/CMakeLists.txt +++ b/core/thirdparty/CMakeLists.txt @@ -46,3 +46,8 @@ endif () if ( MILVUS_WITH_YAMLCPP ) add_subdirectory( yaml-cpp ) endif() + +# ****************************** Thirdparty opentracing *************************************** +if ( MILVUS_WITH_OPENTRACING ) + add_subdirectory( opentracing ) +endif() diff --git a/core/thirdparty/opentracing/CMakeLists.txt b/core/thirdparty/opentracing/CMakeLists.txt new file mode 100644 index 0000000000..84a9b0d3a0 --- /dev/null +++ b/core/thirdparty/opentracing/CMakeLists.txt @@ -0,0 +1,67 @@ +#------------------------------------------------------------------------------- +# Copyright (C) 2019-2020 Zilliz. All rights reserved. +# +# 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. +#------------------------------------------------------------------------------- + +if ( DEFINED ENV{MILVUS_OPENTRACING_URL} ) + set(OPENTRACING_SOURCE_URL "$ENV{MILVUS_OPENTRACING_URL}") +else () + set(OPENTRACING_SOURCE_URL + "https://github.com/opentracing/opentracing-cpp/archive/${OPENTRACING_VERSION}.tar.gz" ) +endif () + +message(STATUS "Building OPENTRACING-${OPENTRACING_VERSION} from source") + +FetchContent_Declare( + opentracing + URL ${OPENTRACING_SOURCE_URL} + URL_MD5 "e598ba4b81ae8e1ceed8cd8bbf86f2fd" + SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/opentracing-src + BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/opentracing-build + ) + +set( BUILD_SHARED_LIBS CACHE BOOL OFF FORCE) +set( ENABLE_LINTING CACHE BOOL OFF FORCE) +set( BUILD_TESTING CACHE BOOL OFF FORCE ) +FetchContent_GetProperties( opentracing ) +if ( NOT opentracing_POPULATED ) + + FetchContent_Populate( opentracing ) + + # Adding the following targets: + # opentracing-static + # opentracing_mocktracer-static + add_subdirectory( ${opentracing_SOURCE_DIR} + ${opentracing_BINARY_DIR} + EXCLUDE_FROM_ALL ) + + # Opentracing-cpp CMakeLists.txt file didn't give a + # correct interface directories + target_include_directories( opentracing-static + INTERFACE $ + $ + $ ) + target_include_directories( opentracing_mocktracer-static + INTERFACE $ ) + # Adding the following ALIAS Targets: + # opentracing::opentracing + # opentracing::mocktracer + if ( NOT TARGET opentracing::opentracing ) + add_library( opentracing::opentracing ALIAS opentracing-static ) + endif() + if ( NOT TARGET opentracing::mocktracer ) + add_library( opentracing::mocktracer ALIAS opentracing_mocktracer-static ) + endif() + +endif() + +get_property( var DIRECTORY "${opentracing_SOURCE_DIR}" PROPERTY COMPILE_OPTIONS ) +message( STATUS "opentracing compile options: ${var}" ) diff --git a/core/unittest/CMakeLists.txt b/core/unittest/CMakeLists.txt index 440906cdf6..76aa504ea5 100644 --- a/core/unittest/CMakeLists.txt +++ b/core/unittest/CMakeLists.txt @@ -54,8 +54,8 @@ set( UNITTEST_LIBS sqlite libstdc++fs.a pthread gfortran - opentracing - opentracing_mocktracer + opentracing::opentracing + opentracing::mocktracer fiu dl z