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