x86平台musl编译的时候http在发起https请求的时候会报错
thread 'tokio-runtime-worker' panicked at /Users/alex/.cargo/registry/src/github.com-25cdd57fae9f0462/rustls-0.23.25/src/crypto/mod.rs:249:14:
no process-level CryptoProvider available -- call CryptoProvider::install_default() before this point
stack backtrace:
0: __rustc::rust_begin_unwind
1: core::panicking::panic_fmt
2: core::option::expect_failed
3: rustls::client::client_conn::ClientConfig::builder_with_protocol_versions
4: rustls::client::client_conn::ClientConfig::builder
5: gostd_http::client::Transport::roundTrip
6: gostd_http::client::Client::Do
7: alipay_sdk_rust::pay::PayClient::execute
8: <alipay_sdk_rust::pay::PayClient as alipay_sdk_rust::pay::Payer>::trade_query
9: unin_pay_gateway::alipay_functions::check_trade
10: unin_pay_gateway::services::pay_service::PayServices::check_un_checked_task::{{closure}}
11: unin_pay_gateway::app::init::{{closure}}::{{closure}}
12: tokio::runtime::task::core::Core<T,S>::poll
13: tokio::runtime::task::harness::Harness<T,S>::poll
14: tokio::runtime::scheduler::multi_thread::worker::Context::run_task
15: tokio::runtime::scheduler::multi_thread::worker::Context::run
16: tokio::runtime::context::scoped::Scoped<T>::set
17: tokio::runtime::context::runtime::enter_runtime
18: tokio::runtime::scheduler::multi_thread::worker::run
19: <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll
20: tokio::runtime::task::core::Core<T,S>::poll
21: tokio::runtime::task::harness::Harness<T,S>::poll
22: tokio::runtime::blocking::pool::Inner::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
x86_64-unknown-linux-musl 确实是不行,编译不了 warning: [email protected]: Building with: CC warning: [email protected]: Symbol Prefix: Some("aws_lc_0_29_0") warning: [email protected]: Compiler family detection failed due to error: ToolNotFound: failed to find tool "x86_64-linux-musl-gcc": No such file or directory (os error 2) warning: [email protected]: Compiler family detection failed due to error: ToolNotFound: failed to find tool "x86_64-linux-musl-gcc": No such file or directory (os error 2) warning: [email protected]: Compiler family detection failed due to error: ToolNotFound: failed to find tool "x86_64-linux-musl-gcc": No such file or directory (os error 2) warning: [email protected]: Compiler family detection failed due to error: ToolNotFound: failed to find tool "x86_64-linux-musl-gcc": No such file or directory (os error 2) warning: [email protected]: Compilation of 'c11.c' failed - Err(Error { kind: ToolNotFound, message: "failed to find tool "x86_64-linux-musl-gcc": No such file or directory (os error 2)" }). warning: [email protected]: Compiler family detection failed due to error: ToolNotFound: failed to find tool "x86_64-linux-musl-gcc": No such file or directory (os error 2) warning: [email protected]: Compiler family detection failed due to error: ToolNotFound: failed to find tool "x86_64-linux-musl-gcc": No such file or directory (os error 2) warning: [email protected]: Compilation of 'stdalign_check.c' failed - Err(Error { kind: ToolNotFound, mess
aws-lc-sys 上游包的问题,提交上游看看
如果是ubuntu Linux系统,只要安装一下包就可以解决这个问题,环境缺少x86_64-linux-musl-gcc的问题 sudo apt install musl-tools build-essential
以下命令就能正常交叉编译,这个是环境缺失问题。
cargo build --target x86_64-unknown-linux-musl
运行系统环境, 我放在pactfoundation/rust-musl-build 的容器中运行: 825a4d5b2fae:/rusttest# rustc -Vv rustc 1.85.1 (4eb161250 2025-03-15) binary: rustc commit-hash: 4eb161250e340c8f48f66e2b929ef4a5bed7c181 commit-date: 2025-03-15 host: x86_64-unknown-linux-musl release: 1.85.1 LLVM version: 19.1.7 项目配置文件:
825a4d5b2fae:/rusttest# cat Cargo.toml
[package]
name = "rusttest"
version = "0.1.0"
edition = "2024"
[dependencies]
anyhow ="1.0"
tokio = { version = "1.44", features = ["full"] }
gostd = { version = "0.4" , features = ["tokio-rt"] }
rust 代码:
use gostd::net::http::async_http;
// use gostd_http::async_http;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let url = "https://petstore.swagger.io/v2/pet";
let postbody = r#"{"id":0,"category":{"id":0,"name":"string"},"name":"doggie","photoUrls":["string"],"tags":[{"id":0,"name":"string"}],"status":"available"}"#
.as_bytes()
.to_vec();
let response = async_http::Post(url, "application/json", Some(postbody.into())).await?;
println!(
"{}",
String::from_utf8(response.Body.expect("return body error").to_vec()).unwrap()
);
Ok(())
}
运行结果:
825a4d5b2fae:/rusttest# cargo run
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.13s
Running `target/debug/rusttest`
{"id":9223372036854747506,"category":{"id":0,"name":"string"},"name":"doggie","photoUrls":["string"],"tags":[{"id":0,"name":"string"}],"status":"available"}
@ipconfiger 请你贴出完整的环境和原代码。我这里无法重现你的问题
或者在mian函数中加入一下代码,看是否能解决问题
// 你的 main 函数
#[tokio::main]
async fn main() {
// !!!在这里进行修改!!!
// 这是唯一需要添加代码的地方。
// 在程序启动的最开始,安装默认的加密提供程序。
if let Err(e) = rustls::crypto::aws_lc_rs::install_default() {
// 在实际应用中,这里最好使用日志库记录错误,然后退出。
eprintln!("Failed to install default crypto provider: {:?}", e);
std::process::exit(1);
}