Created
February 12, 2025 00:47
-
-
Save LSLeary/6551f1dc3e25fe0d0d629b4ddb385359 to your computer and use it in GitHub Desktop.
Structuring a cabal file so as to provide a unified `dev` component.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- A demonstration, using a fragment of an unpublished library as-is. | |
-- Split out fields shared by all components into a common stanza: | |
common shared | |
build-depends: base | |
default-language: Haskell2010 | |
default-extensions: ImportQualifiedPost | |
GeneralisedNewtypeDeriving | |
DerivingVia | |
DeriveTraversable | |
LexicalNegation | |
NamedFieldPuns | |
BangPatterns | |
LambdaCase | |
BlockArguments | |
FlexibleInstances | |
FlexibleContexts | |
TupleSections | |
ghc-options: -Wall | |
-- Split `hs-source-dirs`, `other-modules` and /external/ `build-depends` from each component into common stanzas: | |
common main | |
hs-source-dirs: src | |
build-depends: cairo | |
library | |
import: shared, main | |
exposed-modules: Graphics.Rendering.Cairo.Declarative | |
Graphics.Rendering.Cairo.Declarative.Internal | |
common sanity | |
hs-source-dirs: test | |
other-modules: Sanity | |
test-suite sanity | |
import: shared, sanity | |
type: exitcode-stdio-1.0 | |
main-is: Main.hs | |
build-depends: cairo-declarative | |
common example | |
hs-source-dirs: example | |
other-modules: Example | |
executable example | |
import: shared, example | |
main-is: Main.hs | |
build-depends: cairo-declarative | |
-- Finally, introduce a new `dev` component importing all the common stanzas: | |
library dev | |
import: shared, main, sanity, example | |
-- When using `dev`, this warning may be issued, but should be ignored. | |
ghc-options: -Wno-missing-home-modules | |
-- You can now use `cabal repl dev` to effectively obtain multi-repl, whether | |
-- directly or in `ghciwatch`. Note that only the listed `other-modules` and | |
-- their transitive dependencies will be loaded on start, but the others can | |
-- be loaded on need, as if using `--repl-no-load`. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment