intent

intent的blog

🚴自行车骑的最远的全栈工程师
github

Rust安装/更新/打包

Rust - 安装 / 打包#

安装#

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • cargo 换源
vi $HOME/.cargo/config

内容

[source.crates-io]
replace-with = 'ustc'

[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

Nightly#

# 可通过如下命令安装 rustc 的 nightly 版本,并把该版本设置为 rustc 的缺省版本。
rustup install nightly
rustup default nightly

其它#

# 查看有哪些平台
rustc --print target-list | pr -tw100 --columns 3

# 查看已安装
rustup target list | grep installed

# 安装x86_64-unknown-linux-musl
rustup target add x86_64-unknown-linux-musl

更新#

 rustup update

打包#

查看依赖#

macOS 查看依赖

otool -L target/release/workout

Linux 查看依赖

ldd target/release/二进制文件

静态文件#

或者使用cargo install cross --git https://github.com/cross-rs/cross

打包静态文件可能出现问题,docker 打包最终解决方法!

问题#

blocking waiting for file lock…#

rm -rf ~/.cargo/.package-cache

windows 打包#

q: the msvc targets depend on the msvc linker but link.exe was not found

解决:

C:\Users\intent\.cargo\bin\rustup uninstall toolchain stable-x86_64-pc-windows-msvc
C:\Users\intent\.cargo\bin\rustup toolchain install stable-x86_64-pc-windows-gnu
C:\Users\intent\.cargo\bin\rustup default stable-x86_64-pc-windows-gnu

或者安装 VSStudio!!!

q: Internal error occurred: Failed to find tool. Is musl-gcc installed?#

a: 这个是因为 musl 没安装

git clone https://github.com/richfelker/musl-cross-make.git --depth=1
cd musl-cross-make && TARGET=x86_64-linux-musl make -j8
cd build/local/x86_64-linux-musl/ && make install

# 配置好PATH变量
# rust x86_64-linux-musl
export PATH=/mnt/dev/git/rust/musl-cross-make/build/local/x86_64-linux-musl/output/bin:$PATH

q: error: failed to run custom build command for openssl-sys v0.9.72#

Ubuntu

 sudo apt install pkg-config
 sudo apt install libudev-dev
 sudo apt install librust-openssl-sys-dev
 sudo apt install libssl-dev

Gentoo

OPENSSL_LIB_DIR=/usr/lib64 OPENSSL_INCLUDE_DIR=/usr/include TARGET_CC=x86_64-linux-musl-gcc cargo build --release --target=x86_64-unknown-linux-musl

q: reqwest Segmentation fault when building a blocking::Client from a blocking::ClientBuilder#

# Segmentation fault when building a blocking::Client from a blocking::ClientBuilder

OPENSSL_STATIC=true OPENSSL_DIR=/mnt/dev/git/c/openssl-OpenSSL_1_1_1f/musl TARGET_CC=x86_64-linux-musl-gcc cargo build --release --target=x86_64-unknown-linux-musl

q: error: failed to run custom build command for `ring v0.16.20`#

sudo apt install musl-tools

编译慢,更改 linker 为 llvm#

https://stackoverflow.com/questions/57812916/how-do-i-change-the-default-rustc-cargo-linker

参考#

Rust 交叉编译相关总结 - Silentdoer - 博客园

加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。