Cannot install Rust on Termux

When I try to install Rust on Termux, I get errors on the lines of:

thread 'main' panicked at /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustls-platform-verifier-0.5.2/src/android.rs:87:10:
Expect rustls-platform-verifier to be initialized

Termux is a terminal emulator running on Android that provides a nearly-compliant Linux command line. I can install Rust using the Termux package manager but I was trying to install Rust using the recommended method.

Have you read https://docs.rs/rustls-platform-verifier/latest/rustls_platform_verifier/index.html#android? You need some special setup on Android that involves building Kotlin code at build time and load it at runtime for rustls-platform-verifier to be able to call the Java certificate validation apis.

The instructions there do assume you are writing a standalone Android app rather than writing an executable to run inside Termux. I don't know if you can just load the Dalvik VM inside an arbitrary process or if you have to have to run the dalvikvm executable and let it load your application through JNI for that to work.

This seems relevant (I’m assuming that by “the recommended method” you are in fact referring to the method of “using rustup” – which is indeed recommended here.)

In particular, let’s read the reply OP got there :slight_smile:

2 Likes

It looks like Termux bundles it's own ca-certificates. After all, it works similar to a specialised Debian install that runs under a prefix rather than from /. It really isn't FHS compliant, I seem to have CA certs at /data/data/com.termux/files/usr/etc/tls/.

Mind you, I have not tried to do rust development on my phone, I just use Termux for emergency ssh and for rsync for photos (to avoid cloud services).

You could, but that would be pointless.

The only way to get access to Java-side APIs is to be loaded from process that forks from Zygote. Simply loading Dalvik VM in your process would achieve nothing since you would still have no access to these APIs.

1 Like

Can't help with termux but I have used UserLAnd on my phone, installed a debian system and rustup worked fine. There were some problems, some crates will not compile. For example

cargo install --locked trunk

failed when wasm-bindgen couldn't compile, if I remember. devserver did compile so I j ust did my trunk stuff on a desktop and moved the filed to my phone for them to serve.

To have the complete rustup experience on Termux without using proot or root access, you must use the Termux glibc userland, as these toolchains are built against glibc not bionic: And there is already one. I have been using rustup for moths on termux now without issues, no proot. You only need to patch the new binaries, such as toolchain binaries; the programs you compile using that toolchain don't require any patching since they were built against your Termux glibc userland. I created an efficient Rust script with AI assistance that will make this easy, so all you have to do is run: rustup install toolchain nightly or any specific version. Then you run 'autopatchelf rust nightly or any version', and you’re all set.

I have been using Termux just for fun

My method is:

  1. Install proot-distro: pkg install proot-distro

  2. Decide the distro you want. To check the available list and the id, run: proot-distro list

  3. Install the distro you want, with command: proot-distro install the_distro_id. For example I want to install arch, so the command is: proot-distro install archlinux

  4. Login to the distro with command: proot-distro login the_distro_id

  5. Then you can install the rustup using the official website tutorial: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

  6. Done. The rustup with rust stable channel should be installed successfully

  7. Additionally, if you want to add nightly channel and miri too:

  • Install nightly: rustup toolchain install nightly
  • Add miri: rustup component add miri --toolchain nightly

For code editor, you can use neovim, and then install config that has rust analyzer installed ready to use

Or if you want code editor that is not terminal, you can use acode editor app, but there is no working rust analyzer plugin there. You may want to write the plugin yourself

I just updated my nightly channel to the latest version :>

For better experience, you can use external keyboard and mouse, then connect it to your smartphone