Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
Fix Build Under Windows ( #112)
Browse files Browse the repository at this point in the history
* Move to OpenTracing 1.5.0 that builds under Windows
* Change link of OpenTracing to dynamic. With Static linking of OpenTracing, we end up with multi definition of OT Symbols. This is not acceptable especially for the OT Global Tracer
* Fix OS specificities
** Networking API
** Windows headers
* Fix some tests with random behavior that failed on Windows
* Fix some MSVC specific compilation
* Add appveyor build file.

Signed-off-by: FR-MUREX-COM\mchaikhadouaihy <mehrez.douaihy@gmail.com>
  • Loading branch information
mdouaihy committed Jul 1, 2018
1 parent fdc3b86 commit 9091fc4
Show file tree
Hide file tree
Showing 67 changed files with 846 additions and 109 deletions.
26 changes: 26 additions & 0 deletions .appveyor.yml
@@ -0,0 +1,26 @@
version: '{build}'

image: Visual Studio 2017

init:
- cmd: git config --global core.autocrlf true

platform:
- x64

configuration:
- Debug
- Release

before_build:
- cmake -H. -Bbuild -A%PLATFORM% -DBUILD_TESTING=ON

build:
project: build\jaegertracing.sln
parallel: false
verbosity: normal

test_script:
- ps: |
cd build
ctest -V -C $env:configuration --timeout 600 --output-on-failure
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": "x86-Debug"
}
64 changes: 55 additions & 9 deletions CMakeLists.txt
Expand Up @@ -12,8 +12,9 @@ set(HUNTER_CONFIGURATION_TYPES "Release;Debug" CACHE STRING
include(CMakeDependentOption)
include(HunterGate)
HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.20.70.tar.gz"
SHA1 "95fb7d11f0828746e2983b5f06ff7981a676da3f"
URL "https://github.com/ruslo/hunter/archive/v0.22.19.tar.gz"
SHA1 "54749ffc945f78362aa680a7abbafcaa40ff9069"
LOCAL # Local config to ask for OpenTracing dynamic libs
)

project(jaegertracing VERSION 0.5.0)
Expand All @@ -27,6 +28,14 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-private-field")
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_definitions(-D_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING)

# https://studiofreya.com/2018/01/06/visual-studio-2017-with-cpp17-and-boost/
add_definitions(-DBOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE)
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(HUNTER_ENABLED)
Expand All @@ -51,11 +60,12 @@ else()
endif()
list(APPEND package_deps thrift)


hunter_add_package(opentracing-cpp)
# Not `${hunter_config}` because OpenTracing provides its own
# OpenTracingConfig.cmake file
find_package(OpenTracing CONFIG REQUIRED)
list(APPEND LIBS OpenTracing::opentracing-static)
list(APPEND LIBS OpenTracing::opentracing)
list(APPEND package_deps OpenTracing)

hunter_add_package(nlohmann_json)
Expand Down Expand Up @@ -187,7 +197,8 @@ set(SRC
src/jaegertracing/utils/HexParsing.cpp
src/jaegertracing/utils/RateLimiter.cpp
src/jaegertracing/utils/UDPClient.cpp
src/jaegertracing/utils/YAML.cpp)
src/jaegertracing/utils/YAML.cpp
src/jaegertracing/ThriftMethods.cpp)

