blob: 6bb0f7fabd9fae93a34ada1913d68ab7cf8f2941 [file] [log] [blame]
Andrew Geissler517393d2023-01-13 08:55:19 -06001DESCRIPTION = "nodeJS Evented I/O for V8 JavaScript"
2HOMEPAGE = "http://nodejs.org"
Andrew Geisslerfc113ea2023-03-31 09:59:46 -05003LICENSE = "MIT & ISC & BSD-2-Clause & BSD-3-Clause & Artistic-2.0 & Apache-2.0"
Andrew Geissler220dafd2023-10-04 10:18:08 -05004LIC_FILES_CHKSUM = "file://LICENSE;md5=059ecf3a6f87111685e51b611b9563e5"
Andrew Geissler517393d2023-01-13 08:55:19 -06005
Andrew Geissler6aa7eec2023-03-03 12:41:14 -06006CVE_PRODUCT = "nodejs node.js"
7
Andrew Geisslerfc113ea2023-03-31 09:59:46 -05008DEPENDS = "openssl file-replacement-native"
Andrew Geissler517393d2023-01-13 08:55:19 -06009DEPENDS: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 \
Andrew Geissler517393d2023-01-13 08:55:19 -060025 file://system-c-ares.patch \
26 file://0001-liftoff-Correct-function-signatures.patch \
Andrew Geisslerfc113ea2023-03-31 09:59:46 -050027 file://run-ptest \
Andrew Geissler517393d2023-01-13 08:55:19 -060028 "
Andrew Geisslerc5535c92023-01-27 16:10:19 -060029
Andrew Geissler517393d2023-01-13 08:55:19 -060030SRC_URI:append:class-target = " \
31 file://0001-Using-native-binaries.patch \
32 "
33SRC_URI:append:toolchain-clang:x86 = " \
34 file://libatomic.patch \
35 "
36SRC_URI:append:toolchain-clang:powerpc64le = " \
37 file://0001-ppc64-Do-not-use-mminimal-toc-with-clang.patch \
38 "
Andrew Geissler220dafd2023-10-04 10:18:08 -050039SRC_URI[sha256sum] = "439c71aa2f38c2861657bfa538e99191a571258066cbfd4548586049c8134190"
Andrew Geissler517393d2023-01-13 08:55:19 -060040
41S = "${WORKDIR}/node-v${PV}"
42
43# v8 errors out if you have set CCACHE
44CCACHE = ""
45
46def map_nodejs_arch(a, d):
47 import re
48
49 if re.match('i.86$', a): return 'ia32'
50 elif re.match('x86_64$', a): return 'x64'
51 elif re.match('aarch64$', a): return 'arm64'
52 elif re.match('(powerpc64|powerpc64le|ppc64le)$', a): return 'ppc64'
53 elif re.match('powerpc$', a): return 'ppc'
54 return a
55
56ARCHFLAGS:arm = "${@bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', '--with-arm-float-abi=hard', '--with-arm-float-abi=softfp', d)} \
57 ${@bb.utils.contains('TUNE_FEATURES', 'neon', '--with-arm-fpu=neon', \
58 bb.utils.contains('TUNE_FEATURES', 'vfpv3d16', '--with-arm-fpu=vfpv3-d16', \
59 bb.utils.contains('TUNE_FEATURES', 'vfpv3', '--with-arm-fpu=vfpv3', \
60 '--with-arm-fpu=vfp', d), d), d)}"
61ARCHFLAGS:append:mips = " --v8-lite-mode"
62ARCHFLAGS:append:mipsel = " --v8-lite-mode"
63ARCHFLAGS ?= ""
64
65PACKAGECONFIG ??= "ares brotli icu zlib"
66
67PACKAGECONFIG[ares] = "--shared-cares,,c-ares"
68PACKAGECONFIG[brotli] = "--shared-brotli,,brotli"
69PACKAGECONFIG[icu] = "--with-intl=system-icu,--without-intl,icu"
70PACKAGECONFIG[libuv] = "--shared-libuv,,libuv"
71PACKAGECONFIG[nghttp2] = "--shared-nghttp2,,nghttp2"
72PACKAGECONFIG[shared] = "--shared"
73PACKAGECONFIG[zlib] = "--shared-zlib,,zlib"
74
75# We don't want to cross-compile during target compile,
76# and we need to use the right flags during host compile,
77# too.
78EXTRA_OEMAKE = "\
Andrew Geissler8f840682023-07-21 09:09:43 -050079 CC.host='${CC} -pie -fPIE' \
Andrew Geissler517393d2023-01-13 08:55:19 -060080 CFLAGS.host='${CPPFLAGS} ${CFLAGS}' \
Andrew Geissler8f840682023-07-21 09:09:43 -050081 CXX.host='${CXX} -pie -fPIE' \
Andrew Geissler517393d2023-01-13 08:55:19 -060082 CXXFLAGS.host='${CPPFLAGS} ${CXXFLAGS}' \
83 LDFLAGS.host='${LDFLAGS}' \
84 AR.host='${AR}' \
85 \
86 builddir_name=./ \
87"
88
Andrew Geisslerfc113ea2023-03-31 09:59:46 -050089EXTRANATIVEPATH += "file-native"
90
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060091python prune_sources() {
Andrew Geissler517393d2023-01-13 08:55:19 -060092 import shutil
93
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060094 shutil.rmtree(d.getVar('S') + '/deps/openssl')
Andrew Geissler517393d2023-01-13 08:55:19 -060095 if 'ares' in d.getVar('PACKAGECONFIG'):
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060096 shutil.rmtree(d.getVar('S') + '/deps/cares')
Andrew Geissler517393d2023-01-13 08:55:19 -060097 if 'brotli' in d.getVar('PACKAGECONFIG'):
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060098 shutil.rmtree(d.getVar('S') + '/deps/brotli')
Andrew Geissler517393d2023-01-13 08:55:19 -060099 if 'libuv' in d.getVar('PACKAGECONFIG'):
Andrew Geissler6aa7eec2023-03-03 12:41:14 -0600100 shutil.rmtree(d.getVar('S') + '/deps/uv')
Andrew Geissler517393d2023-01-13 08:55:19 -0600101 if 'nghttp2' in d.getVar('PACKAGECONFIG'):
Andrew Geissler6aa7eec2023-03-03 12:41:14 -0600102 shutil.rmtree(d.getVar('S') + '/deps/nghttp2')
Andrew Geissler517393d2023-01-13 08:55:19 -0600103 if 'zlib' in d.getVar('PACKAGECONFIG'):
Andrew Geissler6aa7eec2023-03-03 12:41:14 -0600104 shutil.rmtree(d.getVar('S') + '/deps/zlib')
Andrew Geissler517393d2023-01-13 08:55:19 -0600105}
Andrew Geissler6aa7eec2023-03-03 12:41:14 -0600106do_unpack[postfuncs] += "prune_sources"
Andrew Geissler517393d2023-01-13 08:55:19 -0600107
108# V8's JIT infrastructure requires binaries such as mksnapshot and
109# mkpeephole to be run in the host during the build. However, these
110# binaries must have the same bit-width as the target (e.g. a x86_64
111# host targeting ARMv6 needs to produce a 32-bit binary). Instead of
112# depending on a third Yocto toolchain, we just build those binaries
113# for the target and run them on the host with QEMU.
114python do_create_v8_qemu_wrapper () {
115 """Creates a small wrapper that invokes QEMU to run some target V8 binaries
116 on the host."""
117 qemu_libdirs = [d.expand('${STAGING_DIR_HOST}${libdir}'),
118 d.expand('${STAGING_DIR_HOST}${base_libdir}')]
Patrick Williams864cc432023-02-09 14:54:44 -0600119 qemu_cmd = qemu_wrapper_cmdline(d, d.getVar('STAGING_DIR_HOST'),
Andrew Geissler517393d2023-01-13 08:55:19 -0600120 qemu_libdirs)
121 wrapper_path = d.expand('${B}/v8-qemu-wrapper.sh')
122 with open(wrapper_path, 'w') as wrapper_file:
123 wrapper_file.write("""#!/bin/sh
124
125# This file has been generated automatically.
126# It invokes QEMU to run binaries built for the target in the host during the
127# build process.
128
129%s "$@"
130""" % qemu_cmd)
131 os.chmod(wrapper_path, 0o755)
132}
133
134do_create_v8_qemu_wrapper[dirs] = "${B}"
135addtask create_v8_qemu_wrapper after do_configure before do_compile
136
137LDFLAGS:append:x86 = " -latomic"
138
Andrew Geissler6aa7eec2023-03-03 12:41:14 -0600139CROSS_FLAGS = "--cross-compiling"
140CROSS_FLAGS:class-native = "--no-cross-compiling"
141
Andrew Geissler517393d2023-01-13 08:55:19 -0600142# Node is way too cool to use proper autotools, so we install two wrappers to forcefully inject proper arch cflags to workaround gypi
143do_configure () {
Andrew Geissler517393d2023-01-13 08:55:19 -0600144 GYP_DEFINES="${GYP_DEFINES}" export GYP_DEFINES
145 # $TARGET_ARCH settings don't match --dest-cpu settings
Andrew Geissler6aa7eec2023-03-03 12:41:14 -0600146 python3 configure.py --verbose --prefix=${prefix} \
Andrew Geissler517393d2023-01-13 08:55:19 -0600147 --shared-openssl \
Andrew Geissler517393d2023-01-13 08:55:19 -0600148 --dest-cpu="${@map_nodejs_arch(d.getVar('TARGET_ARCH'), d)}" \
149 --dest-os=linux \
Andrew Geissler6aa7eec2023-03-03 12:41:14 -0600150 --libdir=${baselib} \
151 ${CROSS_FLAGS} \
Andrew Geissler517393d2023-01-13 08:55:19 -0600152 ${ARCHFLAGS} \
153 ${PACKAGECONFIG_CONFARGS}
154}
155
156do_compile () {
Andrew Geisslerc5535c92023-01-27 16:10:19 -0600157 install -D ${RECIPE_SYSROOT_NATIVE}/etc/ssl/openssl.cnf ${B}/deps/openssl/nodejs-openssl.cnf
Andrew Geissler517393d2023-01-13 08:55:19 -0600158 install -D ${B}/v8-qemu-wrapper.sh ${B}/out/Release/v8-qemu-wrapper.sh
159 oe_runmake BUILDTYPE=Release
160}
161
162do_install () {
163 oe_runmake install DESTDIR=${D}
164}
165
Andrew Geisslerc5535c92023-01-27 16:10:19 -0600166do_install_ptest () {
167 cp -r ${B}/out/Release/cctest ${D}${PTEST_PATH}/
168 cp -r ${B}/test ${D}${PTEST_PATH}
169 chown -R root:root ${D}${PTEST_PATH}
170}
171
Andrew Geissler517393d2023-01-13 08:55:19 -0600172PACKAGES =+ "${PN}-npm"
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500173FILES:${PN}-npm = "${nonarch_libdir}/node_modules ${bindir}/npm ${bindir}/npx ${bindir}/corepack"
Andrew Geissler517393d2023-01-13 08:55:19 -0600174RDEPENDS:${PN}-npm = "bash python3-core python3-shell python3-datetime \
175 python3-misc python3-multiprocessing"
176
177PACKAGES =+ "${PN}-systemtap"
178FILES:${PN}-systemtap = "${datadir}/systemtap"
179
180BBCLASSEXTEND = "native"