blob: 5ac4f9dc7d000da0264891260ef0f13c95ad4314 [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 Geissler69721092021-07-23 12:57:00 -04004LIC_FILES_CHKSUM = "file://LICENSE;md5=a1016f9b7979cfe6fc3466a9bba60b1e"
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://mips-less-memory.patch \
Andrew Geissler82c905d2020-04-13 13:39:40 -050025 "
26SRC_URI_append_class-target = " \
27 file://0002-Using-native-binaries.patch \
28 "
Andrew Geisslerf103a7f2021-05-07 16:09:40 -050029SRC_URI_append_toolchain-clang_x86 = " \
30 file://libatomic.patch \
31 "
Andrew Geissler69721092021-07-23 12:57:00 -040032SRC_URI_append_toolchain-clang_powerpc64le = " \
33 file://0001-ppc64-Do-not-use-mminimal-toc-with-clang.patch \
34 "
35SRC_URI[sha256sum] = "ddf1d2d56ddf35ecd98c5ea5ddcd690b245899f289559b4330c921255f5a247f"
Andrew Geissler82c905d2020-04-13 13:39:40 -050036
37S = "${WORKDIR}/node-v${PV}"
38
39# v8 errors out if you have set CCACHE
40CCACHE = ""
41
42def map_nodejs_arch(a, d):
43 import re
44
45 if re.match('i.86$', a): return 'ia32'
46 elif re.match('x86_64$', a): return 'x64'
47 elif re.match('aarch64$', a): return 'arm64'
Andrew Geisslerc2a772f2021-04-01 10:06:38 -050048 elif re.match('(powerpc64|powerpc64le|ppc64le)$', a): return 'ppc64'
Andrew Geissler82c905d2020-04-13 13:39:40 -050049 elif re.match('powerpc$', a): return 'ppc'
50 return a
51
52ARCHFLAGS_arm = "${@bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', '--with-arm-float-abi=hard', '--with-arm-float-abi=softfp', d)} \
53 ${@bb.utils.contains('TUNE_FEATURES', 'neon', '--with-arm-fpu=neon', \
54 bb.utils.contains('TUNE_FEATURES', 'vfpv3d16', '--with-arm-fpu=vfpv3-d16', \
55 bb.utils.contains('TUNE_FEATURES', 'vfpv3', '--with-arm-fpu=vfpv3', \
56 '--with-arm-fpu=vfp', d), d), d)}"
57GYP_DEFINES_append_mipsel = " mips_arch_variant='r1' "
58ARCHFLAGS ?= ""
59
Andrew Geisslerbffdb3e2020-08-21 16:13:29 -050060PACKAGECONFIG ??= "ares brotli icu zlib"
61
Andrew Geissler82c905d2020-04-13 13:39:40 -050062PACKAGECONFIG[ares] = "--shared-cares,,c-ares"
63PACKAGECONFIG[brotli] = "--shared-brotli,,brotli"
64PACKAGECONFIG[icu] = "--with-intl=system-icu,--without-intl,icu"
65PACKAGECONFIG[libuv] = "--shared-libuv,,libuv"
66PACKAGECONFIG[nghttp2] = "--shared-nghttp2,,nghttp2"
67PACKAGECONFIG[shared] = "--shared"
68PACKAGECONFIG[zlib] = "--shared-zlib,,zlib"
69
70# We don't want to cross-compile during target compile,
71# and we need to use the right flags during host compile,
72# too.
73EXTRA_OEMAKE = "\
74 CC.host='${CC}' \
75 CFLAGS.host='${CPPFLAGS} ${CFLAGS}' \
76 CXX.host='${CXX}' \
77 CXXFLAGS.host='${CPPFLAGS} ${CXXFLAGS}' \
78 LDFLAGS.host='${LDFLAGS}' \
79 AR.host='${AR}' \
80 \
81 builddir_name=./ \
82"
83
84python do_unpack() {
85 import shutil
86
87 bb.build.exec_func('base_do_unpack', d)
88
89 shutil.rmtree(d.getVar('S') + '/deps/openssl', True)
90 if 'ares' in d.getVar('PACKAGECONFIG'):
91 shutil.rmtree(d.getVar('S') + '/deps/cares', True)
92 if 'brotli' in d.getVar('PACKAGECONFIG'):
93 shutil.rmtree(d.getVar('S') + '/deps/brotli', True)
94 if 'libuv' in d.getVar('PACKAGECONFIG'):
95 shutil.rmtree(d.getVar('S') + '/deps/uv', True)
96 if 'nghttp2' in d.getVar('PACKAGECONFIG'):
97 shutil.rmtree(d.getVar('S') + '/deps/nghttp2', True)
98 if 'zlib' in d.getVar('PACKAGECONFIG'):
99 shutil.rmtree(d.getVar('S') + '/deps/zlib', True)
100}
101
Andrew Geisslerf103a7f2021-05-07 16:09:40 -0500102# V8's JIT infrastructure requires binaries such as mksnapshot and
103# mkpeephole to be run in the host during the build. However, these
104# binaries must have the same bit-width as the target (e.g. a x86_64
105# host targeting ARMv6 needs to produce a 32-bit binary). Instead of
106# depending on a third Yocto toolchain, we just build those binaries
107# for the target and run them on the host with QEMU.
108python do_create_v8_qemu_wrapper () {
109 """Creates a small wrapper that invokes QEMU to run some target V8 binaries
110 on the host."""
111 qemu_libdirs = [d.expand('${STAGING_DIR_HOST}${libdir}'),
112 d.expand('${STAGING_DIR_HOST}${base_libdir}')]
113 qemu_cmd = qemu_wrapper_cmdline(d, d.getVar('STAGING_DIR_HOST', True),
114 qemu_libdirs)
115 wrapper_path = d.expand('${B}/v8-qemu-wrapper.sh')
116 with open(wrapper_path, 'w') as wrapper_file:
117 wrapper_file.write("""#!/bin/sh
118
119# This file has been generated automatically.
120# It invokes QEMU to run binaries built for the target in the host during the
121# build process.
122
123%s "$@"
124""" % qemu_cmd)
125 os.chmod(wrapper_path, 0o755)
126}
127
128do_create_v8_qemu_wrapper[dirs] = "${B}"
129addtask create_v8_qemu_wrapper after do_configure before do_compile
130
131LDFLAGS_append_x86 = " -latomic"
132
Andrew Geissler82c905d2020-04-13 13:39:40 -0500133# Node is way too cool to use proper autotools, so we install two wrappers to forcefully inject proper arch cflags to workaround gypi
134do_configure () {
135 export LD="${CXX}"
136 GYP_DEFINES="${GYP_DEFINES}" export GYP_DEFINES
137 # $TARGET_ARCH settings don't match --dest-cpu settings
Andrew Geisslerf103a7f2021-05-07 16:09:40 -0500138 python3 configure.py --prefix=${prefix} --cross-compiling --shared-openssl \
Andrew Geissler82c905d2020-04-13 13:39:40 -0500139 --without-dtrace \
140 --without-etw \
141 --dest-cpu="${@map_nodejs_arch(d.getVar('TARGET_ARCH'), d)}" \
142 --dest-os=linux \
143 --libdir=${D}${libdir} \
144 ${ARCHFLAGS} \
145 ${PACKAGECONFIG_CONFARGS}
146}
147
148do_compile () {
149 export LD="${CXX}"
Andrew Geisslerf103a7f2021-05-07 16:09:40 -0500150 install -Dm 0755 ${B}/v8-qemu-wrapper.sh ${B}/out/Release/v8-qemu-wrapper.sh
Andrew Geissler82c905d2020-04-13 13:39:40 -0500151 oe_runmake BUILDTYPE=Release
152}
153
154do_install () {
155 oe_runmake install DESTDIR=${D}
156
157 # wasn't updated since 2009 and is the only thing requiring python2 in runtime
158 # 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]
159 rm -f ${D}${exec_prefix}/lib/node_modules/npm/node_modules/node-gyp/gyp/samples/samples
160}
161
162do_install_append_class-native() {
163 # use node from PATH instead of absolute path to sysroot
164 # node-v0.10.25/tools/install.py is using:
165 # shebang = os.path.join(node_prefix, 'bin/node')
166 # update_shebang(link_path, shebang)
167 # and node_prefix can be very long path to bindir in native sysroot and
168 # when it exceeds 128 character shebang limit it's stripped to incorrect path
169 # and npm fails to execute like in this case with 133 characters show in log.do_install:
170 # 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
171 # /usr/bin/npm is symlink to /usr/lib/node_modules/npm/bin/npm-cli.js
172 # use sed on npm-cli.js because otherwise symlink is replaced with normal file and
173 # npm-cli.js continues to use old shebang
174 sed "1s^.*^#\!/usr/bin/env node^g" -i ${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js
175
176 # Install the native binaries to provide it within sysroot for the target compilation
177 install -d ${D}${bindir}
178 install -m 0755 ${S}/out/Release/torque ${D}${bindir}/torque
179 install -m 0755 ${S}/out/Release/bytecode_builtins_list_generator ${D}${bindir}/bytecode_builtins_list_generator
180 if ${@bb.utils.contains('PACKAGECONFIG','icu','true','false',d)}; then
181 install -m 0755 ${S}/out/Release/gen-regexp-special-case ${D}${bindir}/gen-regexp-special-case
182 fi
183 install -m 0755 ${S}/out/Release/mkcodecache ${D}${bindir}/mkcodecache
184 install -m 0755 ${S}/out/Release/node_mksnapshot ${D}${bindir}/node_mksnapshot
185}
186
187do_install_append_class-target() {
188 sed "1s^.*^#\!${bindir}/env node^g" -i ${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js
189}
190
191PACKAGES =+ "${PN}-npm"
192FILES_${PN}-npm = "${exec_prefix}/lib/node_modules ${bindir}/npm ${bindir}/npx"
193RDEPENDS_${PN}-npm = "bash python3-core python3-shell python3-datetime \
194 python3-misc python3-multiprocessing"
195
196PACKAGES =+ "${PN}-systemtap"
197FILES_${PN}-systemtap = "${datadir}/systemtap"
198
199BBCLASSEXTEND = "native"