Skip to content

NW.js for RISC V

Rebecca Chang Swee Fun edited this page Nov 17, 2022 · 5 revisions

NW.js for RISC-V (Cross-compilation)

System requirements

  • Preferred Linux build machine with Ubuntu v20.04 installed.
  • A 64-bit build machine with at least 8GB of RAM. More than 16GB is highly recommended.
  • At least 100GB of free disk space.
  • You must have Git and Python v3.6+ installed already (and python3 must point to a Python v3.6+ binary).

Install depot_tools

Clone the depot_tools repository:

$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

Add depot_tools to the end of your PATH (you will probably want to put this in your ~/.bashrc). Assuming you cloned depot_tools to /path/to/depot_tools:

$ export PATH="$PATH:/path/to/depot_tools"

When cloning depot_tools to your home directory do not use ~ on PATH, otherwise gclient runhooks will fail to run. Rather, you should use either $HOME or the absolute path:

$ export PATH="$PATH:${HOME}/depot_tools"

Get the code

Create a nwjs directory for the checkout and change to it (you can call this whatever you like and put it wherever you like, as long as the full path has no spaces):

$ mkdir ~/nwjs && cd ~/nwjs

Download the gclient configuration file:

$ wget https://raw.githubusercontent.com/rebeccasf/nwjs.config/master/gclient_nw65 -O .gclient

Run gclient sync to sync the source code into the directory:

$ gclient sync --with_branch_heads -D

Install additional build dependencies

Once you have checked out the code, and assuming you're using Ubuntu, run:

$ ./src/build/install-build-deps.sh

You may need to adjust the build dependencies for other distros. Refer to Chromium guide for other distros.

RISC-V Debian Sysroot

Download the pre-built sysroot based on RISC-V Debian sid: StarFive RISC-V Debian Sysroot

Setup a folder to store a pre-built RISC-V Debian sysroot for cross-compilation libraries:

$ cd src/build/linux
$ mkdir debian_sid_riscv64-sysroot && cd debian_sid_riscv64-sysroot

Extract the sysroot tarball into //build/linux/debian_sid_riscv64-sysroot:

$ tar -xvzf debian_starfive_chroot.tar.gz --strip-components=1

Update the sysroot file and folder permission settings:

$ sudo chown --from=root <user> * -R

NOTE: <user> should be replaced with your own user account on the build machine OS.

Setting up the build

NW.js uses Ninja as its main build tool along with a tool called GN to generate .ninja files. You can create any number of build directories with different configurations. To create a build directory, run:

$ cd ~/nwjs/src
$ gn gen out/nw --args='target_cpu="riscv64" target_os="linux" is_debug=false is_component_ffmpeg=true symbol_level=1 blink_symbol_level=0 use_gnome_keyring=false is_clang=true use_lld=false use_gold=false'

Build llvm / clang toolchain for RISC-V

We need to rebuild the llvm/clang toolchain with RISC-V enabled as one of the target:

$ cd ~/nwjs/src/build/tools/clang/script
$ ./build.py --without-android --without-fuchsia

Build NW.js

Build NW.js (the “nw” target) with Ninja using the command:

$ ninja -C out/nw nwjs

Build Node

Setup the environment before compile libnode:

$ GYP_CHROMIUM_NO_ACTION=0 ./build/gyp_chromium -I third_party/node-nw/common.gypi -D building_nw=1 -D clang=1 third_party/node-nw/node.gyp -D target_arch=riscv64 -D nwjs_sdk=1 -D disable_nacl=0 -D buildtype=Official

Note: The command above will generate a directory named Release and Debug within out directory.

Run the command below to build libnode:

$ ninja -C out/Release node

Note: This will build node in Release mode. You can invoke ninja -C out/Debug node to build node in Debug mode.

Copy the compiled libnode.so into out/nw/lib:

$ ninja -C out/nw copy_node

Run NW.js

Once it is built, you can transfer the out/nw directory into StarFive VisionFive board and run NW.js on target:

$ out/nw/nw /path/to/application