-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add icon to binary file #9
Comments
Hi, I’m interested in having a go at this! |
Of course, you are very much welcome to do so! I had been looking into it lately too, I think Another crate to look into is https://crates.io/crates/embed-resource (Windows). Edit: Linux executables do not have icons |
@bryonye Are you still interested in this? |
@MrTanoshii Hey how's it going? I just looked up your profile and found this, Would you like me to submit a PR for this? If you haven't made the changes already that is. Regarding macOS, I think I've read before on how to add an Icon to a macOS binary (will have to look that up again) but I don't really have an access to a macOS, so can't really test it out. |
Yes, if you're up for it please do submit a PR. I'm assigning this to you |
Alright, I'll submit it tomorrow. It's late here rn. |
Hey @MrTanoshii, I wanted to confirm something; Why do we've a lib crate in this package? The reason I'm mentioning this is because unfortunately Some possible solutions:
|
And coming to Icons, should I just use the existing |
Let's go with 256x256 |
Hey, just to let you know that I successfully forced resources to be added to the binary crate in a project with both library and binary crate. You can check my workaround there: mxre/winres#32 (comment). I'm not involved in this project, but removing |
Hi @ITachiLab, It's not that I wanted to remove Actually I'm new to rust, so it'd be great if you could let me know your thoughts on this. I guess this is probably already have been discussed in some later chapter of the Rust book, which I'm currently going through. Thanks for mentioning the workaround btw, I'll look into it. |
Oh @ITachiLab actually, I remember trying that workaround before I removed the lib crate. It didn't workout on my end unfortunately; using Rust 1.64 and this winres fork. I guess I'll try it again, just to be sure. Edit: tried again, didn't work (doesn't work with
Here's the use std::io;
use winres::WindowsResource;
fn main() -> io::Result<()> {
if std::env::var("CARGO_CFG_TARGET_FAMILY").unwrap() == "windows" {
let mut res = WindowsResource::new();
let env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap();
match env.as_str() {
"gnu" => {
res.set_ar_path("x86_64-w64-mingw32-ar")
.set_windres_path("x86_64-w64-mingw32-windres");
}
"msvc" => {}
_ => panic!("unsupported target-env: {}", env),
};
res.set_icon("assets/icon-256.ico");
res.compile()?;
println!("cargo:rustc-link-arg-bins=resource.lib");
}
Ok(())
} Hmm, I was using |
From what I can see in With that being said, you can try using one of these for the GNU tools: println!("cargo:rustc-link-arg-bins=libresource.a"); println!("cargo:rustc-link-arg-bins=-lresource");
No worries, me too 😅. |
Didn't thought of that.
This works (with original #[cfg(unix)]
{
println!("cargo:rustc-link-arg=-Wl,--whole-archive");
println!("cargo:rustc-link-arg=-Wl,-Bstatic");
println!("cargo:rustc-link-arg-bins=-lresource");
println!("cargo:rustc-link-arg=-Wl,--no-whole-archive");
} |
For Windows and MSVC, having just Apparently, MSVC expects resources to appear in linker command line and knows how to deal with them without additional flags. |
I see, got it, Thanks! btw @ITachiLab, I've looked up your project rectangular and it looks like it's completely related to the windows platform. Sorry for being a bother and this is getting off topic but I was hoping maybe you could help me with this Rust windows related issue (nozwock/ventoy-toybox#1) of mine. TL;DR I need to launch an While searching I came across this post "how do I trigger a new process to be run as admin?". |
No worries, we both learn by solving issues ^^.
It's waaaay outdated. The latest version of windows crate is So, in order to run an executable as an administrator, you indeed must use Putting this all together, [dependencies.windows]
version = "0.43.0"
features = [
"Win32_UI_Shell",
"Win32_Foundation",
"Win32_UI_WindowsAndMessaging"
]
use windows::{
s, Win32::UI::Shell::ShellExecuteA, Win32::Foundation::GetLastError,
Win32::UI::WindowsAndMessaging::SW_NORMAL
};
fn main() {
unsafe {
let result = ShellExecuteA(
None,
s!("runas"),
s!("C:\\Users\\Itachi\\AppData\\Local\\Programs\\Python\\Python38-32\\python.exe"),
s!("-c \"import os; os.mkdir('test');\""),
s!("C:\\Users\\Administrator"),
SW_NORMAL
);
println!("{}", GetLastError().0);
}
assert!(result.0 > 32);
} What I'm doing here is running Python as an Administrator, setting |
@ITachiLab Thanks a lot! |
Problem
The app icon is currently implemented in the app itself but not on the binary file.
Potential Solutions
The text was updated successfully, but these errors were encountered: