Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Bug fixes:
* The output of Stack's `path --bin-path` command is now consistent with the
Stack environment in Stack's `exec` command and includes the `bin` directory
of Stack's local install root directory.
* Stack now builds packages that depend directly on packages with the same name
as a sublibrary or foreign library of the package.

## v3.9.3 - 2026-02-19

Expand Down
21 changes: 4 additions & 17 deletions src/Stack/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ module Stack.Package

import qualified Data.Map.Strict as M
import qualified Data.Set as S
import qualified Data.Text as T
import Distribution.CabalSpecVersion ( cabalSpecToVersionDigits )
import Distribution.Compiler
( CompilerFlavor (..), PerCompilerFlavor (..) )
import Distribution.ModuleName ( ModuleName )
import Distribution.Package ( mkPackageName )
import Distribution.PackageDescription
( Benchmark (..), BuildInfo (..), BuildType (..)
, CondTree (..), Condition (..), ConfVar (..)
Expand Down Expand Up @@ -87,7 +85,6 @@ import Stack.Types.BuildConfig ( HasBuildConfig (..), getWorkDir )
import Stack.Types.CompCollection
( CompCollection, collectionLookup, foldAndMakeCollection
, foldComponentToAnotherCollection, getBuildableSet
, getBuildableSetText
)
import Stack.Types.Compiler ( ActualCompiler (..) )
import Stack.Types.CompilerPaths ( cabalVersionL )
Expand Down Expand Up @@ -762,21 +759,11 @@ processPackageDeps pkg combineResults fn =
where
iterator :: PackageName -> DepValue -> m a -> m a
iterator depPackageName depValue acc
| shouldIgnoreDep = acc
-- If the name of the dependency package is the same as the package, we
-- ignore the former. It is possible for a dependency package to have the
-- same name as a named sublibrary or a named foreign library.
| depPackageName == pkg.name = acc
| otherwise = combineResults <$> fn depPackageName depValue <*> acc
where
shouldIgnoreDep
| depPackageName == pkg.name = True
| depPackageName `S.member` subLibNames = True
| depPackageName `S.member` foreignLibNames = True
| otherwise = False
where
!subLibNames = asPackageNameSet (.subLibraries)
!foreignLibNames = asPackageNameSet (.foreignLibraries)
asPackageNameSet ::
(Package -> CompCollection component) -> Set PackageName
asPackageNameSet accessor =
S.map (mkPackageName . T.unpack) $ getBuildableSetText $ accessor pkg

-- | This is a function to iterate in a monad over all of a package's
-- dependencies (including any custom-setup ones), and yield a list of
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/tests/6920-dep-name-clash/files/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
myPackageA.cabal
myPackageB.cabal
11 changes: 11 additions & 0 deletions tests/integration/tests/6920-dep-name-clash/files/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- | Stack builds a package which depends directly on a package with the same
-- name as a sublibrary or foreign library of that package.
--
-- See: https://github.com/commercialhaskell/stack/issues/6920

import StackTest

main :: IO ()
main = do
stack ["build", "myPackageA"]
stack ["build", "myPackageB"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Internal
( launchMissiles
) where

import Acme.Missiles ( launchMissiles )
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
spec-version: 0.36.0

# Required, otherwise Hpack picks cabal-version: 3.0 and the dependency on
# acme-missiles is assumed to refer to the name of the internal-library.
verbatim:
cabal-version: 3.4

name: myPackageA

dependencies:
- base

internal-libraries:
acme-missiles:
source-dirs: int
dependencies:
- acme-missiles
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
spec-version: 0.36.0

name: myPackageB

dependencies:
- base

verbatim: |
foreign-library acme-missiles
type: native-shared
other-modules:
Foreign
build-depends:
base
, acme-missiles
hs-source-dirs:
src-foreign
default-language: Haskell2010
if os(Windows)
options: standalone
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Foreign
( launchMissiles
) where

import Acme.Missiles ( launchMissiles )
8 changes: 8 additions & 0 deletions tests/integration/tests/6920-dep-name-clash/files/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
snapshot: ghc-9.10.3

packages:
- myPackageA
- myPackageB

extra-deps:
- acme-missiles-0.3
Loading