#Cross compiling on linux for windows, adding an icon to the executable?

1 messages · Page 1 of 1 (latest)

surreal forge
#

Scenario / background:
I have a basic Gitlab CI/CD pipeline setup for automatically building a tool I wrote.

When compiling on windows I can add an icon to the executable trivially with using winres, however I can't seem to find a way to add an icon to the exe from the linux runner.

I can easily add a icon to a windows x64 executable while compiling on windows. However I can't seem to find a way to do it when compiling for windows on linux.
Does anyone have any suggestions?

On windows its as easy as:

use std::io;
#[cfg(windows)]
use winres::WindowsResource;
fn main() -> io::Result<()> {
    static_vcruntime::metabuild();
    #[cfg(windows)] {
        WindowsResource::new()
            .set_icon("resources/up.ico")
            .compile()?;
    }
    Ok(())
}```
#

I have tried a basic implementation as follows however its stated that it may be UB on linux systems

use std::io;
use winres::WindowsResource;

fn main() -> io::Result<()> {
    static_vcruntime::metabuild();
    if cfg!(unix) {
        WindowsResource::new()
            .set_toolkit_path("/usr/bin")
            .set_windres_path("x86_64-w64-mingw32-windres")
            .set_icon("resources/up.ico")
            .compile()?;
    } else if cfg!(windows) {
            WindowsResource::new()
                .set_icon("resources/up.ico")
                .compile()?;
    }
    Ok(())
}
#

Not sure if anyone has succeeded in doing this ?