about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/rapidjson
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/libraries/rapidjson')
-rw-r--r--nixpkgs/pkgs/development/libraries/rapidjson/0000-unstable-use-nixpkgs-gtest.patch35
-rw-r--r--nixpkgs/pkgs/development/libraries/rapidjson/0001-unstable-valgrind-suppress-failures.patch36
-rw-r--r--nixpkgs/pkgs/development/libraries/rapidjson/default.nix65
-rw-r--r--nixpkgs/pkgs/development/libraries/rapidjson/test-skip-valgrind.diff7
-rw-r--r--nixpkgs/pkgs/development/libraries/rapidjson/unstable.nix82
5 files changed, 225 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/libraries/rapidjson/0000-unstable-use-nixpkgs-gtest.patch b/nixpkgs/pkgs/development/libraries/rapidjson/0000-unstable-use-nixpkgs-gtest.patch
new file mode 100644
index 000000000000..df334cc91264
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/rapidjson/0000-unstable-use-nixpkgs-gtest.patch
@@ -0,0 +1,35 @@
+diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
+index 11c1b04c..762eaa75 100644
+--- a/test/CMakeLists.txt
++++ b/test/CMakeLists.txt
+@@ -1,20 +1,14 @@
+-find_package(GTestSrc)
++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()
+ 
+-    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)
+-    add_subdirectory(perftest)
+-    add_subdirectory(unittest)
+-
+-ENDIF(GTESTSRC_FOUND)
++add_custom_target(tests ALL)
++add_subdirectory(perftest)
++add_subdirectory(unittest)
diff --git a/nixpkgs/pkgs/development/libraries/rapidjson/0001-unstable-valgrind-suppress-failures.patch b/nixpkgs/pkgs/development/libraries/rapidjson/0001-unstable-valgrind-suppress-failures.patch
new file mode 100644
index 000000000000..dd06ba6a6971
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/rapidjson/0001-unstable-valgrind-suppress-failures.patch
@@ -0,0 +1,36 @@
+diff --git a/test/valgrind.supp b/test/valgrind.supp
+index c9d3d226..63af7bf9 100644
+--- a/test/valgrind.supp
++++ b/test/valgrind.supp
+@@ -24,3 +24,31 @@
+    fun:*Uri*Parse_UTF16_Std*
+ }
+ 
++{
++   Suppress memcpy_chk valgrind report 5
++   Memcheck:Overlap
++   fun:__memcpy_chk
++   fun:*dtoa_normal*
++}
++
++{
++   Suppress memcpy_chk valgrind report 6
++   Memcheck:Overlap
++   fun:__memcpy_chk
++   fun:*dtoa_maxDecimalPlaces*
++}
++
++{
++   Suppress memcpy_chk valgrind report 7
++   Memcheck:Overlap
++   fun:__memcpy_chk
++   ...
++   fun:*Reader*ParseDoubleHandler*
++}
++
++{
++   Suppress memcpy_chk valgrind report 8
++   Memcheck:Overlap
++   fun:__memcpy_chk
++   fun:*Reader*ParseNumber_NormalPrecisionError*
++}
diff --git a/nixpkgs/pkgs/development/libraries/rapidjson/default.nix b/nixpkgs/pkgs/development/libraries/rapidjson/default.nix
new file mode 100644
index 000000000000..edd427da725d
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/rapidjson/default.nix
@@ -0,0 +1,65 @@
+{ lib
+, stdenv
+, fetchFromGitHub
+, fetchpatch
+, pkg-config
+, cmake
+, gtest
+, valgrind
+}:
+
+stdenv.mkDerivation rec {
+  pname = "rapidjson";
+  version = "1.1.0";
+
+  src = fetchFromGitHub {
+    owner = "Tencent";
+    repo = "rapidjson";
+    rev = "v${version}";
+    sha256 = "1jixgb8w97l9gdh3inihz7avz7i770gy2j2irvvlyrq3wi41f5ab";
+  };
+
+  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
+  ];
+
+  postPatch = ''
+    find -name CMakeLists.txt | xargs \
+      sed -i -e "s/-Werror//g" -e "s/-march=native//g"
+  '';
+
+  nativeBuildInputs = [ pkg-config cmake ];
+
+  # 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"
+
+    # 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"
+  ];
+
+  nativeCheckInputs = [ valgrind ];
+  doCheck = !stdenv.hostPlatform.isStatic && !stdenv.isDarwin;
+
+  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 ];
+  };
+}
diff --git a/nixpkgs/pkgs/development/libraries/rapidjson/test-skip-valgrind.diff b/nixpkgs/pkgs/development/libraries/rapidjson/test-skip-valgrind.diff
new file mode 100644
index 000000000000..a791d88699ff
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/rapidjson/test-skip-valgrind.diff
@@ -0,0 +1,7 @@
+--- 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)
+
diff --git a/nixpkgs/pkgs/development/libraries/rapidjson/unstable.nix b/nixpkgs/pkgs/development/libraries/rapidjson/unstable.nix
new file mode 100644
index 000000000000..0f4c3d40403e
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/rapidjson/unstable.nix
@@ -0,0 +1,82 @@
+{ lib
+, stdenv
+, fetchFromGitHub
+, cmake
+, doxygen
+, graphviz
+, gtest
+, valgrind
+# One of "11" or "17"; default in source is CXX 11
+, cxxStandard ? "11"
+, 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)
+    (lib.cmakeBool "RAPIDJSON_BUILD_CXX11" (cxxStandard == "11"))
+    (lib.cmakeBool "RAPIDJSON_BUILD_CXX17" (cxxStandard == "17"))
+  ] ++ 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 ];
+    broken = (cxxStandard != "11" && cxxStandard != "17");
+  };
+})