Cabal's `main-is` field (source file) does not alter GHC's `-main-is` option (module and function name)

Aperta
#6,695 13 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@mpilgrem ci sta già lavorando.

Dal 15/3/2025.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

component: build component: Cabal library resolution: upstream issue type: question

If the module in main-is has a name and there is another module that has no explicit name (no module header), then the other module is picked as main module.

Bar.hs

main = putStrLn "I am the shady main..."

Foo.hs

module Foo where

main = putStrLn "I am the real main!"

wrong-main.cabal

cabal-version: 1.12
name:           wrong-main
version:        0.0.0
build-type:     Simple

executable wrong-main
  main-is: Foo.hs
  other-modules:
      Bar
      Paths_wrong_main
  hs-source-dirs:
      ./
  build-depends:
      base
  default-language: Haskell2010
$ stack run
...                                                                                                       
I am the shady main...

Packaged reproducer: wrong-main.tgz

The wrong result can be reproduced with this vanilla GHC call:

ghc --make Foo.hs Bar.hs

The correct result can be obtained by adding -main-is Foo:

ghc --make -main-is Foo Bar.hs Foo.hs    

I suppose the difficulty is to extract the module name Foo from Foo.hs, since -main-is does not accept a file, just a qualified (module) name.

This issue is shared with cabal:

Lingua principale
Haskell
Stelle
4.1k
Fork
857
Merge medio
17h 32m
PR unite (30g)
5

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di commercialhaskell/stack

Tutte le issue di commercialhaskell/stack

Issue simili

Altre issue su Haskell

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.