cabal-gresource: GResource build integration with Cabal

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

The package provides build integration with GLib GResources. It allows for automatically building GResources with Haskell programs. The resource is linked into the binary and automatically registered at startup.


[Skip to Readme]

Properties

Versions 0.1.0.0
Change log CHANGELOG.md
Dependencies base (>=4.18 && <4.23), Cabal (>=3.18 && <3.19), Cabal-hooks (>=3.18 && <3.19), filepath (>=1.4 && <1.6) [details]
License BSD-3-Clause
Author Rafał Kuźnia
Maintainer rafal.kuznia@protonmail.com
Category Distribution
Home page https://github.com/e-rk/cabal-gresource
Source repo head: git clone https://github.com/e-rk/cabal-gresource.git
Uploaded by rafalkuznia at 2026-08-17T19:18:28Z

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for cabal-gresource-0.1.0.0

[back to package description]

Intro

The package provides build integration with GLib GResources. It allows for automatically building GResources with Haskell programs. The resource is linked into the binary and automatically registered at startup.

Quick start

Cabal

Install with your package manager a package containing the glib-compile-resources program and ensure it is available from your PATH.

Add the following fields to your cabal file.

build-type: Hooks

custom-setup
  setup-depends:
    base,
    Cabal-hooks
    cabal-gresource,

executable application:
    x-gresource-xml-file: resource/resource.xml
    x-gresource-source-dir: resource

Remember to add the files to extra-source-files in order to be included in sdist.

Build integration

There are two ways to integrate cabal-gresource depending on your package's build-type, one for Custom second for Hooks.

build-type: Hooks

Set the build-type: Hooks and create SetupHooks.hs file.

module SetupHooks (setupHooks) where

import Distribution.Simple.GResource.Hooks (gResourceSetupHooks)
import Distribution.Simple.SetupHooks (SetupHooks)

setupHooks :: SetupHooks
setupHooks = gResourceSetupHooks

build-type: Custom

Set the build-type: Custom and create Setup.hs file.

import Distribution.Simple
import Distribution.Simple.GResource

main = defaultMainWithHooks $ gResourceUserHooks simpleUserHooks

Runtime

During runtime, the GResource is automatically registered. You can access the data as shown below:

import Data.Maybe (fromJust)
import Data.Text qualified as T
import GI.GLib.Structs.Bytes qualified as GLib
import GI.Gio qualified as Gio

main :: IO ()
main = do
  gresdata <- fromJust <$> (Gio.resourcesLookupData (T.pack "/path/to/your/data.txt") [Gio.ResourceLookupFlagsNone] >>= GLib.bytesGetData)

Refer to gi-gio and gi-glib packages from haskell-gi project for details about GResource API.

Short on how it works

The XML describing the GResource file is compiled with glib-compile-resources to a C source file. The C source file is then compiled and linked with the Haskell program by GHC during build. The C source contains a constructor that is automatically called by the C runtime during program startup.

Thanks to this the GResource is automatically registered with Gio.