Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

splunk-opentelemetry-cpp: migrate to Conan v2 #18685

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions recipes/splunk-opentelemetry-cpp/all/CMakeLists.txt

This file was deleted.

5 changes: 5 additions & 0 deletions recipes/splunk-opentelemetry-cpp/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ sources:
0.4.0:
url: "https://github.com/signalfx/splunk-otel-cpp/archive/refs/tags/v0.4.0.tar.gz"
sha256: "e44f3167cecfea6d1fb0fa3060cc479a0873ab6d481b9b9f57629cbc7d17bfd4"
patches:
"0.4.0":
- patch_file: "patches/0.4.0-001-fix-cmake.patch"
patch_description: "Make CMakeLists.txt compatible with Conan"
patch_type: "conan"
126 changes: 79 additions & 47 deletions recipes/splunk-opentelemetry-cpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,83 +1,115 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os
import glob

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, rmdir, export_conandata_patches, apply_conandata_patches
from conan.tools.scm import Version

required_conan_version = ">=1.53.0"


class SplunkOpentelemetryConan(ConanFile):
name = "splunk-opentelemetry-cpp"
description = "Splunk's distribution of OpenTelemetry C++"
license = "Apache-2.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/signalfx/splunk-otel-cpp"
description = "Splunk's distribution of OpenTelemetry C++"
topics = ("opentelemetry", "observability", "tracing")
settings = "os", "compiler", "build_type", "arch"

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"fPIC": [True, False],
"shared": [True, False],
"fPIC": [True, False],
"build_jaeger_exporter": [True, False],
}
default_options = {
"fPIC": True,
"shared": False,
"fPIC": True,
"build_jaeger_exporter": True,
}
generators = "cmake", "cmake_find_package_multi"
requires = "opentelemetry-cpp/1.0.1"
exports_sources = "CMakeLists.txt"
short_paths = True
_cmake = None

def validate(self):
if self.settings.arch != "x86_64":
raise ConanInvalidConfiguration("Architecture not supported")
@property
def _min_cppstd(self):
return 14

def configure(self):
if self.options.shared:
del self.options.fPIC
@property
def _compilers_minimum_version(self):
return {
"gcc": "6",
"clang": "5",
"apple-clang": "10",
"Visual Studio": "16",
"msvc": "192",
}

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

@property
def _source_subfolder(self):
return "source_subfolder"
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

@property
def _build_subfolder(self):
return "build_subfolder"
def layout(self):
cmake_layout(self, src_folder="src")

def _remove_unnecessary_package_files(self):
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
def requirements(self):
self.requires("opentelemetry-cpp/1.8.3", transitive_headers=True) # v1.12 is not compatible
self.requires("grpc/1.54.3")
self.requires("nlohmann_json/3.11.3")
if self.options.build_jaeger_exporter:
self.requires("thrift/0.17.0")
self.requires("libcurl/[>=7.78.0 <9]")

def validate(self):
if self.settings.arch != "x86_64":
raise ConanInvalidConfiguration(f"{self.settings.arch} architecture not supported")
if self.options.build_jaeger_exporter and not self.dependencies["opentelemetry-cpp"].options.get_safe("with_jaeger"):
raise ConanInvalidConfiguration("Cannot build Jaeger exporter without with_jaeger=True in opentelemetry-cpp")

if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

def source(self):
tools.get(
**self.conan_data["sources"][self.version],
strip_root=True,
destination=self._source_subfolder
)

def _configure_cmake(self):
if self._cmake:
return self._cmake

self._cmake = CMake(self)
defs = {
"SPLUNK_CPP_EXAMPLES": False
}
self._cmake.configure(defs=defs, build_folder=self._build_subfolder)
return self._cmake
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["SPLUNK_CPP_TESTS"] = False
tc.variables["SPLUNK_CPP_EXAMPLES"] = False
tc.variables["SPLUNK_CPP_WITH_JAEGER_EXPORTER"] = self.options.build_jaeger_exporter
tc.generate()
tc = CMakeDeps(self)
tc.generate()

def build(self):
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()
self._remove_unnecessary_package_files()
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "SplunkOpenTelemetry")
self.cpp_info.set_property("cmake_target_name", "SplunkOpenTelemetry::SplunkOpenTelemetry")
self.cpp_info.libs = ["SplunkOpenTelemetry"]

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.names["cmake_find_package"] = "SplunkOpenTelemetry"
self.cpp_info.names["cmake_find_package_multi"] = "SplunkOpenTelemetry"
self.cpp_info.libs = ["SplunkOpenTelemetry"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.5.1)
+cmake_minimum_required(VERSION 3.15)

project(SplunkOpenTelemetry CXX)

@@ -6,8 +6,6 @@
include(GenerateExportHeader)

set(PACKAGE_VERSION "0.1.0")
-
-set(CMAKE_CXX_STANDARD 11)

option(SPLUNK_CPP_TESTS "Enable building of tests" OFF)
option(SPLUNK_CPP_EXAMPLES "Enable building of examples" ON)
@@ -36,7 +34,7 @@

target_link_libraries(SplunkOpenTelemetry
PUBLIC
- ${OPENTELEMETRY_CPP_LIBRARIES}
+ opentelemetry-cpp::opentelemetry-cpp
gRPC::grpc++
protobuf::libprotobuf
${SPLUNK_CPP_JAEGER_EXPORTER_LIBS}
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
cmake_minimum_required(VERSION 3.12)

cmake_minimum_required(VERSION 3.15)
project(test_package CXX)
set(CMAKE_CXX_STANDARD 11)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(SplunkOpenTelemetry CONFIG REQUIRED)

add_executable(test_package test_package.cpp)

target_link_libraries(test_package SplunkOpenTelemetry::SplunkOpenTelemetry)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
21 changes: 15 additions & 6 deletions recipes/splunk-opentelemetry-cpp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
#include <opentelemetry/sdk/trace/tracer_provider.h>
#include <splunk/opentelemetry.h>

#include <stdio.h>

int main(int argc, char** argv) {
int main() {
splunk::OpenTelemetryOptions otelOptions = splunk::OpenTelemetryOptions()
.WithServiceName("my-service")
.WithServiceVersion("1.0")
.WithExporter(splunk::ExporterType_JaegerThriftHttp)
.WithDeploymentEnvironment("test");
auto provider = splunk::InitOpentelemetry(otelOptions);
auto span = opentelemetry::trace::Tracer::GetCurrentSpan();

char traceId[32] = {0};
char spanId[16] = {0};
span->GetContext().trace_id().ToLowerBase16(traceId);
span->GetContext().span_id().ToLowerBase16(spanId);
printf("current span: %.*s:%.*s\n", 32, traceId, 16, spanId);

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
17 changes: 17 additions & 0 deletions recipes/splunk-opentelemetry-cpp/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
Loading