1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 fetchpatch,
6 enableShared ? !stdenv.hostPlatform.isStatic,
7 enableStatic ? stdenv.hostPlatform.isStatic,
8}:
9
10stdenv.mkDerivation rec {
11 pname = "http-parser";
12 version = "2.9.4";
13
14 src = fetchFromGitHub {
15 owner = "nodejs";
16 repo = "http-parser";
17 rev = "v${version}";
18 sha256 = "1vda4dp75pjf5fcph73sy0ifm3xrssrmf927qd1x8g3q46z0cv6c";
19 };
20
21 env.NIX_CFLAGS_COMPILE = "-Wno-error";
22
23 patches = [
24 ./enable-static-shared.patch
25 ]
26 ++ lib.optionals stdenv.hostPlatform.isAarch32 [
27 # https://github.com/nodejs/http-parser/pull/510
28 (fetchpatch {
29 url = "https://github.com/nodejs/http-parser/commit/4f15b7d510dc7c6361a26a7c6d2f7c3a17f8d878.patch";
30 sha256 = "sha256-rZZMJeow3V1fTnjadRaRa+xTq3pdhZn/eJ4xjxEDoU4=";
31 })
32 ];
33
34 makeFlags = [
35 "DESTDIR="
36 "PREFIX=$(out)"
37 "BINEXT=${stdenv.hostPlatform.extensions.executable}"
38 "Platform=${lib.toLower stdenv.hostPlatform.uname.system}"
39 "AEXT=${lib.strings.removePrefix "." stdenv.hostPlatform.extensions.staticLibrary}"
40 "ENABLE_SHARED=${if enableShared then "1" else "0"}"
41 "ENABLE_STATIC=${if enableStatic then "1" else "0"}"
42 ]
43 ++ lib.optionals enableShared [
44 "SOEXT=${lib.strings.removePrefix "." stdenv.hostPlatform.extensions.sharedLibrary}"
45 ]
46 ++ lib.optionals enableStatic [
47 "AEXT=${lib.strings.removePrefix "." stdenv.hostPlatform.extensions.staticLibrary}"
48 ]
49 ++ lib.optionals (enableShared && stdenv.hostPlatform.isWindows) [
50 "SONAME=$(SOLIBNAME).$(SOMAJOR).$(SOMINOR).$(SOEXT)"
51 "LIBNAME=$(SOLIBNAME).$(SOMAJOR).$(SOMINOR).$(SOREV).$(SOEXT)"
52 "LDFLAGS=-Wl,--out-implib=$(LIBNAME).a"
53 ];
54
55 buildFlags = lib.optional enableShared "library" ++ lib.optional enableStatic "package";
56
57 doCheck = true;
58 checkTarget = "test";
59
60 enableParallelBuilding = true;
61
62 postInstall = lib.optionalString stdenv.hostPlatform.isWindows ''
63 install -D *.dll.a $out/lib
64 ln -sf libhttp_parser.${version}.dll.a $out/lib/libhttp_parser.dll.a
65 '';
66
67 meta = with lib; {
68 description = "HTTP message parser written in C";
69 homepage = "https://github.com/nodejs/http-parser";
70 maintainers = with maintainers; [ matthewbauer ];
71 license = licenses.mit;
72 platforms = platforms.all;
73 };
74}