Installation Environment
The company’s virtualization solution is written in Rust, and here is a configuration for the Rust environment.
Remember, do not use the version from the Ubuntu repository; instead, follow the documentation to use the latest version.
Necessary Tools
apt install curl rsync gdb-multiarch openocd cargo doxygen qemu-user-static \
build-essential libncurses5-dev libssl-dev libgtk2.0-dev libglib2.0-dev
`
Domestic Sources
vim ~/.bash_profile
export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
Official Installation
curl -L https://static.rust-lang.org/rustup.sh -O
sh rustup.sh
Current installation options:
default host triple: x86_64-unknown-linux-gnu
default toolchain: stable (default)
profile: default
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
Select custom configuration, which will look like this:
default host triple: x86_64-unknown-linux-gnu
default toolchain: nightly
profile: complete
modify PATH variable: yes
Finally, after installation, you will receive the following message:
nightly-x86_64-unknown-linux-gnu installed - rustc 1.77.0-nightly (30dfb9e04 2024-01-14)
source ~/.bashrc
rustc --version
rustc 1.59.0
rustup --version
rustup 1.26.0 (5af9b9484 2023-04-05)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.77.0-nightly (30dfb9e04 2024-01-14)`
Thus, Rust is installed.
Version Introduction
Rust is installed with the stable version by default, but there are nightly and beta versions available. It uses a “train release model” where Rust specifically stipulates that stable cannot use features marked with feature flags, and our repository requires this, so I had to choose nightly. A simple understanding is as follows:
- Nightly: The version under development, automatically built and released every night.
- Beta: The testing version, generated from Nightly every 6 weeks, includes new features.
- Stable: The stable version, generated from Beta every 6 weeks.
For more detailed information about versions, see the following link:
https://rustwiki.org/zh-CN/book/appendix-07-nightly-rust.html
Otherwise, you may encounter the following error:
`#![feature]` may not be used on the stable release channel
If you need to switch between stable, nightly, or beta, use the following command:
rustup default stable/nightly/beta
Cross Compilation
rustc –print target-listrustup target add aarch64-unknown-linux-gnu
Download the compilation toolchain:
wget https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz
xz -d gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz
tar xvf gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar
Configure the toolchain:
vim ~/.cargo/config
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
[build]
target = "aarch64-unknown-linux-gnu"
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-none-linux-gnu-gcc"
Usage
cargo new hello –bincd hello && cargo build
If you want to compile for x86, use the following command:
cargo build –target=x86_64-unknown-linux-gnu
Reference Links
The Rust documentation is quite comprehensive, as follows:
https://www.kancloud.cn/thinkphp/rust/36040https://kaisery.github.io/trpl-zh-cn/ch01-01-installation.htmlhttps://forge.rust-lang.org/index.htmlhttps://doc.rust-lang.org/book/second-edition/foreword.html
Supplement
As an operating system distributor, I have recently maintained a complete set of ruscc and Rust ecosystem libraries, which can effectively solve the issue of Rust being unavailable on Ubuntu mentioned in my article. This solution allows KylinOS to natively enjoy all Rust development environments. I will share more when I have time.