-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathbuild.rs
60 lines (50 loc) · 1.82 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use std::{
env,
path::{Path, PathBuf},
};
use semver::{Comparator, Op, Version};
fn main() {
let libcamera_version = Version::new(0, 3, 2);
let versioned_files = Path::new("versioned_files");
let mut candidates = std::fs::read_dir(versioned_files)
.unwrap()
.filter_map(|entry| entry.ok())
.filter_map(|entry| {
let path = entry.path();
let version = Version::parse(path.file_name()?.to_str()?).ok()?;
Some((version, path))
})
.collect::<Vec<_>>();
candidates.sort_unstable_by_key(|(version, _)| version.clone());
// Filter to only compatible versions
let matching = candidates.iter().filter(|(candidate, _)| {
#[cfg(feature = "libcamera_semver_versioning")]
let op = Op::Caret;
#[cfg(not(feature = "libcamera_semver_versioning"))]
let op = Op::Exact;
let comparator = Comparator {
op,
major: candidate.major,
minor: Some(candidate.minor),
patch: Some(candidate.patch),
pre: Default::default(),
};
comparator.matches(&libcamera_version)
});
// And take the most recent compatible version
let (_, selected_version) = match matching.max_by_key(|(version, _)| version.clone()) {
Some(v) => v,
None => panic!(
"Unsupported version of libcamera detected: {libcamera_version}\nsupported versions are: \n{}",
candidates
.iter()
.map(|(v, _)| format!("\t{v}"))
.collect::<Vec<_>>()
.join("\n")
),
};
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
for file in ["controls.rs", "properties.rs"] {
std::fs::copy(selected_version.join(file), out_path.join(file)).unwrap();
}
}