I’m happy to announce I’ve released a library exporting Cabal SetupHooks which automatically produce an .xcframework (an Apple Binary Framework Bundle) from a Haskell library’s binary artifacts and foreign export headers at the end of cabal build.
The library is called xcframework and can be found on Hackage. Here’s the blog post introducing it:
This is very cool, I’ve had problems with integrating with macOS frameworks in the past because of Apple’s use of blocks (lambdas) not being supported by Haskell’s C tooling. I’d wanted to play with the endpoint security framework, but hit issues basically straight away. Have you run into any similar issues? Looking at your post, it feels like I was coming at the problem from the wrong direction, hoping to wrap the macOS headers using the C-FFI, but perhaps I should have been thinking about exposing Haskell functions.
I haven’t tried to go the other direction in calling Swift from Haskell, but I know of inline-c-objc by @chak which allows you to inline objc code into Haskell – it does require that the framework has objc bindings and I can imagine there are other problems beyond it. Anyway I thought it would be worth mentioning.
Interesting, it’s a shame there’s no docs. The library I was looking to wrap was the endpoint security framework (Endpoint Security | Apple Developer Documentation) which caused problems with header files that were imported using Apple’s blocks extension to C, so none of the Haskell tooling could understand it, and I couldn’t wrap the structs. There’s probably a way to avoid using tools like c2hs or whatever I was trying, but it felt like a hell of a lot of busywork to just get to the point of being able to read and write structs.
Some of the core types in the library require using blocks too:
Anyway, sorry for getting off topic, I feel like maybe I could build something in C that wraps Haskell and use your framework instead of trying to do things the other way around. Maybe I’ll see how far I can get with doing that sometime.