How to Run v8 on Android RISCV - riscv-collab/v8 GitHub Wiki

How to build and test v8 on Android RISCV

This article describes how to build and run regression tests of v8 on Android RISCV.

1. Prepare for build

Firstly, make sure you can get and build the v8 source code via either cross compiler build or Simulator Build way. That means you have proper settings for "depot_tools", you can fetch v8 source code and the "gn" tool is good. Further reference can be found here1(https://v8.dev/docs/build).

2. Build RISCV64 V8 for Android

2.1 Set up the ".gclient" file and sync the repo

First, edit the ".gclient" file under the directory where you fetch v8 code, and add the "target_os" lines as the following shows.

solutions = [ 
{
"name": "v8",
"url": "https://chromium.googlesource.com/v8/v8.git",
"deps_file": "DEPS",
"managed": False,
},  
]
target_os = ['android']

Then launch the "gclient sync" command in the v8 directory to fetch the proper repos for Android build. (Note: ".gclient" file is not in v8 directory but in v8's parent directory.)

2.2 Set gn args and launch build

Directory launch android builds using gm.py by an argument like "android_riscv64.release" or "android_riscv64.debug". Wait until a completed progress bar shows the successful build.

2.3 Package the build output to prepare the regression test

tar czvf v8out.tar.gz --exclude=./out/android_riscv64.release/gen/ --exclude=./out/ android_riscv64.release/obj ./out/android_riscv64.release/ ./third_party

3. Set up the Android emulator (cuttlefish) for RISCV64

3.1 Download cuttlefish source code and build

Do the following steps:

sudo apt install -y git devscripts config-package-dev debhelper-compat golang curl
git clone https://github.com/google/android-cuttlefish
cd android-cuttlefish
for dir in base frontend; do
  cd $dir
  debuild -i -us -uc -b -d
cd ..
done
sudo dpkg -i ./cuttlefish-base_*_*64.deb || sudo apt-get install -f
sudo dpkg -i ./cuttlefish-user_*_*64.deb || sudo apt-get install -f
sudo usermod -aG kvm,cvdnetwork,render $USER
sudo reboot

Note: Make sure the host platform you install and run cuttlefish has KVM support. It can be checked by the "grep -c -w "vmx|svm" /proc/cpuinfo" command, a non-zero result means it supports kvm. Meanwhile, we recommend using Ubuntu22.04.

3.2 Prepare the AOSP files for aosp_cf_riscv64_phone target

Find one of the successfully built aosp_cf_riscv64_phone in the grid of the web page 2(https://ci.android.com/builds/branches/aosp-main/grid?legacy=1), click the "Artifacts" tag and you will get a list view of all the available build output for aosp_cf_riscv64_phone target. To run on cuttlefish, we need download 2 zip files, which are "cvd-host_package.tar.gz " and " aosp_cf_x86_64_phone-img-xxxxxx.zip ".

On your host machine, do the following steps:

mkdir cf
cd cf
tar -xvf /path/to/cvd-host_package.tar.gz
unzip /path/to/aosp_cf_x86_64_phone-img-xxxxxx.zip

3.3 Lauch cuttlefish emulator and validate adb usage

HOME=$PWD ./bin/launch_cvd -cpus=4 --memory_mb=8192 --gpu_mode=none --vm_manager=qemu_cli
./bin/adb devices

3.4 Regression test for v8 on cuttlefish

3.4.1 Get clear v8 source code

Download the clear v8 source from here, you can choose one that has the same or near tag with the buildable v8 in step 1. After downloading, extract the zip or tgz file into a directory.

wget https://github.com/v8/v8/archive/refs/tags/12.2.267.tar.gz
mkdir testv8
cd testv8
tar xzvf ./12.2.267.tar.gz

3.4.2 Extract the build output of v8 into the test directory

cd testv8
tar xzvf ./v8out.tar.gz

3.4.3 Launch the regression test

Make sure you have launched the cuttlefish, then:

cd testv8
./tools/run-test.py --outdir=./out/android_riscv64.release

Wait until the test progress bar shows the test is finished. Now we still get a lot of "time out" failures, which are probably caused by slow emulation speed. Further investigation is still progressing.

Reference:

[1] https://v8.dev/docs/build

[2] https://ci.android.com/builds/branches/aosp-main/grid?legacy=1