c2hsc: Convert C API header files to .hsc and .hsc.helper.c files

[ bsd3, development, library, program ] [ Propose Tags ]

Convert C API header files to .hsc and .hsc.helper.c files

[Skip to Readme]




Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


  • No Candidates
Versions [RSS] 0.1.0, 0.2.0, 0.3.0, 0.3.1, 0.3.2, 0.3.3, 0.4.0, 0.5.0, 0.5.1, 0.6.2, 0.6.3, 0.6.4, 0.6.5, 0.7.1
Dependencies base (>=4 && <5), c2hsc, cmdargs (>=0.9), containers (>=0.4), data-default (>=0.5.3), directory (>=1.1), filepath (>=1.3), HStringTemplate (>=0.7.1), language-c (>=0.4), logging (>=1.3.0), mtl (>=2.0), pretty (>=1.1), split (>=0.2), temporary (>=, text (>=, transformers (>=0.2) [details]
License BSD-3-Clause
Author John Wiegley
Maintainer John Wiegley <johnw@newartisans.com>
Category Development
Home page https://github.com/jwiegley/c2hsc
Source repo head: git clone https://github.com/jwiegley/c2hsc
Uploaded by JohnWiegley at 2017-12-09T22:41:18Z
Distributions NixOS:0.7.1
Reverse Dependencies 1 direct, 0 indirect [details]
Executables c2hsc
Downloads 12587 total (26 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-12-09 [all 1 reports]

Readme for c2hsc-0.7.1

[back to package description]

Converts C API header files to .hsc and .hsc.helper.c files

Usage: c2hsc --prefix=<Lib Prefix> <FILE>.h

This will create <FILE>.hsc, and <FILE>.hsc.helper.c if the header file contains inline functions.

For example, in hlibgit2 on the Mac I'm using:

c2hsc --prefix=Bindings.Libgit2 --cppopts=-U__BLOCKS__ \

Known issues:

  • Need to output vararg functions with a comment mentioning they are not translatable to the Haskell FFI

Also, please note that this tool will never be 100% accurate. It cannot translate macros, or anything related to the preprocessor, for example. It often misses necessary #include files, and will get them wrong in any case if preprocessor conditionals are involved.

The goal of c2hsc is to solve the hardest 80% of the problem of creating an FFI library. The remaining 20%, plus validation of the results, is an exercise necessarily left to the user.