diff --git a/pkgs/by-name/cp/cpptrace/findpackage-integration.nix b/pkgs/by-name/cp/cpptrace/findpackage-integration.nix new file mode 100644 index 000000000000..72d205acf8d3 --- /dev/null +++ b/pkgs/by-name/cp/cpptrace/findpackage-integration.nix @@ -0,0 +1,39 @@ +{ + stdenv, + lib, + cmake, + cpptrace, + src, + checkOutput, +}: + +stdenv.mkDerivation (finalAttrs: { + name = "cpptrace-findpackage-integration-test"; + + inherit src; + + nativeBuildInputs = [ cmake ]; + buildInputs = [ cpptrace ]; + + installPhase = '' + runHook preInstall + mkdir -p $out/bin + install main $out/bin + runHook postInstall + ''; + + doInstallCheck = true; + + installCheckPhase = lib.strings.concatLines ( + [ "$out/bin/main" ] + # Check that the backtrace contains the path to the executable. + ++ lib.optionals (checkOutput) [ + '' + if [[ !(`$out/bin/main 2>&1` =~ "${finalAttrs.name}") ]]; then + echo "ERROR: $out/bin/main does not output '${finalAttrs.name}'" + exit 1 + fi + '' + ] + ); +}) diff --git a/pkgs/by-name/cp/cpptrace/package.nix b/pkgs/by-name/cp/cpptrace/package.nix new file mode 100644 index 000000000000..2936bee7953c --- /dev/null +++ b/pkgs/by-name/cp/cpptrace/package.nix @@ -0,0 +1,61 @@ +{ + lib, + stdenv, + fetchFromGitHub, + cmake, + pkg-config, + libdwarf, + gtest, + callPackage, + zstd, + static ? stdenv.hostPlatform.isStatic, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "cpptrace"; + version = "0.6.2"; + + src = fetchFromGitHub { + owner = "jeremy-rifkin"; + repo = "cpptrace"; + rev = "v${finalAttrs.version}"; + hash = "sha256-zjPxPtq+OQ104sJoeBD3jpMV9gV57FSHEJS4W6SF8GM="; + }; + + nativeBuildInputs = [ + cmake + pkg-config + ]; + + buildInputs = [ libdwarf ]; + propagatedBuildInputs = [ zstd ]; + + cmakeFlags = [ + (lib.cmakeBool "CPPTRACE_USE_EXTERNAL_LIBDWARF" true) + (lib.cmakeBool "CPPTRACE_FIND_LIBDWARF_WITH_PKGCONFIG" true) + (lib.cmakeBool "BUILD_SHARED_LIBS" (!static)) + (lib.cmakeBool "BUILD_TESTING" finalAttrs.finalPackage.doCheck) + (lib.cmakeBool "CPPTRACE_USE_EXTERNAL_GTEST" true) + ]; + + checkInputs = [ gtest ]; + + # Unit tests are flaky and hard to get right. + doCheck = false; + + passthru.tests = { + findpackage-integration = callPackage ./findpackage-integration.nix { + src = "${finalAttrs.src}/test/findpackage-integration"; + checkOutput = finalAttrs.finalPackage.doCheck; + }; + }; + + meta = { + changelog = "https://github.com/jeremy-rifkin/cpptrace/releases/tag/v${finalAttrs.version}"; + description = "Simple, portable, and self-contained stacktrace library for C++11 and newer"; + homepage = "https://github.com/jeremy-rifkin/cpptrace"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ xokdvium ]; + platforms = lib.platforms.all; + }; +})