You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Supporting builddir in cabal.project and global config #5271
To the best of my knowledge, new-X don't currently obey builddir entries in cabal.project. There was some speculation that there was a technical reason for this, but at first glance of the code it just seems the problem is laziness. That is, all code paths dealing with computing the DistDirLayout try and resolve the cabal.project path and builddir in a single step.
It seems fairly straightforward* to split this into two steps, first looking up cabal.project and the project path, then checking establishing the DistDirLayout after that. I would assume that the logical priority for determining builddir would be:
commandline --builddir flag
builddir in cabal.project
default to dist-newstyle
If no one has any theoretical objections I'll try and see if I can get it working as straightforwardly as I hope it to be :p
Parsing of configuration (basically rebuildProjectConfig) uses file monitors to check for changes in config files
File monitors use a cache to be able to tell file changes over multiple runs of cabal
These caches have to be stored somewhere... and of course its the dist directory
So rebuildProjectConfig, the function that reads and assembles our project configuration, actually writes to dist dir on a cold start. Not sure how you would work around that.
Well, we can just parse the cabal.project, check what the builddir is, THEN check with the cache if anything changed and things need to be rerun. Sure, that introduces a redundant read/parse of cabal.project if the config hasn't changed, but I doubt reading and parsing cabal.project is so slow that it will noticeably impact the speed of any cabal command.
@merijn the problem is that you're assuming that we've already fully implemented all features; but there's more planned, like file-globbing includes for cabal project files. And then I'm afraid the induced latency would be a lot more noticeable, and it'd also risk destroying the latency savings that caching would give us (I care to keep the no-op detection latency way below 100ms, as otherwise cabal new-run becomes useless for my scripting)
I think the ability to specify a builddir loses most of it's value if you can't do it per-project and you have to always specify it on the commandline for each command. At that point, why even support specifying a custom builddir at all?
Reacted by Bardur Arantsson, AndreasPK, George Thomas, André Szabolcs Szelp, Javier Neira , Agustín Mista, Lucas Gangstad and Curt J. Sampson
Maybe we should bite the bullet and stop caching of ProjectConfig stuff?
I've also had issues with the stored (outdated) config overwriting command line settings for store-dir.
Might also also be a result of the cache not being recognized properly as outdated.
I have not opened a Ticket on that yet as it's not quite clear to me when that happens.
I had a brief discussion with @alexbiehl for two potential pragmatic workarounds; either,
Introduce a new file cabal.builddir which is located the same way cabal.project is, but merely contains a string denoting the --builddir argument value; this is basically a textual symlink (Git uses something like this too inside its .git folder), or
Allow builddir: ... inside cabal.project files but in a restricted way that can be scanned for by a trivial dumb parser, and w/o needing to read the full cabal.project file; this should allow to keep the latency overhead well in the 1ms order of magnitude.
The latter approach could be implemented as follows:
The key/value pair
builddir: <path>
must occur (completely, i.e. including a terminating LF) within the first 4096 bytes;
it must start in column one, and
must be a single line, and it
must be lower-case and there
must be no whitespace between builddir and :
there must at most be a single occurrence of builddir (as we only scan for the first one)
we can validate this easily when doing a full parse of the cabal.project by doing a consistency check (the full parser must report the same builddir as the lightweight parser; this is a similiar scheme to the one we already used for the cabal-version scanning)
Then scanning is very cheap, assuming that projfrag contains the prefix of a cabal.project file:
Try stripPrefix "builddir:" projfrag, if successful take rest of line
Otherwise, breakSubstring "\nbuilddir:" projfrag, if found, take rest of the line after the :
The second approach feels very restrictive. I can imagine someone asking for builddir inside if conditionals after/if those are added to cabal.project, i.e.
if impl(ghc ==8.0.*)
builddir: dist-ghc-8.0
why one would like to do that? So one can access plan.json for example. Making builddir special would ruin that.
Parsing cabal.project should really be a bottleneck, Using parsec parser (though very simple on, in cabal-install-parsers, the small cabal.project is parsed in
-- Cabal project configuration
-- Consult http://cabal.readthedocs.io/en/latest/nix-local-build.html for more information
packages: .
packages: cabal-parsers
tests: true
package haskell-ci
ghc-options: -Wall
ghc-options: -Werror
And if that will become a problem, we can cache the parsed Project, there's FileMonitor stuff which does exactly that. (EDIT: and rather figure out where to cache the parsed cabal.project, as builddir isn't yet known)
As #6849 was closed as duplicate of this I'd like to bring in some points mentioned there.
The documentation of the flag only talks about cabal.project-files. I took this as the local cabal.project files. It should be somewhere mentioned that this equally applies to ~/.cabal/config -- that wasn't immediately clear to me as a user.
Why do some users even want to change the name of the build directory? At least I want to change it because the current name is bad in several ways:
The dist part is inappropriate, since the contents of this directory are not for distribution. Typically, the only thing that gets distributed is what’s generated with cabal sdist.
The newstyle part is inappropriate, because Nix-style local builds are by no means new. They are in fact quite old now.
The newstyle part is written as if “new style” was a single word instead of two.
Maybe just switch to a better name, like build-products, and the problem would be solved for the most part. I actually might prefer .build-products in order to hide the directory, but this wouldn’t work on Windows.
By the way, from experiments I get the impression that the --builddir option can be passed before the subcommand and can be passed there even when it doesn’t make sense for the subcommand used (it’s possible to specify it also with update). Therefore, a workaround for us people being tired of seeing dist-newstyle in their directory listings 😉 could be to define a shell alias that expands to cabal --builddir=⟨desired-directory⟩. I’ll try this out.
@jeltsch that is common misconception that dist-newstyle doesn't make sense for update. It does.
Even update command interacts with cabal.project: you can specify extra package repositories in cabal.project and these will be updated by cabal update. (and the parsing/resolving of cabal.project is cached in the --builddir).
@jeltsch that is common misconception that dist-newstyle doesn't make sense for update. It does.
Even update command interacts with cabal.project: you can specify extra package repositories in cabal.project and these will be updated by cabal update. (and the parsing/resolving of cabal.project is cached in the --builddir).
Interesting! What are actually the cabal-install subcommands that do not accept --builddir? So far, I’m only aware of init (for which in fact an alias as I’ve suggested above does not work).
Why do some users even want to change the name of the build directory?
I want to change it to declutter things. I use a pseudo-XDG Base Directory layout for my projects, where (as much as possible) I put things in $PROJECT_ROOT/.config, $PROJECT_ROOT/.cache, etc.
So I want to be able to do builddir: .cache/cabal/dist-newstyle.
Why do some users even want to change the name of the build directory? At least I want to change it because the current name is bad in several ways:
This is probably a less common use case. But I commonly need to build a project with different configurations for GHC work, and the clearest way to do this is with setting different build/store dirs for different configurations.
And it obviously can be helpful to store the configuration in a project file. As it reduces the chance of the command line accidentally being messed up.
Activity
alexbiehl commentedon Apr 18, 2018
I think it won't be that easy. There is a knot:
rebuildProjectConfig) uses file monitors to check for changes in config filesSo
rebuildProjectConfig, the function that reads and assembles our project configuration, actually writes to dist dir on a cold start. Not sure how you would work around that.alexbiehl commentedon Apr 18, 2018
Maybe we should bite the bullet and stop caching of
ProjectConfigstuff?merijn commentedon Apr 18, 2018
Well, we can just parse the cabal.project, check what the builddir is, THEN check with the cache if anything changed and things need to be rerun. Sure, that introduces a redundant read/parse of cabal.project if the config hasn't changed, but I doubt reading and parsing cabal.project is so slow that it will noticeably impact the speed of any cabal command.
hvr commentedon Apr 18, 2018
@merijn the problem is that you're assuming that we've already fully implemented all features; but there's more planned, like file-globbing
includes for cabal project files. And then I'm afraid the induced latency would be a lot more noticeable, and it'd also risk destroying the latency savings that caching would give us (I care to keep the no-op detection latency way below 100ms, as otherwisecabal new-runbecomes useless for my scripting)merijn commentedon Apr 18, 2018
I think the ability to specify a builddir loses most of it's value if you can't do it per-project and you have to always specify it on the commandline for each command. At that point, why even support specifying a custom builddir at all?
23Skidoo commentedon Jun 8, 2018
Looks like it's not certain we actually want to implement this, so labeled as "discussion".
AndreasPK commentedon Aug 1, 2018
I've also had issues with the stored (outdated) config overwriting command line settings for store-dir.
Might also also be a result of the cache not being recognized properly as outdated.
I have not opened a Ticket on that yet as it's not quite clear to me when that happens.
hvr commentedon Aug 1, 2018
I had a brief discussion with @alexbiehl for two potential pragmatic workarounds; either,
Introduce a new file
cabal.builddirwhich is located the same waycabal.projectis, but merely contains a string denoting the--builddirargument value; this is basically a textual symlink (Git uses something like this too inside its.gitfolder), orAllow
builddir: ...insidecabal.projectfiles but in a restricted way that can be scanned for by a trivial dumb parser, and w/o needing to read the fullcabal.projectfile; this should allow to keep the latency overhead well in the 1ms order of magnitude.The latter approach could be implemented as follows:
The key/value pair
builddir: <path>LF) within the first 4096 bytes;builddirand:builddir(as we only scan for the first one)we can validate this easily when doing a full parse of the
cabal.projectby doing a consistency check (the full parser must report the samebuilddiras the lightweight parser; this is a similiar scheme to the one we already used for thecabal-versionscanning)Then scanning is very cheap, assuming that
projfragcontains the prefix of acabal.projectfile:stripPrefix "builddir:" projfrag, if successful take rest of linebreakSubstring "\nbuilddir:" projfrag, if found, take rest of the line after the:--builddir23Skidoo commentedon Aug 1, 2018
I lean towards the second solution.
phadej commentedon Dec 12, 2019
The second approach feels very restrictive. I can imagine someone asking for
builddirinsideifconditionals after/if those are added tocabal.project, i.e.why one would like to do that? So one can access
plan.jsonfor example. Makingbuilddirspecial would ruin that.Parsing
cabal.projectshould really be a bottleneck, Using parsec parser (though very simple on, incabal-install-parsers, the smallcabal.projectis parsed inhaskell-ci.project:And if that will become a problem, we can cache the parsed
Project, there'sFileMonitorstuff which does exactly that. (EDIT: and rather figure out where to cache the parsedcabal.project, asbuilddirisn't yet known)szabi commentedon May 26, 2020
As #6849 was closed as duplicate of this I'd like to bring in some points mentioned there.
cabal.project-files. I took this as the local cabal.project files. It should be somewhere mentioned that this equally applies to~/.cabal/config-- that wasn't immediately clear to me as a user.phadej commentedon May 26, 2020
The core problem is that
--builddirdetermines the cache location. Reading configs is noticeable time-sink which makescabalway less interactive.So having
builddirin~/.cabal/configwould be tricky.TL;DR it's not as simple as adding a field to config. The
builddiris very special, and should be available fast (in milliseconds).[-]Supporting builddir in cabal.project[/-][+]Supporting builddir in cabal.project and global config[/+]jneira commentedon Nov 14, 2021
Renaming the issue to include global config, as #6849, mentioning it, was closed as duplicate of this
Mikolaj commentedon Sep 4, 2023
See also #7924 for a much more modest related task.
jeltsch commentedon Feb 13, 2024
Why do some users even want to change the name of the build directory? At least I want to change it because the current name is bad in several ways:
distpart is inappropriate, since the contents of this directory are not for distribution. Typically, the only thing that gets distributed is what’s generated withcabal sdist.newstylepart is inappropriate, because Nix-style local builds are by no means new. They are in fact quite old now.newstylepart is written as if “new style” was a single word instead of two.Maybe just switch to a better name, like
build-products, and the problem would be solved for the most part. I actually might prefer.build-productsin order to hide the directory, but this wouldn’t work on Windows.jeltsch commentedon Feb 13, 2024
By the way, from experiments I get the impression that the
--builddiroption can be passed before the subcommand and can be passed there even when it doesn’t make sense for the subcommand used (it’s possible to specify it also withupdate). Therefore, a workaround for us people being tired of seeingdist-newstylein their directory listings 😉 could be to define a shell alias that expands tocabal --builddir=⟨desired-directory⟩. I’ll try this out.phadej commentedon Feb 13, 2024
@jeltsch that is common misconception that
dist-newstyledoesn't make sense forupdate. It does.Even
updatecommand interacts withcabal.project: you can specify extra package repositories incabal.projectand these will be updated bycabal update. (and the parsing/resolving ofcabal.projectis cached in the--builddir).fgaz commentedon Feb 14, 2024
@jeltsch see #5731 for switching to a better default
jeltsch commentedon Feb 16, 2024
Interesting! What are actually the cabal-install subcommands that do not accept
--builddir? So far, I’m only aware ofinit(for which in fact an alias as I’ve suggested above does not work).sellout commentedon Jul 23, 2025
I want to change it to declutter things. I use a pseudo-XDG Base Directory layout for my projects, where (as much as possible) I put things in
$PROJECT_ROOT/.config,$PROJECT_ROOT/.cache, etc.So I want to be able to do
builddir: .cache/cabal/dist-newstyle.AndreasPK commentedon Jul 24, 2025
This is probably a less common use case. But I commonly need to build a project with different configurations for GHC work, and the clearest way to do this is with setting different build/store dirs for different configurations.
And it obviously can be helpful to store the configuration in a project file. As it reduces the chance of the command line accidentally being messed up.