Fork me on GitHub
#graalvm
<
2021-07-16
>
Chandru19:07:28

Hi, I asked a question on #clojure and was pointed in this channel’s direction. So I’m trying to compile a small clj file that makes use of sqlite via `org.xerial/sqlite-jdbc` … All works good as long as I’m in the REPL and running it through clj. I compile the file into a binary through GraalVM native-image utility. It compiles fine but when I run, I get this issue:

Caused by: java.lang.Exception: No native library is found for os.name=Mac and os.arch=x86_64. path=/org/sqlite/native/Mac/x86_64
I’m completely new to Clojure (and have no knowledge of Java/JDBC etc) so wondering if anyone has compiled a clj+sqlite to binary and got it to work .. and if yes, how?

phronmophobic19:07:48

It looks like someone was able to get it to work with java: https://github.com/mageddo/graalvm-examples/tree/59f1f1bf09894681edfddaa100b4504770ad0685/sqlite There's also a babashka sqlite pod, https://github.com/babashka/pod-babashka-go-sqlite3 I've never used the pod stuff before, but it seems like that might be a possible way to use sqlite.

phronmophobic19:07:58

I don't see anything that looks like sqlite listed under https://github.com/BrunoBonacci/graalvm-clojure, so if you do find a working setup, it would be great to have it added to the list.

👍 3
borkdude19:07:46

@chandru89new the clojure-lsp project uses sqlite and compiles it with graalvm native. /cc @ericdallo

👍 3
ericdallo19:07:14

@chandru89new I needed to do some hacks to make it work with clojure-lsp: I created this jar with some JNI fixes: https://github.com/ericdallo/sqlite-jni-graal-fix Check how clojure-lsp uses it here: https://github.com/clojure-lsp/clojure-lsp/blob/master/graalvm/native-unix-compile.sh

Chandru01:07:25

thank you. i will take a look!

Chandru04:07:19

Hi Eric. I’ve been trying to replicate your method to get this clj+sqlite to compile and work. But clearly I’m out of depth and would appreciate any help: • I notice that you use deps.edn and clojure command instead of lein and this was an intentional migration at clojure-lsp. Does this have any effect on the sqlite issue? • I added your sqlite-jni-graal-fix to my project but after looking at a few repos and examples, I’m unable to figure out how/where to add and use the configuration files you have in your other link (https://github.com/clojure-lsp/clojure-lsp/tree/master/resources/META-INF/native-image/clojure-lsp/clojure-lsp) … any pointers for this? • Also, any benefit of going deps.edn over lein and project.clj?

Chandru04:07:57

I know you must be busy so thank you very much for taking time to even answer my initial query! 🙂

ericdallo13:07:50

• Clojure-lsp used to work with lein and Graalvm, but the Uber jar generated from lein started to not work for some weird reason, and at the time I red it was a issue on how Leon generate the jar, that's one of the reasons I changed to deps.edn • To make that lib work, that deps needs to be on your generated jar that you will compile with Graalvm, so my suggestion is to add a profile to lein that would add that deps and then generate the jar with it like: lein +with-profiles=native uberjar • Besides that issue with lein, I prefer deps.edn to be simpler configuration edn, faster repl startup, and probably replace lei n soon IMO

ericdallo13:07:53

Also, make sure you configure your reflect-config.json jni json and etc, IMO the best way to configure that is to add that to the resources folder META-INF like I did to clojure-lsp, following that convention Graalvm should pick that config during compilation

Chandru04:07:34

thank you very much! I'll try this.