在 Windows 10 上使用 MinGW 和 MSYS2 编译 mongodb 驱动程序时出现问题

问题描述 投票:0回答:1

我正在编译一个使用mongodb驱动程序的项目。现在程序无法编译,因为在包依赖项中,需要引用两个库ring_core_0_17_8_fiat_curve25519_adx_mul和另一个库ring_core_0_17_8_fiat_curve25519_adx_square。这是使用 MSYS2 中的 gcc/x86_64-w64-mingw32/14.2.0 在 Windows 10 上编译的。

task_process.rs

mod queues_mongo;

use queues_mongo::email_queue::search_queue;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
  let _ = search_queue().await;

  Ok(())
}

email_queue.rs

extern crate dotenv;

use dotenv::dotenv;
use std::env;

use mongodb::{
 bson::{doc, Document},
 error, Client, Collection, Database,
};

#[allow(dead_code)]
pub async fn search_queue() -> error::Result<()> {
 dotenv().ok();

 let uri: String = env::var("MONGO_URI").expect("MONGO_URI");
 let db: String = env::var("MONGO_DATABASE").expect("MONGO_DATABASE");

 let client: Client = Client::with_uri_str(uri).await?;
 let database: Database = client.database(db.as_str());
 let collection: Collection = database.collection("emails");
 let email: Option = collection.find_one(doc! { "status": "Sent" }).await?;

 println!("Found a email:\n{:#?}", email);

 Ok(())
}

完全错误

货物.toml:

[package]
name = "rustlang-course"
version = "0.1.0"
edition = "2021"

[dependencies]
aead = "0.5.2"
axum = "0.8.1"
base64 = "0.22.1"
bson = "2.13.0"
chrono = "0.4.39"
colored = "2.1.0"
csv = "1.3.1"
dotenv = "0.15.0"
futures = "0.3.31"
hex = "0.4.3"
mongodb = "3.1.1"
notify = "7.0.0"
notify-debouncer-full = "0.4.0"
notify-debouncer-mini = "0.5.0"
openssl = "0.10.68"
prost = "0.13.3"
rand = "0.8.5"
regex = "1.11.1"
reqwest = { version = "0.12.9", features = ["json"] }
roxmltree = "0.20.0"
serde = "1.0.214"
serde_json = "1.0.133"
sqlx = "0.8.2"
tokio = { version = "1.41.0", features = ["full"] }
tonic = "0.12.3"
uuid = "1.11.0"

[build-dependencies]
cc = "1.2.7"
tonic-build = "0.12.3"

[[bin]]
name = "task_process"
path = "src/task_process.rs"
mongodb rust mingw driver msys2
1个回答
0
投票

这几天我一直在努力并找到了解决方案:

  1. 克隆项目或将其复制到 MSYS2 中的“C:\msys64\home\my_user”,不要在 Windows 用户文件夹“C:\Users\My User”中执行此操作,因为 Rust 编译器会依赖项有问题。

  2. 使用 “build.rs”预编译库 “ring_core_0_17_8_fiat_curve25519_adx_mul” 和库 “ring_core_0_17_8_fiat_curve25519_adx_square”

示例:

fn main() -> Result<(), Box<dyn std::error::Error>> {
  let build_lib_path: &str =
    r"C:\msys64\home\My User\projects\rustlang-course\target\debug\build_lib";

  let includes: [&str; 2] = [
    r"C:\Users\My User\.cargo\registry\src\index.crates.io-6f17d22bba15001f\ring-0.17.8\pregenerated\tmp",
    r"C:\Users\My User\.cargo\registry\src\index.crates.io-6f17d22bba15001f\ring-0.17.8\include",
  ];

  cc::Build::new()
    .file(r"C:\Users\My User\.cargo\registry\src\index.crates.io-6f17d22bba15001f\ring-0.17.8\third_party\fiat\asm\fiat_curve25519_adx_mul.S")
    .includes(&includes)
    .out_dir(&build_lib_path)
    .compile("ring_core_0_17_8_fiat_curve25519_adx_mul");

  cc::Build::new()
    .file(r"C:\Users\My User\.cargo\registry\src\index.crates.io-6f17d22bba15001f\ring-0.17.8\third_party\fiat\asm\fiat_curve25519_adx_square.S")
    .includes(&includes)
    .out_dir(&build_lib_path)
    .compile("ring_core_0_17_8_fiat_curve25519_adx_square");

  println!("cargo::rustc-link-lib=static=ring_core_0_17_8_fiat_curve25519_adx_mul");
  println!("cargo::rustc-link-lib=static=ring_core_0_17_8_fiat_curve25519_adx_square");
  println!("cargo::rustc-link-search=native={}", build_lib_path);

  Ok(())
}

您还必须在 C:\Users\My User.carg 中进行此调整

© www.soinside.com 2019 - 2024. All rights reserved.