cabal icon indicating copy to clipboard operation
cabal copied to clipboard

Support `main-is` inside "common stanzas"

Open chshersh opened this issue 6 years ago • 6 comments

My use case is that I have a lot of executables placed in different folders. Every executable contains a single Haskell source code file called Main.is. I would like to remove some boilerplate by putting main-is: Main.hs into common stanza (with other options). However, when I do this, I see the following build error message:

No 'main-is' field found for executable my-exe1
No 'main-is' field found for executable my-exe2
No 'main-is' field found for executable my-exe3
No 'main-is' field found for executable my-exe4
No 'main-is' field found for executable my-exe5

It would be really nice if common stanzas could support main-is field as well.

chshersh avatar Jun 28 '19 03:06 chshersh

@chshersh common stanzas are designed to be "typed" and the current one we support is of type "build-info" which is the common denominator of all stanzas where you're allowed to include common stanzas.

What you're asking is basically to implement the common-executable type; see also discussion at https://github.com/haskell/cabal/issues/2832#issuecomment-236696081

hvr avatar Jun 28 '19 06:06 hvr

@hvr Thanks for the information! This makes sense. Issue #5531 looks similar.

chshersh avatar Jun 28 '19 06:06 chshersh

Me too. I think it is unintuitive that common only supports some fields. I tried to include main-is and type (for test-suite) but both are rejected.

andreasabel avatar Jul 22 '22 11:07 andreasabel

Hmm otoh i agree with hvr point of view (also accepted by the issue author). I think it is cleaner to have a common-executables stanza than add fields to the common one which are only applicable to some stanzas

jneira avatar Jul 22 '22 13:07 jneira

I would encourage to not introduce separate common-executables stanza. This introduces another layer of unnecessary complexity. I think nothing stops common stanzas from being typed but still support different stanza types. You just need a proper type for this 😉

I see choosing BuildInfo for common stanzas as an easy and first step to implement this feature. But we can iterate on it and support more and more fields over type.

chshersh avatar Jul 22 '22 15:07 chshersh

I think nothing stops common stanzas from being typed but still support different stanza types. You just need a proper type for this

yeah, that sounds better

jneira avatar Jul 22 '22 16:07 jneira