`cabal exec` violates -Wunused-packages
- Dominant language
- Haskell
- Stars
- 1.7k
- Forks
- 750
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 28
Description
**Describe the bug**
When `-Wunused-packages` is enabled, building or running tests with `cabal exec` errors with all dependencies being used.
**To Reproduce**
Steps to reproduce the behavior:
```cabal
cabal-version: 3.0
name: foo
version: 0
library
exposed-modules: Foo
build-depends: base
ghc-options: -Werror -Wunused-packages
```
```bash
cabal exec cabal v2-build
```
This results in
```
Build profile: -w ghc-9.6.1 -O1
In order, the following will be built (use -v for more details):
- foo-0 (lib) (first run)
Preprocessing library for foo-0..
Building library for foo-0..
Loaded package environment from ...
: error: [GHC-42258] [-Wunused-packages, Werror=unused-packages]
The following packages were specified via -package or -package-id flags,
but were not needed for compilation:
- ghc-bignum-1.3 (exposed by flag -package-id ghc-bignum-1.3)
- ghc-prim-0.10.0 (exposed by flag -package-id ghc-prim-0.10.0)
- rts-1.0.2 (exposed by flag -package-id rts-1.0.2)
Error: cabal: Failed to build foo-0.
```
**Expected behavior**
`cabal v2-build` and `cabal exec cabal v2-build` should behave the same.
**System information**
- Mac OS
- Cabal 3.10.1.0
- GHC 9.6.1
**Additional context**
Add any other context about the problem here.
Contributor guide
Assessment
This issue has not been assessed yet.