Giter Site home page Giter Site logo

cabal-buildinfo-example's Introduction

This example shows how to parameterize your cabal project with preprocessor definitions, passed to haskell code.

What makes it work:

  1. build-type: Configure in a project cabal file
  2. configure script (file), that generates $PROJECT.buildinfo file with cpp-options: -DMYDEF=SOME_TEXT contents
  3. haskell (library) code, that uses CPP extension to access MYDEF

This can be used with executables too if generated text starts with executable: EXECUTABLE_NAME .

develop

$ nix develop
[devshell]$ cabal build
Build profile: -w ghc-9.2.8 -O1
In order, the following will be built (use -v for more details):
 - cabal-buildinfo-example-0.1.0.0 (lib:cabal-buildinfo-example, exe:cabal-buildinfo-example) (first run)
Preprocessing library for cabal-buildinfo-example-0.1.0.0..
Building library for cabal-buildinfo-example-0.1.0.0..
Preprocessing executable 'cabal-buildinfo-example' for cabal-buildinfo-example-0.1.0.0..
Building executable 'cabal-buildinfo-example' for cabal-buildinfo-example-0.1.0.0..
[1 of 1] Compiling Main             ( app/Main.hs, /data/proj/cabal-buildinfo-example/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-buildinfo-example-0.1.0.0/build/cabal-buildinfo-example/cabal-buildinfo-example-tmp/Main.o )
Linking /data/proj/cabal-buildinfo-example/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-buildinfo-example-0.1.0.0/build/cabal-buildinfo-example/cabal-buildinfo-example ...

[devshell]$ cabal run
CPP_definition

[devshell]$ cabal repl
Build profile: -w ghc-9.2.8 -O1
In order, the following will be built (use -v for more details):
 - cabal-buildinfo-example-0.1.0.0 (ephemeral targets)
Preprocessing library for cabal-buildinfo-example-0.1.0.0..
GHCi, version 9.2.8: https://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling MyLib            ( src/MyLib.hs, interpreted )

src/MyLib.hs:6:14: error:
    Data constructor not in scope: MYDEF :: String
  |
6 | definition = MYDEF
  |              ^^^^^
Failed, no modules loaded.

Currently, cabal repl fails to pick up the definition. Remarkably, nix build doesn't work either. Whereas, cabal build inside nix develop succeeds!

cabal-buildinfo-example's People

Contributors

alexoundos avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.