build.rs
54 lines · 1870 bytes
2 symbols in this file
1#[allow(unused)]
2#[repr(u64)]
3enum WeechatApiVersions {
4 V4_1_0 = 20230908,
5 V4_2_0 = 20240105,
6}
7
8fn main() {
9 println!("cargo::rerun-if-changed=build.rs");
10 println!("cargo::rerun-if-changed=.git/HEAD");
11 println!("cargo::rerun-if-changed=.git/refs");
12 println!("cargo::rerun-if-changed=.git/packed-refs");
13 println!("cargo::rerun-if-env-changed=WEECHAT_BUNDLED");
14 println!("cargo::rerun-if-env-changed=WEECHAT_PLUGIN_FILE");
15 println!("cargo::rustc-check-cfg=cfg(weechat410)");
16 println!("cargo::rustc-check-cfg=cfg(weechat420)");
17
18 let (version, _) =
19 std::str::from_utf8(weechat_sys::WEECHAT_PLUGIN_API_VERSION)
20 .expect("Failed to parse WeeChat API version string")
21 .split_once('-')
22 .expect("Failed to split WeeChat API version string");
23
24 let version: u64 = version
25 .parse()
26 .expect("Failed to parse WeeChat API version string as u64");
27
28 if version >= WeechatApiVersions::V4_2_0 as u64 {
29 println!("cargo::rustc-cfg=weechat420");
30 } else {
31 println!("cargo::rustc-cfg=weechat410");
32 }
33
34 // Capture git describe output for the version command
35 if let Ok(output) = std::process::Command::new("git")
36 .args([
37 "describe", "--long", "--tags", "--always", "--all", "--dirty",
38 ])
39 .current_dir(std::env::var("CARGO_MANIFEST_DIR").unwrap())
40 .output()
41 {
42 if output.status.success() {
43 let describe =
44 String::from_utf8_lossy(&output.stdout).trim().to_string();
45 println!("cargo::rustc-env=GIT_DESCRIBE={}", describe);
46 println!(
47 "cargo::warning=weechat-matrix git describe: {}",
48 describe
49 );
50 } else {
51 println!("cargo::warning=weechat-matrix: git describe failed");
52 }
53 }
54}