I have managed to produce a working Node.js 6 binary for OpenWrt and RPi (brcm2708/brcm2709).
Binaries
15.05.1: brcm2708 | 6.9.5 | |
15.05.1: brcm2709 | 6.9.5 | |
15.05.1: mvebu | 6.9.5 | Please test (on WRT1x00AC router) and get back to me with feedback |
15.05.1: x86 | 6.9.5 | Please test and get back to me with feedback |
Note: all the binaries work with equal performance on RPi v2 (brcm2709). For practical purposes the brcm2708 may be the only binary needed.
How to build 6.9.5 brcm2708/brcm2709
The procudure is:
- Set PATH and STAGING_DIR
- Set a few compiler flags and run configure with not so few options
- Fix nearbyint/nearbyintf
- Fix config.gypi
- make
1. I have a little script to set my toolchain variables.
# file: env-15.05.1-brcm2709.sh # usage: $ source ./env-15.05.1-brcm2709.sh PATH=/path/to/staging_dir/bin:$PATH export PATH STAGING_DIR=/path/to/staging_dir export STAGING_DIR
Your path should now contain arm-openwrt-linux-uclibcgnueabi-g++ and other binaries.
2. (brcm2709 / mvebu) I have another script to run configure:
#!/bin/sh -e #Tools export CSTOOLS="$STAGING_DIR" export CSTOOLS_INC=${CSTOOLS}/include export CSTOOLS_LIB=${CSTOOLS}/lib export CC="arm-openwrt-linux-uclibcgnueabi-gcc" export CXX="arm-openwrt-linux-uclibcgnueabi-g++" export LD="arm-openwrt-linux-uclibcgnueabi-ld" export CFLAGS="-isystem${CSTOOLS_INC} -mfloat-abi=softfp" export CPPFLAGS="-isystem${CSTOOLS_INC} -mfloat-abi=softfp" export PATH="${CSTOOLS}/bin:$PATH" ./configure --without-snapshot --dest-cpu=arm --dest-os=linux --without-npm --without-ssl --without-intl --without-inspector bash --norc
Please not that this script was the first one that worked. It may not be the best. Some things may not be needed. –without-intl and –without-inspector helped me avoid build errors. If you need those features you have more work to do.
2. (brcm2708)
#!/bin/sh -e #Tools export CSTOOLS="$STAGING_DIR" export CSTOOLS_INC=${CSTOOLS}/include export CSTOOLS_LIB=${CSTOOLS}/lib export CC="arm-openwrt-linux-uclibcgnueabi-gcc" export CXX="arm-openwrt-linux-uclibcgnueabi-g++" export LD="arm-openwrt-linux-uclibcgnueabi-ld" export CFLAGS="-isystem${CSTOOLS_INC} -march=armv6j -mfloat-abi=softfp" export CPPFLAGS="-isystem${CSTOOLS_INC} -march=armv6j -mfloat-abi=softfp" export PATH="${CSTOOLS}/bin:$PATH" ./configure --without-snapshot --dest-cpu=arm --dest-os=linux --without-npm --without-ssl --without-intl --without-inspector bash --norc
3. Use “grep -nR nearbyint” to find and replace:
nearbyint => round nearbyintf => roundf
This may not be a good idea! However, nearbyint(f) is not supported in OpenWrt, and with the above replacements Node.js builds and it passes the octane benchmark – so it is not that broken. I suppose there is correct way to replace nearbyint(f).
4. Add to config.gypi:
{ 'target_defaults': { 'cflags': [ '-D__STDC_LIMIT_MACROS' ,'-D__STDC_CONSTANT_MACROS'], 'ldflags': [ '-Wl,-rpath,/path/to/staging_dir/lib/' ]},
These are just compilation error workarounds.
This works for me.
Dependencies
You need to install dependencies in OpenWrt:
# opkg update # opkg install librt # opkg install libstdcpp
Performance
My initial tests indicate that Node.js v6 is a little (~2%) slower than Node.js 4 on ARM v7 (RPi v2).
Other targets
mvebu: I will build a binary, but I need help to test
x86/x86_64: This shall be easy, but I see little need/use. Let me know if you want a binary.
mpc85xx: The chip is quite capable, but the PowerPC port of Node.js will most likely never support it.
Most MIPS architectures lack FPU and are truly unsuitable for running Node.js.
std::snprintf
It seems the OpenWrt C++ std library does not support std::snprintf. You can replace it with just snprintf and add #include <stdio.h> in the file:
deps/v8_inspector/third_party/v8_inspector/platform/inspector_protocol/String16_cpp.template
However, this is not needed when –without-inspector is applied.
Node.js 6.12.2
I have failed building Node.js 6.12.2 on x86 with some openssl error.
Node.js 7
I have failed building Node.js 7 before. But perhaps I will give it a try sometime that Node.js 6 is working.
Older versions of Node.js
I have previously built and distributed Node.js 4 for OpenWrt.