Fork me on GitHub
#graalvm
<
2020-05-13
>
markbastian19:05:21

I'm trying to native compile the following:

(ns graal.me.maybe.core
  (:gen-class)
  (:require [clj-http.client :as client]))

(defn -main [& args]
  (time
    (:body (client/request
             {:method :get
              :url    ""}))))
And here's my build script:
clj -A:uberjar

/Library/Java/JavaVirtualMachines/graalvm-ce-java11-19.3.2/Contents/Home/bin/native-image \
 -H:+ReportUnsupportedElementsAtRuntime \
 -H:ReflectionConfigurationFiles=reflectConfig.json \
 -H:+ReportExceptionStackTraces \
 -H:+TraceClassInitialization \
 -jar ./target/foo-1.0.0-SNAPSHOT-standalone.jar \
 foo
I've tried two paths with the following issues: 1. The above. When I run the output I get .FileNotFoundException: Could not locate clojure/core__init.class, clojure/core.clj or clojure/core.cljc on classpath.. 2. I've added the --initialize-at-build-time flag. When I do this I get a bunch of build errors along the lines of "Error: No instances of http://javax.net.ssl.SSLContext". However, the image does build. Any tips on a happy path here?

borkdude19:05:55

@markbastian clj-http is known not to work with GraalVM. clj-http-lite is

markbastian19:05:38

Cool, I'll try that. Do you recommend ce version 20 or 19?

borkdude19:05:33

I'm using 19.3.1 myself because it's LTS, more stable

👍 4
borkdude19:05:34

@markbastian also take a look at https://github.com/taylorwood/clojurl which essentially wraps clj-http-lite in a graal binary

borkdude19:05:03

@markbastian there's also this even lighter curl wrapper: https://github.com/borkdude/babashka.curl

markbastian19:05:54

Cool, thanks! I'll check those out.