Java教程

解决rust编译目标为musl时openssl报错

本文主要是介绍解决rust编译目标为musl时openssl报错,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

同步:https://zhufn.fun/archives/rust-musl-ssl/
为了节省容器启动时间,准备把rust写的api编译好后扔进docker里,于是编译到target:x86_64-unknown-linux-musl
然后openssl炸了,不认libssl-dev了,查了下要重新编译。。。
但是,我们发现了一个神奇的docker镜象https://github.com/emk/rust-musl-builder,它已经配好了openssl的musl环境以及diesel, sqlx
于是只要这样:

alias rust-musl-builder='docker run --rm -it -v "$(pwd)":/home/rust/src ekidd/rust-musl-builder'
rust-musl-builder cargo build --release

就可以了
(不过好像也可以把openssl换成rustls来解决)

However, rustls now works well with most of the Rust ecosystem, including reqwest, tokio, tokio-postgres, sqlx and many others. The only major project which still requires libpq and OpenSSL is Diesel. If you don't need diesel or libpq:

See if you can switch away from OpenSSL, typically by using features in Cargo.toml to ask your dependencies to use rustls instead.
If you don't need OpenSSL, try cross build --target=x86_64-unknown-linux-musl --release to cross-compile your binaries for libmusl. This supports many more platforms, with less hassle!

这篇关于解决rust编译目标为musl时openssl报错的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!