Files

129 lines
3.3 KiB
Nix

{
lib,
stdenv,
fetchFromGitHub,
cmake,
gtest,
protobuf,
curl,
grpc,
prometheus-cpp,
nlohmann_json,
nix-update-script,
cxxStandard ? null,
enableHttp ? false,
enableGrpc ? false,
enablePrometheus ? false,
enableElasticSearch ? false,
enableZipkin ? false,
# for passthru.tests
opentelemetry-cpp,
}:
let
opentelemetry-proto = fetchFromGitHub {
owner = "open-telemetry";
repo = "opentelemetry-proto";
rev = "v1.10.0";
hash = "sha256-RJrS0C4GZfUdETff+ZlbJr67Z+JObrLsDvyGqobf4UI=";
};
in
stdenv.mkDerivation (finalAttrs: {
pname = "opentelemetry-cpp";
version = "1.28.0";
src = fetchFromGitHub {
owner = "open-telemetry";
repo = "opentelemetry-cpp";
rev = "v${finalAttrs.version}";
hash = "sha256-+S/C+msuUEzOVIcx/1lEuQh6ZmyujALVXsiSqb0s2FM=";
};
patches = [
./0001-Disable-tests-requiring-network-access.patch
]
++ lib.optional stdenv.hostPlatform.isDarwin ./0002-Disable-segfaulting-test-on-Darwin.patch;
nativeBuildInputs = [ cmake ];
buildInputs = [
curl
nlohmann_json
];
propagatedBuildInputs =
lib.optionals (enableGrpc || enableHttp) [ protobuf ]
++ lib.optionals enableGrpc [
grpc
]
++ lib.optionals enablePrometheus [
prometheus-cpp
];
doCheck = true;
checkInputs = [
gtest
];
strictDeps = true;
cmakeFlags = [
(lib.cmakeBool "BUILD_SHARED_LIBS" (!stdenv.hostPlatform.isStatic))
(lib.cmakeBool "WITH_BENCHMARK" false)
(lib.cmakeBool "WITH_OTLP_HTTP" enableHttp)
(lib.cmakeBool "WITH_OTLP_GRPC" enableGrpc)
(lib.cmakeBool "WITH_PROMETHEUS" enablePrometheus)
(lib.cmakeBool "WITH_ELASTICSEARCH" enableElasticSearch)
(lib.cmakeBool "WITH_ZIPKIN" enableZipkin)
(lib.cmakeFeature "OTELCPP_PROTO_PATH" "${opentelemetry-proto}")
]
++ lib.optionals (cxxStandard != null) [
(lib.cmakeFeature "CMAKE_CXX_STANDARD" cxxStandard)
(lib.cmakeFeature "WITH_STL" "CXX${cxxStandard}")
];
outputs = [
"out"
"dev"
];
# "--replace-fail" would normally be preferred, since it is better at
# highlighting obsolete/uneeded substitutions, but in this case
# "--replace-quiet" must be used.
# substituteInPlace with "--replace-fail" already fails if there is no
# substitution in at least one of the specified files. Below is applied to
# multiple files where some but not all of them match the substitution
# strings.
postInstall = ''
substituteInPlace $out/lib/cmake/opentelemetry-cpp/opentelemetry-cpp*-target.cmake \
--replace-quiet "\''${_IMPORT_PREFIX}/include" "$dev/include"
'';
passthru.updateScript = nix-update-script { };
passthru.tests = {
# Unfortunately there is no such thing as finalAttrs.finalPackage.override,
# so we have to resort to this.
full = opentelemetry-cpp.override {
enableHttp = true;
enableGrpc = true;
enablePrometheus = true;
enableElasticSearch = true;
enableZipkin = true;
};
};
meta = {
description = "OpenTelemetry C++ Client Library";
homepage = "https://github.com/open-telemetry/opentelemetry-cpp";
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [
jfroche
panicgh
];
platforms = lib.platforms.all;
# https://github.com/protocolbuffers/protobuf/issues/14492
broken = !(stdenv.buildPlatform.canExecute stdenv.hostPlatform);
};
})