跳转至

centos 下安装Rust

安装Rust工具链

# 编辑文件
$ vim ~/.bashrc 或者 ~/.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
# 接下来运行命令使文件生效
source ~/.bashrc
# 然后就可以进行安装
curl https://sh.rustup.rs -sSf | sh
# 如果传选项 选1 默认安装
# 配置cargo
cd ~ && cd .cargo && touch config
vi config
# 添加下面的信息
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'sjtu'
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"
[target.x86_64-apple-darwin]
rustflags = [
  "-C", "link-arg=-undefined",
  "-C", "link-arg=dynamic_lookup",
]

# 使用source把环境变量读进来
source $HOME/.cargo/env

# 查看安装结果
cargo -V
rustc --version

配置远程开发环境

vscode 安装Rust工具链

rustfmt 插件

  • 自动格式代码 快捷键 option+shift+f

rust-analyzer

  • 自动类型提示, 代码补全

安装过程出现的问题

Cannot activate rust-analyzer: bootstrap error. See the logs in "OUTPUT > Rust Analyzer Client" (should open automatically). To enable verbose logs use { "rust-analyzer.trace.extension": true }

通过运行 /home/bheisler/.vscode-server/data/User/globalStorage/matklad.rust-analyzer/rust-analyzer-linux 查看一些运行情况

/home/bheisler/.vscode-server/data/User/globalStorage/matklad.rust-analyzer/rust-analyzer-linux --version 查看得知预编译的二进制文件期待的glibc版本

一般这个情况可能是我们服务器上glibc版本不对, vscode用的2.18, 我这里centos本机上是2.17

可以手动编译rust-analyzer, 这里我们手动下载 https://github.com/rust-analyzer/rust-analyzer

然后cargo build --release --verbose编译下载下来的文件, cp target/release/rust-analyzer ~/.vscode-server/data/User/globalStorage/matklad.rust-analyzer/rust-analyzer-x86_64-unknown-linux-gnu

就是用我们编译后的二进制文件, 替换掉vscode里面的预编译二进制文件(关于文件名 需要先看一下vscode用的什么文件名)

安装gdb(非必须)

wget http://ftp.gnu.org/gnu/gdb/gdb-10.1.tar.xz

xz -d gdb-10.1.tar.xz 

tar xvf gdb-10.1.tar gdb-10.1/

cd gdbserver && ./configure

# 输出
checking whether the target supports __sync_*_compare_and_swap... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depdir commands
mkdir -p -- .deps
config.status: executing gdbdepdir commands
mkdir -p -- arch/.deps
mkdir -p -- gdbsupport/.deps
mkdir -p -- nat/.deps
mkdir -p -- target/.deps