Introduce configure-flags
- Dominant language
- Haskell
- Stars
- 1.7k
- Forks
- 750
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 28
Description
**Describe the bug**
Currently `Cabal`'s `build-type: configure` support lacks any mechanism by which cabal file content can be predicated on the outcome of `configure`. Instead, the `configure` script must emit Cabal syntax in a produced `buildinfo` file. This unnecessarily splits up build configuration across multiple files. We have felt this acutely in GHC, where efforts to move autoconf checks serving only the RTS into the RTS `configure` script has regressed readability rather significantly.
I propose that Cabal add a new set of post-solver flags (here we will call this `configure-flags`) which can be set by `configure` scripts. This mechanism would introduce a new type of predicate in the package description syntax, `configure-flag`, similar to the existing `flag` predicate. The configure script would then be able to emit a `.flags` file, which would contain a setting of these flags (using Cabal's traditional `{+,-}` syntax).
I would also propose that the cabal file explicitly declare `configure-flag`s to make explicit the interface between the `configure` script and cabal file. For this, we introduce a new stanza type, `configure-flag`, which would specify the name and optional description of each flag expected to be set by the `configure` script. Cabal would verify that the `configure` script emits a setting for each declared flag.
For instance, a package author might write,
```cabal
-- my-package.cabal
name: my-package
build-type: configure
configure-flag has_zlib
description: Whether the system has the zlib library
library
-- ...
if configure-flag(has_zlib)
internal-modules: MyPackage.Zlib
cpp-options: -DHAS_ZLIB
```
```bash
# configure
#!/usr/bin/env bash
if has_zlib; then
echo +has_zlib >> my-package.flags
else
echo -has_zlib >> my-package.flags
fi
```
## Design variants
While reflecting on this I considered a few extensions on this idea.
* Allow defaulting of `configure-flag`s. This would allow the user to declare a default value in a `configure-flag` stanza. The flag would take this value if the `configure` script did not offer a setting for the flag.
* Allow the default value of a `configure-flag` to reference other predicates. This would essentially turn `configure-flags` into a form of `let` binding, allowing common patterns of predicates to be captured once instead of being repeated throughout the cabal file
Contributor guide
Assessment
This issue has not been assessed yet.