gnu: Add llhttp-bootstrap.
[jackhill/guix/guix.git] / gnu / packages / node.scm
index 5336012..26025c5 100644 (file)
@@ -510,6 +510,76 @@ Node.js and web browsers.")
 parser definition into a C output.")
     (license license:expat)))
 
+(define-public llhttp-bootstrap
+  (package
+    (name "llhttp")
+    (version "2.1.3")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/nodejs/llhttp.git")
+                    (commit (string-append "v" version))))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "0pqj7kyyzr1zs4h9yzn5rdxnxspm3wqgsv00765dd42fszlmrmk8"))
+              (patches (search-patches "llhttp-bootstrap-CVE-2020-8287.patch"))
+              (modules '((guix build utils)))
+              (snippet
+               '(begin
+                  ;; Fix imports for esbuild.
+                  ;; https://github.com/evanw/esbuild/issues/477
+                  (substitute* "src/llhttp/http.ts"
+                    (("\\* as assert") "assert"))
+                  (substitute* "Makefile"
+                    (("npx ts-node bin/generate.ts")
+                     "node bin/generate.js"))
+                  #t))))
+    (build-system gnu-build-system)
+    (arguments
+     `(#:tests? #f                      ; no tests
+       #:make-flags (list (string-append "CLANG=" ,(cc-for-target))
+                          (string-append "DESTDIR=" (assoc-ref %outputs "out"))
+                          "PREFIX=")
+       #:phases
+       (modify-phases %standard-phases
+         (replace 'configure
+           (lambda* (#:key inputs #:allow-other-keys)
+             (let ((esbuild (string-append (assoc-ref inputs "esbuild")
+                                           "/bin/esbuild")))
+               (invoke esbuild
+                       "--platform=node"
+                       "--outfile=bin/generate.js"
+                       "--bundle" "bin/generate.ts"))))
+         (add-before 'install 'create-install-directories
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let ((out (assoc-ref outputs "out")))
+               (for-each (lambda (dir)
+                           (mkdir-p (string-append out dir)))
+                         (list "/lib" "/include" "/src"))
+               #t)))
+         (add-after 'install 'install-src
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (src-dir (string-append out "/src")))
+               (install-file "build/c/llhttp.c" src-dir)
+               (install-file "src/native/api.c" src-dir)
+               (install-file "src/native/http.c" src-dir)
+               #t))))))
+    (native-inputs
+     `(("esbuild" ,esbuild)
+       ("node" ,node-bootstrap)
+       ("node-semver" ,node-semver-bootstrap)
+       ("node-llparse-bootstrap" ,node-llparse-bootstrap)))
+    (home-page "https://github.com/nodejs/llhttp")
+    (properties '((hidden? . #t)))
+    (synopsis "Parser for HTTP messages")
+    (description "This is a rewrite of
+@url{https://github.com/nodejs/http-parser, http-parser} using
+@url{https://github.com/nodejs/llparse, llparse} to generate the C
+source files.")
+    (license license:expat)))
+
 (define-public libnode
   (package/inherit node
     (name "libnode")