haskell / haskell/cabal

Why does `cabal install` do different things inside and outside a project?

Open
#10,924 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**
I am getting different behavior from `cabal install` of a library (which arguably shouldn't be allowed without `--lib`; was checking a report on the FP Discord) when inside a project, vs. when I'm in my home directory.

**To Reproduce**
```
hilfy «xmonad:hilfy-2023$» ⁅xmonad-bsa⁆ Z$ cabal install vector-0.13.2.0
Warning: this is a debug build of cabal-install with assertions enabled.
Resolving dependencies...
Error: [Cabal-7127]
Cannot build the executables in the package vector because it does not contain any executables. Check the .cabal file for the package and make sure that it properly declares the components that you expect.

zsh: exit 1 cabal install vector-0.13.2.0
hilfy «xmonad:hilfy-2023$» ⁅xmonad-bsa⁆ Z$ pushd ~
~ ~/.config/xmonad ~/Sources/dotty ~/Sources/ghc-utils ~/Sources/cabal ~/Sources/ghc
hilfy Z$ cabal install vector-0.13.2.0
Warning: this is a debug build of cabal-install with assertions enabled.
Resolving dependencies...
Build profile: -w ghc-9.6.6 -O1
In order, the following will be built (use -v for more details):
- optparse-applicative-0.18.1.0 (lib) (requires build)
- random-1.3.1 (lib) (requires download & build)
- tasty-1.5.3 (lib) (requires build)
- vector-0.13.2.0 (lib:benchmarks-O2) (requires build)
Warning:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: Installation might not be completed as desired! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The command "cabal install [TARGETS]" doesn't expose libraries.
* You might have wanted to add them as dependencies to your package. In this
case add "vector, vector" to the build-depends field(s) of your package's
.cabal file.
* You might have wanted to add them to a GHC environment. In this case use
"cabal install --lib vector vector". The "--lib" flag is provisional: see
https://github.com/haskell/cabal/issues/6481 for more information.
Downloading random-1.3.1
Starting optparse-applicative-0.18.1.0 (lib)
Downloaded random-1.3.1
Starting random-1.3.1 (lib)
Building optparse-applicative-0.18.1.0 (lib)
Building random-1.3.1 (lib)
Haddock optparse-applicative-0.18.1.0 (lib)
Installing optparse-applicative-0.18.1.0 (lib)
Completed optparse-applicative-0.18.1.0 (lib)
Starting tasty-1.5.3 (lib)
Building tasty-1.5.3 (lib)
Haddock random-1.3.1 (lib)
Installing random-1.3.1 (lib)
Haddock tasty-1.5.3 (lib)
Completed random-1.3.1 (lib)
Installing tasty-1.5.3 (lib)
Completed tasty-1.5.3 (lib)
Starting vector-0.13.2.0 (lib:benchmarks-O2)
Building vector-0.13.2.0 (lib:benchmarks-O2)
Installing vector-0.13.2.0 (lib:benchmarks-O2)
Completed vector-0.13.2.0 (lib:benchmarks-O2)
Warning:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: Installation might not be completed as desired! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The command "cabal install [TARGETS]" doesn't expose libraries.
* You might have wanted to add them as dependencies to your package. In this
case add "vector, vector" to the build-depends field(s) of your package's
.cabal file.
* You might have wanted to add them to a GHC environment. In this case use
"cabal install --lib vector vector". The "--lib" flag is provisional: see
https://github.com/haskell/cabal/issues/6481 for more information.
cabal install vector-0.13.2.0 43.43s user 5.91s system 151% cpu 32.649 total
hilfy Z$
```

**Expected behavior**
I would expect both attempts to behave the same, preferably the first behavior. Also:
- why did it only build `lib:benchmarks-O2`?
- why did it output the warning twice?

**System information**
- Ubuntu 24.04.2 x86_64
- `cabal` HEAD (`cabal-install version 3.15.0.0 (commit 2b166b8, Thu Apr 10 18:11:54 2025 +0000)`), ghc 9.6.6

Contributor guide

Open the contributing guide

Research direction

Start by reproducing `cabal install vector-0.13.2.0` from inside a project and from the home directory, then compare how cabal-install selects targets and emits warnings. Investigate the project-context handling and component selection; done means the behavior is consistent or the difference is explicitly justified, including the benchmark target and duplicate warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
build-system, cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.