Skip to content

Better cabal (new-build) integration for ghc-mod #3872

Closed

Description

@DanielG

So here are some notes on how ghc-mod interacts with Cabal to get a discussion going on how we can do better for cabal new-build. (As discussed with @dcoutts)

Currently ghc-mod interacts with cabal though a library/program wrapper called cabal-helper. ghc-mod uses cabal-helper's library which compiles a small program at runtime which uses the Cabal library internally.

To ensure version compatibility this helper program is compiled against the exact same version of Cabal as was used to generate the configuration state (dist/setup-config) we're reading.

We only really have to do this runtime-compilation dance because ghc-mod doesn't control which version of cabal-install/Cabal the user might have so we need to adapt to whatever is there. If cabal-install itself provided a command to get at the information we extract using cabal-helper there wouldn't be any need for it in the first place.

Therefore I think something simmilar in spirit to #2771 would be a good way to move forward.

So let's run through how ghc-mod usually interacts with Cabal:

  1. First we reconfigure the project if needed. To do this we have to re-implement the reconfiguration logic cabal-install already has since there isn't a cabal configure --reconfigure flag or something afaik and cabal build (which would reconfigure if needed) would be too much.

  2. Then we get all the information we need about each component out of dist/setup-config (LocalBuildInfo). That includes various rendered subsets of
    GhcOptions as well as exposed-modules, other-modules and main-is as applicable to the component. We need the latter to compute the module closue for components that don't list all modules. (they are meant to according to duncan)

  3. We call write initialBuildStepsForAllComponents to get Paths_* modules and such.

That's pretty much it. One thing we don't handle yet are preprocessors. If a project is using hsc2hs or something like that IIRC the user has to run cabal build first to get ghc-mod to work. It would be nice if there was an interface to just run preprocessors and to get information about source files that need them.

For more details about what GhcOptions subsets we need see cabal-helper's "helper" executable source: https://github.com/DanielG/cabal-helper/blob/master/CabalHelper/Main.hs#L185

Activity

  1. dcoutts commented on Sep 19, 2016

    @dcoutts
    Contributor

    Thanks!

    To ensure version compatibility this helper program is compiled against the exact same version of Cabal as was used to generate the configuration state (dist/setup-config) we're reading.

    Yeah, that's really not going to work well in future. We can quite easily in a single project have different packages using different versions of Cabal (due to custom setup that can specify their own deps and thus can specify the Cabal lib version, and different Setup.hs don't have to use the same versions of deps as each other).

    1. First we reconfigure the project if needed. To do this we have to re-implement the reconfiguration logic cabal-install already has since there isn't a cabal configure --reconfigure flag or something afaik and cabal build (which would reconfigure if needed) would be too much.

    I think now you could do just cabal (new-)build --dry-run and that'd update everything and check that constraints etc are soluble. You could use cabal (new-)configure but that looses any flags that were previously used manually with cabal (new-)configure. (The model is that cabal (new-)configure --flags just (over)writes the flags in cabal.project.local which is then automagically included). So it depends if you want to have ghc-mode control the local config flags (cabal.project.local) or if you want to have users control that manually.

    1. Then we get all the information we need about each component out of dist/setup-config (LocalBuildInfo).

    Right here's where something like #2771 fits in, in addition to looking at the $distdir/cache/plan.json to find out what packages/components are in the project.

    1. We call write initialBuildStepsForAllComponents to get Paths_* modules and such.

    A build flag that only runs up to the pre-processor phase would cover it. Other people have asked for the same thing (e.g. source code analysis tools) and it shouldn't be too hard to do.

  2. added this to the ⊥ milestone on Sep 21, 2016
  3. merijn commented on Nov 6, 2020

    @merijn
    Collaborator

    @DanielG I'm guessing that with all the hie/hls developments and the end of ghc-mod as a standalone tool this issue has become obsolete?

  4. jneira commented on Nov 6, 2020

    @jneira
    Member

    In any case show-build-info should gives enough info to any tool, including ghc-mod, i suppose

  5. DanielG commented on Nov 7, 2020

    @DanielG
    CollaboratorAuthor

    This issue in particular is pretty obsolete, yeah, but given that cabal has 1.3k open issues what does it matter ;)

    As for s-b-i being "enough for any tool" -- personally I've come to the conclusion that the approach we've taken there is still flawed in some ways, though it's admittedly still better than the status quo. I haven't had much time/motivation for Haskell tooling work in recent times though so I just haven't gotten around to putting up a prototype for another approach though.

  6. merijn commented on Nov 7, 2020

    @merijn
    Collaborator

    but given that cabal has 1.3k open issues what does it matter ;)

    phadej has been trying to clean up as many obsolete issues as possible, so I'm trying to do my part and help when I run into things, because we gotta start somewhere if we ever wanna end up with a reasonable number of issues :)

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions