Skip to content
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

cabal init should not use same hs-source-dirs when choosing "Library and Executable" #6150

Closed
phadej opened this issue Jul 21, 2019 · 3 comments · Fixed by #6676
Closed

cabal init should not use same hs-source-dirs when choosing "Library and Executable" #6150

phadej opened this issue Jul 21, 2019 · 3 comments · Fixed by #6676

Comments

@phadej
Copy link
Collaborator

phadej commented Jul 21, 2019

This is bad practice as if an exe component depends on a lib component, GHC will recompile the modules, and not use the compiled library: double compilation of same modules.


An alternative is to implement a "don't compile modules we didn't told you to" to GHC, but I think this small step is still a good engineering practice, even cabal could tell (future) GHC to be less smart.


See #6143 (comment)

@kindaro
Copy link

kindaro commented Jul 24, 2019

Actually I think this was (almost) fixed in #5740 by introducing --application-dir. This is
how it looks in the most recent cabal-install version:

% cabal init
...
Application (Main.hs) directory:
 * 1) (none)
   2) src-exe
   3) app
   4) Other (specify)
Your choice? [default: (none)] 
Library source directory:
 * 1) (none)
   2) src
   3) lib
   4) src-lib
   5) Other (specify)
Your choice? [default: (none)] 
...

So, if the person running the program so desires, they could specify a distinct directory for the
executable code such as app. The default is none, which is the project root directory.
(Though the test suite does get placed to a subdirectory by default.) If all defaults are
accepted, the file hierarchy looks like this:

├── x.cabal
├── test/
│   └── MyLibTest.hs
├── Setup.hs
├── MyLib.hs
├── Main.hs
├── LICENSE
└── CHANGELOG.md

So it seems to me the only thing we may be doing here is re-set the default to app for the
executable and to lib for the library. Should we?

@m-renaud
Copy link
Collaborator

Also, the most recent version of cabal-install allows you to configure this in your ~/.cabal/config file. There is a new init subsection where you can set the default source-dir and application-dir, among others:

init
  ...
  -- application-dir:
  -- source-dir:

@m-renaud
Copy link
Collaborator

m-renaud commented Apr 2, 2020

Circling back to this, given that this is configurable we should be able to avoid too much bikeshedding on whether we use lib or src for source-dir since folks can set the default to whatever they'd prefer.

I'll put together a PR changing the defaults for source-dir to lib/ and application-dir to app/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants