Skip to content
Lu Yahan edited this page Nov 6, 2023 · 12 revisions

Getting Started

To build Node.js for RISC-V, start off by cloning this repository, then follow the steps below.

Prerequisites

Before cross build, ensure that you have the RISC-V toolchain installed. If you do not have riscv64-unknown-linux-gnu-gcc available in your path, install it following the directions here.
If you have riscv64-unknown-linux-gnu-*, you can directly see here.

RISC-V Toolchain

Install Prerequisites
sudo apt install gawk texinfo zlib1g-dev flex bison
Build risc64-gnu Toolchain
git clone https://github.com/riscv/riscv-gnu-toolchain
cd riscv-gnu-toolchain
git submodule update --init --recursive

./configure --prefix=/opt/riscv
sudo make linux -j8

Note -j8 specifies parallel build with 8 processes, and should be adjusted to the number of cores on your machines.

Be sure to add the path to this new toolchain to your path:

export PATH="/opt/riscv/bin:$PATH"

Building Node.js

clone code

git clone git@github.com:nodejs/node.git
cd node/
git checkout v18.16.0

Cross build

export CC=riscv64-unknown-linux-gnu-gcc
export CXX=riscv64-unknown-linux-gnu-g++
export CC_host=gcc
export CXX_host=g++

./configure --cross-compiling --dest-cpu=riscv64  --verbose --openssl-no-asm

make -j8

Native Build

./configure --dest-cpu=riscv64  --verbose --openssl-no-asm
make

Run test

Cross

如果是交叉编译,需要讲 node相关文件拷贝到 riscv64机器上运行

打包nodejs文件
tar czvf riscv64.tar.gz --exclude=./out/Release/obj* --exclude=./out/Release/.deps ././out/Release  ./test ./tools ./benchmark/ ./deps

将riscv64.tar.gz 拷贝到 riscv64机器

解压缩
tar xzvf riscv64.tar.gz

运行测试

./tools/test.py

Native

./tools/test.py