15

I often install a package which depends on external libraries and manage to move those external libraries to other locations afterwards, so that compiled programs exit with a loader error.

In those cases I just want stack to rebuild an already installed package, but I don't see how that is possible. stack install --force-dirty doesn't seem to work, as it just tries to rebuild the project in the current working directory.


Recent example:

I'd liked to see whether regex-pcre requires a C library not present on Windows systems, so I hit stack install regex-pcre. That went fine, but then I realized I installed mingw-w64-x86_64-pcre via stacks pacman prior to this. I removed it again via pacman -R and tried to run stack install regex-pcre again, which did not rebuild it. Neither did adding --force-dirty work for the above reason.

1 Answer 1

23

Update:

Based on @Michael Snoyman's comment just using this command should be enough to remove the package:

stack exec -- ghc-pkg unregister --force regex-pcre

Original Answer:

I don't know if it's the sanctioned way to do it, but it seems to work. Here is a synopsis:

  1. Locate the ghc-pkg program for the version of GHC you are using
  2. Locate the package-db directory for your resolver version
  3. Run $ghcpkg --package-db $pkgdb unregister --force <package>
  4. Also remove the package file from stack's precompiled directory

Suppose the package we want to remove is zlib-0.5.4.2.

Locating ghc-pkg

Under ~/.stack/programs find the ghc-pkg program appropriate for your compiler version, e.g. ~/.stack/programs/x86_64-osx/ghc-7.10.2/bin/ghc-pkg. Call this $ghcpkg

Locating the package db

Under ~/.stack/snapshots find the pkgdb directory for the resolver you are using, e.g. ~/.stack/snapshots/x86_64-osx/lts-3.1/7.10.2/pkgdb. Call this $pkgdb.

Unregister the package

Run:

$ghcpkg --package-db $pkgdb unregister --force zlib-0.5.4.2

Ignore any warnings about broken or breaking packages.

You can check to see if your package is registered or not with this command:

$ghcpkg --package-db $pkgdb list | grep zlib

Remove the package from the precompiled directory

Under ~/.stack/precompiled locate any directories named zlib-0.5.4.2 and remove the one for your the relevant version of GHC:

find ~/.stack/precompiled -name 'zlib-*'
/bin/rm -rf ...

Reinstall the package

stack --resolver=... install zlib

Stack should report that it is rebuilding the package.

4
  • 3
    You can probably get away with just stack exec -- ghc-pkg unregister pkgname Commented May 15, 2016 at 16:40
  • @MichaelSnoyman @erikR does stack exec -- ghc-pkg unregister pkgname work with the newer versions of stack (the ones which use pantry)? Commented May 20, 2020 at 9:31
  • Pantry shouldn't affect it Commented May 21, 2020 at 1:35
  • 2
    I believe with Stack 2, you now need to manipulate the sqlite file. I got it working like: sqlite3 ~/.stack/stack.sqlite3 "DELETE FROM precompiled_cache WHERE library LIKE '%pkgdb/zlib-%'". @MichaelSnoyman do you think we should open an issue on Stack to make the process of unregistering a dependency easier? For some background, we have to do this every time the icu4c package updates on brew, because text-icu will be linked to an old non-existent version of the icu4c dylibs Commented Jul 30, 2020 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.