Skip to content
Tutorial

Rust on Android: rustc and Cargo on Your Phone

Run real Rust on your Android phone: PocketCode installs rustc and Cargo in one tap from its optional Linux. How to run a file or a Cargo project, and the limits.

Updated:
3 min
By Pelayo Naredo

The Rust compiler is a big piece of software, so Rust on a phone sounds like a stretch. PocketCode runs it: the app has an optional Linux (Alpine, for 64-bit ARM phones), and from there it installs rustc and Cargo with one tap. Your .rs files compile and run on the device.

How to run a Rust file

  1. Open or create a .rs file and tap Run.
  2. The first time, the Run panel says Rust isn't installed and shows its size, about 370 MB once installed, with an Install button. If the app's Linux isn't set up yet, this sets it up too.
  3. The download keeps going if you leave the app. When it's ready, your file runs.

From then on, Run compiles the file with rustc and runs the program. The panel's first line says Rust (rustc, Linux). You can also install or remove Rust from Settings → Compilers and runtimes → Additional language runtimes, in the Languages section.

Cargo projects

The install includes Cargo, and PocketCode's Rust project template is a Cargo project (src/main.rs and Cargo.toml). The Run button compiles one file, so for a whole project use Cargo:

  • As a project task. cargo commands run inside the Linux, with your projects mounted. If Cargo is missing, the panel offers to install it and runs the task again.
  • In the terminal. Once the Linux is set up, the local shell opens Alpine, with your projects at ~/projects, where you can run cargo build, cargo run and cargo test. See the terminal guide.

Crates come from crates.io, so adding a dependency needs a connection.

Rhai, for phones without the Linux

Before the Linux, the only option was Rhai, a small scripting language with Rust-like syntax: let, fn, loops, maps and arrays. Its 1.4 MB pack is still in Settings → Compilers and runtimes → Additional language runtimes (header Optional compilers). It runs .rhai files, and .rs files on phones without the Linux. Rhai has no ownership, borrow checker or crates, so it won't teach you Rust. On a phone that can run the Linux, a chip in the Run panel offers real Rust after a run on Rhai.

The limits

  • 64-bit ARM only for rustc and Cargo. Other phones get Rhai.
  • Space. About 370 MB, plus the Linux itself.
  • A connection to install Rust and to fetch crates. Your own code then compiles and runs on the phone.
  • Compile times. rustc is slow on any machine, and a phone has less CPU and memory than a laptop. Big dependency trees belong on a desktop.
  • No one-tap language server. The editor highlights and formats Rust (see the code editor guide), but there's no rust-analyzer button.

Rust was verified on a Galaxy S24 with Android 17.

Part of the lineup

Rust is one of 21 languages and file types PocketCode runs on the device. From the same Linux: C++, Go, Lua, Perl, Zig, C# and R. Bundled in the app: JavaScript, TypeScript, C, Python, Ruby, PHP and Java. Kotlin runs after a one-time download of about 119 MB from Google Play. See the full lineup.


PocketCode is available on Google Play. Get PocketCode to try it on your own device.

Frequently asked questions

Can you run Rust on an Android phone?

Yes. PocketCode installs rustc and Cargo in one tap from its optional Linux, an Alpine Linux for 64-bit ARM phones (about 370 MB). The Run button compiles a .rs file with rustc and runs it on the device.

Does Cargo work?

Yes. Cargo comes with the same install. cargo commands run as project tasks or in a Linux tab of the terminal, with your projects mounted. Downloading crates needs a connection.

What is Rhai, and do I still need it?

Rhai is a small scripting language with Rust-like syntax. PocketCode keeps a 1.4 MB Rhai pack for phones that can't run the app's Linux, and for .rhai files. It isn't Rust: no ownership, borrow checker or crates.

The tool behind this article

Code Editor