haskell / haskell/cabal

`cabal-install` gets horribly confused about sublibrary dependencies if they share a `hs-source-dirs`

Open
#10,780 4 comments 1 reaction 0 assignees View on GitHub
cabal-install: cmd/check documentation type: enhancement
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

**Describe the bug**

I have a project with two sublibraries, one of which depends on the other. Omitting irrelevant fields, the layout is thus:

```
library foo
...
hs-source-dirs: src

library bar
...
build-depends: foo
hs-source-dirs: src
```

Notably, we see that both `foo` and `bar` share the same `hs-source-dirs`. When I try to do `cabal build`, the dependency of `bar` on `foo` is not detected: instead, I get GHC warnings about files needed for compilation not being noted as dependencies.

This can be fixed by changing the `hs-source-dirs` to this:

```
library foo
...
hs-source-dirs: foo

library bar
...
build-depends: foo
hs-source-dirs: bar
```

or even this:

```
library foo
...
hs-source-dirs: src/foo

library bar
...
build-depends: foo
hs-source-dirs: src/bar
```

**To Reproduce**
Steps to reproduce the behavior:

Set up two sublibraries as above, then call

```
$ cabal build
```

**Expected behavior**

Dependencies should be detected properly, and no warnings from GHC should be showing up due to 'missing' files needed for compilation.

**System information**
- Arch Linux
- `Cabal` 3.14.1.1 (same as `cabal-install` version)
- GHC 9.8.2

**Additional context**

This behaviour is quite long-standing: I only discovered this was a problem by finding a response from _years_ ago specifying that sharing `hs-source-dirs` like this would trigger this behaviour.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with two sublibraries sharing the same hs-source-dirs, then run cabal build using the configurations shown in the report. Compare the dependency detection and GHC warnings with separate source directories; done means the dependency on foo is detected correctly without those warnings.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.