Skip to content

Can cabal-install drive MicroHS? #11370

Open

Description

@ulysses4ever

This is a spinoff from #11341

Has anyone experimented with this? @augustss maybe?

Activity

  1. augustss commented on Dec 22, 2025

    @augustss
    Contributor

    I didn't really try it. I just looked a bit at the code. And then decided to write my own.

  2. ulysses4ever commented on Dec 22, 2025

    @ulysses4ever
    CollaboratorAuthor

    I got you. I understand bootstrapping is high on the list of goals for MicroHS. But independently, I'm curious if we have cabal-install built with GHC (as usual), can it drive mhs. It'd be interesting to try it I think...

  3. augustss commented on Dec 22, 2025

    @augustss
    Contributor

    I think that would be very interesting to try.

  4. ulysses4ever commented on Jan 5, 2026

    @ulysses4ever
    CollaboratorAuthor

    My first experiment was to cabal init -nm --lib and try to "just build" it, and it exploded quickly:

    [nix-shell:~/dev]$ cabal build -w mhs
    Warning: this is a debug build of cabal-install with assertions enabled.
    Error: [Cabal-8038]
    The program 'ghc' version >=7.0.1 is required but the version found at /nix/store/3sg4dss3j9i8ikpzvm1gmrp0vncsm2x3-microhs-0.14.21.0/bin/mhs is version 0.14.21.0
  5. geekosaur commented on Jan 5, 2026

    @geekosaur
    Collaborator

    I'm surprised it got even that far; there's a fair amount of support that needs to be added to actually drive a compiler.

  6. ulysses4ever commented on Jan 5, 2026

    @ulysses4ever
    CollaboratorAuthor

    after debugging this s bit: although the MHS compiler flavor was added recently, the flavor detection mechanism identifies GHC flavor for MHS and proceeds accordingly. We need to correctly detect the flavor at least.

  7. geekosaur commented on Jan 5, 2026

    @geekosaur
    Collaborator

    My recollection is that the only thing that was added was recognition in a cabal file. There's no way to detect it, no way to run it, and in particular no way to know what would go into the store or what hashes to use and what modifies those.

  8. ulysses4ever commented on Jan 5, 2026

    @ulysses4ever
    CollaboratorAuthor

    There's no logic to detect a flavor, rather, ghc is the default, and if you don't like it, you're supposed to set it manually with the compiler flag. Funny enough, the docs say that it should be possible to do it via CLI, but I'm getting:

    [nix-shell:~/dev]$ cabal build -w mhs --compiler=mhs -v3
    Error: cabal: unrecognized 'build' option `--compiler=mhs'

    (and same with MHS, all caps). A project file works though. It get's me a bit further but not by much:

    [nix-shell:~/dev]$ cabal build -w mhs  -v3
    Warning: this is a debug build of cabal-install with assertions enabled.
    Searching for curl in path.
    Found curl at /run/current-system/sw/bin/curl
    Searching for powershell in path.
    Cannot find powershell on the path
    Searching for wget in path.
    Found wget at /run/current-system/sw/bin/wget
    Selected http transport implementation: curl
    File monitor 'config' changed: file /home/artem/Dev/cabal.project
    Project settings changed, reconfiguring...
    Reading project file using the fallback parser
    creating /home/artem/Dev/dist-newstyle
    creating /home/artem/Dev/dist-newstyle/cache
    Configuration is affected by cabal.project at '/home/artem/Dev'.
    File monitor 'improved-plan' changed: first run
    File monitor 'elaborated-plan' changed: first run
    File monitor 'compiler' changed: first run
    Compiler settings changed, reconfiguring...
    Error: [Cabal-3022]
    Unknown compiler
    CallStack (from HasCallStack):
      dieWithException, called at src/Distribution/Simple/Configure.hs:2528:16 in Cabal-3.17.0.0-inplace:Distribution.Simple.Configure

    Configure.hs:2528 is:

    -- | Configure the compiler ONLY.
    configCompiler
      :: Maybe CompilerFlavor
      -> Maybe FilePath
      -- ^ user-specified @hc@ path (optional)
      -> ProgramDb
      -> Verbosity
      -> IO (Compiler, Platform, ProgramDb)
    configCompiler mbFlavor hcPath progdb verbosity = do
      print mbFlavor
      (comp, maybePlatform, programDb) <-
        case mbFlavor of
          Nothing -> dieWithException verbosity UnknownCompilerException
          Just hcFlavor ->
            case hcFlavor of
              GHC -> GHC.configureCompiler verbosity hcPath progdb
              GHCJS -> GHCJS.configureCompiler verbosity hcPath progdb
              UHC -> UHC.configure verbosity hcPath progdb
              _ -> dieWithException verbosity UnknownCompilerException
      return (comp, fromMaybe buildPlatform maybePlatform, programDb)

    the next step would be to see if we can implement configure for MHS. Maybe it can be trivial. E.g. for UHC it reads:

    -- Cabal/src/Distribution/Simple/UHC.hs:59
    configure
      :: Verbosity
      -> Maybe FilePath
      -> ProgramDb
      -> IO (Compiler, Maybe Platform, ProgramDb)
    configure verbosity hcPath progdb = do
      (_uhcProg, uhcVersion, progdb') <-
        requireProgramVersion
          verbosity
          uhcProgram
          (orLaterVersion (mkVersion [1, 0, 2]))
          (userMaybeSpecifyPath "uhc" hcPath progdb)
    
      let comp =
            Compiler
              { compilerId = CompilerId UHC uhcVersion
              , compilerAbiTag = NoAbiTag
              , compilerCompat = []
              , compilerLanguages = uhcLanguages
              , compilerExtensions = uhcLanguageExtensions
              , compilerProperties = Map.empty
              , compilerWiredInUnitIds = Nothing
              }
          compPlatform = Nothing
      return (comp, compPlatform, progdb')
  9. geekosaur commented on Jan 5, 2026

    @geekosaur
    Collaborator

    Right, that's part of what I was getting at. But after that we have a possibly silent problem where mhs-options may contain things that need a different build hash in the store. Also I think objects aren't OS objects but combinator bytecode, and final link tacks a small bytecode interpreter on the front.

  10. augustss commented on Jan 6, 2026

    @augustss
    Contributor

    MicroHs has no concept of object files. There are two kinds of build products: 1, a .pkg file which is the result of compiling an entire library from a package. 2, an executable which is the result of compiling a runnable program from a package.
    The format of the .pkg file is private and should not concern cabal.

    It's true that you can get other outputs, like a combinator file, but that's more for debugging and testing.

    Telling mhs to install a package will populate a directory with various files, again, the contents of these is private.

  11. ulysses4ever commented on Jan 6, 2026

    @ulysses4ever
    CollaboratorAuthor

    @augustss where is this documented? do I switch between the two modes explicitly or MHS just figures it out? I've started some experimenting here: #11392

  12. augustss commented on Jan 6, 2026

    @augustss
    Contributor

    To create an executable mhs MDL -o FILE.
    To create a package mhs -PPKG MDL MDL ... -o FILE.
    Where MDL are module names, FILE are file names, and PKG a package name.

    To install a package mhs -Q FILE, where FILE is produced by mhs -P.

    You can run mcabal -v -v to see what it's doing.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions