#executable #icons #tauri #metadata #resources #cross-platform #winres

build tauri-winres

Create and set windows icons and metadata for executables

2 releases

Uses old Rust 2015

0.1.1 May 4, 2023
0.1.0 Jan 19, 2023

#349 in Build Utils

Download history 34134/week @ 2024-07-27 34941/week @ 2024-08-03 37715/week @ 2024-08-10 35037/week @ 2024-08-17 38160/week @ 2024-08-24 44633/week @ 2024-08-31 36350/week @ 2024-09-07 34397/week @ 2024-09-14 33937/week @ 2024-09-21 40773/week @ 2024-09-28 40168/week @ 2024-10-05 41767/week @ 2024-10-12 38976/week @ 2024-10-19 41166/week @ 2024-10-26 40718/week @ 2024-11-02 34464/week @ 2024-11-09

161,379 downloads per month
Used in 123 crates (3 directly)

MIT license

30KB
329 lines

tauri-winres

A simple library to facilitate adding Resources (metainformation and icons) to Portable Executables.

Note: tauri-winres is a fork of winres which no longer works on Rust 1.61 or higher and has been left unmaintained. This fork completely replaced the resource compiler implementation with the awesome embed-resource crate for better cross-platform compilation support. This fork was primarily updated and modified for use in Tauri. For a more general-purpose-like fork, which currently sticks closer to upstream, we suggest to also take a look at winresource.

Documentation

Toolkit

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

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

The Windows SDK can generally be found in the registry, but minGW64 must be in the $PATH environment.

Using tauri-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]
tauri-winres = "0.1"

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

// build.rs

fn main() {
  if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" {
    let mut res = tauri_winres::WindowsResource::new();
    res.set_icon("test.ico");
    res.compile().unwrap();
  }
}

That's 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 support for using this crate on non-Windows platforms is experimental. It is recommended to only use tauri-winres on Windows hosts, by using cfg as a directive to avoid building tauri-winres on unix platforms alltogether.

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

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

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

// build.rs

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

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

Additional Options

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

[package.metadata.tauri-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

The original author and maintainers use this crate for their personal projects and although it 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.

Dependencies

~0.7–11MB
~66K SLoC