haskell / haskell/cabal

Conditions don't work with flags

Open
#10,070 3 comments 0 reactions 0 assignees View on GitHub
needs triage type: bug
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

**Describe the bug**
Hello,

I tried to use [conditions](https://cabal.readthedocs.io/en/stable/cabal-package-description-file.html#conditions) with [flags](https://cabal.readthedocs.io/en/stable/cabal-project-description-file.html#cfg-field-flags).
I tried to use a `dev` flag that sets `-O0` and a `release` flag that sets `-O1`. However, no matter what I set the flags to, dry-running cabal always shows that it's building with `-O1`.

**To Reproduce**
Steps to reproduce the behavior:
Here's my repository with a minimal example: https://github.com/leana8959/cabal-opts-repr

Setting `release=false`, `dev=true`
```
$ cabal build -f-release -fdev --dry-run -v #this should set flag -O0 (but got O1)
... (elided)
Build profile: -w ghc-9.6.5 -O1
In order, the following would be built:
- simple-0.1.0.0 (exe:simple-bin) (first run)
```

Setting `release=true`, `dev=false`
```
$ cabal build -frelease -f-dev --dry-run -v #this should set flag -O1 (and got O1)
... (elided)
Build profile: -w ghc-9.6.5 -O1
In order, the following would be built:
- simple-0.1.0.0 (exe:simple-bin) (first run)
```

**Expected behavior**
I should be able to toggle the conditionals using flags in the command line.

**System information**
- Fedora Linux 39
- `cabal-install` package from `nixpkgs`, version `3.10.3.0`
- `ghc` package from `nixpkgs`, version `9.6.5`

Contributor guide

Open the contributing guide

Research direction

Start with the linked minimal example and reproduce both `cabal build` dry runs using the documented `dev` and `release` flags. Trace how Cabal evaluates conditions and selects the build profile; done means the two flag combinations produce their respective optimization settings instead of always selecting `-O1`.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.