The tool to create an environment on a Host for cross-compiling node.js native modules/add-ons for MT7688 mips platform. Once the environment is created, just use ./npm_install.sh
to install the cross-compiled version of node modules, it's easy.
[Note]
- Please do not use mt7688-cross v1.0 release, since Google has removed the gyp from svn to git repo. You will get an error of
svn: E160013: Unable to connect to...
when running./create_env.sh
. mt7688-cross v1.1 already fixes this dependencies broken issue.
- Host: Ubuntu/Debian x86_64 (Mine is Ubuntu 14.04 LTS running on a virtual machine)
- Target: MT7688, MIPS24KEc (little endian)
- node.js: 0.12.7
- npm: 2.11.3
- v8 engine: 3.28.71 (patch 19)
$ sudo apt-get install subversion build-essential gcc-multilib g++-multilib
mt7688-cross requires wget to download the mt7688 SDK and node.js source, make sure you have wget on your Ubuntu.
$ sudo apt-get install wget
step 2: Make sure you are equipped with [email protected] and [email protected] on your Host PC
If you don't, try to install them: (I am using n
as my node version manager. You can use nvm
if you like.)
$ sudo n 0.12.7
$ sudo npm install -g [email protected]
~$ git clone https://github.com/simenkid/mt7688-cross.git
~$ cd mt7688-cross
~/mt7688-cross$
mt7688-cross/ is the working directory for cross-compiling native node modules/add-ons.
Shoot create_env.sh
to start the building process. This may take around 20 minutes depends on your PC performance.
~/mt7688-cross$ ./create_env.sh
As building accomplished, inlinkit/opt/
, there is the cross-compiled node.js that can run on MT7688 MIPS platform. In addition, v8/
, node-v0.12.7-mips/
, and mt7688sdk/
are the sources of v8, node, and mt7688 SDK, respectively.
Once this step is successfully done, the environment is ready for your later use. Every time you want to cross-compile a node native module, just come into the working directory mt7688-cross/
and install a module with script npm_install.sh
, there is no need to rebuild the environment again.
Assume that you like to install the serialport
module on your MT7688. First install it with npm_install.sh
on the Host:
~/mt7688-cross$ ./npm_install.sh serialport
You will get a compressed tarball in node_modules_mips/
, in this example, it is serialport-2.0.6_mips.tar.gz
. If you like to install other version, just specify the version with @
:
~/mt7688-cross$ ./npm_install.sh [email protected]
Next step is push it to MT7688 via scp
and decompress it to any place you want. In this example, I will put it to ~/app
with the root account and extract it to ~/app/node_modules/
.
At Host:
~/mt7688-cross$ scp node_modules_mips/serialport-2.0.6_mips.tar.gz [email protected]:/root/app
At Target:
root@mylinkit:~/app# tar xvf serialport-2.0.6_mips.tar.gz -C node_modules/
Now, you are ready to write a script in ~/app
on your target.
- Module cross-build may fail if the module is highly platform-dependent, e.g. module that operates SoC gpio/uart and other peripherals.
- Module cross-build may fail if the module requires some libraries that SDK doesn't provide.
- You are welcome to modify this script to fit your needs, e.g. automation of file transmission from Host to Target.
- If you only like to have the environment variable settings for cross tools, it is in
env.sh
.
This tool is inspired by Build your own Node.js package with the linino toolchain. Thanks to linino!