cabal icon indicating copy to clipboard operation
cabal copied to clipboard

One freeze-file per GHC version

Open andreasabel opened this issue 3 years ago • 11 comments

There should be one freeze file per GHC version (like there is a build directory per GHC version in v2-cabal). Otherwise, freeze does not work as expected in a multi-GHC environment. I expect cabal v2-freeze -w ghc-x.y.z to work analogously to cabal v2-build -w ghc-x.y.z.

Currently there is a single cabal.project.freeze.

See also #2245.

andreasabel avatar Apr 21 '21 18:04 andreasabel

I agree, freeze file makes mostly sense for single compiler only.

This is challenging. Freeze file is just a convention, it's not "special". It is an unrestricted appendix to cabal.project (hardcoded like cabal.project.include). So this feature request is not much different then asking to select different cabal.project files based on --with-compiler flag. This is even more challenging then builddir in cabal.project (#5271), but the reason is the same: compiler can be set in cabal.project with with-compiler: ....

I'm afraid that project configuration have to be reworked in some non-trivial way to support this.

EDIT: an important constraint is that project configuration can be read in <10ms, to guarantee interactive-fast responses for no-build-op operations (e.g. cabal list-bin). Otherwise people (including myself) will loudly complain about why cabal-install become slow.

phadej avatar Apr 22 '21 07:04 phadej

We could partially get there by adding a --freeze-file flag that works like the --project-file one

fgaz avatar May 03 '21 13:05 fgaz

By the way, the freeze file can be changed, just together with the main project file: --project-file affects all kinds of project files together, so using --project-file=cabal.project.ghc-x.y would make cabal pick up a cabal.project.ghc-x.y.freeze (and cabal.project.ghc-x.y.local) file.

This might be a nuisance when the project file is big and has to be copied multiple times, but it works, and symlinks can solve the duplication

fgaz avatar Jun 21 '21 09:06 fgaz

only want to note that symlinking in windows is not reliable in general

jneira avatar Jun 21 '21 14:06 jneira

I think that explicit includes (discussed on related ticket) plus allowing includes in conditional stanzas would give a way to do this, albeit not the most seamless ux for it.

gbaz avatar Aug 26 '21 22:08 gbaz

After getting explicit includes and cabal freeze -w; is there anything left to this ticket or it can it be close?

andreabedini avatar May 15 '23 05:05 andreabedini

Just wanted to note that it's not enough to have one per compiler version, it can also vary per platform. So in principle you need one per compiler-version/platform combination.

michaelpj avatar May 16 '23 15:05 michaelpj

it can also vary per platform

It can also vary based on the output of pkg-config. IMHO this can be left to the user. I have seen many projects have separate project files per compiler version, so it's not impossible.

andreabedini avatar May 17 '23 04:05 andreabedini

This is already possible using imports[^1];

$ cabal freeze --project-file=cabal.project --with-compiler=ghc-9.8.2
...
Resolving dependencies...
Wrote freeze file:
/.../cabal.project.freeze

$ mv cabal.project.freeze cabal.ghc-9.8.2.freeze

Then edit the project to import the compiler-specific freeze file guarded by a conditional;

$ git diff
diff --git a/cabal.project b/cabal.project
index e368c280c..d71207795 100644
--- a/cabal.project
+++ b/cabal.project
@@ -4,3 +4,6 @@ import: project-cabal/pkgs.config
 import: project-cabal/constraints.config
 
 tests: True
+
+if impl(ghc == 9.8.2)
+    import: cabal.ghc-9.8.2.freeze

[^1]: This was already suggested on #3587 in https://github.com/haskell/cabal/issues/3587#issuecomment-234773265 and https://github.com/haskell/cabal/issues/3587#issuecomment-234788956. That same issue also notes it is also "difficult to support multiple compiler versions in a project" but this was before conditionals in projects, wasn't it?

philderbeast avatar Apr 23 '24 22:04 philderbeast

This is already possible using imports;

We could add this to the cookbook section on reproducible builds.

philderbeast avatar Apr 23 '24 22:04 philderbeast

Another option is to have one project per GHC version. Each would then be individually freezable.

That's what Updo does with its cabal.project for the current GHC version and its cabal.upgrade.project when upgrading to another GHC version. If more versions are required than current (default) and upgrade then Updo can generate GHC-prefixed projects.

philderbeast avatar Apr 23 '24 22:04 philderbeast