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

Use cabal's code-generators to reimplement singletons-base test suite without custom Setup.hs #532

Closed
RyanGlScott opened this issue Aug 23, 2022 · 3 comments · Fixed by #622

Comments

@RyanGlScott
Copy link
Collaborator

Cabal-3.8 debuts a new code-generators feature that can be used to generate modules when preprocessing a test suite and include them as part of building the test suite. One of the intended use cases for a code generator is to fill the role that is often served today by custom Setup.hs scripts. In particular, singletons-base's custom Setup.hs script seems like a prime candidate for being implemented as a code generator, since the primary reason for using a custom Setup.hs script is to learn what -package-id arguments to pass to GHC to get the dependencies right. That is exactly the sort of information that code generators have access to.

@RyanGlScott
Copy link
Collaborator Author

In light of the CI issues observed in #620 related to singletons-base's custom Setup.hs script, I propose that we expedite implementing this so that we can finally rid ourselves of the custom Setup.hs script.

I have a very rough implementation of this in the T532 that needs some further polish. Two slightly annoying (but not deal-breaking) issues that I encountered:

  1. After switching from a custom Setup.hs script to a code-generators–based test suite, you can no longer load the test suite into GHCi. See Test suite using code generator fails to compile with cabal v2-repl haskell/cabal#8424.
  2. I am unable to define the code generator executable as an internal library (see code-generators fails to find executable defined in same package as test suite haskell/cabal#8421), which means that I will have to upload the code generator as a standalone tool on Hackage. A bit cumbersome, but probably less cumbersome than having a custom Setup.hs script.

@phadej
Copy link

phadej commented Dec 9, 2024

@RyanGlScott be aware that it's likely that stack will choke on code-generators stuff as well, so Stackage probably wont run the test-suites. Probably not a big deal, but something to be aware of.

As far as I know no package on Hackage uses code-generators (based on https://hackage-search.serokell.io/?q=code-generators), so you are in uncharted territory.

@RyanGlScott
Copy link
Collaborator Author

be aware that it's likely that stack will choke on code-generators stuff as well, so Stackage probably wont run the test-suites. Probably not a big deal, but something to be aware of.

Interestingly, the singletons-base test suite has disabled in Stackage ever since this commit. In that sense, people are unlikely to notice if it suddenly doesn't work with stack :)

As far as I know no package on Hackage uses code-generators (based on https://hackage-search.serokell.io/?q=code-generators), so you are in uncharted territory.

Fun! singletons has always pushed the boundaries of what the Haskell ecosystem can do, and this is no exception. Let's see what happens.

RyanGlScott added a commit that referenced this issue Dec 10, 2024
This replaces `singletons-base`'s custom `Setup.hs` script with a `cabal` code
generator. This finally allows `singletons-base` to have a `Simple` build type,
but at the (relatively less extreme) cost of requiring `Cabal-3.8` or later in
order to build.

Remarkably, everything that the custom `Setup.hs` script did can be done in a
much simpler way with a `cabal` code generator, as all of the information that
the `singletons-base` test suite needs to invoke GHC can be inferred from the
arguments passed to a code generator. One downside is that due to
haskell/cabal#8421, the code generator must be
implemented in a standalone executable package
(`singletons-base-code-generator`). Until that `cabal` issue is fixed, we will
need to upload `singletons-base-code-generator` to Hackage with each
`singletons` release.

Fixes #532.
RyanGlScott added a commit that referenced this issue Dec 11, 2024
This replaces `singletons-base`'s custom `Setup.hs` script with a `cabal` code
generator. This finally allows `singletons-base` to have a `Simple` build type,
but at the (relatively less extreme) cost of requiring `Cabal-3.8` or later in
order to build.

Remarkably, everything that the custom `Setup.hs` script did can be done in a
much simpler way with a `cabal` code generator, as all of the information that
the `singletons-base` test suite needs to invoke GHC can be inferred from the
arguments passed to a code generator. One downside is that due to
haskell/cabal#8421, the code generator must be
implemented in a standalone executable package
(`singletons-base-code-generator`). Until that `cabal` issue is fixed, we will
need to upload `singletons-base-code-generator` to Hackage with each
`singletons` release.

Fixes #532.
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.

2 participants