Merge branch 'master' into core-updates-frozen
[jackhill/guix/guix.git] / gnu / packages / node.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 Cyrill Schenkel <cyrill.schenkel@gmail.com>
3 ;;; Copyright © 2015 Andreas Enge <andreas@enge.fr>
4 ;;; Copyright © 2015, 2016 David Thompson <davet@gnu.org>
5 ;;; Copyright © 2016, 2021 Ludovic Courtès <ludo@gnu.org>
6 ;;; Copyright © 2017 Mike Gerwitz <mtg@gnu.org>
7 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
8 ;;; Copyright © 2018, 2019, 2020, 2021 Marius Bakke <marius@gnu.org>
9 ;;; Copyright © 2020, 2021 Pierre Langlois <pierre.langlois@gmx.com>
10 ;;; Copyright © 2020 Ricardo Wurmus <rekado@elephly.net>
11 ;;; Copyright © 2021 Simon Tournier <zimon.toutoune@gmail.com>
12 ;;; Copyright © 2021 Guillaume Le Vaillant <glv@posteo.net>
13 ;;;
14 ;;; This file is part of GNU Guix.
15 ;;;
16 ;;; GNU Guix is free software; you can redistribute it and/or modify it
17 ;;; under the terms of the GNU General Public License as published by
18 ;;; the Free Software Foundation; either version 3 of the License, or (at
19 ;;; your option) any later version.
20 ;;;
21 ;;; GNU Guix is distributed in the hope that it will be useful, but
22 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;;; GNU General Public License for more details.
25 ;;;
26 ;;; You should have received a copy of the GNU General Public License
27 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
28
29 (define-module (gnu packages node)
30 #:use-module ((guix licenses) #:prefix license:)
31 #:use-module ((guix build utils) #:select (alist-replace))
32 #:use-module (guix packages)
33 #:use-module (guix derivations)
34 #:use-module (guix download)
35 #:use-module (guix git-download)
36 #:use-module (guix utils)
37 #:use-module (guix build-system gnu)
38 #:use-module (guix build-system node)
39 #:use-module (gnu packages)
40 #:use-module (gnu packages adns)
41 #:use-module (gnu packages base)
42 #:use-module (gnu packages bash)
43 #:use-module (gnu packages compression)
44 #:use-module (gnu packages gcc)
45 #:use-module (gnu packages icu4c)
46 #:use-module (gnu packages libevent)
47 #:use-module (gnu packages linux)
48 #:use-module (gnu packages node-xyz)
49 #:use-module (gnu packages perl)
50 #:use-module (gnu packages pkg-config)
51 #:use-module (gnu packages python)
52 #:use-module (gnu packages tls)
53 #:use-module (gnu packages web)
54 #:use-module (ice-9 match)
55 #:use-module (srfi srfi-26))
56
57 (define-public node
58 (package
59 (name "node")
60 (version "10.24.0")
61 (source (origin
62 (method url-fetch)
63 (uri (string-append "https://nodejs.org/dist/v" version
64 "/node-v" version ".tar.xz"))
65 (sha256
66 (base32
67 "1k1srdis23782hnd1ymgczs78x9gqhv77v0am7yb54gqcspp70hm"))
68 (modules '((guix build utils)))
69 (snippet
70 `(begin
71 ;; Patch for compatibility with ICU 68 and newer, which
72 ;; removed the public TRUE and FALSE macros.
73 (substitute* '("deps/v8/src/objects/intl-objects.cc"
74 "deps/v8/src/runtime/runtime-intl.cc")
75 (("TRUE") "true")
76 (("FALSE") "false"))
77
78 ;; Remove bundled software.
79 (for-each delete-file-recursively
80 '("deps/cares"
81 "deps/http_parser"
82 "deps/icu-small"
83 "deps/nghttp2"
84 "deps/openssl"
85 "deps/uv"
86 "deps/zlib"))
87 (substitute* "Makefile"
88 ;; Remove references to bundled software.
89 (("deps/http_parser/http_parser.gyp") "")
90 (("deps/uv/include/\\*.h") "")
91 (("deps/uv/uv.gyp") "")
92 (("deps/zlib/zlib.gyp") ""))
93 #t))))
94 (build-system gnu-build-system)
95 (arguments
96 `(#:configure-flags '("--shared-cares"
97 "--shared-http-parser"
98 "--shared-libuv"
99 "--shared-nghttp2"
100 "--shared-openssl"
101 "--shared-zlib"
102 "--without-snapshot"
103 "--with-intl=system-icu")
104 ;; Run only the CI tests. The default test target requires additional
105 ;; add-ons from NPM that are not distributed with the source.
106 #:test-target "test-ci-js"
107 #:phases
108 (modify-phases %standard-phases
109 (add-before 'configure 'patch-files
110 (lambda* (#:key inputs #:allow-other-keys)
111 ;; Fix hardcoded /bin/sh references.
112 (substitute* '("lib/child_process.js"
113 "lib/internal/v8_prof_polyfill.js"
114 "test/parallel/test-child-process-spawnsync-shell.js"
115 "test/parallel/test-stdio-closed.js"
116 "test/sequential/test-child-process-emfile.js")
117 (("'/bin/sh'")
118 (string-append "'" (assoc-ref inputs "bash") "/bin/sh'")))
119
120 ;; Fix hardcoded /usr/bin/env references.
121 (substitute* '("test/parallel/test-child-process-default-options.js"
122 "test/parallel/test-child-process-env.js"
123 "test/parallel/test-child-process-exec-env.js")
124 (("'/usr/bin/env'")
125 (string-append "'" (assoc-ref inputs "coreutils")
126 "/bin/env'")))
127
128 ;; FIXME: These tests fail in the build container, but they don't
129 ;; seem to be indicative of real problems in practice.
130 (for-each delete-file
131 '("test/parallel/test-cluster-master-error.js"
132 "test/parallel/test-cluster-master-kill.js"
133 ;; See also <https://github.com/nodejs/node/issues/25903>.
134 "test/sequential/test-performance.js"))
135
136 ;; This requires a DNS resolver.
137 (delete-file "test/parallel/test-dns.js")
138
139 ;; FIXME: This test fails randomly:
140 ;; https://github.com/nodejs/node/issues/31213
141 (delete-file "test/parallel/test-net-listen-after-destroying-stdin.js")
142
143 ;; FIXME: These tests fail on armhf-linux:
144 ;; https://github.com/nodejs/node/issues/31970
145 ,@(if (string-prefix? "arm" (%current-system))
146 '((for-each delete-file
147 '("test/parallel/test-zlib.js"
148 "test/parallel/test-zlib-brotli.js"
149 "test/parallel/test-zlib-brotli-flush.js"
150 "test/parallel/test-zlib-brotli-from-brotli.js"
151 "test/parallel/test-zlib-brotli-from-string.js"
152 "test/parallel/test-zlib-convenience-methods.js"
153 "test/parallel/test-zlib-random-byte-pipes.js"
154 "test/parallel/test-zlib-write-after-flush.js")))
155 '())
156
157 ;; These tests have an expiry date: they depend on the validity of
158 ;; TLS certificates that are bundled with the source. We want this
159 ;; package to be reproducible forever, so remove those.
160 ;; TODO: Regenerate certs instead.
161 (for-each delete-file
162 '("test/parallel/test-tls-passphrase.js"
163 "test/parallel/test-tls-server-verify.js"))))
164 (add-before 'configure 'set-bootstrap-host-rpath
165 (lambda* (#:key native-inputs inputs #:allow-other-keys)
166 (let* ((inputs (or native-inputs inputs))
167 (c-ares (assoc-ref inputs "c-ares"))
168 (http-parser (assoc-ref inputs "http-parser"))
169 (icu4c (assoc-ref inputs "icu4c"))
170 (nghttp2 (assoc-ref inputs "nghttp2"))
171 (openssl (assoc-ref inputs "openssl"))
172 (libuv (assoc-ref inputs "libuv"))
173 (zlib (assoc-ref inputs "zlib")))
174 (substitute* "deps/v8/gypfiles/v8.gyp"
175 (("'target_name': 'torque'," target)
176 (string-append target
177 "'ldflags': ['-Wl,-rpath="
178 c-ares "/lib:"
179 http-parser "/lib:"
180 icu4c "/lib:"
181 nghttp2 "/lib:"
182 openssl "/lib:"
183 libuv "/lib:"
184 zlib "/lib"
185 "'],"))))))
186 (replace 'configure
187 ;; Node's configure script is actually a python script, so we can't
188 ;; run it with bash.
189 (lambda* (#:key outputs (configure-flags '()) native-inputs inputs
190 #:allow-other-keys)
191 (let* ((prefix (assoc-ref outputs "out"))
192 (xflags ,(if (%current-target-system)
193 `'("--cross-compiling"
194 ,(string-append
195 "--dest-cpu="
196 (match (%current-target-system)
197 ((? (cut string-prefix? "arm" <>))
198 "arm")
199 ((? (cut string-prefix? "aarch64" <>))
200 "arm64")
201 ((? (cut string-prefix? "i686" <>))
202 "ia32")
203 ((? (cut string-prefix? "x86_64" <>))
204 "x64")
205 ((? (cut string-prefix? "powerpc64" <>))
206 "ppc64")
207 (_ "unsupported"))))
208 ''()))
209 (flags (cons (string-append "--prefix=" prefix)
210 (append xflags configure-flags))))
211 (format #t "build directory: ~s~%" (getcwd))
212 (format #t "configure flags: ~s~%" flags)
213 ;; Node's configure script expects the CC environment variable to
214 ;; be set.
215 (setenv "CC_host" "gcc")
216 (setenv "CXX_host" "g++")
217 (setenv "CC" ,(cc-for-target))
218 (setenv "CXX" ,(cxx-for-target))
219 (setenv "PKG_CONFIG" ,(pkg-config-for-target))
220 (apply invoke
221 (search-input-file (or native-inputs inputs)
222 "/bin/python")
223 "configure" flags))))
224 (add-after 'patch-shebangs 'patch-npm-shebang
225 (lambda* (#:key outputs #:allow-other-keys)
226 (let* ((bindir (string-append (assoc-ref outputs "out")
227 "/bin"))
228 (npm (string-append bindir "/npm"))
229 (target (readlink npm)))
230 (with-directory-excursion bindir
231 (patch-shebang target (list bindir))))))
232 (add-after 'install 'patch-node-shebang
233 (lambda* (#:key outputs #:allow-other-keys)
234 (let* ((bindir (string-append (assoc-ref outputs "out")
235 "/bin"))
236 (npx (readlink (string-append bindir "/npx"))))
237 (with-directory-excursion bindir
238 (patch-shebang npx (list bindir)))))))))
239 (native-inputs
240 `(;; Runtime dependencies for binaries used as a bootstrap.
241 ("c-ares" ,c-ares)
242 ("http-parser" ,http-parser)
243 ("icu4c" ,icu4c)
244 ("libuv" ,libuv)
245 ("nghttp2" ,nghttp2 "lib")
246 ("openssl" ,openssl)
247 ("zlib" ,zlib)
248 ;; Regular build-time dependencies.
249 ("perl" ,perl)
250 ("pkg-config" ,pkg-config)
251 ("procps" ,procps)
252 ("python" ,python-2)
253 ("util-linux" ,util-linux)))
254 (native-search-paths
255 (list (search-path-specification
256 (variable "NODE_PATH")
257 (files '("lib/node_modules")))))
258 (inputs
259 `(("bash" ,bash)
260 ("coreutils" ,coreutils)
261 ("c-ares" ,c-ares)
262 ("http-parser" ,http-parser)
263 ("icu4c" ,icu4c)
264 ("libuv" ,libuv)
265 ("nghttp2" ,nghttp2 "lib")
266 ("openssl" ,openssl)
267 ("zlib" ,zlib)))
268 (synopsis "Evented I/O for V8 JavaScript")
269 (description "Node.js is a platform built on Chrome's JavaScript runtime
270 for easily building fast, scalable network applications. Node.js uses an
271 event-driven, non-blocking I/O model that makes it lightweight and efficient,
272 perfect for data-intensive real-time applications that run across distributed
273 devices.")
274 (home-page "https://nodejs.org/")
275 (license license:expat)
276 (properties '((max-silent-time . 7200) ;2h, needed on ARM
277 (timeout . 21600) ;6h
278 (cpe-name . "node.js")))))
279
280 ;; This should be the latest version of node that still builds without
281 ;; depending on llhttp.
282 (define-public node-bootstrap
283 (hidden-package node))
284
285 ;; Duplicate of node-semver
286 (define-public node-semver-bootstrap
287 (package
288 (name "node-semver")
289 (version "7.2.1")
290 (source (origin
291 (method git-fetch)
292 (uri (git-reference
293 (url "https://github.com/npm/node-semver")
294 (commit (string-append "v" version))))
295 (file-name (git-file-name name version))
296 (sha256
297 (base32
298 "06biknqb05r9xsmcflm3ygh50pjvdk84x6r79w43kmck4fn3qn5p"))))
299 (build-system node-build-system)
300 (arguments
301 `(#:node ,node-bootstrap
302 #:tests? #f
303 #:phases
304 (modify-phases %standard-phases
305 (delete 'configure))))
306 (home-page "https://github.com/npm/node-semver")
307 (properties '((hidden? . #t)))
308 (synopsis "Parses semantic versions strings")
309 (description
310 "@code{node-semver} is a JavaScript implementation of the
311 @uref{https://semver.org/, SemVer.org} specification.")
312 (license license:isc)))
313
314 (define-public node-ms-bootstrap
315 (package
316 (name "node-ms")
317 (version "2.1.2")
318 (source
319 (origin
320 (method git-fetch)
321 (uri (git-reference
322 (url "https://github.com/vercel/ms.git")
323 (commit version)))
324 (file-name (git-file-name name version))
325 (sha256
326 (base32
327 "1pjxzbi4j8pinlsc7yxvfrh0b47kb2dc4lfc2rjq4wx5bdwl33fj"))))
328 (build-system node-build-system)
329 (arguments
330 `(#:node ,node-bootstrap
331 #:tests? #f
332 #:phases
333 (modify-phases %standard-phases
334 (delete 'configure))))
335 (home-page "https://github.com/zeit/ms#readme")
336 (properties '((hidden? . #t)))
337 (synopsis "Tiny millisecond conversion utility")
338 (description "Use this package to easily convert various time
339 formats to milliseconds.")
340 (license license:expat)))
341
342 (define-public node-binary-search-bootstrap
343 (package
344 (name "node-binary-search")
345 (version "1.3.6")
346 (source
347 (origin
348 (method git-fetch)
349 (uri (git-reference
350 (url "https://github.com/darkskyapp/binary-search.git")
351 (commit (string-append "v" version))))
352 (file-name (git-file-name name version))
353 (sha256
354 (base32
355 "1xr2msdc143cd3xwgq7n3rhzy7j8wrnaidxl0r6l6b6g3mpbpjig"))))
356 (build-system node-build-system)
357 (arguments
358 `(#:node ,node-bootstrap
359 #:tests? #f
360 #:phases
361 (modify-phases %standard-phases
362 (delete 'configure))))
363 (home-page "https://github.com/darkskyapp/binary-search#readme")
364 (properties '((hidden? . #t)))
365 (synopsis "Tiny binary search function with comparators")
366 (description "This package is a binary search function for Node.js.")
367 (license license:cc0)))
368
369 (define-public node-debug-bootstrap
370 (package
371 (name "node-debug")
372 (version "4.3.0")
373 (source
374 (origin
375 (method git-fetch)
376 (uri (git-reference
377 (url "https://github.com/visionmedia/debug.git")
378 (commit version)))
379 (file-name (git-file-name name version))
380 (sha256
381 (base32
382 "08g52r1d4yqcsfdfb7n5if33d4cghaq75gx5n9hj6m6fd8jfp2pi"))))
383 (build-system node-build-system)
384 (arguments
385 `(#:node ,node-bootstrap
386 #:tests? #f
387 #:phases
388 (modify-phases %standard-phases
389 (delete 'configure))))
390 (inputs `(("node-ms" ,node-ms-bootstrap)))
391 (home-page "https://github.com/visionmedia/debug#readme")
392 (properties '((hidden? . #t)))
393 (synopsis "Small debugging utility")
394 (description "This package contains a tiny JavaScript debugging
395 utility modelled after Node.js core's debugging technique. It works in
396 Node.js and web browsers.")
397 (license license:expat)))
398
399 (define-public node-llparse-builder-bootstrap
400 (package
401 (name "node-llparse-builder")
402 (version "1.5.2")
403 (source
404 (origin
405 (method git-fetch)
406 (uri (git-reference
407 (url "https://github.com/indutny/llparse-builder.git")
408 (commit (string-append "v" version))))
409 (file-name (git-file-name name version))
410 (sha256
411 (base32
412 "0r82iiwqsb73k2fxw7842rjjiixllxpyc6yl9cq4ma6ybkf6xmzm"))
413 (modules '((guix build utils)))
414 (snippet
415 '(begin
416 ;; FIXME: Unneeded runtime dependency.
417 ;; https://github.com/indutny/llparse-builder/pull/2
418 (substitute* "package.json"
419 (("\"@types/debug.*,") ""))
420 ;; Fix imports for esbuild.
421 ;; https://github.com/evanw/esbuild/issues/477
422 (substitute* '("src/node/invoke.ts"
423 "src/node/base.ts"
424 "src/node/consume.ts"
425 "src/node/match.ts"
426 "src/node/error.ts"
427 "src/node/pause.ts"
428 "src/edge.ts"
429 "src/utils.ts"
430 "src/loop-checker/index.ts"
431 "src/loop-checker/lattice.ts"
432 "src/code/field.ts"
433 "src/span-allocator.ts")
434 (("\\* as assert") "assert")
435 (("\\* as debugAPI") "debugAPI"))
436 #t))))
437 (build-system node-build-system)
438 (arguments
439 `(#:node ,node-bootstrap
440 #:tests? #f
441 #:phases
442 (modify-phases %standard-phases
443 (delete 'configure)
444 (replace 'build
445 (lambda* (#:key inputs #:allow-other-keys)
446 (let ((esbuild (search-input-file inputs "/bin/esbuild")))
447 (invoke esbuild
448 "--platform=node"
449 "--outfile=lib/builder.js"
450 "--bundle"
451 "src/builder.ts")))))))
452 (inputs
453 `(("node-binary-search" ,node-binary-search-bootstrap)
454 ("node-debug" ,node-debug-bootstrap)))
455 (native-inputs
456 `(("esbuild" ,esbuild)))
457 (home-page "https://github.com/indutny/llparse-builder#readme")
458 (properties '((hidden? . #t)))
459 (synopsis "Graph builder for consumption by llparse")
460 (description "This package builds graphs for consumption by llparse.")
461 (license license:expat)))
462
463 (define-public node-llparse-frontend-bootstrap
464 (package
465 (name "node-llparse-frontend")
466 (version "3.0.0")
467 (source
468 (origin
469 (method git-fetch)
470 (uri (git-reference
471 (url "https://github.com/indutny/llparse-frontend.git")
472 (commit (string-append "v" version))))
473 (file-name (git-file-name name version))
474 (sha256
475 (base32 "1rm9g4ifyip30svm5cgnf0gx7d45jgh4mpf2hkd092xhngmfvicc"))
476 (modules '((guix build utils)))
477 (snippet
478 '(begin
479 ;; Fix imports for esbuild.
480 ;; https://github.com/evanw/esbuild/issues/477
481 (substitute* '("src/frontend.ts"
482 "src/code/field-value.ts"
483 "src/container/index.ts"
484 "src/container/wrap.ts"
485 "src/node/sequence.ts"
486 "src/node/single.ts"
487 "src/node/table-lookup.ts"
488 "src/trie/index.ts")
489 (("\\* as assert") "assert")
490 (("\\* as debugAPI") "debugAPI"))
491 #t))))
492 (build-system node-build-system)
493 (arguments
494 `(#:node ,node-bootstrap
495 #:tests? #f
496 #:phases
497 (modify-phases %standard-phases
498 (delete 'configure)
499 (replace 'build
500 (lambda* (#:key inputs #:allow-other-keys)
501 (let ((esbuild (search-input-file inputs "/bin/esbuild")))
502 (invoke esbuild
503 "--platform=node"
504 "--outfile=lib/frontend.js"
505 "--bundle"
506 "src/frontend.ts")))))))
507 (inputs
508 `(("node-debug" ,node-debug-bootstrap)
509 ("node-llparse-builder" ,node-llparse-builder-bootstrap)))
510 (native-inputs
511 `(("esbuild" ,esbuild)))
512 (home-page "https://github.com/indutny/llparse-frontend#readme")
513 (properties '((hidden? . #t)))
514 (synopsis "Frontend for the llparse compiler")
515 (description "This package is a frontend for the llparse compiler.")
516 (license license:expat)))
517
518 (define-public node-llparse-bootstrap
519 (package
520 (name "node-llparse")
521 (version "7.1.0")
522 (source
523 (origin
524 (method git-fetch)
525 (uri (git-reference
526 (url "https://github.com/indutny/llparse.git")
527 (commit (string-append "v" version))))
528 (file-name (git-file-name name version))
529 (sha256
530 (base32
531 "10da273iy2if88hp79cwms6c8qpsl1fkgzll6gmqyx5yxv5mkyp6"))
532 (modules '((guix build utils)))
533 (snippet
534 '(begin
535 ;; Fix imports for esbuild.
536 ;; https://github.com/evanw/esbuild/issues/477
537 (substitute* '("src/compiler/index.ts"
538 "src/implementation/c/node/base.ts"
539 "src/implementation/c/node/table-lookup.ts"
540 "src/implementation/c/compilation.ts"
541 "src/implementation/c/helpers/match-sequence.ts"
542 "src/implementation/c/code/mul-add.ts")
543 (("\\* as assert") "assert")
544 (("\\* as debugAPI") "debugAPI"))
545 #t))))
546 (build-system node-build-system)
547 (arguments
548 `(#:node ,node-bootstrap
549 #:tests? #f
550 #:phases
551 (modify-phases %standard-phases
552 (delete 'configure)
553 (replace 'build
554 (lambda* (#:key inputs #:allow-other-keys)
555 (let ((esbuild (search-input-file inputs "/bin/esbuild")))
556 (invoke esbuild
557 "--platform=node"
558 "--outfile=lib/api.js"
559 "--bundle"
560 "src/api.ts")))))))
561 (inputs
562 `(("node-debug" ,node-debug-bootstrap)
563 ("node-llparse-frontend" ,node-llparse-frontend-bootstrap)))
564 (native-inputs
565 `(("esbuild" ,esbuild)))
566 (home-page "https://github.com/nodejs/llparse#readme")
567 (properties '((hidden? . #t)))
568 (synopsis "Compile incremental parsers to C code")
569 (description "This package offers an API for compiling an incremental
570 parser definition into a C output.")
571 (license license:expat)))
572
573 (define-public llhttp-bootstrap
574 (package
575 (name "llhttp")
576 (version "2.1.4")
577 (source (origin
578 (method git-fetch)
579 (uri (git-reference
580 (url "https://github.com/nodejs/llhttp.git")
581 (commit (string-append "v" version))))
582 (file-name (git-file-name name version))
583 (sha256
584 (base32
585 "115mwyds9655p76lhglxg2blc1ksgrix6zhigaxnc2q6syy3pa6x"))
586 (patches (search-patches "llhttp-bootstrap-CVE-2020-8287.patch"))
587 (modules '((guix build utils)))
588 (snippet
589 '(begin
590 ;; Fix imports for esbuild.
591 ;; https://github.com/evanw/esbuild/issues/477
592 (substitute* "src/llhttp/http.ts"
593 (("\\* as assert") "assert"))
594 (substitute* "Makefile"
595 (("npx ts-node bin/generate.ts")
596 "node bin/generate.js"))
597 #t))))
598 (build-system gnu-build-system)
599 (arguments
600 `(#:tests? #f ; no tests
601 #:make-flags (list (string-append "CLANG=" ,(cc-for-target))
602 (string-append "DESTDIR=" (assoc-ref %outputs "out"))
603 "PREFIX=")
604 #:phases
605 (modify-phases %standard-phases
606 (replace 'configure
607 (lambda* (#:key inputs native-inputs #:allow-other-keys)
608 (let ((esbuild (search-input-file (or native-inputs inputs)
609 "/bin/esbuild")))
610 (invoke esbuild
611 "--platform=node"
612 "--outfile=bin/generate.js"
613 "--bundle" "bin/generate.ts"))))
614 (add-before 'install 'create-install-directories
615 (lambda* (#:key outputs #:allow-other-keys)
616 (let ((out (assoc-ref outputs "out")))
617 (for-each (lambda (dir)
618 (mkdir-p (string-append out dir)))
619 (list "/lib" "/include" "/src"))
620 #t)))
621 (add-after 'install 'install-src
622 (lambda* (#:key outputs #:allow-other-keys)
623 (let* ((out (assoc-ref outputs "out"))
624 (src-dir (string-append out "/src")))
625 (install-file "build/c/llhttp.c" src-dir)
626 (install-file "src/native/api.c" src-dir)
627 (install-file "src/native/http.c" src-dir)
628 #t))))))
629 (native-inputs
630 `(("esbuild" ,esbuild)
631 ("node" ,node-bootstrap)
632 ("node-semver" ,node-semver-bootstrap)
633 ("node-llparse-bootstrap" ,node-llparse-bootstrap)))
634 (home-page "https://github.com/nodejs/llhttp")
635 (properties '((hidden? . #t)))
636 (synopsis "Parser for HTTP messages")
637 (description "This is a rewrite of
638 @url{https://github.com/nodejs/http-parser, http-parser} using
639 @url{https://github.com/nodejs/llparse, llparse} to generate the C
640 source files.")
641 (license license:expat)))
642
643 (define-public node-lts
644 (package
645 (inherit node)
646 (version "14.18.1")
647 (source (origin
648 (method url-fetch)
649 (uri (string-append "https://nodejs.org/dist/v" version
650 "/node-v" version ".tar.xz"))
651 (sha256
652 (base32
653 "1vc9rypkgr5i5y946jnyr9jjpydxvm74p1s17rg2zayzvlddg89z"))
654 (modules '((guix build utils)))
655 (snippet
656 `(begin
657 ;; Remove bundled software, where possible
658 (for-each delete-file-recursively
659 '("deps/cares"
660 "deps/icu-small"
661 "deps/nghttp2"
662 "deps/openssl"
663 "deps/zlib"))
664 (substitute* "Makefile"
665 ;; Remove references to bundled software.
666 (("deps/uv/uv.gyp") "")
667 (("deps/zlib/zlib.gyp") ""))
668 #t))))
669 (arguments
670 (substitute-keyword-arguments (package-arguments node)
671 ((#:configure-flags configure-flags)
672 ''("--shared-cares"
673 "--shared-libuv"
674 "--shared-nghttp2"
675 "--shared-openssl"
676 "--shared-zlib"
677 "--shared-brotli"
678 "--with-intl=system-icu"))
679 ((#:phases phases)
680 `(modify-phases ,phases
681 (replace 'set-bootstrap-host-rpath
682 (lambda* (#:key native-inputs inputs #:allow-other-keys)
683 (let* ((inputs (or native-inputs inputs))
684 (c-ares (assoc-ref inputs "c-ares"))
685 (brotli (assoc-ref inputs "brotli"))
686 (icu4c (assoc-ref inputs "icu4c"))
687 (nghttp2 (assoc-ref inputs "nghttp2"))
688 (openssl (assoc-ref inputs "openssl"))
689 (libuv (assoc-ref inputs "libuv"))
690 (zlib (assoc-ref inputs "zlib"))
691 (host-binaries '("torque"
692 "bytecode_builtins_list_generator"
693 "gen-regexp-special-case"
694 "node_mksnapshot"
695 "mksnapshot")))
696 (substitute* '("node.gyp" "tools/v8_gypfiles/v8.gyp")
697 (((string-append "'target_name': '("
698 (string-join host-binaries "|")
699 ")',")
700 target)
701 (string-append target
702 "'ldflags': ['-Wl,-rpath="
703 c-ares "/lib:"
704 brotli "/lib:"
705 icu4c "/lib:"
706 nghttp2 "/lib:"
707 openssl "/lib:"
708 libuv "/lib:"
709 zlib "/lib"
710 "'],"))))))
711 (replace 'configure
712 ;; Node's configure script is actually a python script, so we can't
713 ;; run it with bash.
714 (lambda* (#:key outputs (configure-flags '()) native-inputs inputs
715 #:allow-other-keys)
716 (let* ((prefix (assoc-ref outputs "out"))
717 (xflags ,(if (%current-target-system)
718 `'("--cross-compiling"
719 ,(string-append
720 "--dest-cpu="
721 (match (%current-target-system)
722 ((? (cut string-prefix? "arm" <>))
723 "arm")
724 ((? (cut string-prefix? "aarch64" <>))
725 "arm64")
726 ((? (cut string-prefix? "i686" <>))
727 "ia32")
728 ((? (cut string-prefix? "x86_64" <>))
729 "x64")
730 ((? (cut string-prefix? "powerpc64" <>))
731 "ppc64")
732 (_ "unsupported"))))
733 ''()))
734 (flags (cons
735 (string-append "--prefix=" prefix)
736 (append xflags configure-flags))))
737 (format #t "build directory: ~s~%" (getcwd))
738 (format #t "configure flags: ~s~%" flags)
739 ;; Node's configure script expects the CC environment variable to
740 ;; be set.
741 (setenv "CC_host" "gcc")
742 (setenv "CXX_host" "g++")
743 (setenv "CC" ,(cc-for-target))
744 (setenv "CXX" ,(cxx-for-target))
745 (setenv "PKG_CONFIG" ,(pkg-config-for-target))
746 (apply invoke
747 (search-input-file (or native-inputs inputs)
748 "/bin/python3")
749 "configure" flags))))
750 (replace 'patch-files
751 (lambda* (#:key inputs #:allow-other-keys)
752 ;; Fix hardcoded /bin/sh references.
753 (substitute* '("lib/child_process.js"
754 "lib/internal/v8_prof_polyfill.js"
755 "test/parallel/test-child-process-spawnsync-shell.js"
756 "test/parallel/test-fs-write-sigxfsz.js"
757 "test/parallel/test-stdio-closed.js"
758 "test/sequential/test-child-process-emfile.js")
759 (("'/bin/sh'")
760 (string-append "'" (assoc-ref inputs "bash") "/bin/sh'")))
761
762 ;; Fix hardcoded /usr/bin/env references.
763 (substitute* '("test/parallel/test-child-process-default-options.js"
764 "test/parallel/test-child-process-env.js"
765 "test/parallel/test-child-process-exec-env.js")
766 (("'/usr/bin/env'")
767 (string-append "'" (assoc-ref inputs "coreutils")
768 "/bin/env'")))
769
770 ;; FIXME: These tests fail in the build container, but they don't
771 ;; seem to be indicative of real problems in practice.
772 (for-each delete-file
773 '("test/parallel/test-cluster-master-error.js"
774 "test/parallel/test-cluster-master-kill.js"))
775
776 ;; These require a DNS resolver.
777 (for-each delete-file
778 '("test/parallel/test-dns.js"
779 "test/parallel/test-dns-lookupService-promises.js"))
780
781 ;; These tests require networking.
782 (delete-file "test/parallel/test-https-agent-unref-socket.js")
783
784 ;; FIXME: This test fails randomly:
785 ;; https://github.com/nodejs/node/issues/31213
786 (delete-file "test/parallel/test-net-listen-after-destroying-stdin.js")
787
788 ;; FIXME: These tests fail on armhf-linux:
789 ;; https://github.com/nodejs/node/issues/31970
790 ,@(if (target-arm32?)
791 '((for-each delete-file
792 '("test/parallel/test-zlib.js"
793 "test/parallel/test-zlib-brotli.js"
794 "test/parallel/test-zlib-brotli-flush.js"
795 "test/parallel/test-zlib-brotli-from-brotli.js"
796 "test/parallel/test-zlib-brotli-from-string.js"
797 "test/parallel/test-zlib-convenience-methods.js"
798 "test/parallel/test-zlib-random-byte-pipes.js"
799 "test/parallel/test-zlib-write-after-flush.js")))
800 '())
801
802 ;; These tests have an expiry date: they depend on the validity of
803 ;; TLS certificates that are bundled with the source. We want this
804 ;; package to be reproducible forever, so remove those.
805 ;; TODO: Regenerate certs instead.
806 (for-each delete-file
807 '("test/parallel/test-tls-passphrase.js"
808 "test/parallel/test-tls-server-verify.js"))
809
810 ;; Replace pre-generated llhttp sources
811 (let ((llhttp (assoc-ref inputs "llhttp")))
812 (copy-file (string-append llhttp "/src/llhttp.c")
813 "deps/llhttp/src/llhttp.c")
814 (copy-file (string-append llhttp "/src/api.c")
815 "deps/llhttp/src/api.c")
816 (copy-file (string-append llhttp "/src/http.c")
817 "deps/llhttp/src/http.c")
818 (copy-file (string-append llhttp "/include/llhttp.h")
819 "deps/llhttp/include/llhttp.h"))))))))
820 (native-inputs
821 `(;; Runtime dependencies for binaries used as a bootstrap.
822 ("c-ares" ,c-ares-for-node)
823 ("brotli" ,brotli)
824 ("icu4c" ,icu4c-67)
825 ("libuv" ,libuv-for-node)
826 ("nghttp2" ,nghttp2 "lib")
827 ("openssl" ,openssl)
828 ("zlib" ,zlib)
829 ;; Regular build-time dependencies.
830 ("perl" ,perl)
831 ("pkg-config" ,pkg-config)
832 ("procps" ,procps)
833 ("python" ,python)
834 ("util-linux" ,util-linux)))
835 (inputs
836 `(("bash" ,bash)
837 ("coreutils" ,coreutils)
838 ("c-ares" ,c-ares-for-node)
839 ("icu4c" ,icu4c-67)
840 ("libuv" ,libuv-for-node)
841 ("llhttp" ,llhttp-bootstrap)
842 ("brotli" ,brotli)
843 ("nghttp2" ,nghttp2 "lib")
844 ("openssl" ,openssl)
845 ("zlib" ,zlib)))))
846
847 (define-public libnode
848 (package/inherit node
849 (name "libnode")
850 (arguments
851 (substitute-keyword-arguments (package-arguments node)
852 ((#:configure-flags flags ''())
853 `(cons* "--shared" "--without-npm" ,flags))
854 ((#:phases phases '%standard-phases)
855 `(modify-phases ,phases
856 (delete 'patch-npm-shebang)
857 (delete 'patch-node-shebang)))))))