Skip to content

inplace packages, expose by unit id, recompile check - #1

Closed
philderbeast wants to merge 3 commits into
simonmar:masterfrom
cabalism:add/cabal-repo
Closed

philderbeast wants to merge 3 commits into
simonmar:masterfrom
cabalism:add/cabal-repo

Conversation

@philderbeast

Copy link
Copy Markdown
Contributor

Following its mention on discourse, I tried haskell-buck2 with haskell/cabal, with help from Claude Fable 5.1.

Because Cabal is a boot library, I needed to vendor1 hackage-security, so it became inplace.

After an initial build, I tested the rebuild by making a whitespace change to Cabal/src/Distribution/Simple/GHCJS.hs and then building:

  • cabal build all --enable-tests took 22s
  • buck2 build //... took 1m 30s

After the changes in this pull request, the buck2 build now takes 4s.

Footnotes

  1. Cabal doesn't yet have a vendor command, https://github.com/haskell/cabal/issues/10935. ↩

A Hackage package that depends on a local package (hackage-security
depends on Cabal-syntax in the cabal repository) is built by cabal
in-place, with style "inplace" in plan.json, rather than installed in
the store. Two problems followed:

  * collect_packages() records such a package as None, and main() then
    crashed unpacking it:

      used_roots = {db for _, db in packages.values() if db in STORE_DBS}
      TypeError: cannot unpack non-iterable NoneType object

  * get_root_dep_ids() only walked the dependencies of "local"
    components, so the store packages that only an in-place package
    needs (ed25519, base64-bytestring for hackage-security) got no
    haskell_prebuilt_library() rule.

Treat "inplace" like "local" when collecting root dependencies: not a
root itself (buck2 has to build it from source, like a local package),
but everything it depends on from the store is. Skip the None entries
when choosing the store root.
get_packages_info() passed each direct dependency as `-package <name>`,
which GHC resolves by picking the highest version visible in any of the
package dbs on the command line. That goes wrong as soon as two
versions of a package are visible:

  * a boot package rebuilt in the cabal store (time-1.14, directory,
    unix, process) lost to the newer one in GHC's global db
    (time-1.15), and everything built against the store version then
    failed with mismatched types such as
    `time-1.14:Data.Time.Clock.Internal.UTCTime.UTCTime` vs `UTCTime`;

  * a library built from source by buck2 (registered as version 1.0.0)
    lost to a same-named package in the global db, e.g. the Cabal and
    Cabal-syntax that ship with GHC.

HaskellLibraryInfo already carries the unit id (the full hashed id for
prebuilt packages, the target name for buck2-built ones), so use
`-package-id <id>` whenever it is set. Resolution is then exact
regardless of what else the dbs contain. The `-package`/
`-expose-package` path is kept for infos without an id.
Each haskell_library()/haskell_binary() is a single `ghc --make` action
writing to fresh -odir/-hidir directories, so any edit recompiled the
whole package, and every dependent package in full after it. On the
cabal repository a whitespace-only change in one Cabal module cost 87s.

Set no_outputs_cleanup on the compile action so that the previous
run's objects and interfaces are still there and `ghc --make` only
recompiles the modules whose sources or imported interfaces changed.
Dependent packages still re-run their action, but their --make finds
the ABIs unchanged and finishes in well under a second. The same
edit now takes 3s.

The comment being replaced said this had to wait for GHC 9.4, which
tracks file changes by hash rather than timestamp; that is long since
the case.
@simonmar

simonmar commented Oct 5, 2026

Copy link
Copy Markdown
Owner

I think this is done - the gen-haskell-prebuilt.py script is subsumed by cabal buck2 (see haskell/cabal#12410) which does handle the inplace packages correctly, and the other two commits are merged. Thanks!

@simonmar simonmar closed this Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants