Files
ElyOffice/packaging/windows/icon.rs
T
ZacharyZhang-NYandClaude Opus 5.5 d07f0ddb7c ely-mark: rustfmt the files R3.1 left unformatted
Formatting alone; cargo fmt --check failed on these six.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-14 09:12:48 -04:00

27 lines
1.1 KiB
Rust

//! Each app's build script: its icon as resource 1 on Windows.
use std::{env, fs, path::PathBuf};
fn main() {
if env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") {
return;
}
let app = env::var("CARGO_PKG_NAME").expect("cargo names the package");
let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("cargo names the folder"));
let icon = root.join("../../assets/icons").join(format!("{app}.ico"));
let icon =
fs::canonicalize(&icon).unwrap_or_else(|error| panic!("{}: {error}", icon.display()));
println!("cargo:rerun-if-changed={}", icon.display());
// gpui's window icon is resource 1.
let rc = PathBuf::from(env::var("OUT_DIR").expect("cargo gives OUT_DIR")).join("icon.rc");
let path = icon
.to_str()
.expect("a UTF-8 path")
.trim_start_matches(r"\\?\")
.replace('\\', "/");
fs::write(&rc, format!("1 ICON \"{path}\"\n")).expect("the resource script is written");
embed_resource::compile(&rc, embed_resource::NONE)
.manifest_optional()
.expect("the icon resource compiles");
}