123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424 |
- # Copyright 1999-2024 Gentoo Authors
- # Distributed under the terms of the GNU General Public License v2
- EAPI=8
- CONFIG_CHECK="~ADVISE_SYSCALLS"
- PYTHON_COMPAT=( python3_{11..13} )
- PYTHON_REQ_USE="threads(+)"
- MULTIPLEXER_VER="11"
- inherit bash-completion-r1 check-reqs flag-o-matic linux-info pax-utils python-any-r1 toolchain-funcs xdg-utils
- DESCRIPTION="A JavaScript runtime built on Chrome's V8 JavaScript engine"
- HOMEPAGE="https://nodejs.org/"
- LICENSE="Apache-1.1 Apache-2.0 BSD BSD-2 MIT"
- SLOT_MAJOR="$(ver_cut 1 ${PV})"
- SLOT="${SLOT_MAJOR}/$(ver_cut 1-2 ${PV})"
- if [[ ${PV} == *9999 ]]; then
- inherit git-r3
- EGIT_REPO_URI="https://github.com/nodejs/node"
- SLOT="23/0"
- else
- SRC_URI="https://nodejs.org/dist/v${PV}/node-v${PV}.tar.xz"
- KEYWORDS="~amd64 ~arm ~arm64 ~loong ~ppc64 ~riscv ~x86 ~amd64-linux ~x64-macos"
- S="${WORKDIR}/node-v${PV}"
- fi
- IUSE="+corepack cpu_flags_x86_sse2 debug doc +icu inspector +jit \
- lto lld man mold +npm pax-kernel -pointer-compression +snapshot +ssl \
- system-icu +system-ssl test"
- REQUIRED_USE="
- ^^ ( mold lld )
- corepack
- inspector? ( icu ssl )
- npm? ( corepack )
- system-icu? ( icu )
- system-ssl? ( ssl )
- x86? ( cpu_flags_x86_sse2 )
- "
- RESTRICT="
- !test? ( test )
- mirror
- "
- RDEPEND="
- !net-libs/nodejs:0
- >=app-arch/brotli-1.1.0
- >=app-eselect/eselect-nodejs-20230521
- dev-db/sqlite:3
- >=dev-libs/libuv-1.48.0:=
- >=dev-libs/simdjson-3.9.4:=
- >=net-dns/c-ares-1.29.0
- >=net-libs/nghttp2-1.62.1:=
- >=net-libs/ngtcp2-1.6.0:=
- >=sys-libs/zlib-1.3
- corepack? ( !sys-apps/yarn )
- system-icu? ( >=dev-libs/icu-73.0:= )
- system-ssl? (
- >=net-libs/ngtcp2-1.3.0:=
- >=dev-libs/openssl-3.0.13:0=
- )
- !system-ssl? ( >=net-libs/ngtcp2-1.3.0:=[-gnutls] )
- "
- BDEPEND="${PYTHON_DEPS}
- app-alternatives/ninja
- sys-apps/coreutils
- virtual/pkgconfig
- test? ( net-misc/curl )
- pax-kernel? ( sys-apps/elfix )
- mold? ( sys-devel/mold )
- lld? ( sys-devel/lld )
- "
- DEPEND="${RDEPEND}"
- # These are measured on a loong machine with -ggdb on, and only checked
- # if debugging flags are present in CFLAGS.
- #
- # The final link consumed a little more than 7GiB alone, so 8GiB is the lower
- # limit for memory usage. Disk usage was 19.1GiB for the build directory and
- # 1.2GiB for the installed image, so we leave some room for architectures with
- # fatter binaries and set the disk requirement to 22GiB.
- CHECKREQS_MEMORY="8G"
- CHECKREQS_DISK_BUILD="22G"
- PATCHES=(
- "${FILESDIR}/${PN}-12.22.5-shared_c-ares_nameser_h.patch"
- "${FILESDIR}/${PN}-22.2.0-global-npm-config.patch"
- "${FILESDIR}/${PN}-22.2.0-lto-update.patch"
- "${FILESDIR}/${PN}-20.1.0-support-clang-pgo.patch"
- "${FILESDIR}/${PN}-19.3.0-v8-oflags.patch"
- )
- pkg_pretend() {
- if [[ ${MERGE_TYPE} != "binary" ]]; then
- if is-flagq "-g*" && ! is-flagq "-g*0" ; then
- einfo "Checking for sufficient disk space and memory to build ${PN} with debugging CFLAGS"
- check-reqs_pkg_pretend
- fi
- fi
- ( use x86 && ! use cpu_flags_x86_sse2 ) && \
- die "Your CPU doesn't support the required SSE2 instruction."
- }
- pkg_setup() {
- python-any-r1_pkg_setup
- linux-info_pkg_setup
- }
- is_flagq_last() {
- local flag="${1}"
- local olast=$(echo "${CFLAGS}" | grep -o -E -e "-O(0|g|1|z|s|2|3|4|fast)" | tr " " "\n" | tail -n 1)
- einfo "CFLAGS:\t${CFLAGS}"
- einfo "olast:\t${olast}"
- [[ "${flag}" == "${olast}" ]] && return 0
- return 1
- }
- src_prepare() {
- tc-export AR CC CXX PKG_CONFIG
- export V=1
- export BUILDTYPE="Release"
- # Fix compilation on Darwin
- # https://code.google.com/p/gyp/issues/detail?id=260
- sed -i -e "/append('-arch/d" tools/gyp/pylib/gyp/xcode_emulation.py || die
- # Less verbose install output (stating the same as portage, basically)
- #sed -i -e "/print/d" tools/install.py || die
- # Proper libdir, hat tip @ryanpcmcquen https://github.com/iojs/io.js/issues/504
- local LIBDIR=$(get_libdir)
- sed -i -e "s|lib/|${LIBDIR}/|g" tools/install.py || die
- sed -i -e "s/'lib'/'${LIBDIR}'/" deps/npm/lib/npm.js || die
- # Avoid writing a depfile, not useful
- sed -i -e "/DEPFLAGS =/d" tools/gyp/pylib/gyp/generator/make.py || die
- # We need to disable mprotect on two files when it builds Bug 694100.
- use pax-kernel && PATCHES+=( "${FILESDIR}"/${PN}-20.6.0-paxmarking.patch )
- # https://github.com/nodejs/node/issues/51339
- use pointer-compression && PATCHES+=( "${FILESDIR}"/${PN}-23.0.0-fix-v8-external-code-space.patch )
- default
- local FP=(
- $(grep -l -r -e "-O3" $(find deps/openssl -name "*.gn*" -o -name "*gyp*"))
- common.gypi
- deps/llhttp/common.gypi
- deps/uv/common.gypi
- node.gypi
- )
- # -O3 removal breaks _FORITIFY_SOURCE
- local a1="-O3"
- local r1="-O2"
- local a2="-O2"
- local r2="-O3"
- local oflag="-O3"
- if is_flagq_last '-O0'; then
- oflag="-O0"
- elif is_flagq_last '-Og'; then
- oflag="-Og"
- elif is_flagq_last '-O1'; then
- oflag="-O1"
- elif is_flagq_last '-O2'; then
- oflag="-O2"
- elif is_flagq_last '-O3'; then
- oflag="-O3 "
- elif is_flagq_last '-O4'; then
- oflag="-O4 "
- elif is_flagq_last '-Ofast'; then
- oflag="-Ofast"
- elif is_flagq_last '-Os'; then
- oflag="-Os"
- elif is_flagq_last '-Oz'; then
- oflag="-Oz"
- fi
- sed -i -e "s|- O3|${oflag}|g" ${FP[@]} || die
- a1="${oflag}"
- a2="${oflag}"
- sed -i \
- -e "s|__OFLAGS_A1__|${a1}|g" \
- -e "s|__OFLAGS_R1__|${r1}|g" \
- -e "s|__OFLAGS_A2__|${a2}|g" \
- -e "s|__OFLAGS_R2__|${r2}|g" \
- tools/v8_gypfiles/toolchain.gypi \
- || die
- # debug builds. change install path, remove optimisations and override buildtype
- if use debug; then
- sed -i -e "s|out/Release/|out/Debug/|g" tools/install.py || die
- BUILDTYPE="Debug"
- fi
- }
- src_configure() {
- export ENINJA_BUILD_DIR="out/"$(usex debug "Debug" "Release")
- xdg_environment_reset
- # LTO compiler flags are handled by configure.py itself
- filter-lto
- # nodejs unconditionally links to libatomic #869992
- # specifically it requires __atomic_is_lock_free which
- # is not yet implemented by sys-libs/compiler-rt (see
- # https://reviews.llvm.org/D85044?id=287068), therefore
- # we depend on gcc and force using libgcc as the support lib
- tc-is-clang && append-ldflags "--rtlib=libgcc --unwindlib=libgcc"
- local myconf=(
- --ninja
- # ada is not packaged yet
- # https://github.com/ada-url/ada
- # --shared-ada
- --shared-brotli
- --shared-cares
- --shared-libuv
- --shared-nghttp2
- --shared-ngtcp2
- --shared-simdjson
- # sindutf is not packaged yet
- # https://github.com/simdutf/simdutf
- # --shared-simdutf
- --shared-sqlite
- --shared-zlib
- )
- use debug && myconf+=( --debug )
- use lto && myconf+=( --enable-lto )
- use mold && myconf+=( --with-moldlto )
- use lld && myconf+=( --with-thinlto )
- if use system-icu; then
- myconf+=( --with-intl=system-icu )
- elif use icu; then
- myconf+=( --with-intl=full-icu )
- else
- myconf+=( --with-intl=none )
- fi
- use corepack || myconf+=( --without-corepack )
- use inspector || myconf+=( --without-inspector )
- use npm || myconf+=( --without-npm )
- use snapshot || myconf+=( --without-node-snapshot )
- if use ssl; then
- use system-ssl && myconf+=( --shared-openssl --openssl-use-def-ca-store )
- else
- myconf+=( --without-ssl )
- fi
- use jit || myconf+=( --v8-lite-mode )
- if use jit && use debug && has_version "dev-debug/gdb" ; then
- myconf+=( --gdb )
- fi
- use pointer-compression && myconf+=( --experimental-enable-pointer-compression )
- if use kernel_linux && linux_chkconfig_present "TRANSPARENT_HUGEPAGE" ; then
- myconf+=( --v8-enable-hugepage )
- fi
- if ! use pointer-compression ; then
- ewarn "Disabing USE=pointer-compression will disable the V8 Sandbox."
- fi
- local myarch
- myarch="${ABI/amd64/x64}"
- myarch="${myarch/x86/ia32}"
- [[ "${ARCH}:${ABI}" =~ "loong:lp64" ]] && myarch="loong64"
- [[ "${ARCH}:${ABI}" =~ "riscv:lp64" ]] && myarch="riscv64"
- GYP_DEFINES="linux_use_gold_flags=0
- linux_use_bundled_binutils=0
- linux_use_bundled_gold=0" \
- "${EPYTHON}" configure.py \
- --prefix="${EPREFIX}/usr" \
- --dest-cpu="${myarch}" \
- ${myconf[@]} || die
- # Prevent double build on install.
- sed -i -e "s|^install: all|install: |g" "Makefile" || die
- }
- src_compile() {
- emake
- }
- src_install() {
- local LIBDIR="${ED}/usr/$(get_libdir)"
- default
- local REL_D_BASE="usr/$(get_libdir)"
- local D_BASE="/${REL_D_BASE}"
- local ED_BASE="${ED}/${REL_D_BASE}"
- ${EPYTHON} tools/install.py install \
- --dest-dir "${D}" \
- --prefix "${EPREFIX}/usr" \
- || die
- mv "${ED}/usr/bin/node" "${ED}/usr/bin/node${SLOT_MAJOR}" || die
- dosym "node${SLOT_MAJOR}" "/usr/bin/node"
- pax-mark -m "${ED}/usr/bin/node${SLOT_MAJOR}"
- # set up a symlink structure that node-gyp expects..
- local D_INCLUDE_BASE="/usr/include/node${SLOT_MAJOR}"
- dodir "${D_INCLUDE_BASE}/deps/"{"v8","uv"}
- dosym "." "${D_INCLUDE_BASE}/src"
- local var
- for var in deps/{uv,v8}/include; do
- dosym "../.." "${D_INCLUDE_BASE}/${var}"
- done
- # Avoid merge conflict
- mv "${ED}/usr/include/node/"* "${ED}${D_INCLUDE_BASE}" || die
- rm -rf "${ED}/usr/include/node" || die
- if use doc; then
- docinto html
- dodoc -r "${S}/doc/"*
- fi
- if ! use man ; then
- rm -rf "${ED}//usr/share/man/man1/node.1"* || die
- fi
- # Use tarball instead.
- rm -rf "${ED}/usr/$(get_libdir)/node_modules/npm"
- rm -rf "${ED}/usr/bin/npm"
- rm -rf "${ED}/usr/bin/npx"
- mv \
- "${ED}/usr/share/doc/node" \
- "${ED}/usr/share/doc/${PF}" \
- || die
- # Let eselect-nodejs handle switching corepack
- dodir "/usr/$(get_libdir)/corepack"
- mv \
- "${ED}/usr/$(get_libdir)/node_modules/corepack" \
- "${ED}/usr/$(get_libdir)/corepack/node${SLOT_MAJOR}" \
- || die
- rm -rf "${ED}/usr/bin/corepack"
- if use npm; then
- keepdir /etc/npm
- echo "NPM_CONFIG_GLOBALCONFIG=${EPREFIX}/etc/npm/npmrc" > "${T}"/50npm
- doenvd "${T}"/50npm
- # Install bash completion for `npm`
- local tmp_npm_completion_file="$(TMPDIR="${T}" mktemp -t npm.XXXXXXXXXX)"
- "${ED}/usr/bin/npm" completion > "${tmp_npm_completion_file}"
- newbashcomp "${tmp_npm_completion_file}" npm
- # Clean up
- rm -f "${LIBDIR}"/node_modules/npm/{.mailmap,.npmignore,Makefile}
- rm -rf "${LIBDIR}"/node_modules/npm/{doc,html,man}
- local find_exp="-or -name"
- local find_name=()
- for match in "AUTHORS*" "CHANGELOG*" "CONTRIBUT*" "README*" \
- ".travis.yml" ".eslint*" ".wercker.yml" ".npmignore" \
- "*.md" "*.markdown" "*.bat" "*.cmd"; do
- find_name+=( ${find_exp} "${match}" )
- done
- # Remove various development and/or inappropriate files and
- # useless docs of dependend packages.
- find "${LIBDIR}"/node_modules \
- \( -type d -name examples \) -or \( -type f \( \
- -iname "LICEN?E*" \
- "${find_name[@]}" \
- \) \) -exec rm -rf "{}" \;
- fi
- cp --remove-destination "${FILESDIR}/node-multiplexer-v${MULTIPLEXER_VER}" "${ED}/usr/bin/node" || die
- sed -e "s|__EPREFIX__|${EPREFIX}|g" -i "${ED}/usr/bin/node" || die
- fperms 0755 "/usr/bin/node" || die
- fowners -R root:root "/usr/bin/node" || die
- }
- src_test() {
- if has usersandbox ${FEATURES}; then
- rm -f "${S}/test/parallel/test-fs-mkdir.js"
- ewarn
- ewarn "You are emerging ${PN} with 'usersandbox' enabled. Excluding tests known"
- ewarn "to fail in this mode. For full test coverage, emerge =${CATEGORY}/${PF}"
- ewarn "with 'FEATURES=-usersandbox'."
- ewarn
- fi
- "out/${CONFIGURATION}/cctest" || die
- "${EPYTHON}" \
- "tools/test.py" \
- --mode="${CONFIGURATION,,}" \
- --flaky-tests="dontcare" \
- -J \
- message \
- parallel \
- sequential \
- || die
- }
- pkg_postinst() {
- if use npm; then
- ewarn "remember to run: source /etc/profile if you plan to use nodejs"
- ewarn " in your current shell"
- fi
- if has_version ">net-libs/nodejs-${PV}" ; then
- einfo "Found higher slots, manually change the headers with \`eselect nodejs\`."
- else
- eselect nodejs set "node${SLOT_MAJOR}"
- fi
- grep -q -F "NODE_VERSION" "${EROOT}/usr/bin/node" || die "Wrapper did not copy."
- einfo
- einfo "When compiling with nodejs multislot, you to switch via"
- einfo "\`eselect nodejs\` in order to compile against the headers matching the"
- einfo "corresponding SLOT. This means that you cannot compile with different"
- einfo "SLOTS simultaneously."
- einfo
- }
|