I'm currently hacking my way through trying to make quasiquotes for writing Rust code inline in Haskell. I think I have the code generation work done (including things like marshaling Haskell types to and from generated Rust ones). I now have the problem of figuring out how to do all the compilation and linking from within Template Haskell. The pipeline is as follows:
- The quasiquote gets parsed
- Source code is generated for
- a corresponding Rust function
- Haskell FFI imports
- the Haskell call to the imported function
- The Rust code gets compiled into a static library (like
rustc --crate-type=staticlib qq_function.rs -o qq_function.a) - The Haskell code gets compiled and linked against
qq_function.a(and a handful of other libraries likem,c, etc.)
My issue is getting steps 3 and 4 to happen entirely within TemplateHaskell. Here is as far as I've gotten:
runIOcan write out the Rust source files that I've generatedaddDependentFileinforms GHC that the generated Rust file is a dependencyaddForeignFileregrettably does not work for automatically managing the compilation since Rust is not a supported language (this is the approachinline-ctakes since C is a supported language)runIOcould be used to generate the static Rust library (and delete the Rust source file afterwards) by calling out torustc.
What is still very much not clear to me is
- how I can use Template Haskell to add libraries against which to link and
- how I can use Template Haskell to clean up these generated libraries afterwards?
EDIT
I've filed a GHC feature request related to this.