llvm-ffi: FFI bindings to the LLVM compiler toolkit.

[ bsd3, code-generation, compilers-interpreters, library ] [ Propose Tags ] [ Report a vulnerability ]

FFI bindings to the LLVM compiler toolkit.

We try to stay up to date with LLVM releases. The current version of this package is compatible with LLVM 13-21. Please understand that the package may or may not work against older LLVM releases.

Caution: In many cases installation cannot run fully automatic. See ReadMe.md for the details.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
developer

developer mode - warnings let compilation fail

Disabled
buildexamples

Build example executables

Disabled
pkgconfig

use pkgconfig (llvm.pc) instead of extra-libraries

Disabled
specificpkgconfig

use llvm-x.pc instead of llvm.pc

Enabled
llvm1300

use LLVM-13 instead of latest supported LLVM

Disabled
llvm1400

use LLVM-14 instead of latest supported LLVM

Disabled
llvm1500

use LLVM-15 instead of latest supported LLVM

Disabled
llvm1600

use LLVM-16 instead of latest supported LLVM

Disabled
llvm1700

use LLVM-17 instead of latest supported LLVM

Disabled
llvm1800

use LLVM-18 instead of latest supported LLVM

Disabled
llvm1900

use LLVM-19 instead of latest supported LLVM

Disabled
llvm2000

use LLVM-20 instead of latest supported LLVM

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 3.0.0, 3.0.0.1, 3.0.0.2, 3.1.0, 3.2.0, 3.2.1, 3.3.0, 3.4.0, 3.5.0, 3.5.1, 3.6.0, 3.7.0, 3.8.0, 3.8.1, 3.8.1.1, 3.8.1.2, 3.9.0, 3.9.1, 9.0.0, 9.1.0, 9.1.0.1, 9.1.1, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 21.0.0.1, 21.0.0.2
Dependencies base (>=3 && <5), enumset (>=0.0.5 && <0.2) [details]
Tested with ghc ==7.4.2, ghc ==7.6.3, ghc ==7.8.4, ghc ==8.0.2, ghc ==8.2.2, ghc ==8.4.4, ghc ==8.6.5, ghc ==8.8.4, ghc ==8.10.4
License BSD-3-Clause
Author Henning Thielemann, Bryan O'Sullivan, Lennart Augustsson
Maintainer Henning Thielemann <llvm@henning-thielemann.de>
Category Compilers/Interpreters, Code Generation
Home page http://haskell.org/haskellwiki/LLVM
Source repo head: darcs get https://hub.darcs.net/thielema/llvm-ffi/
this: darcs get https://hub.darcs.net/thielema/llvm-ffi/ --tag 21.0.0.2
Uploaded by HenningThielemann at 2025-08-10T16:40:10Z
Distributions NixOS:16.0
Reverse Dependencies 2 direct, 8 indirect [details]
Executables llvm-ffi-offset, llvm-ffi-jit, llvm-ffi-host
Downloads 13782 total (130 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user [build log]
All reported builds failed as of 2025-08-10 [all 2 reports]

Readme for llvm-ffi-21.0.0.2

[back to package description]

Installation

Installation cannot be done fully automatically. It would require Cabal code that is bound to certain Cabal versions and is prone to fail. We give several non-automatic ways that also allow you to choose a particular LLVM version.

First possibility is to point Cabal to the LLVM installation directories manually. It is recommended to add options to your global .cabal/config:

extra-include-dirs: /usr/lib/llvm-21/include
extra-lib-dirs: /usr/lib/llvm-21/lib

This works for both v1-build and v2-build. The shown paths work for Debian and Ubuntu using the LLVM repositories at https://apt.llvm.org/. You can obtain them with

llvm-config-21 --includedir --libdir

You can choose specific LLVM versions per project. For v1-builds it works like so:

cabal install -fllvm1300 --extra-include-dirs=$(llvm-config-13 --includedir) --extra-lib-dirs=$(llvm-config-13 --libdir) yourpackage

For Nix-style build you must add some options to the cabal.project.local file of your LLVM-related project:

package llvm-ffi
  flags: +llvm1300
  extra-include-dirs: /usr/lib/llvm-13/include
  extra-lib-dirs: /usr/lib/llvm-13/lib

Alternatively, you may set environment variables globally or locally:

export CPATH=/usr/lib/llvm-21/include:$CPATH
export C_INCLUDE_PATH=/usr/lib/llvm-21/include:$C_INCLUDE_PATH
export LD_LIBRARY_PATH=/usr/lib/llvm-21/lib:$LD_LIBRARY_PATH

You can install and make LLVM library available in an elegant way using Nix:

nix-shell -p llvmPackages_21.libllvm

Though, for compatibility of GHC with LLVM and GLIBC you will need to use more packages from Nix and you better use a shell.nix file for bundling those:

let
  pkgs = import <nixpkgs> {};
  llvmPkgs = pkgs.llvmPackages_21.libllvm;
in
pkgs.mkShell {
  nativeBuildInputs = (with pkgs; [
    gnumake
    pkg-config
    ghc
    cabal-install
    llvmPkgs
  ]);
  CPATH="${llvmPkgs.dev}/include";
  C_INCLUDE_PATH="${llvmPkgs.dev}/include";
  LD_LIBRARY_PATH="${llvmPkgs.lib}/lib";
}

The second way uses pkg-config. You can store above paths permanently in a pkg-config file like llvm.pc. The optimal way would be if LLVM installations or GNU/Linux distributions would contain such a file, but they don't. Instead, you may generate it using the llvm-pkg-config package or write one manually. Then you run

cabal install -fpkgConfig

We ship a pkg-config.nix file. If you import this into your Nix expression, Nix will prepare and install a llvm.pc file for you.

Known issues

Warning for inplace builds: Re-configuring the package using, say -fllvm1600, and re-buildung it might result in corrupt code. You must make sure that the stuff in cbits is re-compiled. Cabal or GHC may forget about that. You are safe if you run cabal clean.

Caution: Surprises are ahead if you have configured paths for LLVM version X in .cabal/config and try to build llvm-ffi for a different LLVM version Y by adding custom include and library paths to cabal.project. Counterintuitively, global search paths take higher precedence than local ones.

We now depend on libLLVM.so, not on libLLVM-X.so anymore. This is for consistency with the include files, where there are no include file names including version numbers. In former versions of this binding package we depend on generic LLVM/Core.h but specific libLLVM-X.so. This meant, that the include files configured in .cabal/config were mixed with the library configured in cabal.project. This lead to ugly, hard to debug crashes.