1. 13
  1. 2

    This is a nice little guide. And one would hope eventually someone will package this up into a lein plugin that is something like lein binary.

    I watched a tech talk about GraalVM a few months ago that indicated that, though this is probably one of the best options for making Clojure code into native binaries, there are some caveats. This guide doesn’t cover any caveats but I’m sure they still exist. Anyone know a link that details what they are?


    Also, someone I know has built a similar guide for shipping Clojure binaries, but relying instead on ClojureScript and Node. Obviously this is a very different set of tradeoffs. You can see that here:

    https://github.com/rduplain/hello-cljs

    1. 6

      And one would hope eventually someone will package this up into a lein plugin

      I made a Leiningen plugin for this: https://github.com/taylorwood/lein-native-image

      This guide doesn’t cover any caveats but I’m sure they still exist.

      There are many caveats when it comes to AOT compiling Clojure, not least of which is sacrificing a lot of run-time dynamism because native-image compilation is “closed world” — pretty much everything about your program must be known at compile-time, which is somewhat counter to Clojure’s design goals. Clojure 1.10 (or essentially anything that uses the current locking macro) doesn’t compile without a patch. The lein-native-image README has some caveats and examples with workarounds.

      I made a similar utility for deps.edn projects https://github.com/taylorwood/clj.native-image, and a little template for making CLI tools https://github.com/taylorwood/clj.native-cli.

      1. 2

        there is a lein-native-image plugin actually

        1. 2

          Ah, excellent. And this project’s README does include a Caveats section!

      2. 1

        Any details on how big the resulting binary is and what dependencies it has on system libraries?

        1. 1

          The size of the binary will depend on what you include in your project. For example, clj-kondo linter compiles to a 16 meg binary, while pgmig migration tool compiles to about 45 megs. The resulting binary is akin to an uberjar containing all the dependencies for the projecct. My understanding is that in terms of external dependencies it’s same as the regular JVM.