-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
44 lines (39 loc) · 1.21 KB
/
Copy pathbuild.rs
File metadata and controls
44 lines (39 loc) · 1.21 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
39
40
41
42
43
44
fn main() {
let manifest = std::fs::read_to_string("Cargo.toml").expect("failed to read Cargo.toml");
// Inline: aver-rt = { ..., version = "=0.4.1", ... }
for line in manifest.lines() {
let trimmed = line.trim();
if trimmed.starts_with("aver-rt")
&& let Some(v) = extract_version(trimmed)
{
emit(v);
return;
}
}
// Expanded: [dependencies.aver-rt] section
let mut in_section = false;
for line in manifest.lines() {
let trimmed = line.trim();
if trimmed == "[dependencies.aver-rt]" {
in_section = true;
} else if in_section && trimmed.starts_with('[') {
break;
} else if in_section
&& trimmed.starts_with("version")
&& let Some(v) = extract_version(trimmed)
{
emit(v);
return;
}
}
panic!("could not find aver-rt version in Cargo.toml");
}
fn extract_version(line: &str) -> Option<&str> {
let start = line.find("version = \"")? + 11;
let rest = &line[start..];
let end = rest.find('"')?;
Some(&rest[..end])
}
fn emit(version: &str) {
println!("cargo::rustc-env=AVER_RT_VERSION={version}");
}