Unverified Commit 28ec6ee9 authored by Masum Reza's avatar Masum Reza Committed by GitHub
Browse files

Merge pull request #330698 from tobim/pkgs/rapidjson-unstable-default

rapidjson: 1.1.0 -> unstable-2024-04-09, rapidjson-unstable: drop
parents b69c8386 11ff4aef
Loading
Loading
Loading
Loading
+47 −33
Original line number Diff line number Diff line
{ lib
, stdenv
, fetchFromGitHub
, fetchpatch
, pkg-config
, cmake
, doxygen
, graphviz
, gtest
, valgrind
}:

stdenv.mkDerivation rec {
stdenv.mkDerivation (finalAttrs: {
  pname = "rapidjson";
  version = "1.1.0";
  version = "unstable-2024-04-09";

  outputs = [
    "out"
    "doc"
  ];

  src = fetchFromGitHub {
    owner = "Tencent";
    repo = "rapidjson";
    rev = "v${version}";
    sha256 = "1jixgb8w97l9gdh3inihz7avz7i770gy2j2irvvlyrq3wi41f5ab";
    rev = "ab1842a2dae061284c0a62dca1cc6d5e7e37e346";
    hash = "sha256-kAGVJfDHEUV2qNR1LpnWq3XKBJy4hD3Swh6LX5shJpM=";
  };

  patches = [
    (fetchpatch {
      url = "https://src.fedoraproject.org/rpms/rapidjson/raw/48402da9f19d060ffcd40bf2b2e6987212c58b0c/f/rapidjson-1.1.0-c++20.patch";
      sha256 = "1qm62iad1xfsixv1li7qy475xc7gc04hmi2q21qdk6l69gk7mf82";
    })
    (fetchpatch {
      name = "do-not-include-gtest-src-dir.patch";
      url = "https://git.alpinelinux.org/aports/plain/community/rapidjson/do-not-include-gtest-src-dir.patch?id=9e5eefc7a5fcf5938a8dc8a3be8c75e9e6809909";
      hash = "sha256-BjSZEwfCXA/9V+kxQ/2JPWbc26jQn35CfN8+8NW24s4=";
    })
    # One of these three tests reports memcpy overlap after update to glibc-2.38
    ./test-skip-valgrind.diff
    ./use-nixpkgs-gtest.patch
    # https://github.com/Tencent/rapidjson/issues/2214
    ./suppress-valgrind-failures.patch
  ];

  postPatch = ''
    find -name CMakeLists.txt | xargs \
      sed -i -e "s/-Werror//g" -e "s/-march=native//g"
    for f in doc/Doxyfile.*; do
      substituteInPlace $f \
        --replace-fail "WARN_IF_UNDOCUMENTED   = YES" "WARN_IF_UNDOCUMENTED   = NO"
    done
  '';

  nativeBuildInputs = [ pkg-config cmake ];
  nativeBuildInputs = [
    cmake
    doxygen
    graphviz
  ];

  # for tests, adding gtest to checkInputs does not work
  # https://github.com/NixOS/nixpkgs/pull/212200
  buildInputs = [ gtest ];
  cmakeFlags = [
    "-DGTEST_SOURCE_DIR=${gtest.dev}/include"
  buildInputs = [
    gtest
  ];

  strictDeps = true;

    # Build rapidjson with std=c++17 so gtest 1.13.0+ works
    # https://github.com/NixOS/nixpkgs/pull/282245#issuecomment-1951796902
    "-DRAPIDJSON_BUILD_CXX11=OFF"
    "-DRAPIDJSON_BUILD_CXX17=ON"
  cmakeFlags = [
    (lib.cmakeBool "RAPIDJSON_BUILD_DOC" true)
    (lib.cmakeBool "RAPIDJSON_BUILD_TESTS" true)
    (lib.cmakeBool "RAPIDJSON_BUILD_EXAMPLES" true)
    # gtest 1.13+ requires C++14 or later.
    (lib.cmakeBool "RAPIDJSON_BUILD_CXX11" false)
    (lib.cmakeBool "RAPIDJSON_BUILD_CXX17" true)
    # Prevent -march=native
    (lib.cmakeBool "RAPIDJSON_ENABLE_INSTRUMENTATION_OPT" false)
    # Disable -Werror by using build type specific flags, which are
    # added after general CMAKE_CXX_FLAGS.
    (lib.cmakeFeature "CMAKE_CXX_FLAGS_RELEASE" "-Wno-error")
  ];

  nativeCheckInputs = [ valgrind ];
  doCheck = !stdenv.hostPlatform.isStatic && !stdenv.isDarwin;
  doCheck = !(stdenv.hostPlatform.isStatic || stdenv.isDarwin);

  nativeCheckInputs = [
    valgrind
  ];

  meta = with lib; {
    description = "Fast JSON parser/generator for C++ with both SAX/DOM style API";
    homepage = "http://rapidjson.org/";
    license = licenses.mit;
    platforms = platforms.unix;
    maintainers = with maintainers; [ dotlambda ];
    maintainers = with maintainers; [ dotlambda Madouura tobim ];
  };
}
})
+0 −7
Original line number Diff line number Diff line
--- a/test/unittest/CMakeLists.txt
+++ b/test/unittest/CMakeLists.txt
@@ -82,3 +81,0 @@
-    add_test(NAME valgrind_unittest
-        COMMAND valgrind --leak-check=full --error-exitcode=1 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest --gtest_filter=-SIMD.*
-        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
+0 −80
Original line number Diff line number Diff line
{ lib
, stdenv
, fetchFromGitHub
, cmake
, doxygen
, graphviz
, gtest
, valgrind
, buildDocs ? true
, buildTests ? !stdenv.hostPlatform.isStatic && !stdenv.isDarwin
, buildExamples ? true
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "rapidjson";
  version = "unstable-2023-09-28";

  outputs = [
    "out"
  ] ++ lib.optionals buildDocs [
    "doc"
  ] ++ lib.optionals buildExamples [
    "example"
  ];

  src = fetchFromGitHub {
    owner = "Tencent";
    repo = "rapidjson";
    rev = "f9d53419e912910fd8fa57d5705fa41425428c35";
    hash = "sha256-rl7iy14jn1K2I5U2DrcZnoTQVEGEDKlxmdaOCF/3hfY=";
  };

  patches = lib.optionals buildTests [
    ./0000-unstable-use-nixpkgs-gtest.patch
    # https://github.com/Tencent/rapidjson/issues/2214
    ./0001-unstable-valgrind-suppress-failures.patch
  ];

  nativeBuildInputs = [
    cmake
  ] ++ lib.optionals buildDocs [
    doxygen
    graphviz
  ];

  cmakeFlags = [
    (lib.cmakeBool "RAPIDJSON_BUILD_DOC" buildDocs)
    (lib.cmakeBool "RAPIDJSON_BUILD_TESTS" buildTests)
    (lib.cmakeBool "RAPIDJSON_BUILD_EXAMPLES" buildExamples)
    # gtest 1.13+ requires C++14 or later.
    (lib.cmakeBool "RAPIDJSON_BUILD_CXX11" false)
    (lib.cmakeBool "RAPIDJSON_BUILD_CXX17" true)
  ] ++ lib.optionals buildTests [
    (lib.cmakeFeature "GTEST_INCLUDE_DIR" "${lib.getDev gtest}")
  ];

  doCheck = buildTests;

  nativeCheckInputs = [
    gtest
    valgrind
  ];

  postInstall = lib.optionalString buildExamples ''
    mkdir -p $example/bin

    find bin -type f -executable \
      -not -name "perftest" \
      -not -name "unittest" \
      -exec cp -a {} $example/bin \;
  '';

  meta = with lib; {
    description = "Fast JSON parser/generator for C++ with both SAX/DOM style API";
    homepage = "http://rapidjson.org/";
    license = licenses.mit;
    platforms = platforms.unix;
    maintainers = with maintainers; [ Madouura ];
  };
})
+18 −10
Original line number Diff line number Diff line
From b9206d360c19412d185263795d67c884feab281a Mon Sep 17 00:00:00 2001
From: Tobias Mayer <tobim@fastmail.fm>
Date: Mon, 29 Jul 2024 07:26:50 +0200
Subject: [PATCH] Use nixpkgs gtest

---
 test/CMakeLists.txt | 24 ++++++------------------
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 11c1b04c..762eaa75 100644
index 11c1b04c..3d02d475 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -1,20 +1,14 @@
@@ -1,20 +1,8 @@
-find_package(GTestSrc)
+find_package(GTest REQUIRED)
+enable_testing()
 
-IF(GTESTSRC_FOUND)
-    enable_testing()
+if (WIN32 AND (NOT CYGWIN) AND (NOT MINGW))
+    set(gtest_disable_pthreads ON)
+    set(gtest_force_shared_crt ON)
+endif()
+set(TEST_LIBRARIES GTest::gtest GTest::gtest_main)
 
-    if (WIN32 AND (NOT CYGWIN) AND (NOT MINGW))
-        set(gtest_disable_pthreads ON)
-        set(gtest_force_shared_crt ON)
-    endif()
+include_directories(SYSTEM ${GTEST_INCLUDE_DIR})
 
-
-    add_subdirectory(${GTEST_SOURCE_DIR} ${CMAKE_BINARY_DIR}/googletest)
-    include_directories(SYSTEM ${GTEST_INCLUDE_DIR})
+set(TEST_LIBRARIES gtest gtest_main)
 
-
-    set(TEST_LIBRARIES gtest gtest_main)
-
-    add_custom_target(tests ALL)
@@ -33,3 +38,6 @@ index 11c1b04c..762eaa75 100644
+add_custom_target(tests ALL)
+add_subdirectory(perftest)
+add_subdirectory(unittest)
-- 
2.45.2
Loading