graalvm

Dallas Surewood 2024-05-08T15:17:47.187289Z

I tried making a minimal project I could compile with graalvm, but I am having issues getting native-image to build. Getting reflection warnings, despite it being a pretty minimal file. I am runnin native-image -jar ./target/standalone.jar --features=clj_easy.graal_build_time.InitClojureClasses Here is my file.

(ns main
  ;; any :require and/or :import clauses
  (:gen-class))

(set! *warn-on-reflection* true)

(defn do-stuff [] (println "Woah"))

(defn -main [& args]
  (do-stuff))
And deps
{:paths ["src"]
 :deps {com.github.clj-easy/graal-build-time {:mvn/version "1.0.5"}}
 :aliases
 {:build {:deps {io.github.clojure/tools.build {:mvn/version "0.10.3"}}
          :ns-default build}}}

phronmophobic 2024-05-08T19:24:56.265479Z

Two things I might try: • your main namespace is single segment (ie. no . in the name) and I seem to remember that graal-build-time use to not work with those. It might have been fixed, but I would try changing the main namespace to something like my.main • It doesn't look like your native-image invocation specifies a main class. It should probably be something like my.main if you update your main namespace.

Dallas Surewood 2024-05-08T23:00:12.652529Z

Your first suggestion worked!

phronmophobic 2024-05-08T23:04:24.374969Z

Its probably worth seeing if there’s an appropriate place in the docs to mention that if it’s not already addressed somewhere.

phronmophobic 2024-05-08T23:50:02.253349Z

@sdata374 do you have an example error message? It would be useful to include in the docs in case someone else runs into the same issue and is searching for a fix.

phronmophobic 2024-05-08T23:53:20.199059Z

Is it something like:

java.io.FileNotFoundException: Could not locate clojure/core__init.class, clojure/core.clj or clojure/core.cljc on classpath

Dallas Surewood 2024-05-09T00:20:41.664869Z

It was a bunch of reflection warnings like these.

Warning: Reflection method java.lang.Class.getMethod invoked at clojure.lang.Reflector.tryFindMethod(Reflector.java:75)

Dallas Surewood 2024-05-09T00:21:28.393799Z

And then making a fallback.

Warning: Aborting stand-alone image build due to reflection use without configuration.
if I tried with --no-fallback, the generated binary didn't run

phronmophobic 2024-05-09T00:22:08.455099Z

Oh, interesting.

phronmophobic 2024-05-09T00:22:19.783509Z

I created a pull request for graal-docs at https://github.com/clj-easy/graal-docs/pull/64

phronmophobic 2024-05-09T00:22:49.612679Z

Not sure if there's any particular places you checked when you hit the error, but those might be good candidates for doc improvements.

Dallas Surewood 2024-05-09T00:25:23.826739Z

I was in the https://github.com/clj-easy/graal-build-time docs, I was unaware of this repo. But that looks like a good place to add a note

phronmophobic 2024-05-09T00:26:03.203619Z

The docs do mention single segment namespaces, https://github.com/clj-easy/graal-build-time?tab=readme-ov-file#single-segment-namespaces

phronmophobic 2024-05-09T00:26:53.804219Z

hmmm, the docs say it reports an error if it finds single segment namespaces, > [clj-easy/graal-build-time] WARN: Single segment namespace found for class: digest__init.class. Because this class has no package, it cannot be registered for initialization at build time.

phronmophobic 2024-05-09T00:27:34.474929Z

Do you know if your setup didn't show the warning for some reason?

Dallas Surewood 2024-05-09T15:01:15.076749Z

It did, I apologize. I didn't realize that would show at the beginning of the process which moves pretty fast on my computer

phronmophobic 2024-05-09T18:32:37.481589Z

No problem. It’s an easy thing to miss. Just checking to see if it wasn’t working and we should create a bug report.