Fork me on GitHub
Joshua Suskalo17:10:41

Announcing, a foreign function interface for Clojure on JDK 17. The library includes features like: • wrapper functions that make native code feel like Clojure code • automatic serialization and deserialization to marshal data between the native world and Clojure • support for callbacks and function pointers • support for low-level wrappers to manage native allocations and avoid marshaling costs • the best performance on primitive types of all FFI libraries currently available in Clojure (struct benchmarks have not been compared to other options yet) • a data model to support importing a library's whole interface as data (with some limitations) As a test for the library, I've wrapped and validated it works as intended. If you start wrapping something and find any errors, please open an issue, or come say hi in #coffi!

👏 35
🎉 17
👍 9
🚀 1

This is really neat, thank you 🙂


Looks really impressive, congrats !


did JDK 17 get a new FFI? I know only about JNI, which requires some generated java files and other stuff.

Joshua Suskalo13:10:46

Yes, JDK 17 has an incubator release of Project Panama.

Joshua Suskalo13:10:35

It's an FFI which requires no native code to be written and can just link against dynamic libraries at runtime. It's pretty cool, but since it's an incubator the API may still change before it's added to java.base. @U66G3SGP5


very interesting


went and tried out using OSX system api (CoreWLAN via objc) with coffi, worked nicely :)


That looks awesome. I'm also happy to see that exported clj-kondo configs are being put to good use.

Joshua Suskalo13:10:09

Hey @U06QSF3BK I looked at your repo on a call with some of my friends trying to get it working last night, but we kept running into issues. We're not sure, but it might be that the macbook we tried it on was using MacOS 12. Are you actually on OS 10? I'm also curious, with dlopen, was there a reason you couldn't use coffi.ffi/load-library? It allows you to specify an absolute file path.

Joshua Suskalo13:10:33

In any case, it's really cool that it worked for you!


I'm on 11.6, I think the library reference stuff got changed in Big Sur


I didn't try JNA on my machine yet, but there is something funny in how System.loadLibrary works in Big Sur, and found from some Python ctypes Stack Overflow post the form where the library name passed to dlopen is <path>/Versions/Current/<libname>


so yeah, probably different for older OSX versions

Joshua Suskalo14:10:51

Ah, okay. Thanks!