graalvm

hanDerPeder 2022-09-01T08:50:40.508289Z

Is it possible to specify additional namespaces that should be included in a native-image? I have namespace that might be dynamically required. Can work around this by adding a require in gen-class ns, but I’m hoping there is a better way.

borkdude 2022-09-01T09:06:05.558899Z

@peder.refsnes yes, you should require them at compile time

borkdude 2022-09-01T09:06:22.596439Z

dynamic requires also tend to bloat the image. see: https://github.com/borkdude/dynaload

hanDerPeder 2022-09-01T09:16:41.396439Z

just want to verify I understand; top-level requires are done at compile-time, while requiring-resolve , etc, are done at run-time, right?

borkdude 2022-09-01T09:18:09.700179Z

top level requiring-resolve are also done at compile time :) - non-top level require is done at runtime. so top level is the key thing

hanDerPeder 2022-09-01T09:19:20.840819Z

Right, now I have:

(ns foo.bar
  ;; Don't remove, needed for native-image
  (:require [foo.stuff]))
was hoping there was a flag I could pass that would do the same, ie:
native-image -jar ... --include-extra-stuff=foo.stuff

borkdude 2022-09-01T09:20:48.096449Z

you can just make another main namespace which requires the stuff and calls your old main namespace. but I highly recommend removing the dynamic requires, see the link I posted earlier

hanDerPeder 2022-09-01T09:26:13.603039Z

if I understand the dynaload docs correctly it’s comparable to tree-shaking in js. is that correct?

borkdude 2022-09-01T09:27:02.864699Z

yes

hanDerPeder 2022-09-01T09:28:52.922959Z

okay, not sure that’s applicable in my case. concretely I need to include a custom publisher in mulog, so I don’t controll the code that does the dynamic require. https://github.com/BrunoBonacci/mulog/blob/master/mulog-core/src/com/brunobonacci/mulog/publisher.clj#L213

2022-09-01T09:37:09.719699Z

Hi @peder.refsnes, you can pass a publisher also using the :inline type https://cljdoc.org/d/com.brunobonacci/mulog/0.9.0/doc/special-publishers/inline-publishers In that case, you have the burden of the initialisation of your custom publisher. I found this to be an easier approach on GraalVM compiled apps

👍 1
hanDerPeder 2022-09-01T09:38:09.532219Z

cool, thanks 🙏