portage-overlay

personal portage ebuild repository
git clone anongit@rnpnr.xyz:portage-overlay.git
Log | Files | Refs | Feed | README

nodejs-22.13.1.ebuild (8576B)


      1 # Copyright 1999-2025 Gentoo Authors
      2 # Distributed under the terms of the GNU General Public License v2
      3 
      4 EAPI=8
      5 
      6 CONFIG_CHECK="~ADVISE_SYSCALLS"
      7 PYTHON_COMPAT=( python3_{10..13} )
      8 PYTHON_REQ_USE="threads(+)"
      9 
     10 inherit bash-completion-r1 check-reqs flag-o-matic linux-info ninja-utils pax-utils python-any-r1 toolchain-funcs xdg-utils
     11 
     12 DESCRIPTION="A JavaScript runtime built on Chrome's V8 JavaScript engine"
     13 HOMEPAGE="https://nodejs.org/"
     14 LICENSE="Apache-1.1 Apache-2.0 BSD BSD-2 MIT npm? ( Artistic-2 )"
     15 
     16 if [[ ${PV} == *9999 ]]; then
     17 	inherit git-r3
     18 	EGIT_REPO_URI="https://github.com/nodejs/node"
     19 	SLOT="0"
     20 else
     21 	SRC_URI="https://nodejs.org/dist/v${PV}/node-v${PV}.tar.xz"
     22 	SLOT="0/$(ver_cut 1)"
     23 	KEYWORDS="amd64 ~arm arm64 ~loong ~ppc64 ~riscv ~x86 ~amd64-linux ~x64-macos"
     24 	S="${WORKDIR}/node-v${PV}"
     25 fi
     26 
     27 IUSE="corepack cpu_flags_x86_sse2 debug doc +icu inspector lto npm pax-kernel +snapshot +ssl +system-icu +system-ssl test"
     28 REQUIRED_USE="inspector? ( icu ssl )
     29 	npm? ( ssl )
     30 	system-icu? ( icu )
     31 	system-ssl? ( ssl )
     32 	x86? ( cpu_flags_x86_sse2 )"
     33 
     34 RESTRICT="!test? ( test )"
     35 
     36 RDEPEND=">=app-arch/brotli-1.1.0:=
     37 	dev-db/sqlite:3
     38 	>=dev-libs/libuv-1.49.2:=
     39 	>=dev-libs/simdjson-3.10.1:=
     40 	>=net-dns/c-ares-1.34.4:=
     41 	>=net-libs/nghttp2-1.64.0:=
     42 	>=net-libs/nghttp3-1.7.0:=
     43 	sys-libs/zlib
     44 	corepack? ( !sys-apps/yarn )
     45 	system-icu? ( >=dev-libs/icu-73:= )
     46 	system-ssl? (
     47 		>=net-libs/ngtcp2-1.9.1:=
     48 		>=dev-libs/openssl-1.1.1:0=
     49 	)
     50 	!system-ssl? ( >=net-libs/ngtcp2-1.9.1:=[-gnutls] )"
     51 BDEPEND="${PYTHON_DEPS}
     52 	app-alternatives/ninja
     53 	sys-apps/coreutils
     54 	virtual/pkgconfig
     55 	test? ( net-misc/curl )
     56 	pax-kernel? ( sys-apps/elfix )"
     57 DEPEND="${RDEPEND}"
     58 PATCHES=(
     59 	"${FILESDIR}"/${PN}-22.8.0-clang-fix-libatomic.patch
     60 )
     61 
     62 # These are measured on a loong machine with -ggdb on, and only checked
     63 # if debugging flags are present in CFLAGS.
     64 #
     65 # The final link consumed a little more than 7GiB alone, so 8GiB is the lower
     66 # limit for memory usage. Disk usage was 19.1GiB for the build directory and
     67 # 1.2GiB for the installed image, so we leave some room for architectures with
     68 # fatter binaries and set the disk requirement to 22GiB.
     69 CHECKREQS_MEMORY="8G"
     70 CHECKREQS_DISK_BUILD="22G"
     71 
     72 pkg_pretend() {
     73 	if [[ ${MERGE_TYPE} != "binary" ]]; then
     74 		if is-flagq "-g*" && ! is-flagq "-g*0" ; then
     75 			einfo "Checking for sufficient disk space and memory to build ${PN} with debugging CFLAGS"
     76 			check-reqs_pkg_pretend
     77 		fi
     78 	fi
     79 }
     80 
     81 pkg_setup() {
     82 	python-any-r1_pkg_setup
     83 	linux-info_pkg_setup
     84 }
     85 
     86 src_prepare() {
     87 	tc-export AR CC CXX PKG_CONFIG
     88 	export V=1
     89 	export BUILDTYPE=Release
     90 
     91 	# fix compilation on Darwin
     92 	# https://code.google.com/p/gyp/issues/detail?id=260
     93 	sed -i -e "/append('-arch/d" tools/gyp/pylib/gyp/xcode_emulation.py || die
     94 
     95 	# proper libdir, hat tip @ryanpcmcquen https://github.com/iojs/io.js/issues/504
     96 	local LIBDIR=$(get_libdir)
     97 	sed -i -e "s|lib/|${LIBDIR}/|g" tools/install.py || die
     98 	sed -i -e "s/'lib'/'${LIBDIR}'/" deps/npm/lib/npm.js || die
     99 
    100 	# Avoid writing a depfile, not useful
    101 	sed -i -e "/DEPFLAGS =/d" tools/gyp/pylib/gyp/generator/make.py || die
    102 
    103 	sed -i -e "/'-O3'/d" common.gypi node.gypi || die
    104 
    105 	# debug builds. change install path, remove optimisations and override buildtype
    106 	if use debug; then
    107 		sed -i -e "s|out/Release/|out/Debug/|g" tools/install.py || die
    108 		BUILDTYPE=Debug
    109 	fi
    110 
    111 	# We need to disable mprotect on two files when it builds Bug 694100.
    112 	use pax-kernel && PATCHES+=( "${FILESDIR}"/${PN}-22.12.0-paxmarking.patch )
    113 
    114 	# bug 931256
    115 	use riscv && PATCHES+=( "${FILESDIR}"/${PN}-22.2.0-riscv.patch )
    116 
    117 	default
    118 }
    119 
    120 src_configure() {
    121 	xdg_environment_reset
    122 
    123 	# LTO compiler flags are handled by configure.py itself
    124 	filter-lto
    125 	# The warnings are *so* noisy and make build.logs massive
    126 	append-cxxflags $(test-flags-CXX -Wno-template-id-cdtor)
    127 	# GCC with -ftree-vectorize miscompiles node's exception handling code
    128 	# causing it to fail to catch exceptions sometimes
    129 	# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116057
    130 	tc-is-gcc && append-cxxflags -fno-tree-vectorize
    131 	# https://bugs.gentoo.org/931514
    132 	use arm64 && append-flags $(test-flags-CXX -mbranch-protection=none)
    133 
    134 	append-atomic-flags
    135 
    136 	local myconf=(
    137 		--ninja
    138 		# ada is not packaged yet
    139 		# https://github.com/ada-url/ada
    140 		# --shared-ada
    141 		--shared-brotli
    142 		--shared-cares
    143 		--shared-libuv
    144 		--shared-nghttp2
    145 		--shared-nghttp3
    146 		--shared-ngtcp2
    147 		--shared-simdjson
    148 		# sindutf is not packaged yet
    149 		# https://github.com/simdutf/simdutf
    150 		# --shared-simdutf
    151 		--shared-sqlite
    152 		--shared-zlib
    153 	)
    154 	use debug && myconf+=( --debug )
    155 	use lto && myconf+=( --enable-lto )
    156 	if use system-icu; then
    157 		myconf+=( --with-intl=system-icu )
    158 	elif use icu; then
    159 		myconf+=( --with-intl=full-icu )
    160 	else
    161 		myconf+=( --with-intl=none )
    162 	fi
    163 	use corepack || myconf+=( --without-corepack )
    164 	use inspector || myconf+=( --without-inspector )
    165 	use npm || myconf+=( --without-npm )
    166 	use snapshot || myconf+=( --without-node-snapshot )
    167 	if use ssl; then
    168 		use system-ssl && myconf+=( --shared-openssl --openssl-use-def-ca-store )
    169 	else
    170 		myconf+=( --without-ssl )
    171 	fi
    172 
    173 	local myarch=""
    174 	case "${ARCH}:${ABI}" in
    175 		*:amd64) myarch="x64";;
    176 		*:arm) myarch="arm";;
    177 		*:arm64) myarch="arm64";;
    178 		loong:lp64*) myarch="loong64";;
    179 		riscv:lp64*) myarch="riscv64";;
    180 		*:ppc64) myarch="ppc64";;
    181 		*:x32) myarch="x32";;
    182 		*:x86) myarch="ia32";;
    183 		*) myarch="${ABI}";;
    184 	esac
    185 
    186 	GYP_DEFINES="linux_use_gold_flags=0
    187 		linux_use_bundled_binutils=0
    188 		linux_use_bundled_gold=0" \
    189 	"${EPYTHON}" configure.py \
    190 		--prefix="${EPREFIX}"/usr \
    191 		--dest-cpu=${myarch} \
    192 		"${myconf[@]}" || die
    193 }
    194 
    195 src_compile() {
    196 	export NINJA_ARGS=" $(get_NINJAOPTS)"
    197 	emake -Onone
    198 }
    199 
    200 src_install() {
    201 	local LIBDIR="${ED}/usr/$(get_libdir)"
    202 	default
    203 
    204 	pax-mark -m "${ED}"/usr/bin/node
    205 
    206 	# set up a symlink structure that node-gyp expects..
    207 	dodir /usr/include/node/deps/{v8,uv}
    208 	dosym . /usr/include/node/src
    209 	for var in deps/{uv,v8}/include; do
    210 		dosym ../.. /usr/include/node/${var}
    211 	done
    212 
    213 	if use doc; then
    214 		docinto html
    215 		dodoc -r "${S}"/doc/*
    216 	fi
    217 
    218 	if use npm; then
    219 		keepdir /etc/npm
    220 		echo "NPM_CONFIG_GLOBALCONFIG=${EPREFIX}/etc/npm/npmrc" > "${T}"/50npm
    221 		doenvd "${T}"/50npm
    222 
    223 		# Install bash completion for `npm`
    224 		local tmp_npm_completion_file="$(TMPDIR="${T}" mktemp -t npm.XXXXXXXXXX)"
    225 		"${ED}/usr/bin/npm" completion > "${tmp_npm_completion_file}"
    226 		newbashcomp "${tmp_npm_completion_file}" npm
    227 
    228 		# Move man pages
    229 		doman "${LIBDIR}"/node_modules/npm/man/man{1,5,7}/*
    230 
    231 		# Clean up
    232 		rm -f "${LIBDIR}"/node_modules/npm/{.mailmap,.npmignore,Makefile}
    233 		rm -rf "${LIBDIR}"/node_modules/npm/{doc,html,man}
    234 
    235 		local find_exp="-or -name"
    236 		local find_name=()
    237 		for match in "AUTHORS*" "CHANGELOG*" "CONTRIBUT*" "README*" \
    238 			".travis.yml" ".eslint*" ".wercker.yml" ".npmignore" \
    239 			"*.md" "*.markdown" "*.bat" "*.cmd"; do
    240 			find_name+=( ${find_exp} "${match}" )
    241 		done
    242 
    243 		# Remove various development and/or inappropriate files and
    244 		# useless docs of dependend packages.
    245 		find "${LIBDIR}"/node_modules \
    246 			\( -type d -name examples \) -or \( -type f \( \
    247 				-iname "LICEN?E*" \
    248 				"${find_name[@]}" \
    249 			\) \) -exec rm -rf "{}" \;
    250 	fi
    251 
    252 	use corepack &&
    253 		"${D}"/usr/bin/corepack enable --install-directory "${D}"/usr/bin
    254 
    255 	mv "${ED}"/usr/share/doc/node "${ED}"/usr/share/doc/${PF} || die
    256 }
    257 
    258 src_test() {
    259 	local drop_tests=(
    260 		test/parallel/test-dns.js
    261 		test/parallel/test-dns-resolveany-bad-ancount.js
    262 		test/parallel/test-dns-setserver-when-querying.js
    263 		test/parallel/test-fs-mkdir.js
    264 		test/parallel/test-fs-read-stream.js
    265 		test/parallel/test-fs-utimes-y2K38.js
    266 		test/parallel/test-fs-watch-recursive-add-file.js
    267 		test/parallel/test-process-euid-egid.js
    268 		test/parallel/test-process-get-builtin.mjs
    269 		test/parallel/test-process-initgroups.js
    270 		test/parallel/test-process-setgroups.js
    271 		test/parallel/test-process-uid-gid.js
    272 		test/parallel/test-release-npm.js
    273 		test/parallel/test-socket-write-after-fin-error.js
    274 		test/parallel/test-strace-openat-openssl.js
    275 		test/sequential/test-util-debug.js
    276 	)
    277 	[[ "$(nice)" -gt 10 ]] && drop_tests+=( "test/parallel/test-os.js" )
    278 	use inspector ||
    279 		drop_tests+=(
    280 			test/parallel/test-inspector-emit-protocol-event.js
    281 			test/parallel/test-inspector-network-domain.js
    282 			test/sequential/test-watch-mode.mjs
    283 		)
    284 	rm -f "${drop_tests[@]}" || die "disabling tests failed"
    285 
    286 	out/${BUILDTYPE}/cctest || die
    287 	"${EPYTHON}" tools/test.py --mode=${BUILDTYPE,,} --flaky-tests=dontcare -J message parallel sequential || die
    288 }
    289 
    290 pkg_postinst() {
    291 	if use npm; then
    292 		ewarn "remember to run: source /etc/profile if you plan to use nodejs"
    293 		ewarn " in your current shell"
    294 	fi
    295 }