if(JAEGERTRACING_BUILD_CROSSDOCK)
list(APPEND SRC
Expand All @@ -208,13 +219,35 @@ cmake_dependent_option(BUILD_SHARED_LIBS "Build shared libraries" ON
"NOT JAEGERTRACING_PLUGIN" OFF)

if(BUILD_SHARED_LIBS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
add_library(jaegertracing SHARED ${SRC})
# target_compile_definitions(jaegertracing PRIVATE JAEGERTRACING_EXPORTS)
if (WIN32)
target_link_libraries(jaegertracing PUBLIC Iphlpapi Ws2_32)
endif()
add_lib_deps(jaegertracing)
set_target_properties(jaegertracing PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR})
set(JAEGERTRACING_LIB jaegertracing)
list(APPEND JAEGERTRACING_LIBS jaegertracing)

if (MSVC)
# Copy the shared opentracing shared library next to jaeger tracing shared library

add_custom_command(TARGET jaegertracing POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<$<CONFIG:Debug>:${OpenTracing_DIR}/../../opentracingd.dll>
$<$<CONFIG:Release>:${OpenTracing_DIR}/../../opentracing.dll>
$<TARGET_FILE_DIR:jaegertracing>)

add_custom_command(TARGET jaegertracing POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<$<CONFIG:Debug>:${OpenTracing_DIR}/../../opentracingd.lib>
$<$<CONFIG:Release>:${OpenTracing_DIR}/../../opentracing.lib>
$<TARGET_FILE_DIR:jaegertracing>)

endif()
endif()

if(JAEGERTRACING_PLUGIN)
Expand All @@ -229,9 +262,16 @@ if(JAEGERTRACING_PLUGIN)
endif()

add_library(jaegertracing-static STATIC ${SRC})
set_target_properties(jaegertracing-static PROPERTIES
OUTPUT_NAME jaegertracing)
if (NOT WIN32)
#on windows, the shared library generate also a .lib file
set_target_properties(jaegertracing-static PROPERTIES OUTPUT_NAME jaegertracing)
endif()

add_lib_deps(jaegertracing-static)
if (WIN32)
target_link_libraries(jaegertracing-static PUBLIC Iphlpapi Ws2_32)
endif()

if(NOT JAEGERTRACING_LIB)
set(JAEGERTRACING_LIB jaegertracing-static)
endif()
Expand All @@ -244,17 +284,21 @@ configure_file(

if(JAEGERTRACING_BUILD_EXAMPLES)
add_executable(app examples/App.cpp)
target_link_libraries(app PUBLIC ${JAEGERTRACING_LIB})
target_link_libraries(app PUBLIC jaegertracing)
endif()

if(BUILD_TESTING)

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
add_library(testutils
src/jaegertracing/testutils/TUDPTransport.cpp
src/jaegertracing/testutils/SamplingManager.cpp
src/jaegertracing/testutils/MockAgent.cpp
src/jaegertracing/testutils/TracerUtil.cpp)
target_link_libraries(testutils PUBLIC ${JAEGERTRACING_LIB})

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS OFF)

if(BUILD_SHARED_LIBS)
set(dynamic_load_test_src src/jaegertracing/DynamicLoadTest.cpp)
endif()
Expand Down Expand Up @@ -289,18 +333,20 @@ if(BUILD_TESTING)
target_compile_definitions(UnitTest PUBLIC
GTEST_HAS_TR1_TUPLE=0
GTEST_USE_OWN_TR1_TUPLE=0)

target_link_libraries(
UnitTest PRIVATE testutils GTest::main)
UnitTest PRIVATE testutils GTest::main ${JAEGERTRACING_LIB})
add_test(NAME UnitTest COMMAND UnitTest)

if(TARGET jaegertracing)
add_executable(DynamicallyLoadTracerTest
src/jaegertracing/DynamicallyLoadTracerTest.cpp)

target_include_directories(DynamicallyLoadTracerTest PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>)
target_link_libraries(
DynamicallyLoadTracerTest OpenTracing::opentracing-static GTest::main)
DynamicallyLoadTracerTest OpenTracing::opentracing GTest::main)
add_test(NAME DynamicallyLoadTracerTest
COMMAND DynamicallyLoadTracerTest $<TARGET_FILE:jaegertracing>)
if(JAEGERTRACING_COVERAGE)
Expand Down
2 changes: 2 additions & 0 deletions cmake/Hunter/config.cmake
@@ -0,0 +1,2 @@

