Skip to content

-Werror=unused-packages cannot be satisfied for ghc-prim

Summary

My library package has a module which imports Ghc.Prim. If I use -Werror=unused-packages, ghc both requires ghc-prim to be listed as a dependency and requires it not to be listed as a dependency.

Steps to reproduce

Note: cabal is used here for convenience, but is not required to reproduce. The ghc commands to reproduce are also given here.

  • have a cabal project for a library pacakge in the current directory
  • have a source file with import Ghc.Prim, which is listed in exposed-modules in the cabal file
  • cabal file's library.ghc-options includes -Werror=unused-packages
  • when the cabal file's library.build-depends includes ghc-prim:
    • ghc -Werror=unused-packages src/A.hs -pacakge-id ghc-prim-0.8.0, or cabal build gives this error:

      <no location info>: error: [-Wunused-packages, -Werror=unused-packages]
      The following packages were specified via -package or -package-id flags,
      but were not needed for compilation:
        - ghc-prim-0.8.0
  • when the cabal file's library.build-depends does not include ghc-prim:
    • ghc -Werror=unused-packages src/A.hs, or cabal build gives this error:

      src/A.hs:3:1: error:
      Could not find module ‘Ghc.Prim’
      Perhaps you meant GHC.Prim (needs flag -package-id ghc-prim-0.8.0)
      Use -v (or `:set -v` in ghci) to see a list of the files searched for.
        |
      3 | import Ghc.Prim
        | ^^^^^^^^^^^^^^^

Expected behavior

Since ghc-prim is required for compilation, -Werror=unused-packages should not error saying that it is not required.

Environment

  • GHC version used: 9.2.5

Optional:

  • Operating System: NixOS 22.11pre-git (Raccoon)
  • System Architecture: x86_64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information