同步: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!