Cabal Internal error in target matching

Hi,

I am trying to run a GitHub CI workflow where I am using the ubuntu-latest runner with ghc 9.6.6 and cabal 3.12.1.0 .

I am not able to share the CI yaml file here because it is work related, but the gist is
I am building my service using these two lines

cabal build
cabal install exe:some_exe --installdir /root --overwrite-policy=always --install-methody=copy

cabal build succeeds but the install command fails with

Internal error in target matching: could not make and unambiguous fully qualified target selector for ‘exe:some_exe’.
We made the target ‘exe:some_exe’ (unknown-component) that was expected to be unambiguous but matches the following targets:
‘exe:some_exe’, matching:

  • exe:some_exe (unknown-component)
  • :pkg:exe:lib:exe:file:some_exe (unknown-file)
    Note: Cabal expects to be able to make a single fully qualified name for a target or provide a more specific error. Our failure to do so is a bug in cabal. Tracking issue:
    Tracking issue: internal error in target matching · Issue #8684 · haskell/cabal · GitHub
    Hint: this may be caused by trying to build a package that exists in the project directory but is missing from the ‘packages’ stanza in your cabal project file.

More Background:
I have a scotty web service which I am trying to build a binary of which I can deploy on a docker container and run in aws ecs.
How can this be solved? If anybody has overcome this issue please answer.

Thanks

P.S. I asked the same question here in reddit

Hi @kushagarr, three thoughts on this.

  1. You aren’t making is easy to help you, by holding off the repro case. Try minimizing an SSCCE than can be shared.
    • Just attempting to make it might guide you towards a resolution.
  2. This looks like a bug in Cabal — the error message is very clear, and even gives the issue link, haskell/cabal#8684.
    • Did you try other Cabal versions?
    • Did you try adding a cabal.project file?
    • Can you reproduce the error locally?
  3. GitHub Actions runners come pre-loaded with Haskell tools. Today, ubuntu-latest = ubuntu-24.04 and so this link lists out what’s included in the box: GHC 9.12.2, GHCup 0.1.50.0, Cabal 3.14.1.1, Stack 3.3.1.
    • Since you specify ghc 9.6.6 and cabal 3.12.1.0 — these must be not the preloaded defaults. So how did you install them?

let me try and type out the GitHub actions workflow

name: CI

on:
  push:
    branches: ["main"]

jobs:
  build-and-push:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        ghc: ["9.6.6"]
        cabal: ["3.12.1.0"]

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Haskell
        uses: Haskell-actions/setup@v2
        id: setup-haskell-cabal
        with:
          ghc-version: ${{ matrix.ghc }}
          cabal-version: ${{ matrix.cabal }}

      - name: Install Postgresql dev libraries
        run: |
          sudo apt-get update
          sudo apt-get install -y libpq-dev libsasl2-dev libecpg-dev

      - name: Cabal Update and Freeze
        run: |
          cabal update
          cabal freeze

      - name: Get dependencies if present
        uses: actions/cache@v4
        with:
          path: |
            ${{ steps.setup-haskell-cabal.outputs.cabal-store }}
            dist-newstyle
          key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }}
          restore-keys: |
            ${{ runner.os }}-${{ matrix.ghc }}-

      - name: Build Dbservice
        run: |
          cabal build
          cabal install  exe:dbservice --installdir /root --overwrite-policy=always --install-method=copy

I have tried with cabal version 3.10, 3.12 and 3.14 latest one, all of them give the same error

Let my type out the dbservice.cabal file as well

cabal-version:                   3.0
name:                            dbService
version :                        0.1.0.0
license:                         MIT
license-file:                    LICENSE
build-type:                      Simple

common warnings
    ghc-options:  -Wall

executable dbservice
    import:                 warnings
    main-is:                Main.hs
    build-depends:     base ^>=4.18.2.1
                     , text
                     , aeson
                     , lens-aeson
                     , amazonka-secretsmanager
                     , amazonka
                     , scotty
                     , wai
                     , wai-extra
                     , lens
                     , string-interpolate
                     , http-types
                     , unliftio-core
                     , extra
                     , time
                     , crypton
                     , Blammo
                     , stm
                     , mtl
                     , envy
                     , postgresql-simple
                     , resource-pool
                     , bimap
                     , retry
                     , bytestring
                     , uuid

hs-source-dirs:       app

default-language: GHC2021

Formatting can be a bit off, but that’s the gist of it.

I do have a cabal.project.local file

profiling: False
library-profiling: False
optimisation: 2

Let me know if you need some more details.

Thanks

OK @kushagarr, that does clarify your issue — thanks.

Try this:

  • make a throwaway dir, I did mkdir /tmp/tt && cd /tmp/tt;
  • cabal init, and specify:
    • Package name? acmepkg
    • leaving everything else at defaults;
  • edit the resulting acmepkg.cabal:
    • rename executable acme, but leave name: acmepkg.

Then, cabal build exe:acme succeeds, and cabal install acmepkg succeeds:

In order, the following will be built (use -v for more details):
 - acmepkg-0.1.0.0 (exe:acme) (requires build)
Starting     acmepkg-0.1.0.0 (exe:acme)
Building     acmepkg-0.1.0.0 (exe:acme)
Installing   acmepkg-0.1.0.0 (exe:acme)
Completed    acmepkg-0.1.0.0 (exe:acme)
Symlinking 'acme' to '/home/ulidtko/.cabal/bin/acme'

Notice acmepkgacme. :eyes: The former is name of package; the latter is name of an executable in that package. One package may define several executables.

The most specific command would be (if you need to filter out executables, installing just the specific one dbservice and not installing all others defined in the package) — you could do cabal install acmepkg:exe:acme.

Which in your case, would be spelled cabal install dbService:exe:dbservice […]. Does this work?

1 Like

yeah basically the name has to be same. if it is not, then it throws this error.
May be there could be a helpful error message in cabal rather than this obscure error message.

Thank you @ulidtko .