blob: 802c4191bb46eb146b433e1141db41a19b229b3b [file] [log] [blame]
Andrew Geissler517393d2023-01-13 08:55:19 -06001DESCRIPTION = "nodeJS Evented I/O for V8 JavaScript"
2HOMEPAGE = "http://nodejs.org"
3LICENSE = "MIT & ISC & BSD-2-Clause & BSD-3-Clause & Artistic-2.0"
Andrew Geisslerc5535c92023-01-27 16:10:19 -06004LIC_FILES_CHKSUM = "file://LICENSE;md5=dfd7ae796baf5326016a3865ee1dc632"
Andrew Geissler517393d2023-01-13 08:55:19 -06005
Andrew Geissler6aa7eec2023-03-03 12:41:14 -06006CVE_PRODUCT = "nodejs node.js"
7
Andrew Geissler517393d2023-01-13 08:55:19 -06008DEPENDS = "openssl"
9DEPENDS:append:class-target = " qemu-native"
10DEPENDS:append:class-native = " c-ares-native"
11
Andrew Geisslerc5535c92023-01-27 16:10:19 -060012inherit pkgconfig python3native qemu ptest
Andrew Geissler517393d2023-01-13 08:55:19 -060013
14COMPATIBLE_MACHINE:armv4 = "(!.*armv4).*"
15COMPATIBLE_MACHINE:armv5 = "(!.*armv5).*"
16COMPATIBLE_MACHINE:mips64 = "(!.*mips64).*"
17
18COMPATIBLE_HOST:riscv64 = "null"
19COMPATIBLE_HOST:riscv32 = "null"
20COMPATIBLE_HOST:powerpc = "null"
21
22SRC_URI = "http://nodejs.org/dist/v${PV}/node-v${PV}.tar.xz \
23 file://0001-Disable-running-gyp-files-for-bundled-deps.patch \
24 file://0004-v8-don-t-override-ARM-CFLAGS.patch \
25 file://big-endian.patch \
26 file://mips-less-memory.patch \
27 file://system-c-ares.patch \
28 file://0001-liftoff-Correct-function-signatures.patch \
29 file://0001-mips-Use-32bit-cast-for-operand-on-mips32.patch \
Patrick Williams864cc432023-02-09 14:54:44 -060030 file://gcc13.patch \
Andrew Geissler517393d2023-01-13 08:55:19 -060031 "
Andrew Geisslerc5535c92023-01-27 16:10:19 -060032
Andrew Geissler517393d2023-01-13 08:55:19 -060033SRC_URI:append:class-target = " \
34 file://0001-Using-native-binaries.patch \
35 "
36SRC_URI:append:toolchain-clang:x86 = " \
37 file://libatomic.patch \
38 "
39SRC_URI:append:toolchain-clang:powerpc64le = " \
40 file://0001-ppc64-Do-not-use-mminimal-toc-with-clang.patch \
41 "
Andrew Geisslerc5535c92023-01-27 16:10:19 -060042SRC_URI[sha256sum] = "4fa406451bc52659a290e52cfdb2162a760bd549da4b8bbebe6a29f296d938df"
Andrew Geissler517393d2023-01-13 08:55:19 -060043
44S = "${WORKDIR}/node-v${PV}"
45
46# v8 errors out if you have set CCACHE
47CCACHE = ""
48
49def map_nodejs_arch(a, d):
50 import re
51
52 if re.match('i.86$', a): return 'ia32'
53 elif re.match('x86_64$', a): return 'x64'
54 elif re.match('aarch64$', a): return 'arm64'
55 elif re.match('(powerpc64|powerpc64le|ppc64le)$', a): return 'ppc64'
56 elif re.match('powerpc$', a): return 'ppc'
57 return a
58
59ARCHFLAGS:arm = "${@bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', '--with-arm-float-abi=hard', '--with-arm-float-abi=softfp', d)} \
60 ${@bb.utils.contains('TUNE_FEATURES', 'neon', '--with-arm-fpu=neon', \
61 bb.utils.contains('TUNE_FEATURES', 'vfpv3d16', '--with-arm-fpu=vfpv3-d16', \
62 bb.utils.contains('TUNE_FEATURES', 'vfpv3', '--with-arm-fpu=vfpv3', \
63 '--with-arm-fpu=vfp', d), d), d)}"
64ARCHFLAGS:append:mips = " --v8-lite-mode"
65ARCHFLAGS:append:mipsel = " --v8-lite-mode"
66ARCHFLAGS ?= ""
67
68PACKAGECONFIG ??= "ares brotli icu zlib"
69
70PACKAGECONFIG[ares] = "--shared-cares,,c-ares"
71PACKAGECONFIG[brotli] = "--shared-brotli,,brotli"
72PACKAGECONFIG[icu] = "--with-intl=system-icu,--without-intl,icu"
73PACKAGECONFIG[libuv] = "--shared-libuv,,libuv"
74PACKAGECONFIG[nghttp2] = "--shared-nghttp2,,nghttp2"
75PACKAGECONFIG[shared] = "--shared"
76PACKAGECONFIG[zlib] = "--shared-zlib,,zlib"
77
78# We don't want to cross-compile during target compile,
79# and we need to use the right flags during host compile,
80# too.
81EXTRA_OEMAKE = "\
82 CC.host='${CC}' \
83 CFLAGS.host='${CPPFLAGS} ${CFLAGS}' \
84 CXX.host='${CXX}' \
85 CXXFLAGS.host='${CPPFLAGS} ${CXXFLAGS}' \
86 LDFLAGS.host='${LDFLAGS}' \
87 AR.host='${AR}' \
88 \
89 builddir_name=./ \
90"
91
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060092python prune_sources() {
Andrew Geissler517393d2023-01-13 08:55:19 -060093 import shutil
94
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060095 shutil.rmtree(d.getVar('S') + '/deps/openssl')
Andrew Geissler517393d2023-01-13 08:55:19 -060096 if 'ares' in d.getVar('PACKAGECONFIG'):
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060097 shutil.rmtree(d.getVar('S') + '/deps/cares')
Andrew Geissler517393d2023-01-13 08:55:19 -060098 if 'brotli' in d.getVar('PACKAGECONFIG'):
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060099 shutil.rmtree(d.getVar('S') + '/deps/brotli')
Andrew Geissler517393d2023-01-13 08:55:19 -0600100 if 'libuv' in d.getVar('PACKAGECONFIG'):
Andrew Geissler6aa7eec2023-03-03 12:41:14 -0600101 shutil.rmtree(d.getVar('S') + '/deps/uv')
Andrew Geissler517393d2023-01-13 08:55:19 -0600102 if 'nghttp2' in d.getVar('PACKAGECONFIG'):
Andrew Geissler6aa7eec2023-03-03 12:41:14 -0600103 shutil.rmtree(d.getVar('S') + '/deps/nghttp2')
Andrew Geissler517393d2023-01-13 08:55:19 -0600104 if 'zlib' in d.getVar('PACKAGECONFIG'):
Andrew Geissler6aa7eec2023-03-03 12:41:14 -0600105 shutil.rmtree(d.getVar('S') + '/deps/zlib')
Andrew Geissler517393d2023-01-13 08:55:19 -0600106}
Andrew Geissler6aa7eec2023-03-03 12:41:14 -0600107do_unpack[postfuncs] += "prune_sources"
Andrew Geissler517393d2023-01-13 08:55:19 -0600108
109# V8's JIT infrastructure requires binaries such as mksnapshot and
110# mkpeephole to be run in the host during the build. However, these
111# binaries must have the same bit-width as the target (e.g. a x86_64
112# host targeting ARMv6 needs to produce a 32-bit binary). Instead of
113# depending on a third Yocto toolchain, we just build those binaries
114# for the target and run them on the host with QEMU.
115python do_create_v8_qemu_wrapper () {
116 """Creates a small wrapper that invokes QEMU to run some target V8 binaries
117 on the host."""
118 qemu_libdirs = [d.expand('${STAGING_DIR_HOST}${libdir}'),
119 d.expand('${STAGING_DIR_HOST}${base_libdir}')]
Patrick Williams864cc432023-02-09 14:54:44 -0600120 qemu_cmd = qemu_wrapper_cmdline(d, d.getVar('STAGING_DIR_HOST'),
Andrew Geissler517393d2023-01-13 08:55:19 -0600121 qemu_libdirs)
122 wrapper_path = d.expand('${B}/v8-qemu-wrapper.sh')
123 with open(wrapper_path, 'w') as wrapper_file:
124 wrapper_file.write("""#!/bin/sh
125
126# This file has been generated automatically.
127# It invokes QEMU to run binaries built for the target in the host during the
128# build process.
129
130%s "$@"
131""" % qemu_cmd)
132 os.chmod(wrapper_path, 0o755)
133}
134
135do_create_v8_qemu_wrapper[dirs] = "${B}"
136addtask create_v8_qemu_wrapper after do_configure before do_compile
137
138LDFLAGS:append:x86 = " -latomic"
139
Andrew Geissler6aa7eec2023-03-03 12:41:14 -0600140CROSS_FLAGS = "--cross-compiling"
141CROSS_FLAGS:class-native = "--no-cross-compiling"
142
Andrew Geissler517393d2023-01-13 08:55:19 -0600143# Node is way too cool to use proper autotools, so we install two wrappers to forcefully inject proper arch cflags to workaround gypi
144do_configure () {
Andrew Geissler517393d2023-01-13 08:55:19 -0600145 GYP_DEFINES="${GYP_DEFINES}" export GYP_DEFINES
146 # $TARGET_ARCH settings don't match --dest-cpu settings
Andrew Geissler6aa7eec2023-03-03 12:41:14 -0600147 python3 configure.py --verbose --prefix=${prefix} \
Andrew Geissler517393d2023-01-13 08:55:19 -0600148 --shared-openssl \
149 --without-dtrace \
150 --without-etw \
151 --dest-cpu="${@map_nodejs_arch(d.getVar('TARGET_ARCH'), d)}" \
152 --dest-os=linux \
Andrew Geissler6aa7eec2023-03-03 12:41:14 -0600153 --libdir=${baselib} \
154 ${CROSS_FLAGS} \
Andrew Geissler517393d2023-01-13 08:55:19 -0600155 ${ARCHFLAGS} \
156 ${PACKAGECONFIG_CONFARGS}
157}
158
159do_compile () {
Andrew Geisslerc5535c92023-01-27 16:10:19 -0600160 install -D ${RECIPE_SYSROOT_NATIVE}/etc/ssl/openssl.cnf ${B}/deps/openssl/nodejs-openssl.cnf
Andrew Geissler517393d2023-01-13 08:55:19 -0600161 install -D ${B}/v8-qemu-wrapper.sh ${B}/out/Release/v8-qemu-wrapper.sh
162 oe_runmake BUILDTYPE=Release
163}
164
165do_install () {
166 oe_runmake install DESTDIR=${D}
167}
168
Andrew Geisslerc5535c92023-01-27 16:10:19 -0600169do_install_ptest () {
170 cp -r ${B}/out/Release/cctest ${D}${PTEST_PATH}/
171 cp -r ${B}/test ${D}${PTEST_PATH}
172 chown -R root:root ${D}${PTEST_PATH}
173}
174
Andrew Geissler517393d2023-01-13 08:55:19 -0600175PACKAGES =+ "${PN}-npm"
176FILES:${PN}-npm = "${nonarch_libdir}/node_modules ${bindir}/npm ${bindir}/npx"
177RDEPENDS:${PN}-npm = "bash python3-core python3-shell python3-datetime \
178 python3-misc python3-multiprocessing"
179
180PACKAGES =+ "${PN}-systemtap"
181FILES:${PN}-systemtap = "${datadir}/systemtap"
182
183BBCLASSEXTEND = "native"