blob: e2e2f5ae8db29fb22685cd3aa08552f4e61a86a8 [file] [log] [blame]
Patrick Williamsac13d5f2023-11-24 18:59:46 -06001DESCRIPTION = "nodeJS Evented I/O for V8 JavaScript"
2HOMEPAGE = "http://nodejs.org"
3LICENSE = "MIT & ISC & BSD-2-Clause & BSD-3-Clause & Artistic-2.0 & Apache-2.0"
Patrick Williams73bd93f2024-02-20 08:07:48 -06004LIC_FILES_CHKSUM = "file://LICENSE;md5=78ad16dab3c1d15d4878c81770be0be7"
Patrick Williamsac13d5f2023-11-24 18:59:46 -06005
6CVE_PRODUCT = "nodejs node.js"
7
Patrick Williams169d7bc2024-01-05 11:33:25 -06008DEPENDS = "openssl file-replacement-native python3-packaging-native"
Patrick Williamsac13d5f2023-11-24 18:59:46 -06009DEPENDS:append:class-target = " qemu-native"
10DEPENDS:append:class-native = " c-ares-native"
11
12inherit pkgconfig python3native qemu ptest
13
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://system-c-ares.patch \
26 file://0001-liftoff-Correct-function-signatures.patch \
Patrick Williamsb58112e2024-03-07 11:16:36 -060027 file://0001-deps-disable-io_uring-support-in-libuv.patch \
Patrick Williamsac13d5f2023-11-24 18:59:46 -060028 file://run-ptest \
Patrick Williamsac13d5f2023-11-24 18:59:46 -060029 "
30
31SRC_URI:append:class-target = " \
32 file://0001-Using-native-binaries.patch \
33 "
34SRC_URI:append:toolchain-clang:x86 = " \
35 file://libatomic.patch \
36 "
37SRC_URI:append:toolchain-clang:powerpc64le = " \
38 file://0001-ppc64-Do-not-use-mminimal-toc-with-clang.patch \
39 "
Patrick Williamsb58112e2024-03-07 11:16:36 -060040SRC_URI[sha256sum] = "77813edbf3f7f16d2d35d3353443dee4e61d5ee84d9e3138c7538a3c0ca5209e"
Patrick Williamsac13d5f2023-11-24 18:59:46 -060041
42S = "${WORKDIR}/node-v${PV}"
43
Patrick Williams73bd93f2024-02-20 08:07:48 -060044CVE_PRODUCT += "node.js"
45
Patrick Williamsac13d5f2023-11-24 18:59:46 -060046# 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} -pie -fPIE' \
83 CFLAGS.host='${CPPFLAGS} ${CFLAGS}' \
84 CXX.host='${CXX} -pie -fPIE' \
85 CXXFLAGS.host='${CPPFLAGS} ${CXXFLAGS}' \
86 LDFLAGS.host='${LDFLAGS}' \
87 AR.host='${AR}' \
88 \
89 builddir_name=./ \
90"
91
92EXTRANATIVEPATH += "file-native"
93
94python prune_sources() {
95 import shutil
96
97 shutil.rmtree(d.getVar('S') + '/deps/openssl')
98 if 'ares' in d.getVar('PACKAGECONFIG'):
99 shutil.rmtree(d.getVar('S') + '/deps/cares')
100 if 'brotli' in d.getVar('PACKAGECONFIG'):
101 shutil.rmtree(d.getVar('S') + '/deps/brotli')
102 if 'libuv' in d.getVar('PACKAGECONFIG'):
103 shutil.rmtree(d.getVar('S') + '/deps/uv')
104 if 'nghttp2' in d.getVar('PACKAGECONFIG'):
105 shutil.rmtree(d.getVar('S') + '/deps/nghttp2')
106 if 'zlib' in d.getVar('PACKAGECONFIG'):
107 shutil.rmtree(d.getVar('S') + '/deps/zlib')
108}
109do_unpack[postfuncs] += "prune_sources"
110
111# V8's JIT infrastructure requires binaries such as mksnapshot and
112# mkpeephole to be run in the host during the build. However, these
113# binaries must have the same bit-width as the target (e.g. a x86_64
114# host targeting ARMv6 needs to produce a 32-bit binary). Instead of
115# depending on a third Yocto toolchain, we just build those binaries
116# for the target and run them on the host with QEMU.
117python do_create_v8_qemu_wrapper () {
118 """Creates a small wrapper that invokes QEMU to run some target V8 binaries
119 on the host."""
120 qemu_libdirs = [d.expand('${STAGING_DIR_HOST}${libdir}'),
121 d.expand('${STAGING_DIR_HOST}${base_libdir}')]
122 qemu_cmd = qemu_wrapper_cmdline(d, d.getVar('STAGING_DIR_HOST'),
123 qemu_libdirs)
124 wrapper_path = d.expand('${B}/v8-qemu-wrapper.sh')
125 with open(wrapper_path, 'w') as wrapper_file:
126 wrapper_file.write("""#!/bin/sh
127
128# This file has been generated automatically.
129# It invokes QEMU to run binaries built for the target in the host during the
130# build process.
131
132%s "$@"
133""" % qemu_cmd)
134 os.chmod(wrapper_path, 0o755)
135}
136
137do_create_v8_qemu_wrapper[dirs] = "${B}"
138addtask create_v8_qemu_wrapper after do_configure before do_compile
139
140LDFLAGS:append:x86 = " -latomic"
141
142CROSS_FLAGS = "--cross-compiling"
143CROSS_FLAGS:class-native = "--no-cross-compiling"
144
145# Node is way too cool to use proper autotools, so we install two wrappers to forcefully inject proper arch cflags to workaround gypi
146do_configure () {
147 GYP_DEFINES="${GYP_DEFINES}" export GYP_DEFINES
148 # $TARGET_ARCH settings don't match --dest-cpu settings
149 python3 configure.py --verbose --prefix=${prefix} \
150 --shared-openssl \
151 --dest-cpu="${@map_nodejs_arch(d.getVar('TARGET_ARCH'), d)}" \
152 --dest-os=linux \
153 --libdir=${baselib} \
154 ${CROSS_FLAGS} \
155 ${ARCHFLAGS} \
156 ${PACKAGECONFIG_CONFARGS}
157}
158
159do_compile () {
160 install -D ${RECIPE_SYSROOT_NATIVE}/etc/ssl/openssl.cnf ${B}/deps/openssl/nodejs-openssl.cnf
161 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
169do_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
175PACKAGES =+ "${PN}-npm"
176FILES:${PN}-npm = "${nonarch_libdir}/node_modules ${bindir}/npm ${bindir}/npx ${bindir}/corepack"
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"