Fork me on GitHub
#graalvm
<
2019-08-16
>
johnjelinek19:08:06

What version of Clojure is supported?

Alex Miller (Clojure team)19:08:13

we don't consider Graal to be a supported target of Clojure, so the proper answer is "none"

schmee21:08:36

when you say Graal is not supported, do you mean native image specifically or GraalVM the JVM as well?

Alex Miller (Clojure team)21:08:51

We do no testing with either

Alex Miller (Clojure team)19:08:11

the are probably more nuanced answers as to what people have gotten to work using whatever workaround

borkdude19:08:43

I've been using 1.10.1 with great success, just avoiding spec and pprint for the weird locking issue, however that works on 1.9.0

borkdude19:08:23

if that gets ever fixed for Android, hopefully graal people won't run into it anymore either

borkdude20:08:52

for "basic" things it works great, just don't expect to be using eval etc. from that perspective I understand the decision not to see it as an official target

johnjelinek20:08:38

Weird, cuz I'm getting errors (posted in #beginners) using 1.10.1 for a simple hello world app

borkdude20:08:50

some tips: - make sure you set warn-on-reflection in every namespace - use lein to compile an uberjar with AOT all - feed that jar to graalvm

johnjelinek20:08:28

Any tips when using tools.deps instead of lein?

borkdude20:08:48

I find lein more helpful in AOT-ing

borkdude20:08:01

but you can do that with compile manually as well

johnjelinek20:08:05

I was using juxt/pack do to AOT

borkdude20:08:14

I can't help you there

johnjelinek20:08:19

Ok, I can compile manually as well

borkdude20:08:50

feel free to share your repo

borkdude20:08:02

and error message if applicable

johnjelinek20:08:11

Just (compile ... right? I dumps to my classes dir

borkdude20:08:42

yeah I think so. the thing I find easier about lein uberjar + AOT is that it's all in one place and I don't have to set any paths for graal

borkdude20:08:10

but the cotd example shared earlier does it manually with compile

borkdude20:08:13

so you can look there

johnjelinek20:08:20

core.clj:

(ns clj-graalvm.core
  (:gen-class))

(defn -main []
  (println "šŸ‘‹" (clojure-version)))

johnjelinek20:08:55

deps.edn:

{:deps {org.clojure/clojure {:mvn/version "1.10.1"}}
 :aliases {:aot {:extra-paths ["classes"]
                 :main-opts ["-e" "(compile,'clj-graalvm.core)"]}}}

borkdude20:08:59

so what does not work?

johnjelinek20:08:29

$ clojure -m clj-graalvm.core
šŸ‘‹ 1.10.1
native-image -cp $(clj -Spath) -cp classes/ -H:+ReportExceptionStackTraces -H:+PrintClassInitialization -H:Name=clj-graalvm --initialize-at-build-time --report-unsupported-elements-at-runtime --no-server --no-fallback clj-graalvm.core 
[clj-graalvm:47247]    classlist:   2,985.89 ms
Error: Main entry point class 'clj-graalvm.core' not found.
com.oracle.svm.core.util.UserError$UserException: Main entry point class 'clj-graalvm.core' not found.
        at com.oracle.svm.core.util.UserError.abort(UserError.java:65)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:258)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:446)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:112)
Error: Image build request failed with exit status 1

borkdude20:08:41

maybe try -cp $(clj -C aot -Spath)

borkdude20:08:59

or clojure rather, since clj requires rlwrap in CI

borkdude20:08:09

maybe use an underscore?

borkdude20:08:16

this is why I use lein ... šŸ˜‰

borkdude20:08:45

so clj_graalvm.core

johnjelinek20:08:33

this works when I did aot from clojure 1.9.0

native-image -cp $(clojure -Spath) -H:+ReportExceptionStackTraces -H:+PrintClassInitialization -H:Name=clj-graalvm --initialize-at-build-time --report-unsupported-elements-at-runtime --no-server --no-fallback --verbose clj_graalvm.core

borkdude20:08:34

if you put this project on github or similar so I can clone and run it, I'm willing to help you fix it. I'm too lazy to copy paste file and create dirs šŸ™‚

johnjelinek20:08:03

{:deps {org.clojure/clojure {:mvn/version "1.10.1"}}
 :aliases {:aot {:extra-paths ["classes"]
                 :main-opts ["-e" "(compile,'clj-graalvm.core)"]}}
 :paths ["src", "classes"]}

johnjelinek20:08:11

added classes to :paths

johnjelinek20:08:29

./clj-graalvm
šŸ‘‹ 1.10.1

johnjelinek20:08:14

so, can I target different architectures with native-image?

borkdude20:08:13

it doesn't do cross compiling. if you're on Mac you can compile for linux using Docker

šŸ‘ 4
borkdude20:08:22

but I use CircleCI for both platforms

johnjelinek20:08:51

sweet, built via docker āœ…

johnjelinek20:08:12

@borkdude: thanks for your help

sogaiu21:08:23

@johnjelinek fwiw, the windows support for native-image doesn't appear to be as good as that for the *nixes -- e.g. https://github.com/sogaiu/constdin

johnjelinek21:08:07

oic, thanks for sharing