如何避免仅仅因为E依赖于内部库L(而内部库L又依赖于A)而将A列为内部库/可执行文件E的构建依赖项?

问题描述 投票:0回答:1

我有这样的目录结构

.
├── Main.hs
├── mynot.cabal
├── Notification.hs
└── Server.hs

哪里

mynot.cabal
看起来像这样

cabal-version:   3.0
name:            mynot
version:         0.1.0.0

common common
    default-language: GHC2021
    build-depends: base

executable mynot
    import: common
    main-is: Main.hs
    build-depends: dbus
                 , async
                 , containers
                 , extra
                 , flow
    other-modules: Server
                 , Notification

library server
    import: common
    exposed-modules: Server
    build-depends: async
                 , containers
                 , dbus
                 , extra
                 , flow
    other-modules: Notification

library notification
    import: common
    exposed-modules: Notification
    build-depends: containers
                 , dbus
                 , extra

但是

extra
实际上只需要
Notification.hs
,而且我不知道为什么我需要将它也列在其他节下才能使
cabal build
成功。

我找到了this,并尝试了一下,例如通过

$ mkdir exe
$ mv Main.hs exe/.

然后在

hs-source-dirs: exe
节中添加
executable
,但是构建失败了,如下

Resolving dependencies...
Build profile: -w ghc-9.4.8 -O1
In order, the following will be built (use -v for more details):
 - mynot-0.1.0.0 (exe:mynot) (configuration changed)
 - mynot-0.1.0.0 (lib:notification) (configuration changed)
 - mynot-0.1.0.0 (lib:server) (configuration changed)
Configuring executable 'mynot' for mynot-0.1.0.0..
Configuring library 'notification' for mynot-0.1.0.0..
Configuring library 'server' for mynot-0.1.0.0..
Preprocessing library 'notification' for mynot-0.1.0.0..
Building library 'notification' for mynot-0.1.0.0..
Preprocessing executable 'mynot' for mynot-0.1.0.0..
Error: cabal-3.10.2.1: can't find source for Server in exe,
/home/enrico/mynot/dist-newstyle/build/x86_64-linux/ghc-9.4.8/mynot-0.1.0.0/x/mynot/build/mynot/autogen,
/home/enrico/mynot/dist-newstyle/build/x86_64-linux/ghc-9.4.8/mynot-0.1.0.0/x/mynot/build/global-autogen

Preprocessing library 'server' for mynot-0.1.0.0..
Building library 'server' for mynot-0.1.0.0..
Error: cabal: Failed to build exe:mynot from mynot-0.1.0.0.

我的项目是否存在错误,或者只是其中存在缺失

haskell linker dependency-management cabal
1个回答
0
投票

而不是那些

other-modules
,您应该将组件相互添加
build-depends
,如下所示:

executable mynot
    import: common
    main-is: Main.hs
    build-depends: dbus
                 , async
                 , containers
                 , flow
                 , mynot:server
                 , mynot:notification

library server
    import: common
    exposed-modules: Server
    build-depends: async
                 , containers
                 , dbus
                 , flow
                 , mynot:notification

library notification
    import: common
    exposed-modules: Notification
    build-depends: containers
                 , dbus
                 , extra

通常,您希望每个模块仅在单个组件中列出。否则每个组件将单独重建该模块。

© www.soinside.com 2019 - 2024. All rights reserved.