Skip to content

Commit

Permalink
chore: improve Windows resource generation
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Noah committed Aug 23, 2024
1 parent de1775c commit fca2467
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 22 deletions.
69 changes: 69 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 5 additions & 22 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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() {}
Binary file removed resources.rc
Binary file not shown.

0 comments on commit fca2467

Please sign in to comment.