Repository navigation
Expand file tree
/
Copy pathbuild.rs
More file actions
50 lines (40 loc) · 2.22 KB
/
Copy pathbuild.rs
File metadata and controls
50 lines (40 loc) · 2.22 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
use std::{env, fs};
extern crate embed_resource;
extern crate toml;
include!("resources/version_resource.rs");
fn main() {
embed_resource::compile("./resources/client.rc", embed_resource::NONE).manifest_optional().ok();
if let Err(e) = embed_resource::compile("./resources/kute-manifest.rc", embed_resource::NONE).manifest_required() {
eprintln!("{}", e)
};
let toml_content = fs::read_to_string("Cargo.toml").unwrap();
let toml: toml::Value = toml::from_str(&toml_content).unwrap();
let package_version = toml["package"]["version"].as_str().unwrap();
let js_bundle_version = toml["package"]["metadata"]["js_bundle_version"].as_str().unwrap();
let description = toml["package"]["description"].as_str().unwrap();
embed_version_resource(package_version, "Kute", description, "kute.exe", VFT_APP);
let dest_path = env::current_dir().unwrap().join("target/bundle_version");
fs::write(dest_path, js_bundle_version).unwrap();
let wxs_path = "resources/installer_script.wxs";
let wxs_content = fs::read_to_string(wxs_path).unwrap();
let regex = regex::Regex::new(r#"Version="([^"]+)""#).unwrap();
let current_version = regex.captures(&wxs_content).and_then(|cap| cap.get(1)).map(|m| m.as_str());
if current_version != Some(package_version) {
let updated_wxs = regex.replace(&wxs_content, format!(r#"Version="{}""#, package_version)).to_string();
fs::write(wxs_path, updated_wxs).unwrap();
}
// libcef.so ships next to the binary
if env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("linux") {
println!("cargo:rustc-link-arg-bins=-Wl,-rpath,$ORIGIN");
}
println!("cargo:rerun-if-changed=Cargo.toml");
println!("cargo:rerun-if-changed=resources/kute.exe.manifest");
println!("cargo:rerun-if-changed=resources/comctl6.manifest");
println!("cargo:rerun-if-changed=resources/kute-manifest.rc");
println!("cargo:rerun-if-changed=resources/client.rc");
println!("cargo:rerun-if-changed=resources/version_resource.rs");
// the .rc only names the icon
println!("cargo:rerun-if-changed=resources/kute.ico");
println!("cargo:rerun-if-changed=resources/installer_script.wxs");
println!("cargo:rerun-if-changed=target/bundle.js");
}