haskell / haskell/cabal

Why does the generated `Paths_XYZ` contain `#if`s on `base`?

Open
#7,576 4 comments 0 reactions 0 assignees View on GitHub
blocked: decision-needed Cabal: other
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

The generated `Paths` module contains CPP-conditionals on the version of `base`:
```c
#if defined(VERSION_base)
#if MIN_VERSION_base(4,0,0)
```
This is surprising, as the module is generated during the build process where the values of these variables should be known. `cabal-install` has already made a plan which version of each package to use, so there should be no question which version of `base` we are building for.

cabal-install-1.22 does not generate such conditionals, this seems to start with 1.24.

Source:
https://github.com/haskell/cabal/blob/fe9a5243b48de8081320d3c771fd31e29a2960ce/Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs#L75-L86

MWE:
- `XYZ.cabal`:
```cabal
cabal-version: >= 1.10
name: XYZ
version: 0.1.0.0
build-type: Simple

executable XYZ
main-is: Main.hs
other-modules: Paths_XYZ
build-depends: base >= 4
hs-source-dirs: .
default-language: Haskell98
```
- `Main.hs`:
```haskell
import Paths_XYZ

main = putStrLn =<< getDataDir
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.