portage-overlay

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

nodejs-22.8.0.ebuild (8392B)


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