nodejs-23.6.0.ebuild 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. # Copyright 1999-2025 Gentoo Authors
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=8
  4. CONFIG_CHECK="~ADVISE_SYSCALLS"
  5. PYTHON_COMPAT=( python3_{11..13} )
  6. PYTHON_REQ_USE="threads(+)"
  7. MULTIPLEXER_VER="11"
  8. inherit bash-completion-r1 check-reqs flag-o-matic linux-info ninja-utils pax-utils python-any-r1 toolchain-funcs xdg-utils
  9. DESCRIPTION="A JavaScript runtime built on Chrome's V8 JavaScript engine"
  10. HOMEPAGE="https://nodejs.org/"
  11. LICENSE="Apache-1.1 Apache-2.0 BSD BSD-2 MIT"
  12. SLOT_MAJOR="$(ver_cut 1 ${PV})"
  13. SLOT="${SLOT_MAJOR}/$(ver_cut 1-2 ${PV})"
  14. if [[ ${PV} == *9999 ]]; then
  15. inherit git-r3
  16. EGIT_REPO_URI="https://github.com/nodejs/node"
  17. SLOT="23/0"
  18. else
  19. SRC_URI="https://nodejs.org/dist/v${PV}/node-v${PV}.tar.xz"
  20. KEYWORDS="~amd64 ~arm ~arm64 ~loong ~ppc64 ~riscv ~x86 ~amd64-linux ~x64-macos"
  21. S="${WORKDIR}/node-v${PV}"
  22. fi
  23. IUSE="asm +corepack cpu_flags_x86_sse2 debug doc fips +icu inspector +jit \
  24. lto lld man mold +npm pax-kernel pointer-compression +snapshot +ssl \
  25. system-icu +system-ssl test v8-sandbox"
  26. REQUIRED_USE="
  27. ^^ ( mold lld )
  28. corepack
  29. inspector? ( icu ssl )
  30. npm? ( corepack )
  31. system-icu? ( icu )
  32. system-ssl? ( ssl )
  33. v8-sandbox? ( pointer-compression )
  34. "
  35. RESTRICT="
  36. !test? ( test )
  37. mirror
  38. "
  39. RDEPEND="
  40. !net-libs/nodejs:0
  41. >=app-arch/brotli-1.1.0
  42. >=app-eselect/eselect-nodejs-20250106
  43. dev-db/sqlite:3
  44. >=dev-libs/libuv-1.49.2:=
  45. >=dev-libs/simdjson-3.9.4:=
  46. >=net-dns/c-ares-1.34.4
  47. >=net-libs/nghttp2-1.62.1:=
  48. >=sys-libs/zlib-1.3
  49. corepack? ( sys-apps/yarn )
  50. system-icu? (
  51. >=dev-libs/icu-76.1:=
  52. )
  53. system-ssl? (
  54. >=net-libs/ngtcp2-1.3.0:=
  55. >=dev-libs/openssl-3.0.15:0=[asm?,fips?]
  56. )
  57. "
  58. BDEPEND="${PYTHON_DEPS}
  59. app-alternatives/ninja
  60. sys-apps/coreutils
  61. virtual/pkgconfig
  62. test? ( net-misc/curl )
  63. pax-kernel? ( sys-apps/elfix )
  64. mold? ( sys-devel/mold )
  65. lld? ( llvm-core/lld )
  66. "
  67. DEPEND="${RDEPEND}"
  68. # These are measured on a loong machine with -ggdb on, and only checked
  69. # if debugging flags are present in CFLAGS.
  70. #
  71. # The final link consumed a little more than 7GiB alone, so 8GiB is the lower
  72. # limit for memory usage. Disk usage was 19.1GiB for the build directory and
  73. # 1.2GiB for the installed image, so we leave some room for architectures with
  74. # fatter binaries and set the disk requirement to 22GiB.
  75. CHECKREQS_MEMORY="8G"
  76. CHECKREQS_DISK_BUILD="22G"
  77. PATCHES=(
  78. "${FILESDIR}/${PN}-12.22.5-shared_c-ares_nameser_h.patch"
  79. "${FILESDIR}/${PN}-22.2.0-global-npm-config.patch"
  80. "${FILESDIR}/${PN}-22.2.0-lto-update.patch"
  81. "${FILESDIR}/${PN}-20.1.0-support-clang-pgo.patch"
  82. "${FILESDIR}/${PN}-19.3.0-v8-oflags.patch"
  83. "${FILESDIR}/${PN}-23.5.0-split-pointer-compression-and-v8-sandbox-options.patch"
  84. )
  85. pkg_pretend() {
  86. if [[ ${MERGE_TYPE} != "binary" ]]; then
  87. if is-flagq "-g*" && ! is-flagq "-g*0" ; then
  88. einfo "Checking for sufficient disk space and memory to build ${PN} with debugging CFLAGS"
  89. check-reqs_pkg_pretend
  90. fi
  91. fi
  92. ( use x86 && ! use cpu_flags_x86_sse2 ) && \
  93. die "Your CPU doesn't support the required SSE2 instruction."
  94. }
  95. pkg_setup() {
  96. python-any-r1_pkg_setup
  97. linux-info_pkg_setup
  98. }
  99. is_flagq_last() {
  100. local flag="${1}"
  101. local olast=$(echo "${CFLAGS}" | grep -o -E -e "-O(0|g|1|z|s|2|3|4|fast)" | tr " " "\n" | tail -n 1)
  102. einfo "CFLAGS:\t${CFLAGS}"
  103. einfo "olast:\t${olast}"
  104. [[ "${flag}" == "${olast}" ]] && return 0
  105. return 1
  106. }
  107. src_prepare() {
  108. tc-export AR CC CXX PKG_CONFIG
  109. export V=1
  110. export CONFIGURATION="Release"
  111. # Fix compilation on Darwin
  112. # https://code.google.com/p/gyp/issues/detail?id=260
  113. sed -i -e "/append('-arch/d" tools/gyp/pylib/gyp/xcode_emulation.py || die
  114. # Proper libdir, hat tip @ryanpcmcquen https://github.com/iojs/io.js/issues/504
  115. local LIBDIR=$(get_libdir)
  116. sed -i -e "s|lib/|${LIBDIR}/|g" tools/install.py || die
  117. sed -i -e "s/'lib'/'${LIBDIR}'/" deps/npm/lib/npm.js || die
  118. # Avoid writing a depfile, not useful
  119. sed -i -e "/DEPFLAGS =/d" tools/gyp/pylib/gyp/generator/make.py || die
  120. # We need to disable mprotect on two files when it builds Bug 694100.
  121. use pax-kernel && PATCHES+=( "${FILESDIR}"/${PN}-20.6.0-paxmarking.patch )
  122. # https://github.com/nodejs/node/issues/51339
  123. #use pointer-compression && PATCHES+=(
  124. # "${FILESDIR}/${PN}-23.0.0-fix-v8-external-code-space.patch"
  125. # )
  126. default
  127. local FP=(
  128. $(grep -l -r -e "-O3" $(find deps/openssl -name "*.gn*" -o -name "*gyp*"))
  129. common.gypi
  130. deps/llhttp/common.gypi
  131. deps/uv/common.gypi
  132. node.gypi
  133. )
  134. # -O3 removal breaks _FORITIFY_SOURCE
  135. local a1="-O3"
  136. local r1="-O2"
  137. local a2="-O2"
  138. local r2="-O3"
  139. local oflag="-O3"
  140. if is_flagq_last '-O0'; then
  141. oflag="-O0"
  142. elif is_flagq_last '-Og'; then
  143. oflag="-Og"
  144. elif is_flagq_last '-O1'; then
  145. oflag="-O1"
  146. elif is_flagq_last '-O2'; then
  147. oflag="-O2"
  148. elif is_flagq_last '-O3'; then
  149. oflag="-O3 "
  150. elif is_flagq_last '-O4'; then
  151. oflag="-O4 "
  152. elif is_flagq_last '-Ofast'; then
  153. oflag="-Ofast"
  154. elif is_flagq_last '-Os'; then
  155. oflag="-Os"
  156. elif is_flagq_last '-Oz'; then
  157. oflag="-Oz"
  158. fi
  159. sed -i -e "s|- O3|${oflag}|g" ${FP[@]} || die
  160. a1="${oflag}"
  161. a2="${oflag}"
  162. sed -i \
  163. -e "s|__OFLAGS_A1__|${a1}|g" \
  164. -e "s|__OFLAGS_R1__|${r1}|g" \
  165. -e "s|__OFLAGS_A2__|${a2}|g" \
  166. -e "s|__OFLAGS_R2__|${r2}|g" \
  167. tools/v8_gypfiles/toolchain.gypi \
  168. || die
  169. # debug builds. change install path, remove optimisations and override buildtype
  170. if use debug; then
  171. sed -i -e "s|out/Release/|out/Debug/|g" tools/install.py || die
  172. CONFIGURATION="Debug"
  173. fi
  174. }
  175. src_configure() {
  176. export ENINJA_BUILD_DIR="out/"$(usex debug "Debug" "Release")
  177. xdg_environment_reset
  178. # LTO compiler flags are handled by configure.py itself
  179. filter-lto
  180. # GCC with -ftree-vectorize miscompiles node's exception handling code
  181. # causing it to fail to catch exceptions sometimes
  182. # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116057
  183. tc-is-gcc && append-cxxflags -fno-tree-vectorize
  184. # https://bugs.gentoo.org/931514
  185. use arm64 && append-flags $(test-flags-CXX -mbranch-protection=none)
  186. # nodejs unconditionally links to libatomic #869992
  187. # specifically it requires __atomic_is_lock_free which
  188. # is not yet implemented by sys-libs/compiler-rt (see
  189. # https://reviews.llvm.org/D85044?id=287068), therefore
  190. # we depend on gcc and force using libgcc as the support lib
  191. tc-is-clang && append-ldflags "--rtlib=libgcc --unwindlib=libgcc"
  192. local myconf=(
  193. --ninja
  194. # ada is not packaged yet
  195. # https://github.com/ada-url/ada
  196. # --shared-ada
  197. --shared-brotli
  198. --shared-cares
  199. --shared-libuv
  200. --shared-nghttp2
  201. --shared-ngtcp2
  202. --shared-simdjson
  203. # sindutf is not packaged yet
  204. # https://github.com/simdutf/simdutf
  205. # --shared-simdutf
  206. --shared-sqlite
  207. --shared-zlib
  208. )
  209. if ! use asm; then
  210. myconf+=( --openssl-no-asm )
  211. fi
  212. use debug && myconf+=( --debug )
  213. use lto && myconf+=( --enable-lto )
  214. use mold && myconf+=( --with-moldlto )
  215. use lld && myconf+=( --with-thinlto )
  216. if use system-icu; then
  217. myconf+=( --with-intl=system-icu )
  218. elif use icu; then
  219. myconf+=( --with-intl=full-icu )
  220. else
  221. myconf+=( --with-intl=none )
  222. fi
  223. use corepack || myconf+=( --without-corepack )
  224. use inspector || myconf+=( --without-inspector )
  225. use npm || myconf+=( --without-npm )
  226. use snapshot || myconf+=( --without-node-snapshot )
  227. if use ssl; then
  228. use system-ssl && myconf+=( --shared-openssl --openssl-use-def-ca-store )
  229. else
  230. myconf+=( --without-ssl )
  231. fi
  232. if use fips ; then
  233. myconf+=( --openssl-is-fips )
  234. fi
  235. if [[ -n "${NODEJS_OPENSSL_DEFAULT_LIST_CORE}" ]] ; then
  236. myconf+=( --openssl-default-cipher-list=${NODEJS_OPENSSL_DEFAULT_LIST_CORE} )
  237. fi
  238. use jit || myconf+=( --v8-lite-mode )
  239. if use jit && use debug && has_version "dev-debug/gdb" ; then
  240. myconf+=( --gdb )
  241. fi
  242. if use amd64 || use arm64 ; then
  243. use pointer-compression && myconf+=( --experimental-enable-pointer-compression )
  244. fi
  245. use v8-sandbox && myconf+=( --experimental-enable-v8-sandbox )
  246. if use kernel_linux && linux_chkconfig_present "TRANSPARENT_HUGEPAGE" ; then
  247. myconf+=( --v8-enable-hugepage )
  248. fi
  249. local myarch
  250. myarch="${ABI/amd64/x64}"
  251. myarch="${myarch/x86/ia32}"
  252. [[ "${ARCH}:${ABI}" =~ "loong:lp64" ]] && myarch="loong64"
  253. [[ "${ARCH}:${ABI}" =~ "riscv:lp64" ]] && myarch="riscv64"
  254. GYP_DEFINES="linux_use_gold_flags=0
  255. linux_use_bundled_binutils=0
  256. linux_use_bundled_gold=0" \
  257. "${EPYTHON}" configure.py \
  258. --prefix="${EPREFIX}/usr" \
  259. --dest-cpu="${myarch}" \
  260. ${myconf[@]} || die
  261. # Prevent double build on install.
  262. sed -i -e "s|^install: all|install: |g" "Makefile" || die
  263. }
  264. src_compile() {
  265. export NINJA_ARGS=" $(get_NINJAOPTS)"
  266. emake -Onone
  267. }
  268. src_install() {
  269. local LIBDIR="${ED}/usr/$(get_libdir)"
  270. default
  271. local REL_D_BASE="usr/$(get_libdir)"
  272. local D_BASE="/${REL_D_BASE}"
  273. local ED_BASE="${ED}/${REL_D_BASE}"
  274. ${EPYTHON} "tools/install.py" install \
  275. --dest-dir "${D}" \
  276. --prefix "${EPREFIX}/usr" \
  277. || die
  278. mv "${ED}/usr/bin/node" "${ED}/usr/bin/node${SLOT_MAJOR}" || die
  279. dosym "node${SLOT_MAJOR}" "/usr/bin/node"
  280. pax-mark -m "${ED}/usr/bin/node${SLOT_MAJOR}"
  281. # set up a symlink structure that node-gyp expects..
  282. local D_INCLUDE_BASE="/usr/include/node${SLOT_MAJOR}"
  283. dodir "${D_INCLUDE_BASE}/deps/"{"v8","uv"}
  284. dosym "." "${D_INCLUDE_BASE}/src"
  285. local var
  286. for var in deps/{uv,v8}/include; do
  287. dosym "../.." "${D_INCLUDE_BASE}/${var}"
  288. done
  289. # Avoid merge conflict
  290. mv "${ED}/usr/include/node/"* "${ED}${D_INCLUDE_BASE}" || die
  291. rm -rf "${ED}/usr/include/node" || die
  292. if use doc; then
  293. docinto html
  294. dodoc -r "${S}/doc/"*
  295. fi
  296. if ! use man ; then
  297. rm -rf "${ED}//usr/share/man/man1/node.1"* || die
  298. fi
  299. # Use tarball instead.
  300. rm -rf "${ED}/usr/$(get_libdir)/node_modules/npm"
  301. rm -rf "${ED}/usr/bin/npm"
  302. rm -rf "${ED}/usr/bin/npx"
  303. mv \
  304. "${ED}/usr/share/doc/node" \
  305. "${ED}/usr/share/doc/${PF}" \
  306. || die
  307. # Let eselect-nodejs handle switching corepack
  308. dodir "/usr/$(get_libdir)/corepack"
  309. mv \
  310. "${ED}/usr/$(get_libdir)/node_modules/corepack" \
  311. "${ED}/usr/$(get_libdir)/corepack/node${SLOT_MAJOR}" \
  312. || die
  313. rm -rf "${ED}/usr/bin/corepack"
  314. if use npm; then
  315. keepdir /etc/npm
  316. echo "NPM_CONFIG_GLOBALCONFIG=${EPREFIX}/etc/npm/npmrc" > "${T}"/50npm
  317. #echo "PATH=${EPREFIX}/usr/$(get_libdir)/corepack/node${SLOT_MAJOR}" > "${T}"/50npm
  318. doenvd "${T}"/50npm
  319. dosym "/usr/$(get_libdir)/corepack/node${SLOT_MAJOR}/shims/npm" "/usr/bin/npm"
  320. sed -e "/^dirname /s|\"$(.+)\"|\"$(readlink -q \$0)\"|g" -i "${ED}/usr/$(get_libdir)/corepack/node${SLOT_MAJOR}/shims/npm" || die
  321. # Install bash completion for `npm`
  322. local tmp_npm_completion_file="$(TMPDIR="${T}" mktemp -t npm.XXXXXXXXXX)"
  323. "${ED}/usr/$(get_libdir)/corepack/node${SLOT_MAJOR}/shims/npm" completion > "${tmp_npm_completion_file}"
  324. newbashcomp "${tmp_npm_completion_file}" npm
  325. # Move man pages
  326. use man && doman "${LIBDIR}"/node_modules/npm/man/man{1,5,7}/*
  327. # Clean up
  328. rm -f "${LIBDIR}"/node_modules/npm/{.mailmap,.npmignore,Makefile}
  329. rm -rf "${LIBDIR}"/node_modules/npm/{doc,html,man}
  330. local find_exp="-or -name"
  331. local find_name=()
  332. for match in "AUTHORS*" "CHANGELOG*" "CONTRIBUT*" "README*" \
  333. ".travis.yml" ".eslint*" ".wercker.yml" ".npmignore" \
  334. "*.md" "*.markdown" "*.bat" "*.cmd"; do
  335. find_name+=( ${find_exp} "${match}" )
  336. done
  337. # Remove various development and/or inappropriate files and
  338. # useless docs of dependend packages.
  339. find "${LIBDIR}"/node_modules \
  340. \( -type d -name examples \) -or \( -type f \( \
  341. -iname "LICEN?E*" \
  342. "${find_name[@]}" \
  343. \) \) -exec rm -rf "{}" \;
  344. fi
  345. use doc && ( mv "${ED}"/usr/share/doc/node "${ED}"/usr/share/doc/${PF} || die )
  346. cp --remove-destination "${FILESDIR}/node-multiplexer-v${MULTIPLEXER_VER}" "${ED}/usr/bin/node" || die
  347. sed -e "s|__EPREFIX__|${EPREFIX}|g" -i "${ED}/usr/bin/node" || die
  348. fperms 0755 "/usr/bin/node" || die
  349. fowners -R root:root "/usr/bin/node" || die
  350. }
  351. src_test() {
  352. local drop_tests=(
  353. test/parallel/test-dns.js
  354. test/parallel/test-dns-resolveany-bad-ancount.js
  355. test/parallel/test-dns-setserver-when-querying.js
  356. test/parallel/test-fs-read-stream.js
  357. test/parallel/test-fs-utimes-y2K38.js
  358. test/parallel/test-fs-watch-recursive-add-file.js
  359. test/parallel/test-process-euid-egid.js
  360. test/parallel/test-process-get-builtin.mjs
  361. test/parallel/test-process-initgroups.js
  362. test/parallel/test-process-setgroups.js
  363. test/parallel/test-process-uid-gid.js
  364. test/parallel/test-release-npm.js
  365. test/parallel/test-socket-write-after-fin-error.js
  366. test/parallel/test-strace-openat-openssl.js
  367. test/sequential/test-util-debug.js
  368. )
  369. [[ "$(nice)" -gt 10 ]] && drop_tests+=( "test/parallel/test-os.js" )
  370. use inspector ||
  371. drop_tests+=(
  372. test/parallel/test-inspector-emit-protocol-event.js
  373. test/parallel/test-inspector-network-domain.js
  374. test/sequential/test-watch-mode.mjs
  375. )
  376. rm -f "${drop_tests[@]}" || die "disabling tests failed"
  377. if has usersandbox ${FEATURES}; then
  378. rm -f "${S}/test/parallel/test-fs-mkdir.js"
  379. ewarn
  380. ewarn "You are emerging ${PN} with 'usersandbox' enabled. Excluding tests known"
  381. ewarn "to fail in this mode. For full test coverage, emerge =${CATEGORY}/${PF}"
  382. ewarn "with 'FEATURES=-usersandbox'."
  383. ewarn
  384. fi
  385. "out/${CONFIGURATION}/cctest" || die
  386. "${EPYTHON}" \
  387. "tools/test.py" \
  388. --mode="${CONFIGURATION,,}" \
  389. --flaky-tests="dontcare" \
  390. -J \
  391. message \
  392. parallel \
  393. sequential \
  394. || die
  395. }
  396. pkg_postinst() {
  397. if use npm; then
  398. ewarn "remember to run: source /etc/profile if you plan to use nodejs"
  399. ewarn "in your current shell"
  400. fi
  401. if has_version ">net-libs/nodejs-${PV}" ; then
  402. einfo "Found higher slots, manually change the headers with \`eselect nodejs\`."
  403. else
  404. eselect nodejs set "node${SLOT_MAJOR}"
  405. fi
  406. grep -q -F "NODE_VERSION" "${EROOT}/usr/bin/node" || die "Wrapper did not copy."
  407. einfo
  408. einfo "When compiling with nodejs multislot, you to switch via"
  409. einfo "\`eselect nodejs\` in order to compile against the headers matching the"
  410. einfo "corresponding SLOT. This means that you cannot compile with different"
  411. einfo "SLOTS simultaneously."
  412. einfo
  413. }