haskell / c2hs

c2hs is a pre-processor for Haskell FFI bindings to C libraries
http://hackage.haskell.org/package/c2hs
Other
198 stars 50 forks source link

c2hs confused by clang headers on the Windows platform #291

Open Kleidukos opened 11 months ago

Kleidukos commented 11 months ago

Symptoms described at https://github.com/vmchale/libarchive/pull/34

This is presumably because starting from 9.4 GHC uses clang instead of gcc on Windows, thus different headers, which c2hs is incapable to deal with.

wz1000 commented 11 months ago

Here is the bit of the header it chokes on:

static __inline__ unsigned long long __DEFAULT_FN_ATTRS_CAST
_castf64_u64(double __A) {
  return __builtin_bit_cast(unsigned long long, __A);
}
Error: p/ghc/9.4.7/mingw/lib/clang/14.0.6/include/ia32intrin.h:222: (column 29) [ERROR]  >>> Syntax error !
  The symbol `unsigned' does not fit here.
wz1000 commented 11 months ago

It seems like __builtin_bit_cast is a C++ construct, so it is not surprising that c2hs chokes on it.

Bodigrim commented 10 months ago

Maybe, but basically it seems c2hs is dysfunctional on Windows since GHC 9.4, whatever you do. It would be nice to fix it, even if in ad-hoc way.

deech commented 10 months ago

I don't have access to Windows machine at the moment but can you try invoking c2hs like this:

c2hs -C -D"__builtin_bit_cast(A,B)=((A)B)" <file.chs>

The double quotes escape their contents on zsh, for sh you probably need single quotes:

c2hs -C -D'__builtin_bit_cast(A,B)=((A)B)' <file.chs>

This will just parse __builtin_bit_cast(unsigned long long, __A) as ((unsigned long long) __A).

bgamari commented 10 months ago

I have addressed this in https://github.com/visq/language-c/pull/96