dftd3_sys/lib.rs
1//! Build-script-only support crate for the DFT-D3 dispersion correction.
2//!
3//! This crate contains no Rust API. Its `build.rs` provides the native
4//! `s-dftd3` (and its `mctc-lib` dependency) as **static** archives and
5//! emits the corresponding `cargo:rustc-link-lib` directives, so anything
6//! depending on this crate links `libs-dftd3.a` + `libmctc-lib.a` directly
7//! into the final binary — no `libs-dftd3.so` ever ends up next to the
8//! wheel.
9//!
10//! The Rust FFI bindings and the safe wrapper API come from the [`dftd3`]
11//! crate (crates.io, RESTGroup/dftd3-rs), wired up without its
12//! `dynamic_loading` feature (which would `dlopen` a shared library at
13//! runtime). `fastatomstruct-simulation`'s `dftd3` cargo feature pulls in
14//! both crates.
15//!
16//! [`dftd3`]: https://crates.io/crates/dftd3
17
18/// The simple-dftd3 release this crate links. Referenced from
19/// `fastatomstruct-simulation` (or any downstream user) so the crate is
20/// part of every final link graph — rustc prunes unreferenced crates, and
21/// with them the static-archive link flags emitted by this crate's build
22/// script.
23///
24/// Derived from the `SDFTD3_TAG` pin in `build.rs` via
25/// `cargo:rustc-env=SDFTD3_VERSION`, so it can never drift from the
26/// library that was actually built (finding F0459).
27pub const SDFTD3_VERSION: &str = env!("SDFTD3_VERSION");
28
29#[cfg(test)]
30mod tests {
31 use super::SDFTD3_VERSION;
32
33 #[test]
34 fn pinned_version_is_plain_semver() {
35 // Guards the build.rs `cargo:rustc-env` plumbing: the value must be
36 // the tag minus its leading `v`, e.g. "1.4.0".
37 let mut parts = SDFTD3_VERSION.split('.');
38 assert!(
39 parts
40 .next()
41 .is_some_and(|p| !p.is_empty() && p.bytes().all(|b| b.is_ascii_digit())),
42 "SDFTD3_VERSION = {SDFTD3_VERSION:?} is not derived from the v-prefixed tag"
43 );
44 assert!(parts.next().is_some(), "SDFTD3_VERSION must be X.Y.Z");
45 assert!(parts.next().is_some(), "SDFTD3_VERSION must be X.Y.Z");
46 assert_eq!(parts.next(), None, "SDFTD3_VERSION must be X.Y.Z");
47 }
48}