hunter_config(opentracing-cpp VERSION ${HUNTER_opentracing-cpp_VERSION} CMAKE_ARGS BUILD_SHARED_LIBS=ON)
31 changes: 31 additions & 0 deletions src/jaegertracing/Compilers.h
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2017 Uber Technologies, Inc.
*
* 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.
*/

#ifndef JAEGERTRACING_COMPILERS_H
#define JAEGERTRACING_COMPILERS_H

#ifdef _MSC_VER

#pragma warning(push)
#pragma warning(disable : 4251)

// Define NOMINMAX to inhibit definition of Macros min(a,b) and max(a,b) in
// windows.h
#define NOMINMAX

#endif // _MSC_VER

#endif // JAEGERTRACING_COMPILERS_H
2 changes: 2 additions & 0 deletions src/jaegertracing/Config.h
Expand Up @@ -17,6 +17,8 @@
#ifndef JAEGERTRACING_CONFIG_H
#define JAEGERTRACING_CONFIG_H

#include "jaegertracing/Compilers.h"

#include "jaegertracing/Constants.h"
#include "jaegertracing/baggage/RestrictionsConfig.h"
#include "jaegertracing/propagation/HeadersConfig.h"
Expand Down
25 changes: 15 additions & 10 deletions src/jaegertracing/DynamicLoad.cpp
Expand Up @@ -19,31 +19,36 @@

#include <opentracing/dynamic_load.h>

#include "DynamicLoad.h"
#include "TracerFactory.h"
#include "jaegertracing/Tracer.h"

