chore(release): v2.0.0
This commit is contained in:
parent
a6f33284a7
commit
7fbf34ff2e
81 changed files with 16727 additions and 3280 deletions
100
packaging/windows/installer/build.rs
Normal file
100
packaging/windows/installer/build.rs
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
use flate2::write::GzEncoder;
|
||||
use flate2::Compression;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
fn read_root_version(root_cargo_toml: &Path) -> String {
|
||||
if let Ok(text) = fs::read_to_string(root_cargo_toml) {
|
||||
for line in text.lines() {
|
||||
let trimmed = line.trim();
|
||||
if let Some(rest) = trimmed.strip_prefix("version") {
|
||||
if let Some(val) = rest.trim().strip_prefix('=') {
|
||||
let v = val.trim().trim_matches('"').trim_matches('\'');
|
||||
if !v.is_empty() {
|
||||
return v.to_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "0.1.9".to_string())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
|
||||
let repo_root = manifest_dir
|
||||
.parent()
|
||||
.and_then(|p| p.parent())
|
||||
.and_then(|p| p.parent())
|
||||
.expect("installer must live under packaging/windows/installer");
|
||||
|
||||
let root_cargo = repo_root.join("Cargo.toml");
|
||||
println!("cargo:rerun-if-changed={}", root_cargo.display());
|
||||
println!("cargo:rerun-if-env-changed=YM_PAYLOAD_EXE");
|
||||
println!("cargo:rerun-if-env-changed=YM_ALLOW_EMPTY_PAYLOAD");
|
||||
|
||||
let app_version = read_root_version(&root_cargo);
|
||||
println!("cargo:rustc-env=YM_APP_VERSION={}", app_version);
|
||||
|
||||
let payload_src = env::var("YM_PAYLOAD_EXE")
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|_| repo_root.join("target").join("release").join("yandex-music-rs.exe"));
|
||||
println!("cargo:rerun-if-changed={}", payload_src.display());
|
||||
|
||||
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||
let payload_gz = out_dir.join("payload.gz");
|
||||
|
||||
let raw_bytes = if payload_src.exists() {
|
||||
fs::read(&payload_src).unwrap_or_else(|e| {
|
||||
panic!(
|
||||
"Failed to read app binary {}: {}",
|
||||
payload_src.display(),
|
||||
e
|
||||
)
|
||||
})
|
||||
} else if env::var("YM_ALLOW_EMPTY_PAYLOAD").as_deref() == Ok("1") {
|
||||
println!(
|
||||
"cargo:warning=Using empty placeholder payload because {} does not exist",
|
||||
payload_src.display()
|
||||
);
|
||||
Vec::new()
|
||||
} else {
|
||||
panic!(
|
||||
"App binary not found at {}. Run `cargo build --release` in repo root first (or set YM_PAYLOAD_EXE).",
|
||||
payload_src.display()
|
||||
);
|
||||
};
|
||||
|
||||
let uncompressed_kb = ((raw_bytes.len() as u64) + 1023) / 1024;
|
||||
println!("cargo:rustc-env=YM_PAYLOAD_KB={}", uncompressed_kb.max(1));
|
||||
|
||||
let mut encoder = GzEncoder::new(Vec::new(), Compression::best());
|
||||
encoder
|
||||
.write_all(&raw_bytes)
|
||||
.expect("Failed to compress payload");
|
||||
let compressed = encoder.finish().expect("Failed to finish gzip stream");
|
||||
fs::write(&payload_gz, compressed).expect("Failed to write payload.gz");
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
if env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") {
|
||||
let ico = repo_root
|
||||
.join("packaging")
|
||||
.join("icons")
|
||||
.join("yandex-music-rs.ico");
|
||||
println!("cargo:rerun-if-changed={}", ico.display());
|
||||
if ico.exists() {
|
||||
let mut res = winresource::WindowsResource::new();
|
||||
res.set_icon(ico.to_string_lossy().as_ref());
|
||||
res.set("ProductName", "Яндекс Музыка — Установщик");
|
||||
res.set("FileDescription", "Yandex Music Desktop Client Installer");
|
||||
res.set("CompanyName", "marwy");
|
||||
res.set("ProductVersion", &app_version);
|
||||
res.set("FileVersion", &app_version);
|
||||
if let Err(e) = res.compile() {
|
||||
println!("cargo:warning=winresource failed: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue