From fca2467fd58a89b62f31d58197ac891880c793eb Mon Sep 17 00:00:00 2001 From: The Noah Date: Thu, 22 Aug 2024 22:05:06 -0500 Subject: [PATCH] chore: improve Windows resource generation --- Cargo.lock | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 6 +++++ build.rs | 27 ++++---------------- resources.rc | Bin 44 -> 0 bytes 4 files changed, 80 insertions(+), 22 deletions(-) delete mode 100644 resources.rc diff --git a/Cargo.lock b/Cargo.lock index b12d0af..6ccd47b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -964,6 +964,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -1018,6 +1027,7 @@ dependencies = [ "sysinfo", "win32utils", "windows 0.58.0", + "winresource", ] [[package]] @@ -1174,6 +1184,40 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.19.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + [[package]] name = "tower" version = "0.4.13" @@ -1270,6 +1314,12 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + [[package]] name = "walkdir" version = "2.5.0" @@ -1667,6 +1717,15 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "winnow" +version = "0.5.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] + [[package]] name = "winreg" version = "0.52.0" @@ -1677,6 +1736,16 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "winresource" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e2aaaf8cfa92078c0c0375423d631f82f2f57979c2884fdd5f604a11e45329" +dependencies = [ + "toml", + "version_check", +] + [[package]] name = "xml-rs" version = "0.8.20" diff --git a/Cargo.toml b/Cargo.toml index 3b25356..622c46d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,12 @@ features = [ "Win32_UI_WindowsAndMessaging", ] +[build-dependencies] +winresource = "0.1" + +[package.metadata.winresource] +LegalCopyright = "Copyright (c) 2024 Noah Dunbar" + [profile.release] lto = true codegen-units = 1 diff --git a/build.rs b/build.rs index df77bfe..6b4e465 100644 --- a/build.rs +++ b/build.rs @@ -1,24 +1,7 @@ -#[cfg(target_os = "windows")] -pub fn add_resource(name: String) { - let out_dir = std::env::var("OUT_DIR").expect("No OUT_DIR env var"); - - if !std::process::Command::new("rc.exe") - .args(["/fo", &format!("{}/{}.lib", &out_dir, &name), "/I", &out_dir, &(name.to_owned() + &String::from(".rc"))]) - .status() - .expect("Could not find rc.exe") - .success() - { - panic!("Failed to build resource file"); - } - - println!("cargo:rustc-link-search=native={}", &out_dir); - println!("cargo:rustc-link-lib=dylib={}", &name); -} - -#[cfg(target_os = "windows")] fn main() { - add_resource(String::from("resources")); + if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" { + let mut res = winresource::WindowsResource::new(); + res.set_icon("icon.ico"); + res.compile().unwrap(); + } } - -#[cfg(not(target_os = "windows"))] -fn main() {} diff --git a/resources.rc b/resources.rc deleted file mode 100644 index 59f09c0bf49dbfe07fb30c2b671b8fdc02cba2fe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 44 lcmezW&y&HK!Jom8L4g6mQewztNM^`q$YaohvXmIO7y#HZ2k-y@