Skip to content

Commit 2f53ecc

Browse files
committed
Add basic instructions for building on Android
1 parent b4c47a8 commit 2f53ecc

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,49 @@ $ export XARGO_RUST_SRC=/path/to/rust/src
5151
$ cargo xbuild --target msp430-none-elf.json
5252
```
5353

54+
## Using on Android
55+
56+
It's possible to run cargo-xbuild on your Android phone:
57+
58+
### Install Termux and Nightly Rustc
59+
60+
- Install [termux](https://play.google.com/store/apps/details?id=com.termux)
61+
- Install fish shell and set as default (optional): `pkg install fish; chsh -s fish; fish`
62+
- Install some basic tools: `pkg install wget tar`
63+
- Add the [community repository by its-pointless](https://wiki.termux.com/wiki/Package_Management#By_its-pointless_.28live_the_dream.29:): `wget https://its-pointless.github.io/setup-pointless-repo.sh; bash setup-pointless-repo.sh`
64+
- Install rust nightly: `pkg install rustc cargo rustc-nightly`
65+
- Prepend the nightly rustc path to your `$PATH` in order to use nightly (fish syntax): `set -U fish_user_paths $PREFIX/opt/rust-nightly/bin/ $fish_user_paths`
66+
- `rustc --version` should now return a nightly version
67+
68+
### (Optional) Install Git and Clone your Repository
69+
70+
- Install git: `pkg install git`
71+
- Clone a repository of your choice: `git clone https://github.com/phil-opp/blog_os.git`
72+
73+
### Install Xbuild
74+
75+
- Install cargo-xbuild: `cargo install cargo-xbuild`
76+
- Add the cargo bin directory to your `$PATH` (fish syntax): `set -U fish_user_paths ~/.cargo/bin/ $fish_user_paths`
77+
- Now `cargo xbuild` should be available.
78+
79+
It does not work yet because it needs access to the rust source code. By default it tries to use rustup for this, but we have no rustup support so we need a different way.
80+
81+
### Providing the Rust Source Code
82+
83+
The Rust source code corresponding to our installed nightly is available in the `its-pointless` repository:
84+
85+
- Download it: `wget https://github.com/its-pointless/its-pointless.github.io/raw/master/rust-src-nightly.tar.xz`
86+
- Extract it: `tar xf rust-src-nightly.tar.xz`
87+
- Set the `XARGO_RUST_SRC` environment variable to tell cargo-xbuild the source path (fish syntax): `set -Ux XARGO_RUST_SRC ~/rust-src-nightly/rust-src/lib/rustlib/src/rust/src`
88+
89+
Now cargo-xbuild should no longer complain about a missing `rust-src` component. However it will throw an I/O error after building the sysroot. The problem is that the downloaded Rust source code has a different structure than the source provided by rustup. We can fix this by adding a symbolic link:
90+
91+
```
92+
ln -s ~/../usr/opt/rust-nightly/bin ~/../usr/opt/rust-nightly/lib/rustlib/aarch64-linux-android/bin
93+
```
94+
95+
Now `cargo xbuild --target your-target.json` should work!
96+
5497
## License
5598

5699
Licensed under either of

0 commit comments

Comments
 (0)