graalvm

Discuss GraalVM related topics. Use clojure 1.10.2 or newer for all new projects. Contribute to https://github.com/clj-easy/graal-docs and https://github.com/BrunoBonacci/graalvm-clojure. GraalVM slack: https://www.graalvm.org/slack-invitation/.
benedek 2021-02-24T17:08:07.003700Z

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)

benedek 2021-02-24T17:08:36.004400Z

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

benedek 2021-02-24T17:09:28.005200Z

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

tvaughan 2021-02-24T17:16:07.009200Z

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

benedek 2021-02-24T17:17:54.010300Z

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

benedek 2021-02-24T17:20:32.010700Z

i am lying i am using 1.10.3-rc1

borkdude 2021-02-24T17:37:53.011300Z

@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.

borkdude 2021-02-24T17:38:09.011700Z

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

borkdude 2021-02-24T17:38:44.012500Z

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

tvaughan 2021-02-24T17:47:08.013100Z

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

borkdude 2021-02-24T17:48:36.013600Z

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

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

borkdude 2021-02-24T17:48:48.013900Z

The notes are missing the compiled classes on the classpath

borkdude 2021-02-24T17:50:04.014600Z

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

borkdude 2021-02-24T17:51:00.014800Z

Trying now with mvn client:build

borkdude 2021-02-24T17:53:09.015100Z

Ah I can reproduce the problem locally yes

borkdude 2021-02-24T17:54:34.015500Z

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

borkdude 2021-02-24T17:56:53.015900Z

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

benedek 2021-02-24T18:09:37.016300Z

thanks for looking at it @borkdude

borkdude 2021-02-24T18:10:30.017200Z

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

borkdude 2021-02-24T18:10:54.017700Z

Don't really know anything about JavaFX unfortunately

benedek 2021-02-24T18:11:53.018700Z

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

benedek 2021-02-24T18:12:54.020200Z

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

borkdude 2021-02-24T18:16:05.020700Z

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

borkdude 2021-02-24T18:16:12.020900Z

https://app.slack.com/client/TN37RDLPK

borkdude 2021-02-24T18:16:31.021300Z

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

benedek 2021-02-24T18:29:50.021800Z

yup, good idea, thx

benedek 2021-02-24T19:07:33.022600Z

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