Allow loading object files in the interpreter in batch compilation
When building Haskell modules with rules_haskell, we want to require as little dependencies as possible to get fast incremental builds. ghc
makes possible to supply only essential dependencies, but this is not very well documented and, plausibly, people here might have different opinions on how to advertise it and how to support it better.
What I'd like to avoid, most of all, is someone unknowingly changing this behavior in a way that is incompatible with the ability of rules_haskell
to invoke ghc
. So here goes my reconstruction of how it works and then some questions.
The following invocation builds module M.hs
and requires to build first the interface files in somepackage
$ ghc -c M.hs -package-env - -package-db somepackage/pkgdb -package somepackage
Not all the interface files in somepackage
need to be produced in advance though. Only those modules which are (transitively) imported by M
need to be built in advance.
So far, so good. Things are less clear when module M
uses Template Haskell, though. If the splices in M
require modules from somepackage
, we need to build in advance the shared library of somepackage
, so ghc
can load it in the interpreter while building M
. Now, linking the shared library would require building all of the modules of somepackage
first, regardless of whether they are needed or not to run the splices in M
.
In order to avoid depending on all the modules of somepackage
, we can invoke ghc
as follows
$ ghc -c M.hs -package-env - -package-db somepackage/pkgdb -package somepackage somepackage/A.o somepackage/B.o
where A.o
and B.o
are the object files of modules needed to run splices in M
. This invocation works even if I don't build the shared library of somepackage
in advance.
The above works with the internal interpreter, but using either -prof
or -fexternal-interpreter
doesn't work because the object files in the command line do not seem to be passed to the external interpreter.
Is the command line the best way to specify which object files from packages to load in the interpreter? If so, how about documenting this in the user guide and fixing it for external interpreters?
I'm attaching a small project that rehearses these factsghc-linking.tar.gz. It can be built by uncompressing it and typing make
in the top-level dir.