rust 配置
安装rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
export RUSTUP_DIST_ROOT=https://mirrors.ustc.edu.cn/rust-static
rustup 国内源
export RUSTUP_DIST_SERVER="https://mirrors.ustc.edu.cn/rust-static" //用于更新 toolchain
export RUSTUP_UPDATE_ROOT="https://mirrors.ustc.edu.cn/rust-static/rustup" //用于更新 rustup
或者
cargo update 很慢 可以在 $HOME/.cargo/config 中添加如下内容
[source.crates-io]
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
如果所处的环境中不允许使用 git 协议,可以把上述地址改为:
registry = "https://mirrors.ustc.edu.cn/crates.io-index"
rustup update
rustup target list
cargo update/check/build
cargo build --release
交叉编译
查看cpu
cat /proc/cpuinfo
linux 交叉编译
sudo apt install gcc-arm-linux-gnueabihf //armv7
mac 交叉编译
brew install FiloSottile/musl-cross/musl-cross --without-x86_64 --with-arm-hf
rustup 安装不同的目标支持
rustup target list
rustup target add armv7-unknown-linux-musleabihf
vi ~/.cargo/config
[target.arm-unknown-linux-musleabihf]
linker = "arm-linux-musleabihf-ld"
[target.armv7-unknown-linux-musleabihf]
linker = "arm-linux-musleabihf-ld"
[target.arm-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
cargo build --target armv7-unknown-linux-gnueabihf --release //armv7, linux