45 lines
1.5 KiB
Rust
45 lines
1.5 KiB
Rust
use std::env;
|
|
|
|
fn main() {
|
|
let version = resolve_app_version();
|
|
println!("cargo:rustc-env=APP_VERSION={version}");
|
|
|
|
embed_windows_icon();
|
|
|
|
slint_build::compile("ui/app.slint").expect("Slint build failed");
|
|
}
|
|
|
|
/// Shell icon for `rcalc.exe` in Explorer (needs `assets/icon.ico` + windres/rc).
|
|
fn embed_windows_icon() {
|
|
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
|
|
if target_os != "windows" {
|
|
return;
|
|
}
|
|
|
|
println!("cargo:rerun-if-changed=assets/icon.ico");
|
|
|
|
let mut res = winresource::WindowsResource::new();
|
|
res.set_icon("assets/icon.ico");
|
|
|
|
// Cross-compile from Linux: mingw windres is prefixed.
|
|
if cfg!(not(windows)) {
|
|
let target = env::var("TARGET").unwrap_or_default();
|
|
if target.contains("windows-gnu") {
|
|
res.set_windres_path("x86_64-w64-mingw32-windres");
|
|
}
|
|
}
|
|
|
|
res.compile()
|
|
.expect("failed to embed Windows icon (is windres/rc available?)");
|
|
}
|
|
|
|
/// Window / package version shown as `Rcalc-{version}`.
|
|
///
|
|
/// Always the version from `Cargo.toml`. Раньше каждая release-сборка
|
|
/// инкрементировала patch в Cargo.toml посреди сборки — из-за этого
|
|
/// имя AppImage (читается скриптом до сборки) отставало от версии,
|
|
/// зашитой в бинарник. Теперь версия меняется только вручную.
|
|
fn resolve_app_version() -> String {
|
|
env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "0.0.0".into())
|
|
}
|