#winapi #windows

build winres

Create and set windows icons and metadata for executables

12 releases

Uses old Rust 2015

0.1.12 Sep 28, 2021
0.1.11 Jun 20, 2019
0.1.9 Mar 25, 2019
0.1.8 Nov 26, 2018
0.1.0 Jul 28, 2016

#7 in Windows APIs

Download history 39712/week @ 2024-06-20 40580/week @ 2024-06-27 35351/week @ 2024-07-04 42025/week @ 2024-07-11 37895/week @ 2024-07-18 43756/week @ 2024-07-25 36001/week @ 2024-08-01 36778/week @ 2024-08-08 32894/week @ 2024-08-15 39818/week @ 2024-08-22 37717/week @ 2024-08-29 41452/week @ 2024-09-05 32103/week @ 2024-09-12 36938/week @ 2024-09-19 36722/week @ 2024-09-26 32425/week @ 2024-10-03

144,864 downloads per month
Used in 146 crates (122 directly)

MIT license

36KB
506 lines

winres

A simple library to facilitate adding metainformation and icons to windows executables and dynamic libraries.

Documentation

Toolkit

Before we begin you need to have the approptiate tools installed.

If you are using Rust with the MSVC ABI you will need the Windows SDK for the GNU ABI you'll need minGW64.

Windows SDK can be found in the registry, minGW64 has to be in the path.

Using winres

First, you will need to add a build script to your crate (build.rs) by adding it to your crate's Cargo.toml file:

[package]
#...
build = "build.rs"

[build-dependencies]
winres = "0.1"

Next, you have to write a build script. A short example is shown below.

// build.rs

extern crate winres;

fn main() {
  if cfg!(target_os = "windows") {
    let mut res = winres::WindowsResource::new();
    res.set_icon("test.ico");
    res.compile().unwrap();
  }
}

Thats it. The file test.ico should be located in the same directory as build.rs. Metainformation (like program version and description) is taken from Cargo.toml's [package] section.

Note that using this crate on non windows platform is undefined behavior. It does not contain safeguards against doing so. None-the-less it will compile; however build.rs, as shown above, should contain a cfg option.

Another possibility is using cfg as a directive to avoid building winres on unix platforms alltogether. This will save build time. So the example from before could look like this

[package]
#...
build = "build.rs"

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

Next, you have to write a build script. A short example is shown below.

// build.rs

#[cfg(windows)]
extern crate winres;

#[cfg(windows)]
fn main() {
    let mut res = winres::WindowsResource::new();
    res.set_icon("test.ico");
    res.compile().unwrap();
}

#[cfg(unix)]
fn main() {
}

Additional Options

For added convenience, winres parses, Cargo.toml for a package.metadata.winres section:

[package.metadata.winres]
OriginalFilename = "PROGRAM.EXE"
LegalCopyright = "Copyright © 2016"
#...

This section may contain arbitrary string key-value pairs, to be included in the version info section of the executable/library file.

The following keys have special meanings and will be shown in the file properties of the Windows Explorer:

FileDescription, ProductName, ProductVersion, OriginalFilename and LegalCopyright

See MSDN for more details on the version info section of executables/libraries.

About this project

I've written this crate chiefly for my personal projects and although I've tested it on my personal computers I have no idea if the behaviour is the same everywhere.

To be brief, I'm very much reliant on your bug reports and feature suggestions to make this crate better.

Dependencies

~235–485KB
~11K SLoC