[GHC] #14298: Let Template Haskell dynamically add something with which to link (was: Let Template Haskell dynamically add a library against which to link)

GHC ghc-devs at haskell.org
Mon Oct 2 18:58:43 UTC 2017


#14298: Let Template Haskell dynamically add something with which to link
-------------------------------------+-------------------------------------
        Reporter:  harpocrates       |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Template Haskell  |              Version:  8.2.1
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Description changed by harpocrates:

Old description:

> As of today, Template Haskell supports emitting foreign files (for C
> compiler languages) via `addForeignFile`. In doing so, GHC takes on the
> work of compiling these, linking against them, and then cleaning up any
> other files.
>
> This makes packages like `inline-c`
> ([https://hackage.haskell.org/package/inline-c]) possible, where you can
> write C snippets in quasiquotes and these can interact with your Haskell
> code. The user doesn't need to pass extra options to GHC (except to
> enable the right language extensions), and they don't have to see any of
> the intermediate generated artifacts.
>
> Unfortunately, that breaks down for non C compiler languages. It would be
> nice for TH to also support directly adding a static library, since then
> one could
>
>   * use TH's `runIO` to generate static libraries by calling out to
> whatever other compilers
>   * add the contents of those libraries via TH
>   * delete the temporary files created in the process (again using
> `runIO`)
>   * have GHC statically link against the content (from the second bullet
> point)
>
> I'm not sure what the API for this could be, but maybe adding a
> `StaticLibrary` constructor to the `ForeignSrcLang` data type (so one
> could use `addForeignFile :: ForeignSrcLang -> String -> Q ()`)?

New description:

 As of today, Template Haskell supports emitting foreign files (for C
 compiler languages) via `addForeignFile`. In doing so, GHC takes on the
 work of compiling these, linking them, and then cleaning up any other
 files.

 This makes packages like `inline-c`
 ([https://hackage.haskell.org/package/inline-c]) possible, where you can
 write C snippets in quasiquotes and these can interact with your Haskell
 code. The user doesn't need to pass extra options to GHC (except to enable
 the right language extensions), and they don't have to see any of the
 intermediate generated artifacts.

 Unfortunately, that breaks down for non C compiler languages. It would be
 nice for TH to also support directly adding something to pass to the
 linker, since then one could

   * use TH's `runIO` to generate libraries or object files by calling out
 to whatever other compilers
   * add those via TH
   * have GHC statically link against the content (from the second bullet
 point)

 I'm not sure what the API for this could be, but maybe

   1. add a `LangLinkable` constructor to the `ForeignSrcLang` data type
   2. add a `qAddForeignFilePath ::  ForeignSrcLang -> FilePath -> m ()`
 method to `Quasi m`

--

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14298#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list