A simple library to facilitate adding Resources (metainformation and icons) to Portable Executables (Windows executables and dynamic libraries).
Note: winresource
is a fork of winres which no longer works on Rust 1.61 or higher and has been left unmaintained.
Before we begin you need to have the appropriate tools installed.
- rc.exe
from the [Windows SDK]
- windres.exe
and ar.exe
from [minGW64]
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.
First, you will need to add a build script to your crate (build.rs
) by adding it to your crate's Cargo.toml
file:
```toml [package]
build = "build.rs"
[build-dependencies] winresource = "0.1" ```
Next, you have to write a build script. A short example is shown below.
```rust // build.rs
extern crate winresource;
fn main() { if cfg!(targetos = "windows") { let mut res = winresource::WindowsResource::new(); res.seticon("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 winresource
on unix platforms alltogether. This will save build time. So the example from before could look like this
```toml [package]
build = "build.rs"
[target.'cfg(windows)'.build-dependencies] winresource = "0.1" ```
Next, you have to write a build script. A short example is shown below.
```rust // build.rs
extern crate winresource;
fn main() { let mut res = winresource::WindowsResource::new(); res.set_icon("test.ico"); res.compile().unwrap(); }
fn main() { } ```
For added convenience, winresource
parses, Cargo.toml
for a package.metadata.winresource
section:
```toml [package.metadata.winresource] 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.
The original author and maintainers use this crate for their personal projects and although is has been tested in that context, we have no idea if the behaviour is the same everywhere.
To be brief, we are very much reliant on your bug reports and feature suggestions to make this crate better.