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