This example demonstrates generating Haskell bindings for RPM Package Manager, a powerful package management system.
This example includes a shell.nix file that provides all necessary
dependencies for building RPM from source. The shell environment includes:
Build tools:
cmake- Build system generatorpkg-config- Helper tool for compile/link flagsscdoc- Documentation generator
RPM dependencies:
popt- Command line option parsinglibarchive- Multi-format archive and compression librarysqlite- Database engine for RPM databasezstd- Fast compression algorithmelfutils- ELF object file access libraryxz- LZMA compression utilitieslua- Scripting language for RPMzlib- Compression librarybzip2- Compression libraryreadline- Command line editingfile- File type identificationlibcap- POSIX capabilities libraryaudit- Linux audit frameworklibselinux- SELinux runtime librarydbus- Message bus systemrpm-sequoia- OpenPGP implementation (from nixos-unstable)
Tip
If you are using Nix or NixOS, please also have a look at our hs-bindgen
Nix tutorial.
If not using Nix at all, take a look at the INSTALL file for more details
on the instructions of how to build rpm.
According to the instructions in INSTALL:
# On the `rpm` folder
mkdir _build
cd _build
cmake ..
make
make installOnce all these steps have completed successfully the libraries will be under
rpm/_build/_install/lib64.
The .cabal file includes extra-libraries: rpm, rpmio, which tells the
linker to link against both librpm.so and librpmio.so. RPM is split into
multiple libraries, and both are needed for the bindings to work correctly.
./generate-and-run.shThis script will already generate the bindings by their right order, i.e. the
header include dependency order. If for any reason the rpm library updated,
then it might be necessary to change the generate-and-run script so that it
follows the right order.
To visualize the header dependencies, you can generate an include graph using
hs-bindgen-cli:
cd examples/c-rpm
cabal run hs-bindgen-cli -- info include-graph \
-I rpm/include \
-o output-graph.md \
rpm/rpmlib.hThis generates a Mermaid diagram showing all header includes and their dependencies. You can visualize it at mermaid.live or in any Markdown viewer that supports Mermaid diagrams (like GitHub).