Fork me on GitHub
#announcements
<
2021-10-16
>
Joshua Suskalo17:10:41

Announcing https://github.com/IGJoshua/coffi, 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) https://github.com/IGJoshua/coffi As a test for the library, I've wrapped https://github.com/IGJoshua/glfw-clj 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
3
2
🚀 1
viesti19:10:18

This is really neat, thank you 🙂

borkdude20:10:48

Looks really impressive, congrats !

roklenarcic07:10:43

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. https://openjdk.java.net/projects/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

roklenarcic13:10:51

very interesting

viesti19:10:18

went and tried out using OSX system api (CoreWLAN via objc) with coffi, worked nicely :) https://github.com/viesti/osx-coffi

borkdude19:10:18

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!

viesti14:10:26

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

viesti14:10:11

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>

viesti14:10:24

so yeah, probably different for older OSX versions

Joshua Suskalo14:10:51

Ah, okay. Thanks!