This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-08-22
Channels
- # announcements (13)
- # babashka (22)
- # beginners (22)
- # biff (17)
- # calva (6)
- # clerk (20)
- # clj-kondo (25)
- # clj-together (5)
- # clj-yaml (20)
- # cljdoc (16)
- # cljs-dev (1)
- # clojure (42)
- # clojure-brasil (1)
- # clojure-europe (26)
- # clojure-nl (6)
- # clojure-norway (24)
- # clojure-turkiye (3)
- # clojure-uk (5)
- # clojurescript (37)
- # core-async (7)
- # core-logic (2)
- # datalevin (7)
- # datomic (43)
- # events (2)
- # fulcro (7)
- # gratitude (1)
- # hyperfiddle (7)
- # java (7)
- # jobs (3)
- # lsp (4)
- # off-topic (16)
- # pathom (18)
- # polylith (1)
- # portal (27)
- # reitit (4)
- # releases (3)
- # shadow-cljs (47)
- # tools-build (14)
- # tools-deps (16)
- # yamlscript (11)
Is there a preferred FFI library for clojure? I want to swap out the snakeyaml usage in yamlscript/clojure for libfyaml. The result would need to work with graalvm.
For FFI you can use https://github.com/IGJoshua/coffi but I don't think this works with #graalvm and requires JDK19. Worth a shot though, I'm not sure. Graal has their own FFI stuff. You can read more about that here: https://yyhh.org/blog/2021/02/writing-c-code-in-javaclojure-graalvm-specific-programming/ Also @UDRJMEFSN has done some stuff in the FFI area that works for both Clojure and GraalVM. @U7RJTCH6J has too. Might be best to ping them somewhere, perhaps in the #clojure channel.
thanks!
There are lots of good options for using C libraries from clojure. Happy to answer any questions.
My experience is that JNA is the easiest to use at the moment.
I was able to compile a JNA demo with graalvm, https://github.com/phronmophobic/jna-native-image. It's only a demo project, but my impression is that more complicated JNA usage should also work.
There's a lot I really like about coffi, but one of their design decisions is to serialize/deserialize data for every ffi call. This makes sense for some APIs, but doesn't work for other APIs.
Also, as mentioned, coffi's ffi is coupled to specific JVM versions.
dtype-next's ffi is very solid, https://cnuernber.github.io/dtype-next/tech.v3.datatype.ffi.html. It works with multiple ffi implementations (including graalvm). I do seem to remember that there are issues with calling c functions with structs by value. I'm not sure if that's still a problem, but the issue is still open, https://github.com/cnuernber/dtype-next/issues/69. That may or may not be important for libfyaml (many APIs don't need this and there are workarounds).
My humble suggestion is to create a wrapper using https://github.com/phronmophobic/clong + JNA. The documentation for creating wrappers is a bit sparse, but there are several examples. I'd be happy to elaborate on recommendations for writing wrappers if you're interested.
It's likely that serialization for this won't matter, but I'll look into all the options here
I wrote a port of YAMLScript in Clojure using snakeyaml to parse YAML into (clojure object) events. It's really simple: https://github.com/yaml/yamlscript/blob/clojure/clojure/src/yamlscript/parser.clj
I think a better yaml module for clojure could be written using snake for just the parsing like this, and everything else in clojure code.
If anyone is interested in that let me know.
also with FFI we could use libfyaml for parsing which is much more solid than snake.