Is it possible to compile crosvm for Android in Termux?

73 views
Skip to first unread message

Octavian-Codruț Popescu

unread,
Feb 20, 2024, 9:33:19 AMFeb 20
to crosvm-dev
I have a rooted Tas S9 Ultra (Android 14, Snapdragon 8 Gen 2, 16 GB of memory)  which seems to have gunyah enabled by default as I can see /dev/gunyah

:/data/data/com.termux/files/home/crosvm # ls -l /dev/gunyah
crw------- 1 root root 10, 121 2022-08-23 06:31 /dev/gunyah

Is it possible to compile crosvm for Android under Termux? It would be great to be able to run VMs in Android.

I tried

cargo build

but it fails with

cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  make: Entering directory '/data/data/com.termux/files/home/crosvm/third_party/minijail'
  Using BASE_VER=0
  cd "/data/data/com.termux/files/home/crosvm/target/debug/build/minijail-sys-d39457319737aa3e/out/" && make -r -I "/data/data/com.termux/files/home/crosvm/third_party/minijail" -f "/data/data/com.termux/files/home/crosvm/third_party/minijail/Makefile" SRC="/data/data/com.termux/files/home/crosvm/third_party/minijail" OUT="/data/data/com.termux/files/home/crosvm/target/debug/build/minijail-sys-d39457319737aa3e/out/" "all"
  make[1]: Entering directory '/data/data/com.termux/files/home/crosvm/target/debug/build/minijail-sys-d39457319737aa3e/out'
  Using BASE_VER=0
  build configuration:
  - OUT=/data/data/com.termux/files/home/crosvm/target/debug/build/minijail-sys-d39457319737aa3e/out/
  - SRC=/data/data/com.termux/files/home/crosvm/third_party/minijail
  - MODE=debug
  - SPLITDEBUG=0
  - NOSTRIP=1
  - VALGRIND=0
  - COLOR=1
  - CXXEXCEPTIONS=0
  - ARCH=aarch64
  - QEMU_ARCH=aarch64
  - USE_QEMU=0
  - NEEDS_ROOT=0
  - NEEDS_MOUNTS=0
  - SYSROOT=/

  CC libminijail.c -> libminijail.pic.o
  make[1]: Leaving directory '/data/data/com.termux/files/home/crosvm/target/debug/build/minijail-sys-d39457319737aa3e/out'
  make: Leaving directory '/data/data/com.termux/files/home/crosvm/third_party/minijail'

  --- stderr
  /data/data/com.termux/files/home/crosvm/third_party/minijail/libminijail.c:3948:3: error: call to undeclared function 'fexecve'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
   3948 | fexecve(elf_fd, config->argv, child_env);
        | ^
  /data/data/com.termux/files/home/crosvm/third_party/minijail/libminijail.c:3948:3: note: did you mean 'execve'?
  /data/data/com.termux/files/usr/include/unistd.h:103:5: note: 'execve' declared here
    103 | int execve(const char* _Nonnull __file, char* _Nullable const* _Nullable __argv, char* _Nullable const* _Nullable __envp);
        | ^
  1 error generated.
  make[1]: *** [common.mk:607: libminijail.pic.o] Error 1
  make: *** [common.mk:172: _all] Error 2
warning: build failed, waiting for other jobs to finish...


Daniel Verkamp

unread,
Feb 20, 2024, 1:38:53 PMFeb 20
to Octavian-Codruț Popescu, crosvm-dev
With the caveat that I don't know much about how the Android version
of crosvm is built, it looks like fexecve() should be available in
Bionic libc starting with Android P [1], so maybe this would work with
newer headers; alternatively, you could try removing -Werror in
third_party/minijail/common.mk and see if it links despite the missing
declaration.

It might be worth taking a look at the Android downstream repository
of crosvm [2]; I think it is built with Soong rather than cargo, so
maybe there are some hints in the Android.bp files.

[1]: https://android.googlesource.com/platform/bionic/+/master/docs/status.md
[2]: https://android.googlesource.com/platform/external/crosvm

Frederick Mayle

unread,
Feb 20, 2024, 5:56:32 PMFeb 20
to Daniel Verkamp, Octavian-Codruț Popescu, crosvm-dev
Android ships with a crosvm binary at /apex/com.android.virt/bin/crosvm and it is built with gunyah support, so you could try using that directly. I don't mean to discourage you, but running a custom VM image on gunyah will probably be an adventure!

--
You received this message because you are subscribed to the Google Groups "crosvm-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to crosvm-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/crosvm-dev/CABVzXAnRF2wXX%3DCRxMUmuJKoe3Lp02M2Yb8GfAt7nuwfsY-5Kw%40mail.gmail.com.

Octavian-Codruț Popescu

unread,
Feb 21, 2024, 10:36:50 AMFeb 21
to crosvm-dev, Frederick Mayle, Octavian-Codruț Popescu, crosvm-dev, Daniel Verkamp
Perhaps the Google version contains some crosvm binaries, I don't have crosvm in the Samsung version (and it's the latest Android 14 as distributed by Samsung). But perhaps I can extract it from the Google AOSP. Thanks for the tip!
Is it more difficult than qemu?

Reply all
Reply to author
Forward
0 new messages