How to specify in cabal file that external tool is needed

Hi,

I am new to the Haskell ecosystem.

In a certain project I need to use llvm-config as a build/test dependency. This tool is not something cabal can download and build because it is not based on Haskell source code. So I think build-depends or build-tool-depends would not help here.

How would I specify this dependency in a cabal file?

Alternatively how would I do the same in a package.yaml file which can be used to generate cabal file by running hpack?

thanks in advance!

What are you planning to use llvm-config for?

@jaror
llvm-config is used for figuring out the library path of llvm library for linking the generated code against. The project generates llvm bitcode for a DSL and the tests verify that the generated code can be linked with llvm and executed.

It is not my project, but I am trying to help with the CI for the project, and learn Haskell in the process :slight_smile:

Cabal doesn’t handle installing non-Haskell tools and I think even tools written in Haskell should be installed through the package manager of your distribution if it has them. In the case of CI, you can probably run a command like apt install llvm.

1 Like

I suspected as much, thanks for confirming!

Cabal has the field cxx-sources.

The cxx-sources field is for when you are writing Haskell programs that use the FFI to call into C++ code. I don’t think that is relevant in this case.

Not a direct answer to your question (since indeed, I don’t believe Cabal supports this as-is): you could consider using Cabal’s pkg-config support, with a .pc file generated in some PKG_CONFIG_PATH using llvm-pkg-config: Generate Pkg-Config configuration file for LLVM.

1 Like

I’m not sure to what degree it “just works”, but you can specify external things in a cabal file with 6. Package Description — Cabal 3.10.1.0 User's Guide .

Otherwise, you could try looking at something like https://devenv.sh/ as a general purpose tool for building dev environments.

@chreekat yes, nix dev shell is a good option that could work, but I am trying to postpone learning nix for the time being :slight_smile:

pkg-confg is probably a linux specific mechanism? I am trying to get something working for both linux and macOS. I have llvm installed on macOS via brew and it doesn’t showup in pkg-config listing

It won’t show up on Linux either, because for some reason the LLVM devs seem not to ship a pc file but insist on using llvm-config. The tool I linked provides a work-around.

1 Like