Building on Android
I finally managed to get
blog_os building on my Android phone using termux. This post explains the necessary steps to set it up.
🔗Install Termux and Nightly Rust
Install fish shell, set as default shell, and launch it:
pkg install fish chsh -s fish fish
This step is of course optional. However, if you continue with bash you will need to adjust some of the following commands to bash syntax.
Install some basic tools:
pkg install wget tar
wget https://its-pointless.github.io/setup-pointless-repo.sh bash setup-pointless-repo.sh
Install cargo and a nightly version of rustc:
pkg install rustc cargo rustc-nightly
Prepend the nightly rustc path to your
PATHin order to use nightly (fish syntax):
set -U fish_user_paths $PREFIX/opt/rust-nightly/bin/ $fish_user_paths
rustc --version should work and output a nightly version number.
🔗Install Git and Clone blog_os
We need something to compile, so let’s download the
pkg install git
git clone https://github.com/phil-opp/blog_os.git
If you want to clone/push via SSH, you need to install the
pkg install openssh.
🔗Install Xbuild and Bootimage
Now we’re ready to install
cargo xbuild and
cargo install cargo-xbuild bootimage
Add the cargo bin directory to your
set -U fish_user_paths ~/.cargo/bin/ $fish_user_paths
cargo xbuild and
bootimage should be available. It does not work yet because
cargo xbuild 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.
🔗Providing the Rust Source Code
The Rust source code corresponding to our installed nightly is available in the
Download a tar containing the source code:
tar xf rust-src-nightly.tar.xz
XARGO_RUST_SRCenvironment 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
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:
ln -s ~/../usr/opt/rust-nightly/bin ~/../usr/opt/rust-nightly/lib/rustlib/aarch64-linux-android/bin
cargo xbuild --target x86_64-blog_os.json and
bootimage build should both work!
I couldn’t get QEMU to run yet, so you won’t be able to run your kernel. If you manage to get it working, please tell me :).