forked from cholcombe973/blkid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
37 lines (33 loc) · 1.35 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const LIB_NAME: &str = "blkid";
const BLKID_MIN_REQ_VERSION: &str = "2.21.0";
/// MIN numbers of versions where were added new functionality
const BLKID_CHANGED_MIN_VERSIONS: &[usize] = &[23, 24, 25, 30, 31, 36, 37];
fn main() {
let libblkid = pkg_config::Config::new()
.atleast_version(BLKID_MIN_REQ_VERSION)
.probe(LIB_NAME)
.expect("Failed to find minimal required version of library");
// Take a MIN version from: `MAJ.MIN.PATCH`
let min_num = libblkid
.version
.split_terminator('.')
.nth(1)
.expect("Failed to find MIN number of version");
// Parse version to figure out what features should to be enabled
let min_num: usize = min_num
.parse()
.expect("Failed to parse MIN number of version");
// Find the index of the last changed version
let idx = BLKID_CHANGED_MIN_VERSIONS.iter().position(|v| v > &min_num);
if let Some(idx) = idx {
// If we have some index this means not all features need to be enabled
for min_num in &BLKID_CHANGED_MIN_VERSIONS[..idx] {
println!("cargo:rustc-cfg={}=\"2.{}\"", LIB_NAME, min_num);
}
} else {
// In this case we just enable all features
for min_num in BLKID_CHANGED_MIN_VERSIONS {
println!("cargo:rustc-cfg={}=\"2.{}\"", LIB_NAME, min_num);
}
}
}