-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
79 lines (69 loc) · 2.82 KB
/
build.rs
File metadata and controls
79 lines (69 loc) · 2.82 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
fn main() {
// Update skeleton on EVERY build to ensure latest version
// No cargo:rerun-if-changed for skeleton = always runs
// Execute the script
// Use "sh" on Windows (Git Bash), "bash" on Linux/macOS
#[cfg(target_os = "windows")]
let shell = "sh";
#[cfg(not(target_os = "windows"))]
let shell = "bash";
let status_skeleton = std::process::Command::new(shell)
.arg("./scripts/update_skeleton.sh")
.status();
match status_skeleton {
Ok(s) => {
if !s.success() {
// If the script fails, we might want to fail the build or just warn?
// Failing is safer to ensure we don't build with a broken skeleton.
panic!("Failed to update skeleton: exit code {:?}", s.code());
}
}
Err(e) => {
panic!("Failed to execute update_skeleton.sh: {}", e);
}
}
// Bump version using VERSION file
// We do NOT modify Cargo.toml to avoid infinite rebuild loops (Cargo detects manifest changes).
// Skip version bumping in CI to ensure consistent versions across all builds
let is_ci = std::env::var("CI").is_ok();
if !is_ci {
// Rerun if the script changes
println!("cargo:rerun-if-changed=scripts/bump_version.sh");
// Watch source directories so build.rs runs when code changes
println!("cargo:rerun-if-changed=cli");
println!("cargo:rerun-if-changed=core");
println!("cargo:rerun-if-changed=features");
// Also watch the script itself
println!("cargo:rerun-if-changed=scripts/bump_version.sh");
#[cfg(target_os = "windows")]
let shell = "sh";
#[cfg(not(target_os = "windows"))]
let shell = "bash";
let status_bump = std::process::Command::new(shell)
.arg("./scripts/bump_version.sh")
.status();
match status_bump {
Ok(s) => {
if !s.success() {
panic!("Failed to bump version: exit code {:?}", s.code());
}
}
Err(e) => {
panic!("Failed to execute bump_version.sh: {}", e);
}
}
}
// Read the NEW version from Cargo.toml so we can compile it in
// Note: Cargo parses Cargo.toml BEFORE running build.rs, so the env var CARGO_PKG_VERSION
// will hold the *old* version unless we override it.
// Quick and dirty read of line starting with version = "..."
if let Ok(cargo_toml) = std::fs::read_to_string("Cargo.toml") {
for line in cargo_toml.lines() {
if line.starts_with("version = \"") {
let v = line.trim().replace("version = \"", "").replace("\"", "");
println!("cargo:rustc-env=CARGO_PKG_VERSION={}", v);
break;
}
}
}
}