-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
84 lines (69 loc) · 3.1 KB
/
Copy pathbuild.rs
File metadata and controls
84 lines (69 loc) · 3.1 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
80
81
82
83
84
// build script
// this script contains dead code that might have been introduced as platform
// specific, but might also be useful in further editions
#![allow(dead_code)]
use std::env;
// information used during the build process in pre-build actions
const APP_NAME: &str = env!("CARGO_PKG_NAME");
const APP_DESC: &str = env!("CARGO_PKG_DESCRIPTION");
const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
const APP_LICENSE: &str = env!("CARGO_PKG_LICENSE");
const APP_VER_MAJOR: &str = env!("CARGO_PKG_VERSION_MAJOR");
const APP_VER_MINOR: &str = env!("CARGO_PKG_VERSION_MINOR");
const APP_VER_PATCH: &str = env!("CARGO_PKG_VERSION_PATCH");
// provide version info as a 64 bit unsigned: none of the required values
// should actually be forcibly set to zero (except for `pre`), as the version
// always follows the guidelines specified in the dedicated discussion: see
// https://github.com/almostearthling/whenever/discussions/88#discussion-9422899
fn version_info_as_u64() -> u64 {
let app_ver_pre: &str = option_env!("CARGO_PKG_VERSION_PRE").unwrap_or("0");
APP_VER_MAJOR.parse::<u64>().unwrap_or(0) << 48
| APP_VER_MINOR.parse::<u64>().unwrap_or(0) << 32
| APP_VER_PATCH.parse::<u64>().unwrap_or(0) << 16
| app_ver_pre.parse::<u64>().unwrap_or(0)
}
// pre-build actions
fn main() {
// 1. platform dependent actions
if let Ok(platform) = env::var("CARGO_CFG_TARGET_OS") {
match platform.as_str() {
"windows" => {
// 1.a: attach an icon and version information (conditional, in
// order to avoid to require `winresource` unconditionally)
#[cfg(windows)]
{
println!("cargo::rerun-if-changed=Cargo.toml");
println!("cargo::rerun-if-changed=resources/metronome.ico");
let mut res = winresource::WindowsResource::new();
res
.set_icon("resources/metronome.ico")
.set_version_info(
winresource::VersionInfo::PRODUCTVERSION,
version_info_as_u64(),
)
.set("InternalName", APP_NAME)
.set("FileDescription", APP_DESC)
.set("ProductVersion", APP_VERSION)
.set("LegalCopyright", APP_LICENSE);
// panic here if something went wrong
res.compile().expect("error attaching resources");
}
// ...
// ^^^ other Windows specific actions should be added above here
}
"linux" => {
// ...
// ^^^ other Linux specific actions should be added above here
}
// ...
// ^^^ other supported platforms should be added above here
_ => {
// panic for unsupported platforms
panic!("unsupported platform: {platform}");
}
}
// ...
// ^^^ other common pre-build actions should be added above here
}
}
//end.