Skip to content

Let tools read from mhs what base stands for, which packages it forks, and ghc-compat #572

Open

Description

@ulysses4ever

haskell/cabal#11392 lets cabal build packages with mhs. For packages from Hackage to build, it does three things that MicroCabal does too, each from a table that both keep:

  1. it presents the base of mhs as base-4.19.1.0, and the packages that base bundles as installed packages of their own;
  2. it replaces array and random with array-mhs and random-mhs;
  3. it adds ghc-compat to every component.

A reviewer of the PR objects to Cabal keeping these tables, and I think they have a point: the tables describe a particular version of mhs, they change more often than Cabal is released (MicroCabal's copies changed every couple of months over the last year), and a released cabal cannot follow them. If mhs said these things itself, cabal could read them instead, and so could mcabal.

Below are the three, with how many packages of MicroHs's own list (Makefile.packages, 91 packages) build with cabal when each is switched off (all 91 build with all three), and a few ways mhs could take each over, easiest first. Any one of the ways would do for each. I'm happy to send PRs for whichever you prefer.

1. What base stands for

Without it, none of the 91 build: packages from Hackage ask for base >= 4.x, which base-0.16.9.0 does not satisfy, and they depend on bytestring, text and the others by name.

  • Install registration files with mhs. make minstall would write, beside packages/base-<version>.pkg, a Cabal registration file for base, at version 4.19.1.0 and with the modules it does not bundle, and one for each bundled package, such as bytestring-0.12.1.0, with its modules and no package file of its own. cabal already reads registration files in the directories that mhs -L lists, so it would need no table at all. They are text files, written at install time like mhs.conf, for example:

    name: bytestring
    version: 0.12.1.0
    id: bytestring-0.12.1.0
    exposed: True
    exposed-modules: Data.ByteString Data.ByteString.Char8 ...
    depends: base-0.16.9.0
    
  • Record it in the package file. A line in what mhs -L<pkg> prints, such as provides: base-4.19.1.0 bytestring-0.12.1.0 ..., with the modules of each, set when the package is built with -P. This works for any package that bundles others, not only base.

  • Make base say it directly. Version base after the API of GHC's base that it implements, and build the bundled packages into package files of their own, at the versions whose API they implement.

2. The forks

Without them, 71 of the 91 build: array imports GHC.Arr, and random uses ByteArray, neither of which mhs has.

  • Declare them in a file that comes with mhs. A list of the packages mhs needs forks of, and the forks, in mhs.conf or beside it, so that tools read it rather than keep it. cabal would still rename the dependencies, but the list would follow the installed mhs.
  • Ship the forks with mhs, under the original names. As GHC ships array: array-0.5.8.0 and random installed in the package directory of mhs, built from the forks. Then nothing needs renaming, as the solver finds the installed array. With the first way of item 1, they are two more registration files.
  • Get mhs support into array and random upstream. Under if impl(mhs), retiring the forks. This depends on their maintainers, but some packages do this already: time 1.16 has if !impl(mhs) in its .cabal file.

3. ghc-compat

Without it, 67 of the 91 build: packages import modules that are part of base with GHC, such as GHC.Stack and GHC.Exts, or that come from template-haskell, such as Language.Haskell.TH.Syntax (which time 1.16 imports for Lift), while depending only on base.

  • Declare it in a file that comes with mhs. As for the forks, so that tools take the rule from mhs. The same reviewer objects to adding a dependency that a package did not declare, though, wherever the rule comes from, so this may not be enough for cabal.
  • Put these modules where GHC has them. The GHC.* modules of ghc-compat in base, and the Language.Haskell.TH.* ones in a bundled template-haskell, presented like bytestring in item 1. Packages would then find them through the dependencies they declare.
  • Have packages declare ghc-compat under if impl(mhs). This also depends on the maintainers of each package; until they do, an overlay of patched packages could fill in, as head.hackage does for GHC.

The numbers come from replaying the list with cabal at the head of the PR, with mhs 0.16.9.0 and each of the three switched off in turn; the replay and its results are in cabal-mhs-testsuite.

Activity

  1. augustss commented on Nov 8, 2026

    @augustss
    Owner

    I'm happy to implement some of these ideas, but probably not all.
    As you mention, a lot depends on package maintainers. E.g., I had mhs fixes for the random package, but the maintainer refused to merge them. That's his choice.
    Perhaps it would be a good idea to distribute the forked packages with mhs, as you suggested.

  2. ulysses4ever commented on Nov 19, 2026

    @ulysses4ever
    ContributorAuthor

    Item 1 is done with #577: make minstall now writes the registrations, and cabal (haskell/cabal#11392) reads them instead of its table, which is gone.

    We'd like to try item 2 next, distributing the forks with mhs: make minstall would also install array-mhs and random-mhs, under their Hackage names, next to base, so that cabal can drop its table of forks too. I'll experiment on a fork and send a PR if it works out.

  3. ulysses4ever commented on Nov 23, 2026

    @ulysses4ever
    ContributorAuthor

    @augustss For item 2, the forks, four ways to get the forks to the tools without a table in each; which would you prefer?

    1. mhs ships the list of forks, say a file next to its packages (array array-mhs, random random-mhs). The tools read it and swap the names before solving, as mcabal does today; the forks stay on Hackage. The work stays in cabal, and reviewers expressed concerns about this hot swapping logic in cabal.
    2. An overlay repository with the forks under their original names, which users enable (for cabal, a repository mhs stanza with the overlay's URL, and active-repositories: hackage.haskell.org, mhs:override). No tool needs to know about forks. You'd upload to the overlay instead of to Hackage, and keep it signed and indexed; users add two stanzas once.
      2*. The same as a local repository: make minstall puts the two sdists in a directory of the install, and users point cabal at it (url: file+noindex:/…, no index or keys needed). Nearly nothing for you; the user does the configuring.
    3. make minstall installs the forks pre-built, under their original names, next to base. I have this working on a branch: ulysses4ever@aff31253994b. Nothing to configure anywhere. The catch: random drags splitmix, time, transformers, mtl and ghc-compat with it, seven package files (1.9 MB) regenerated at preparedist, which every Regen commit would add to the repository, and users can't upgrade those five.
  4. augustss commented on Nov 23, 2026

    @augustss
    Owner

    Since 1 is out of the question, I think 3 is the only option that I can accept.

    I will check again exactly why I need my own random. Perhaps I can fake enough stuff to compile the real one. It drags in too many things to be part of the MicroHs distribution.

    Maybe the random maintainer can be convinced to accept some small MicroHs patch, but I would not bet on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions