From 1d15fde5d76b0bb055bfecc96401dcbb25ca602b Mon Sep 17 00:00:00 2001 From: printfn Date: Wed, 23 Oct 2024 09:13:54 +0000 Subject: [PATCH] Link app icon using build script --- .cargo/config.toml | 8 ++------ cli/build.rs | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 cli/build.rs diff --git a/.cargo/config.toml b/.cargo/config.toml index f11910bc..1fb3555c 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -9,9 +9,5 @@ # ``` # and checking that the output doesn't contain any MSVCR DLLs -[target.'cfg(all(target_arch = "x86_64", target_os = "windows", target_env = "msvc")'] -rustflags = [ - "-Ctarget-feature=+crt-static", - "-L./icon", - "-Clink-args=resources.res", -] +[target.x86_64-pc-windows-msvc] +rustflags = ["-Ctarget-feature=+crt-static"] diff --git a/cli/build.rs b/cli/build.rs new file mode 100644 index 00000000..b759c36b --- /dev/null +++ b/cli/build.rs @@ -0,0 +1,21 @@ +use std::{env, error, fs}; + +fn link_icon() -> Result<(), Box> { + if env::var("TARGET")? == "x86_64-pc-windows-msvc" { + println!("cargo::rerun-if-changed=../icon/resources.res"); + if fs::exists("../icon/resources.res")? { + println!("cargo::rustc-link-arg-bins=icon/resources.res"); + } else { + return Err( + "could not find `resources.res` file; fend will not have an app icon".into(), + ); + } + } + Ok(()) +} + +fn main() { + if let Err(e) = link_icon() { + println!("cargo::warning={e}"); + } +}