blob: 62188f94a72ccbe6f67fe76fe1124e82fc213973 [file] [log] [blame]
Andrew Geissler9aee5002022-03-30 16:27:02 +00001DESCRIPTION = "nodeJS Evented I/O for V8 JavaScript"
2HOMEPAGE = "http://nodejs.org"
3LICENSE = "MIT & ISC & BSD-2-Clause & BSD-3-Clause & Artistic-2.0"
4LIC_FILES_CHKSUM = "file://LICENSE;md5=6ba5b21ac7a505195ca69344d3d7a94a"
5
6DEPENDS = "openssl"
7DEPENDS:append:class-target = " qemu-native"
8DEPENDS:append:class-native = " c-ares-native"
9
10inherit pkgconfig python3native qemu
11
12COMPATIBLE_MACHINE:armv4 = "(!.*armv4).*"
13COMPATIBLE_MACHINE:armv5 = "(!.*armv5).*"
14COMPATIBLE_MACHINE:mips64 = "(!.*mips64).*"
15
16COMPATIBLE_HOST:riscv64 = "null"
17COMPATIBLE_HOST:riscv32 = "null"
18COMPATIBLE_HOST:powerpc = "null"
19
20SRC_URI = "http://nodejs.org/dist/v${PV}/node-v${PV}.tar.xz \
21 file://0001-Disable-running-gyp-files-for-bundled-deps.patch \
22 file://0002-Install-both-binaries-and-use-libdir.patch \
23 file://0004-v8-don-t-override-ARM-CFLAGS.patch \
24 file://0005-add-openssl-legacy-provider-option.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 \
Patrick Williams03907ee2022-05-01 06:28:52 -050029 file://0001-mips-Use-32bit-cast-for-operand-on-mips32.patch \
Andrew Geissler9aee5002022-03-30 16:27:02 +000030 "
31SRC_URI:append:class-target = " \
32 file://0002-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 Williams03907ee2022-05-01 06:28:52 -050040SRC_URI[sha256sum] = "e922e215cc68eb5f94d33e8a0b61e2c863b7731cc8600ab955d3822da90ff8d1"
Andrew Geissler9aee5002022-03-30 16:27:02 +000041
42S = "${WORKDIR}/node-v${PV}"
43
44# v8 errors out if you have set CCACHE
45CCACHE = ""
46
47def map_nodejs_arch(a, d):
48 import re
49
50 if re.match('i.86$', a): return 'ia32'
51 elif re.match('x86_64$', a): return 'x64'
52 elif re.match('aarch64$', a): return 'arm64'
53 elif re.match('(powerpc64|powerpc64le|ppc64le)$', a): return 'ppc64'
54 elif re.match('powerpc$', a): return 'ppc'
55 return a
56
57ARCHFLAGS:arm = "${@bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', '--with-arm-float-abi=hard', '--with-arm-float-abi=softfp', d)} \
58 ${@bb.utils.contains('TUNE_FEATURES', 'neon', '--with-arm-fpu=neon', \
59 bb.utils.contains('TUNE_FEATURES', 'vfpv3d16', '--with-arm-fpu=vfpv3-d16', \
60 bb.utils.contains('TUNE_FEATURES', 'vfpv3', '--with-arm-fpu=vfpv3', \
61 '--with-arm-fpu=vfp', d), d), d)}"
62ARCHFLAGS:append:mips = " --v8-lite-mode"
63ARCHFLAGS:append:mipsel = " --v8-lite-mode"
64ARCHFLAGS ?= ""
65
66PACKAGECONFIG ??= "ares brotli icu zlib"
67
68PACKAGECONFIG[ares] = "--shared-cares,,c-ares"
69PACKAGECONFIG[brotli] = "--shared-brotli,,brotli"
70PACKAGECONFIG[icu] = "--with-intl=system-icu,--without-intl,icu"
71PACKAGECONFIG[libuv] = "--shared-libuv,,libuv"
72PACKAGECONFIG[nghttp2] = "--shared-nghttp2,,nghttp2"
73PACKAGECONFIG[shared] = "--shared"
74PACKAGECONFIG[zlib] = "--shared-zlib,,zlib"
75
76# We don't want to cross-compile during target compile,
77# and we need to use the right flags during host compile,
78# too.
79EXTRA_OEMAKE = "\
80 CC.host='${CC}' \
81 CFLAGS.host='${CPPFLAGS} ${CFLAGS}' \
82 CXX.host='${CXX}' \
83 CXXFLAGS.host='${CPPFLAGS} ${CXXFLAGS}' \
84 LDFLAGS.host='${LDFLAGS}' \
85 AR.host='${AR}' \
86 \
87 builddir_name=./ \
88"
89
90python do_unpack() {
91 import shutil
92
93 bb.build.exec_func('base_do_unpack', d)
94 shutil.rmtree(d.getVar('S') + '/deps/openssl', True)
95 if 'ares' in d.getVar('PACKAGECONFIG'):
96 shutil.rmtree(d.getVar('S') + '/deps/cares', True)
97 if 'brotli' in d.getVar('PACKAGECONFIG'):
98 shutil.rmtree(d.getVar('S') + '/deps/brotli', True)
99 if 'libuv' in d.getVar('PACKAGECONFIG'):
100 shutil.rmtree(d.getVar('S') + '/deps/uv', True)
101 if 'nghttp2' in d.getVar('PACKAGECONFIG'):
102 shutil.rmtree(d.getVar('S') + '/deps/nghttp2', True)
103 if 'zlib' in d.getVar('PACKAGECONFIG'):
104 shutil.rmtree(d.getVar('S') + '/deps/zlib', True)
105}
106
107# V8's JIT infrastructure requires binaries such as mksnapshot and
108# mkpeephole to be run in the host during the build. However, these
109# binaries must have the same bit-width as the target (e.g. a x86_64
110# host targeting ARMv6 needs to produce a 32-bit binary). Instead of
111# depending on a third Yocto toolchain, we just build those binaries
112# for the target and run them on the host with QEMU.
113python do_create_v8_qemu_wrapper () {
114 """Creates a small wrapper that invokes QEMU to run some target V8 binaries
115 on the host."""
116 qemu_libdirs = [d.expand('${STAGING_DIR_HOST}${libdir}'),
117 d.expand('${STAGING_DIR_HOST}${base_libdir}')]
118 qemu_cmd = qemu_wrapper_cmdline(d, d.getVar('STAGING_DIR_HOST', True),
119 qemu_libdirs)
120 wrapper_path = d.expand('${B}/v8-qemu-wrapper.sh')
121 with open(wrapper_path, 'w') as wrapper_file:
122 wrapper_file.write("""#!/bin/sh
123
124# This file has been generated automatically.
125# It invokes QEMU to run binaries built for the target in the host during the
126# build process.
127
128%s "$@"
129""" % qemu_cmd)
130 os.chmod(wrapper_path, 0o755)
131}
132
133do_create_v8_qemu_wrapper[dirs] = "${B}"
134addtask create_v8_qemu_wrapper after do_configure before do_compile
135
136LDFLAGS:append:x86 = " -latomic"
137
138# Node is way too cool to use proper autotools, so we install two wrappers to forcefully inject proper arch cflags to workaround gypi
139do_configure () {
140 export LD="${CXX}"
141 GYP_DEFINES="${GYP_DEFINES}" export GYP_DEFINES
142 # $TARGET_ARCH settings don't match --dest-cpu settings
143 python3 configure.py --prefix=${prefix} --cross-compiling \
144 --shared-openssl \
145 --without-dtrace \
146 --without-etw \
147 --dest-cpu="${@map_nodejs_arch(d.getVar('TARGET_ARCH'), d)}" \
148 --dest-os=linux \
149 --libdir=${D}${libdir} \
150 ${ARCHFLAGS} \
151 ${PACKAGECONFIG_CONFARGS}
152}
153
154do_compile () {
155 export LD="${CXX}"
156 install -D ${B}/v8-qemu-wrapper.sh ${B}/out/Release/v8-qemu-wrapper.sh
157 oe_runmake BUILDTYPE=Release
158}
159
160do_install () {
161 oe_runmake install DESTDIR=${D}
162}
163
164BINARIES = " \
165 bytecode_builtins_list_generator \
166 ${@bb.utils.contains('PACKAGECONFIG', 'icu', 'gen-regexp-special-case', '', d)} \
167 mkcodecache \
168 node_mksnapshot \
169 torque \
170"
171
172do_install:append:class-native() {
173 # Install the native binaries to provide it within sysroot for the target compilation
174 install -d ${D}${bindir}
175 (cd ${S}/out/Release && install ${BINARIES} ${D}${bindir})
176}
177
178PACKAGES =+ "${PN}-npm"
179FILES:${PN}-npm = "${nonarch_libdir}/node_modules ${bindir}/npm ${bindir}/npx"
180RDEPENDS:${PN}-npm = "bash python3-core python3-shell python3-datetime \
181 python3-misc python3-multiprocessing"
182
183PACKAGES =+ "${PN}-systemtap"
184FILES:${PN}-systemtap = "${datadir}/systemtap"
185
186BBCLASSEXTEND = "native"