`cabal build --enable-profiling` should use a separate build directory
It is quite common to alternate normal and profiling builds while developing. Currently, cabal uses the same build directory for both, which results in a lot of rebuilding. The current workaround is to manually specify separate build directories for each type of build, which works but is noisy.
This seems easy to fix: use some other build directory by default if --enable-profiling is present (e.g., dist-profiling). Users can still use --builddir to pick a different one, if they'd like.
The problem is wider than --enable-profiling, it includes any flag that impacts compilation. Any solution should consider solving this for all flags.
One popular example is ghcide and company. They compile with -w and many project... don't. The end result is building via cabal build will cause a significant re-build, which then gets over-written by the invocations of the IDE. There is also a race here, but I'll make a separate ticket.
Well, I am not sure why the warning flags should affect compilation, so that might be a separate issue.
The general problem seems a bit trickier to solve as I am not sure that I'd want a separate build directory every time I change a flag that affects compilation, but maybe that's OK?
Anyway, using profiling is a very common thing to do, and I can't think of any reason why you might want you profiling build to overwrite your normal build, so I'd be happy with the simple change to use a different directory in that particular case.
See https://github.com/haskell/cabal/pull/5314#pullrequestreview-124206793
Separate directory is not proper solution.
I wasn't suggesting that we add a subdirectory to the existing build directory but rather, to simply use a whole separate directory. So this amounts to just a different set of default settings: currently the build directory is always dist-newtyle unless you explicitly specify it. I was suggesting that if --enable-profiling is present, then the default build directory becomes dist-prof or something, that's all.
This is the workaround that people are using anyway, and while I don't claim to be a cabal expert, it seems perfectly reasonable to keep profiling and normal builds separate.