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 "<http://www.google.com>"}))))
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 <http://java.io|java.io>.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?@markbastian clj-http is known not to work with GraalVM. clj-http-lite is
Cool, I'll try that. Do you recommend ce version 20 or 19?
@markbastian for SSL you must add some flags: https://github.com/borkdude/babashka/blob/master/script/compile#L44-L45
I'm using 19.3.1 myself because it's LTS, more stable
@markbastian also take a look at https://github.com/taylorwood/clojurl which essentially wraps clj-http-lite in a graal binary
@markbastian there's also this even lighter curl wrapper: https://github.com/borkdude/babashka.curl
Cool, thanks! I'll check those out.