int OpenTracingMakeTracerFactory(const char* opentracingVersion,
const void** errorCategory,
void** tracerFactory)
int JaegerTracingMakeTracerFactoryFct(const char* opentracing_version,
const char* opentracing_abi_version,
const void** error_category,
void* error_message,
void** tracer_factory)
{
assert(errorCategory != nullptr);
assert(tracerFactory != nullptr);
assert(error_category != nullptr);
assert(tracer_factory != nullptr);
#ifndef JAEGERTRACING_WITH_YAML_CPP
*errorCategory =
static_cast<const void*>(&opentracing::dynamic_load_error_category());
return opentracing::dynamic_load_not_supported_error.value();
#endif
if (std::strcmp(opentracingVersion, OPENTRACING_VERSION) != 0) {
*errorCategory = static_cast<const void*>(
if (std::strcmp(opentracing_version, OPENTRACING_VERSION) != 0) {
*error_category = static_cast<const void*>(
&opentracing::dynamic_load_error_category());
return opentracing::incompatible_library_versions_error.value();
}

*tracerFactory = new (std::nothrow) jaegertracing::TracerFactory{};
if (*tracerFactory == nullptr) {
*errorCategory = static_cast<const void*>(&std::generic_category());
*tracer_factory = new (std::nothrow) jaegertracing::TracerFactory{};
if (*tracer_factory == nullptr) {
*error_category = static_cast<const void*>(&std::generic_category());
return static_cast<int>(std::errc::not_enough_memory);
}

return 0;
}

OPENTRACING_DECLARE_IMPL_FACTORY(JaegerTracingMakeTracerFactoryFct)
26 changes: 26 additions & 0 deletions src/jaegertracing/DynamicLoad.h
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2017 Uber Technologies, Inc.
*
* 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.
*/

#ifndef JAEGERTRACING_DYNAMIC_LOAD_H
#define JAEGERTRACING_DYNAMIC_LOAD_H

int JaegerTracingMakeTracerFactoryFct(const char* opentracing_version,
const char* opentracing_abi_version,
const void** error_category,
void* error_message,
void** tracer_factory);

#endif // JAEGERTRACING_DYNAMIC_LOAD_H
12 changes: 8 additions & 4 deletions src/jaegertracing/DynamicLoadTest.cpp
Expand Up @@ -19,6 +19,7 @@
#include "jaegertracing/Constants.h"
#include <gtest/gtest.h>
#include <opentracing/dynamic_load.h>
#include "DynamicLoad.h"

namespace jaegertracing {
namespace {
Expand Down Expand Up @@ -60,12 +61,14 @@ disabled: false
} // anonymous namespace

#ifdef JAEGERTRACING_WITH_YAML_CPP

TEST(DynamicLoad, invalidVersion)
{
const void* errorCategory = nullptr;
const void* errorMessage = nullptr;
void* tracerFactory = nullptr;
const auto rcode = OpenTracingMakeTracerFactory(
"0.0.0" /*invalid version*/, &errorCategory, &tracerFactory);
const auto rcode = JaegerTracingMakeTracerFactoryFct(
"0.0.0" /*invalid version*/, "1", &errorCategory, &errorMessage, &tracerFactory);
ASSERT_EQ(rcode, opentracing::incompatible_library_versions_error.value());
ASSERT_EQ(
errorCategory,
Expand All @@ -76,9 +79,10 @@ TEST(DynamicLoad, invalidVersion)
TEST(DynamicLoad, validVersion)
{
const void* errorCategory = nullptr;
const void* errorMessage = nullptr;
void* tracerFactory = nullptr;
const auto rcode = OpenTracingMakeTracerFactory(
OPENTRACING_VERSION, &errorCategory, &tracerFactory);
const auto rcode = JaegerTracingMakeTracerFactoryFct(
OPENTRACING_VERSION, "1", &errorCategory, &errorMessage, &tracerFactory);
ASSERT_EQ(rcode, 0);
ASSERT_EQ(errorCategory, nullptr);
ASSERT_NE(tracerFactory, nullptr);
Expand Down
2 changes: 2 additions & 0 deletions src/jaegertracing/LogRecord.h
Expand Up @@ -17,6 +17,8 @@
#ifndef JAEGERTRACING_LOGRECORD_H
#define JAEGERTRACING_LOGRECORD_H

#include "jaegertracing/Compilers.h"

#include "jaegertracing/Tag.h"
#include "jaegertracing/thrift-gen/jaeger_types.h"
#include <algorithm>
Expand Down
2 changes: 2 additions & 0 deletions src/jaegertracing/Logging.h
Expand Up @@ -20,6 +20,8 @@
#include <memory>
#include <string>

#include "jaegertracing/Compilers.h"

namespace jaegertracing {
namespace logging {

Expand Down
2 changes: 2 additions & 0 deletions src/jaegertracing/Reference.h
Expand Up @@ -22,6 +22,8 @@

#include <opentracing/propagation.h>

#include "jaegertracing/Compilers.h"

#include "jaegertracing/SpanContext.h"
#include "jaegertracing/thrift-gen/jaeger_types.h"

Expand Down
2 changes: 2 additions & 0 deletions src/jaegertracing/Span.h
Expand Up @@ -21,6 +21,8 @@
#include <memory>
#include <mutex>

#include "jaegertracing/Compilers.h"

#include <opentracing/span.h>

#include "jaegertracing/LogRecord.h"
Expand Down
2 changes: 2 additions & 0 deletions src/jaegertracing/SpanContext.h
Expand Up @@ -25,6 +25,8 @@

#include <opentracing/span.h>

#include "jaegertracing/Compilers.h"

#include "jaegertracing/TraceID.h"

namespace jaegertracing {
Expand Down
2 changes: 2 additions & 0 deletions src/jaegertracing/Tag.h
Expand Up @@ -17,6 +17,8 @@
#ifndef JAEGERTRACING_TAG_H
#define JAEGERTRACING_TAG_H

#include "jaegertracing/Compilers.h"

#include "jaegertracing/thrift-gen/jaeger_types.h"
#include <algorithm>
#include <cstdint>
Expand Down

0 comments on commit 9091fc4

Please sign in to comment.