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