Rust - Problem compiling mongodb drivers with MinGW and MSYS2 on Windows 10

Hi everyone

I'm compiling a project that uses mongodb driver. Now the program is not compiling because among the package dependencies one needs the reference to two libraries ring_core_0_17_8_fiat_curve25519_adx_mul and the other ring_core_0_17_8_fiat_curve25519_adx_square. This is being compiled on Windows 10 using gcc/x86_64-w64-mingw32/14.2.0 from MSYS2.

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(())
}

Full error

The Cargo.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"

according to the source code, these two functions are implemented in assembly:

maybe it's because your build environment has unusual configurations, or maybe the build script wrongly detected the envirnonment. anyway, you should report to the ring issue tracker.

I've been working on it these last few days and found a solution:

  1. Clone the project or copy it to "C:\msys64\home\my_user" in MSYS2, don't do this in the Windows user folder "C:\Users\My User" because the Rust compiler will have problems with the dependencies.

  2. Precompile the libraries "ring_core_0_17_8_fiat_curve25519_adx_mul" and the library "ring_core_0_17_8_fiat_curve25519_adx_square" using the "build.rs".

Example:

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(())
}

You also have to make this adjustment in "C:\Users\My User.cargo\config.toml"

[target.x86_64-unknown-linux-gnu]
rustflags = ["-C", "linker=clang", "-C", "link-arg=-fuse-ld=lld"]
linker = "C:\\msys64\\ucrt64\\bin\\clang.exe"
ar = "C:\\msys64\\ucrt64\\bin\\ar.exe"

Finally the program ran.