Thursday, February 23, 2012

More on Haskell Cabal and Protocol Buffers

Solution for compiling protobuf files via preprocessor cabal hook (described in previous post) works while proto file belongs to the same project and is not changed too often. Now situation is different: I have many proto files and want to use them in more than one Haskell project. So I decided to build a library.
The main problem is that names of files and modules generated by hprotoc depend only on the contents of proto files. So if some other developer adds new message type, renames it, or add a new proto file, she'll have to modify the list of modules exposed by the library. Now there are already 45 of them.
So I've written custom Setup.hs that uses confHook to modify cabal behavior during configuration phase. It generates Haskell sources using hprotoc, parses its output to get module names and adds that modules to the list of modules exported by the library.

Suggestions are welcome!

Source code: github.com/ratatosk/proto-cabalize