Resource Bundles

Some Relm4 apps require static assets or resources (such as icons or images) to function.

In GTK apps, static assets are transformed into GResource bundles, which are then loaded by the app. This guide shows how to set up GResource bundles within a Relm4 project.


This demonstrates a Cargo-only approach to including resources (i.e. it does not require extra build tools like Meson, or out-of-band shell scripts).

data directory

We add the static resources (in this example, icon files), plus a gresource descriptor, to the project's data folder:


The icons are placed under the data/icons directory.

The icons.gresource.xml file looks like this (adapt it as required, e.g. using -symbolic icon names):

<?xml version="1.0" encoding="UTF-8"?>
    <gresource prefix="com/example/Foobar/icons/24x24/actions/">
        <file preprocess="xml-stripblanks" alias="icon-foo.svg">icons/icon-foo.svg</file>
        <file preprocess="xml-stripblanks" alias="icon-bar.svg">icons/icon-bar.svg</file>


In Cargo.toml, we add a build dependency on glib-build-tools. This gives us access to the glib_build_tools::compile_resources function which we will need later:

name = "foobar"

glib-build-tools = "0.17.10"

Note: you should ensure that the glib-build-tools version aligns with the general GLib version you are building for.

In, we call the compile_resources function which creates a GResource bundle from the icons:

use glib_build_tools::compile_resources;

fn main() {

In (or wherever you initialise your Relm4 app), we load the icons.gresource bundle that Cargo generates:

fn initialize_custom_icons() {

    let display = gdk::Display::default().unwrap();
    let theme = gtk::IconTheme::for_display(&display);

fn main() {
    let app = RelmApp::new("com.example.Foobar");

    // (optional) initialize default icons

    // custom icons

It should now be possible to reference the resources by name within your app, for example:

fn main() {
view! {
    gtk::Button {
        set_icon_name: "icon-foo"