0

My cargo.toml is:

bin = [
    { name = "first", path = "bin/first.rs" },
    { name = "second", path = "bin/second.rs" },
]
[lib]
name = "some_lib"
crate-type = [
    "cdylib",
    "rlib",
]

[target."cfg(windows)".build-dependencies]
winresource = "0.1"

When compiled, two executables are generated: first.exe and second.exe. In order to have custom icons for the executables on windows, I use the following build.rs script:

use std::io;
#[cfg(windows)] use winresource::WindowsResource;

fn main() -> io::Result<()> {
    println!("cargo:rerun-if-changed=build.rs");
    #[cfg(windows)] {
        WindowsResource::new()
            // This path can be absolute, or relative to your crate root.
            .set_icon("icon_for_first.ico")
            .compile()?;
    }
    Ok(())
}

This applies the resource to every executable, rather than just first.exe. Is there a way to check the target that is being compiled?

Star
  • 131
  • 3
  • 18
  • No there isn't. Note that `build.rs` is only run _once_ even if cargo then builds multiple executables. What you need is some way to have multiple `WindowsResource`s and tell them to which executable they should apply, but AFICS that's not possible with v0.1.15. You can [file an enhancement request](https://github.com/BenjaminRi/winresource/issues/new) and in the meantime you will need to use separate crates for your executables. – Jmb Mar 23 '23 at 07:36
  • Side notes: [the relevant docs](https://doc.rust-lang.org/cargo/reference/build-scripts.html#life-cycle-of-a-build-script) (i.e. once per package, not once per bin), and: For now, you can create a workspace with two separate packages (i.e. two separate `Cargo.toml`s and `build.rs`.) – Caesar Mar 23 '23 at 07:48

0 Answers0