-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
38 lines (30 loc) · 1.19 KB
/
Copy pathbuild.rs
File metadata and controls
38 lines (30 loc) · 1.19 KB
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
use std::fs;
use std::path::Path;
fn main() {
println!("cargo:rerun-if-changed=Cargo.lock");
let cargo_lock_path = Path::new("Cargo.lock");
let cargo_lock = fs::read_to_string(cargo_lock_path)
.unwrap_or_else(|err| panic!("failed to read {}: {err}", cargo_lock_path.display()));
let mut in_numbat_package = false;
let mut numbat_version = None;
for line in cargo_lock.lines() {
let trimmed = line.trim();
if trimmed == "name = \"numbat\"" {
in_numbat_package = true;
continue;
}
if in_numbat_package && trimmed.starts_with("version = ") {
let version = trimmed
.strip_prefix("version = \"")
.and_then(|value| value.strip_suffix('"'))
.unwrap_or_else(|| panic!("unexpected numbat version line: {trimmed}"));
numbat_version = Some(version.to_string());
break;
}
if in_numbat_package && trimmed.is_empty() {
in_numbat_package = false;
}
}
let numbat_version = numbat_version.expect("could not find numbat version in Cargo.lock");
println!("cargo:rustc-env=NUMBAT_VERSION={numbat_version}");
}