Fork me on GitHub
#graalvm
<
2021-02-24
>
benedek17:02:07

hi, still playing with building a native image for javafx app written in clojure. idea is just to rewrite gluon’s HelloFX in clojure and get it built into a native image. getting somwhere: https://github.com/benedekfazekas/clj-hellofx latest build for macos: https://github.com/benedekfazekas/clj-hellofx/actions/runs/596709570 unfortunately it fails with this when I try to run it:

fazekasbenedek@scatha:~/projects/tmp$ ./clj-hellofx
Hello, JAVA main, argc = 1, argv = 0x7ffee201a7f8
2021-02-24 16:54:49.741 clj-hellofx[34827:29435253] Starting Gluon VM...
Exception in thread "main" java.lang.ExceptionInInitializerError
	at com.oracle.svm.core.classinitialization.ClassInitializationInfo.initialize(ClassInitializationInfo.java:315)
Caused by: java.io.FileNotFoundException: Could not locate clojure/core/server__init.class, clojure/core/server.clj or clojure/core/server.cljc on classpath.
	at clojure.lang.RT.load(RT.java:462)
	at clojure.lang.RT.load(RT.java:424)
	at clojure.core$load$fn__6856.invoke(core.clj:6115)
	at clojure.core$load.invokeStatic(core.clj:6114)
	at clojure.core$load.doInvoke(core.clj:6098)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.core$load_one.invokeStatic(core.clj:5897)
	at clojure.core$load_one.invoke(core.clj:5892)
	at clojure.core$load_lib$fn__6796.invoke(core.clj:5937)
	at clojure.core$load_lib.invokeStatic(core.clj:5936)
	at clojure.core$load_lib.doInvoke(core.clj:5917)
	at clojure.lang.RestFn.applyTo(RestFn.java:142)
	at clojure.core$apply.invokeStatic(core.clj:669)
	at clojure.core$load_libs.invokeStatic(core.clj:5974)
	at clojure.core$load_libs.doInvoke(core.clj:5958)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:669)
	at clojure.core$require.invokeStatic(core.clj:5996)
	at clojure.core$require.doInvoke(core.clj:5996)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.lang.Var.invoke(Var.java:384)
	at clojure.lang.RT.doInit(RT.java:491)
	at clojure.lang.RT.init(RT.java:467)
	at clojure.lang.Util.loadWithClass(Util.java:248)
	at thomasa.Main.<clinit>(Unknown Source)
	at com.oracle.svm.core.classinitialization.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:375)

benedek17:02:36

@tvaughan reported a similar problem back in 2020 aug 20th here

benedek17:02:28

(not with javafx tho) wonder if anybody seen similar and maybe has a pointer what to poke to fix it…

tvaughan17:02:07

I tried many different approaches, and this didn't work until newer versions of depstar and graalvm were released. I currently use 2.0.171 and 21.0. Complete setup: https://gitlab.com/tvaughan/kibit-runner/ Oh, and Clojure 1.10.2 too. For some reason I have to explicitly include Clojure 1.10.2 in deps.edn even though this is the only version I have installed

benedek17:02:54

thanks i thought i was using those versions of clojure and graalvm (not using depstar), will dig around in kibit-runner, thanks for the link

benedek17:02:32

i am lying i am using 1.10.3-rc1

borkdude17:02:53

@benedek This problem manifests itself when a project has dynamic requires that aren't executed during compilation. The namespace is then not available anymore after compilation. GraalVM works a bit like the Google Closure compiler, cutting away code it didn't come across during analysis.

borkdude17:02:09

You can probably work around this by requiring clojure.core.server during compilation already

borkdude17:02:44

For whatever reason this is necessary. I think it would even be better to get to the root of what is needing clojure.core.server since this namespace seems a bit unnecessary for a JavaFX project perhaps

tvaughan17:02:08

> You can probably work around this by requiring clojure.core.server during compilation This did not work for me, fyi

borkdude17:02:36

I am trying now locally. I can successfully run the app with:

java -cp target/classes:$(clojure -Spath) thomasa.Main

borkdude17:02:48

The notes are missing the compiled classes on the classpath

borkdude17:02:04

But I can't find any details as how the native-image compilation is supposed to be kicked off with this gluon stuff

borkdude17:02:00

Trying now with mvn client:build

borkdude17:02:09

Ah I can reproduce the problem locally yes

borkdude17:02:34

It might be related to --initialize-at-build-time, this is generally what you need for Clojure projects

borkdude17:02:53

I see the pom.xml already has this for clojure, so it should work, hmm

benedek18:02:37

thanks for looking at it @borkdude

borkdude18:02:30

Yeah, so normally you do --initialize-at-build-time and then making exceptions with --initialize-at-runtime=... for Clojure projects

borkdude18:02:54

Don't really know anything about JavaFX unfortunately

benedek18:02:53

yeah that would be the main aim of this experiment to figure it out :)

benedek18:02:54

but this error feels like related to the config you quoted above not really javafx... but guessing only...

borkdude18:02:05

Maybe you can bug the folks at Gluon about this a bit. I know Johan Vos is on the GraalVM slack as well, you can maybe poke him in the native-image channel

borkdude18:02:31

It would help converting your notes.txt into a shell script which you can actually execute

benedek18:02:50

yup, good idea, thx

benedek19:02:33

the notes file maybe a bit misleading even, the github workflow file is the real definition of the build: https://github.com/benedekfazekas/clj-hellofx/blob/gluon-github-ci/.github/workflows/macos.yml