Building the Rust toolchain for BlueOS kernel
We have forked upstream Rust compiler to support BlueOS kernel targeted to *-vivo-blueos-* and BlueOS kernel’s Rust-std.
我们最终将我们的更改贡献给上游仓库,并使*-vivo-blueos-*成为Rust的tier目标。
克隆下游仓库
Run If you have configured public ssh key on github, please use following commands,
git clone git@github.com:vivoblueos/rust.git
git clone git@github.com:vivoblueos/cc-rs.git
git clone git@github.com:vivoblueos/libc.git
otherwise, please try
git clone https://github.com/vivoblueos/rust.git
git clone https://github.com/vivoblueos/cc-rs.git
git clone https://github.com/vivoblueos/libc.git
blueos-dev 分支已设置为默认,因此无需手动切换分支。
设置Rust镜像站点
在中国,我们推荐你使用 crates.io 和 rustup 的镜像站点。将以下行添加到你的 ~/.bashrc
export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
然后输入
source ~/.bashrc
通过 x 脚本安装
在您的bash shell中运行以下命令。这些指令适用于Linux和macOS平台:
export CARGO_NET_GIT_FETCH_WITH_CLI=true
export DESTDIR=<选择您的安装前缀>
cd rust
cp config.blueos.toml config.toml
./x.py install -i --stage 1 compiler/rustc
./x.py install -i --stage 1 library/std --target aarch64-vivo-blueos-newlib
./x.py install -i --stage 1 library/std --target thumbv7m-vivo-blueos-newlibeabi
./x.py install -i --stage 1 library/std --target thumbv8m.main-vivo-blueos-newlibeabihf
./x.py install -i --stage 1 library/std --target riscv64-vivo-blueos
./x.py install -i --stage 1 library/std --target riscv32-vivo-blueos
./x.py install -i --stage 1 library/std --target riscv32imc-vivo-blueos
./x.py install -i --stage 0 rustfmt
./x.py install -i --stage 0 rust-analyzer
./x.py install -i --stage 0 clippy
您还必须安装主机的标准库和LLVM工具。
对于Linux:
./x.py install -i --stage 1 library/std --target x86_64-unknown-linux-gnu
cp -rav build/x86_64-unknown-linux-gnu/llvm/{bin,lib} ${DESTDIR}/usr/local
对于macOS:
./x.py install -i --stage 1 library/std --target aarch64-apple-darwin
cp -av build/aarch64-apple-darwin/llvm/{bin,lib} ${DESTDIR}/usr/local
要使用内核工具链,请将以下内容添加到您的环境中:
export PATH=${DESTDIR}/usr/local/bin:${PATH}
Or if you want to mange the blueos toolchain using rustup, you can try:
ln -s ${DESTDIR}/usr/local ~/.rustup/toolchains/blueos-dev
rustup default blueos-dev