Skip to content

Commit

Permalink
Link app icon using build script
Browse files Browse the repository at this point in the history
  • Loading branch information
printfn committed Oct 23, 2024
1 parent 9b94209 commit 1d15fde
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
8 changes: 2 additions & 6 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
21 changes: 21 additions & 0 deletions cli/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::{env, error, fs};

fn link_icon() -> Result<(), Box<dyn error::Error>> {
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}");
}
}

0 comments on commit 1d15fde

Please sign in to comment.