blob: 48bf2f4a8a0f07dc83a044c9bf68112536d32297 [file] [log] [blame]
Andrew Geissler82c905d2020-04-13 13:39:40 -05001DESCRIPTION = "nodeJS Evented I/O for V8 JavaScript"
2HOMEPAGE = "http://nodejs.org"
3LICENSE = "MIT & BSD & Artistic-2.0"
Andrew Geisslerf103a7f2021-05-07 16:09:40 -05004LIC_FILES_CHKSUM = "file://LICENSE;md5=85bf260d8b6de1588f57abc5dc66587c"
Andrew Geissler82c905d2020-04-13 13:39:40 -05005
6DEPENDS = "openssl"
Andrew Geisslerf103a7f2021-05-07 16:09:40 -05007DEPENDS_append_class-target = " qemu-native"
Andrew Geissler82c905d2020-04-13 13:39:40 -05008
Andrew Geisslerf103a7f2021-05-07 16:09:40 -05009inherit pkgconfig python3native qemu
Andrew Geissler82c905d2020-04-13 13:39:40 -050010
11COMPATIBLE_MACHINE_armv4 = "(!.*armv4).*"
12COMPATIBLE_MACHINE_armv5 = "(!.*armv5).*"
13COMPATIBLE_MACHINE_mips64 = "(!.*mips64).*"
14
15COMPATIBLE_HOST_riscv64 = "null"
16COMPATIBLE_HOST_riscv32 = "null"
17
18SRC_URI = "http://nodejs.org/dist/v${PV}/node-v${PV}.tar.xz \
19 file://0001-Disable-running-gyp-files-for-bundled-deps.patch \
20 file://0003-Install-both-binaries-and-use-libdir.patch \
21 file://0004-v8-don-t-override-ARM-CFLAGS.patch \
22 file://big-endian.patch \
Andrew Geissler82c905d2020-04-13 13:39:40 -050023 file://mips-warnings.patch \
Andrew Geisslerf103a7f2021-05-07 16:09:40 -050024 file://v8-call-new-ListFormatter-createInstance.patch \
25 file://mips-less-memory.patch \
Andrew Geissler82c905d2020-04-13 13:39:40 -050026 "
27SRC_URI_append_class-target = " \
28 file://0002-Using-native-binaries.patch \
29 "
Andrew Geisslerf103a7f2021-05-07 16:09:40 -050030SRC_URI_append_toolchain-clang_x86 = " \
31 file://libatomic.patch \
32 "
33SRC_URI[sha256sum] = "e44adbbed6756c2c1a01258383e9f00df30c147b36e438f6369b5ef1069abac3"
Andrew Geissler82c905d2020-04-13 13:39:40 -050034
35S = "${WORKDIR}/node-v${PV}"
36
37# v8 errors out if you have set CCACHE
38CCACHE = ""
39
40def map_nodejs_arch(a, d):
41 import re
42
43 if re.match('i.86$', a): return 'ia32'
44 elif re.match('x86_64$', a): return 'x64'
45 elif re.match('aarch64$', a): return 'arm64'
Andrew Geisslerc2a772f2021-04-01 10:06:38 -050046 elif re.match('(powerpc64|powerpc64le|ppc64le)$', a): return 'ppc64'
Andrew Geissler82c905d2020-04-13 13:39:40 -050047 elif re.match('powerpc$', a): return 'ppc'
48 return a
49
50ARCHFLAGS_arm = "${@bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', '--with-arm-float-abi=hard', '--with-arm-float-abi=softfp', d)} \
51 ${@bb.utils.contains('TUNE_FEATURES', 'neon', '--with-arm-fpu=neon', \
52 bb.utils.contains('TUNE_FEATURES', 'vfpv3d16', '--with-arm-fpu=vfpv3-d16', \
53 bb.utils.contains('TUNE_FEATURES', 'vfpv3', '--with-arm-fpu=vfpv3', \
54 '--with-arm-fpu=vfp', d), d), d)}"
55GYP_DEFINES_append_mipsel = " mips_arch_variant='r1' "
56ARCHFLAGS ?= ""
57
Andrew Geisslerbffdb3e2020-08-21 16:13:29 -050058PACKAGECONFIG ??= "ares brotli icu zlib"
59
Andrew Geissler82c905d2020-04-13 13:39:40 -050060PACKAGECONFIG[ares] = "--shared-cares,,c-ares"
61PACKAGECONFIG[brotli] = "--shared-brotli,,brotli"
62PACKAGECONFIG[icu] = "--with-intl=system-icu,--without-intl,icu"
63PACKAGECONFIG[libuv] = "--shared-libuv,,libuv"
64PACKAGECONFIG[nghttp2] = "--shared-nghttp2,,nghttp2"
65PACKAGECONFIG[shared] = "--shared"
66PACKAGECONFIG[zlib] = "--shared-zlib,,zlib"
67
68# We don't want to cross-compile during target compile,
69# and we need to use the right flags during host compile,
70# too.
71EXTRA_OEMAKE = "\
72 CC.host='${CC}' \
73 CFLAGS.host='${CPPFLAGS} ${CFLAGS}' \
74 CXX.host='${CXX}' \
75 CXXFLAGS.host='${CPPFLAGS} ${CXXFLAGS}' \
76 LDFLAGS.host='${LDFLAGS}' \
77 AR.host='${AR}' \
78 \
79 builddir_name=./ \
80"
81
82python do_unpack() {
83 import shutil
84
85 bb.build.exec_func('base_do_unpack', d)
86
87 shutil.rmtree(d.getVar('S') + '/deps/openssl', True)
88 if 'ares' in d.getVar('PACKAGECONFIG'):
89 shutil.rmtree(d.getVar('S') + '/deps/cares', True)
90 if 'brotli' in d.getVar('PACKAGECONFIG'):
91 shutil.rmtree(d.getVar('S') + '/deps/brotli', True)
92 if 'libuv' in d.getVar('PACKAGECONFIG'):
93 shutil.rmtree(d.getVar('S') + '/deps/uv', True)
94 if 'nghttp2' in d.getVar('PACKAGECONFIG'):
95 shutil.rmtree(d.getVar('S') + '/deps/nghttp2', True)
96 if 'zlib' in d.getVar('PACKAGECONFIG'):
97 shutil.rmtree(d.getVar('S') + '/deps/zlib', True)
98}
99
Andrew Geisslerf103a7f2021-05-07 16:09:40 -0500100# V8's JIT infrastructure requires binaries such as mksnapshot and
101# mkpeephole to be run in the host during the build. However, these
102# binaries must have the same bit-width as the target (e.g. a x86_64
103# host targeting ARMv6 needs to produce a 32-bit binary). Instead of
104# depending on a third Yocto toolchain, we just build those binaries
105# for the target and run them on the host with QEMU.
106python do_create_v8_qemu_wrapper () {
107 """Creates a small wrapper that invokes QEMU to run some target V8 binaries
108 on the host."""
109 qemu_libdirs = [d.expand('${STAGING_DIR_HOST}${libdir}'),
110 d.expand('${STAGING_DIR_HOST}${base_libdir}')]
111 qemu_cmd = qemu_wrapper_cmdline(d, d.getVar('STAGING_DIR_HOST', True),
112 qemu_libdirs)
113 wrapper_path = d.expand('${B}/v8-qemu-wrapper.sh')
114 with open(wrapper_path, 'w') as wrapper_file:
115 wrapper_file.write("""#!/bin/sh
116
117# This file has been generated automatically.
118# It invokes QEMU to run binaries built for the target in the host during the
119# build process.
120
121%s "$@"
122""" % qemu_cmd)
123 os.chmod(wrapper_path, 0o755)
124}
125
126do_create_v8_qemu_wrapper[dirs] = "${B}"
127addtask create_v8_qemu_wrapper after do_configure before do_compile
128
129LDFLAGS_append_x86 = " -latomic"
130
Andrew Geissler82c905d2020-04-13 13:39:40 -0500131# Node is way too cool to use proper autotools, so we install two wrappers to forcefully inject proper arch cflags to workaround gypi
132do_configure () {
133 export LD="${CXX}"
134 GYP_DEFINES="${GYP_DEFINES}" export GYP_DEFINES
135 # $TARGET_ARCH settings don't match --dest-cpu settings
Andrew Geisslerf103a7f2021-05-07 16:09:40 -0500136 python3 configure.py --prefix=${prefix} --cross-compiling --shared-openssl \
Andrew Geissler82c905d2020-04-13 13:39:40 -0500137 --without-dtrace \
138 --without-etw \
139 --dest-cpu="${@map_nodejs_arch(d.getVar('TARGET_ARCH'), d)}" \
140 --dest-os=linux \
141 --libdir=${D}${libdir} \
142 ${ARCHFLAGS} \
143 ${PACKAGECONFIG_CONFARGS}
144}
145
146do_compile () {
147 export LD="${CXX}"
Andrew Geisslerf103a7f2021-05-07 16:09:40 -0500148 install -Dm 0755 ${B}/v8-qemu-wrapper.sh ${B}/out/Release/v8-qemu-wrapper.sh
Andrew Geissler82c905d2020-04-13 13:39:40 -0500149 oe_runmake BUILDTYPE=Release
150}
151
152do_install () {
153 oe_runmake install DESTDIR=${D}
154
155 # wasn't updated since 2009 and is the only thing requiring python2 in runtime
156 # ERROR: nodejs-12.14.1-r0 do_package_qa: QA Issue: /usr/lib/node_modules/npm/node_modules/node-gyp/gyp/samples/samples contained in package nodejs-npm requires /usr/bin/python, but no providers found in RDEPENDS_nodejs-npm? [file-rdeps]
157 rm -f ${D}${exec_prefix}/lib/node_modules/npm/node_modules/node-gyp/gyp/samples/samples
158}
159
160do_install_append_class-native() {
161 # use node from PATH instead of absolute path to sysroot
162 # node-v0.10.25/tools/install.py is using:
163 # shebang = os.path.join(node_prefix, 'bin/node')
164 # update_shebang(link_path, shebang)
165 # and node_prefix can be very long path to bindir in native sysroot and
166 # when it exceeds 128 character shebang limit it's stripped to incorrect path
167 # and npm fails to execute like in this case with 133 characters show in log.do_install:
168 # updating shebang of /home/jenkins/workspace/build-webos-nightly/device/qemux86/label/open-webos-builder/BUILD-qemux86/work/x86_64-linux/nodejs-native/0.10.15-r0/image/home/jenkins/workspace/build-webos-nightly/device/qemux86/label/open-webos-builder/BUILD-qemux86/sysroots/x86_64-linux/usr/bin/npm to /home/jenkins/workspace/build-webos-nightly/device/qemux86/label/open-webos-builder/BUILD-qemux86/sysroots/x86_64-linux/usr/bin/node
169 # /usr/bin/npm is symlink to /usr/lib/node_modules/npm/bin/npm-cli.js
170 # use sed on npm-cli.js because otherwise symlink is replaced with normal file and
171 # npm-cli.js continues to use old shebang
172 sed "1s^.*^#\!/usr/bin/env node^g" -i ${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js
173
174 # Install the native binaries to provide it within sysroot for the target compilation
175 install -d ${D}${bindir}
176 install -m 0755 ${S}/out/Release/torque ${D}${bindir}/torque
177 install -m 0755 ${S}/out/Release/bytecode_builtins_list_generator ${D}${bindir}/bytecode_builtins_list_generator
178 if ${@bb.utils.contains('PACKAGECONFIG','icu','true','false',d)}; then
179 install -m 0755 ${S}/out/Release/gen-regexp-special-case ${D}${bindir}/gen-regexp-special-case
180 fi
181 install -m 0755 ${S}/out/Release/mkcodecache ${D}${bindir}/mkcodecache
182 install -m 0755 ${S}/out/Release/node_mksnapshot ${D}${bindir}/node_mksnapshot
183}
184
185do_install_append_class-target() {
186 sed "1s^.*^#\!${bindir}/env node^g" -i ${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js
187}
188
189PACKAGES =+ "${PN}-npm"
190FILES_${PN}-npm = "${exec_prefix}/lib/node_modules ${bindir}/npm ${bindir}/npx"
191RDEPENDS_${PN}-npm = "bash python3-core python3-shell python3-datetime \
192 python3-misc python3-multiprocessing"
193
194PACKAGES =+ "${PN}-systemtap"
195FILES_${PN}-systemtap = "${datadir}/systemtap"
196
197BBCLASSEXTEND = "native"