-
Notifications
You must be signed in to change notification settings - Fork 696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Move GHC environment files into dist-newstyle
and add cabal shell
#7890
Comments
provide enough information to recover build setup (you need to guess where the compiler executable is though). E.g. https://github.com/phadej/cabal-extras/tree/master/cabal-docspec uses these and doesn't rely on environment files at all. |
Thanks for the links! IMO these solutions are much more involved from a user perspective than Cabal setting an environment variable. The alternative, the way Stack handles it and what's proposed here, needs no specific support from GHC API consumers at all. And at the risk of sounding very negative, as a developer I'm not particularly thrilled about relying on external packages parsing Cabal internals and having two separate code paths for Stack and Cabal. This is in no way trying to diminish the work that went into (As a funny note: I did look into |
Let see. I guess That feature shouldn't affect whether environment files are written in the root of the project: their use case is different. Setting up in |
Thanks for the quick reply.
Cool
Alright, I don't mind too much as long as the default is off.
Generally I agree: explicit is better than implicit. But it doesn't seem too implicit to me that an executable run with
What do you think? |
I agree with oleg that a simple baseline of always writing env files next to plan.json is a good idea -- I think this had been suggested as part of an earlier cleanup and got lost in the shuffle. You note that And I also am not sure about what the specific use case is for Because any change to implicit stuff can always cause user frustration and confusion (as we learned the hard way a few times) I'd very much like to understand the exact use cases here. |
Writing env files to dist-newstyle is a good first step.
It would. But yes,
Perhaps. A technical problem I see is that
Very fair. For what it's worth, I really struggle to imagine an executable that would want to access the GHC API without having access to the packages Cabal just built. Also, given that Nix and Stack have both been doing this for years now, I'm inclined to say it isn't really a problem. Lastly, if applications would want to access the GHC API without having access to built libraries, it would be as simple as erasing |
To give a very specific answer to this, I'm currently working on two projects: As @phadej correctly remarked, all this information is available in the I currently work around this by recommending users to put |
|
Thanks! Cabal itself is an interesting edge case, given that it manages its own dependencies. In any case, would the following be (easily) implementable?
|
It won't work as you expect. It's the It is possible to make That will require new Using old-and-proven I'd say it's implementable, but it's not easy. EDIT: note that at the moment EDIT2: but it might be that some build tool doesn't actually call |
Hmm, I'm not familiar enough with Cabal's flow to properly understand what you're saying, but I think I get the gist.
Who's the one running the executables, is that As far as the issue goes: it seems natural to me to unset / ignore
Yes, this is a problem for Clash and doctest-parallel alike. I don't mind too much though, we just ask all our users to use |
Also, I'd like to thank everyone in this thread for their contribution, it's much appreciated :) |
if it's Which makes setting |
TL;DR, |
Ok, so I think there's three parts here.
I'm not super keen on the last still, since i hate adding new commands. Could we instead add a flag to cabal-exec to tell it to build the deps for a given component before execing? |
Hmm, perhaps I'm misunderstanding, but a naive read of End of cabal/cabal-install/src/Distribution/Client/CmdRun.hs Lines 225 to 233 in bbc11f1
Snippet of cabal/Cabal/src/Distribution/Simple/Program/Run.hs Lines 127 to 130 in bbc11f1
I'm only interested in this specific invocation running with a |
@gbaz I understand the hate for adding new commands. I kinda tunnel-visioned myself on moving the env file, while writing it twice would perfectly suffice. I don't actually care about |
@martijnbastiaan don't confuse run and test. tests and benchmarks are "run" during the "build" process. cabal/cabal-install/src/Distribution/Client/ProjectBuilding.hs Lines 1331 to 1337 in 980a532
|
ah oof.. |
Background
GHC environment files (from here on: GEFs) describe where GHC package databases reside and what packages from those databases should be exposed in a particular GHC session. As an example, here's what a GEF looks like after compiling
aeson-pretty
:Unless explicitly surpressed, any GHC session executed in either the directory containing the GEF or any directory under that will use this file to find and expose packages. Cabal used to generate these files automatically, however, this has been disabled as many users found it confusing. Users can now opt-in by passing
--write-ghc-environment-files=always
or by adding a similar section to theircabal.project
.I purposely won't go into the perceived downsides of GEFs, as I think this has been discussed many times over on various fora.
So what's wrong?
While seemingly opt-in, GEFs are currently the only way Cabal communicates what package databases it used and what packages are exposed to subcommands. This leads to some projects (
doctest-parallel
,clash-ghc
+ projects build with Clash) requiring their presence. In general, any downstream consumer of the GHC API is likely to want access to these files. There's currently a couple of ways these projects solve this, but without delving into them: this gets us right back to square one. That is, for these projects, all the downsides of GEFs are exposed once more.Brushing aside projects needing GEFs, even users who liked their behavior are now in a rough spot: they need to remember to either enable them globally, per project, or even on a per command basis.
Consumers
As far as I can see, there are two groups of GEF users:
cabal run
).Then, there's a (I believe, large) group that doesn't care at all but is prone to being bitten by unexpected behavior imposed by GEFs. This group overlaps with group (1).
Tackling this
I strongly believe a few things should happen:
dist-newstyle
.GHC_ENVIRONMENT
and set it to the GEF mentioned in (1) when running subcommands. E.g., forrun
andtest
.shell
that drops you into a shell withGHC_ENVIRONMENT
set. Likebuild
, one can set a target, or none at all. This command should be able to be run anywhere in your project. It should optionally take a command to run, e.g.cabal shell my-exe -- ghci
.Notes
In no particular order:
cabal exec
that generates a temporary GEF and setsGHC_ENVIRONMENT
. However,exec
doesn't actually build anything.--distdir
also exist.GHC_PACKAGE_PATH
andGHC_ENVIRONMENT
for subcommands. This works really well for the projects I work on..ghc.*
files - this is IMO where most of the frustration stems from.v2-*
commands in this RFC.The text was updated successfully, but these errors were encountered: