1{ lib
2, stdenv
3, fetchFromGitHub
4, fetchpatch
5, pkg-config
6, cmake
7, gtest
8, valgrind
9}:
10
11stdenv.mkDerivation rec {
12 pname = "rapidjson";
13 version = "1.1.0";
14
15 src = fetchFromGitHub {
16 owner = "miloyip";
17 repo = "rapidjson";
18 rev = "v${version}";
19 sha256 = "1jixgb8w97l9gdh3inihz7avz7i770gy2j2irvvlyrq3wi41f5ab";
20 };
21
22 patches = [
23 (fetchpatch {
24 url = "https://src.fedoraproject.org/rpms/rapidjson/raw/48402da9f19d060ffcd40bf2b2e6987212c58b0c/f/rapidjson-1.1.0-c++20.patch";
25 sha256 = "1qm62iad1xfsixv1li7qy475xc7gc04hmi2q21qdk6l69gk7mf82";
26 })
27 (fetchpatch {
28 name = "do-not-include-gtest-src-dir.patch";
29 url = "https://git.alpinelinux.org/aports/plain/community/rapidjson/do-not-include-gtest-src-dir.patch?id=9e5eefc7a5fcf5938a8dc8a3be8c75e9e6809909";
30 hash = "sha256-BjSZEwfCXA/9V+kxQ/2JPWbc26jQn35CfN8+8NW24s4=";
31 })
32 ];
33
34 postPatch = ''
35 find -name CMakeLists.txt | xargs \
36 sed -i -e "s/-Werror//g" -e "s/-march=native//g"
37 '';
38
39 nativeBuildInputs = [ pkg-config cmake ];
40
41 # for tests, adding gtest to checkInputs does not work
42 # https://github.com/NixOS/nixpkgs/pull/212200
43 buildInputs = [ gtest ];
44 cmakeFlags = [ "-DGTEST_SOURCE_DIR=${gtest.dev}/include" ];
45
46 nativeCheckInputs = [ valgrind ];
47 doCheck = !stdenv.hostPlatform.isStatic && !stdenv.isDarwin;
48
49 meta = with lib; {
50 description = "Fast JSON parser/generator for C++ with both SAX/DOM style API";
51 homepage = "http://rapidjson.org/";
52 license = licenses.mit;
53 platforms = platforms.unix;
54 maintainers = with maintainers; [ cstrahan dotlambda ];
55 };
56}