File tree Expand file tree Collapse file tree 5 files changed +50
-3
lines changed Expand file tree Collapse file tree 5 files changed +50
-3
lines changed Original file line number Diff line number Diff line change 1
1
.cpcache
2
2
classes
3
- clojurl
3
+ / clojurl
Original file line number Diff line number Diff line change @@ -154,3 +154,16 @@ should satisfy
154
154
-------------------------
155
155
Detected 1 error
156
156
```
157
+
158
+ ## Compiling with Clojure 1.10
159
+
160
+ GraalVM native-image won't work with Clojure's ` locking ` macro, and Clojure 1.10 depends on a version of clojure.spec
161
+ (see [ this commit] ( https://github.com/clojure/spec.alpha/commit/31165fec69ff86129a1ada8b3f50864922dfc88a ) ) that uses ` locking ` .
162
+ You can workaround this by compiling a Java class with a special locking mechanism, and patching any usages of ` locking ` e.g. in clojure.spec.
163
+
164
+ You must first compile the Java class:
165
+ ```
166
+ ➜ javac java/src/clojurl/LockFix.java -cp ~/.m2/repository/org/clojure/clojure/1.10.0/clojure-1.10.0.jar
167
+ ```
168
+
169
+ Then patch any usages of ` locking ` and you should be able to compile a native image. See ` clojurl.clj ` for example.
Original file line number Diff line number Diff line change 1
1
{:deps {expound {:mvn/version " 0.7.1" }
2
- org.clojure/clojure {:mvn/version " 1.9 .0" }
2
+ org.clojure/clojure {:mvn/version " 1.10 .0" }
3
3
org.clojure/tools.cli {:mvn/version " 0.4.1" }
4
4
org.martinklepsch/clj-http-lite {:mvn/version " 0.4.1" }
5
5
hickory {:mvn/version " 0.7.1" }}
6
+ :paths [" src" " java/src" ]
6
7
:aliases {:native-image
7
8
{:main-opts [" -m clj.native-image clojurl"
8
9
" --report-unsupported-elements-at-runtime"
Original file line number Diff line number Diff line change
1
+ package clojurl ;
2
+
3
+ import clojure .lang .IFn ;
4
+
5
+ public class LockFix {
6
+ static public Object lock (final Object lockee , final IFn f ) {
7
+ synchronized (lockee ) {
8
+ return f .invoke ();
9
+ }
10
+ }
11
+ }
Original file line number Diff line number Diff line change 6
6
[clojure.pprint :refer [pprint]]
7
7
[expound.alpha :as expound]
8
8
[hickory.core :as hick])
9
- (:gen-class ))
9
+ (:gen-class )
10
+ (:import (clojurl LockFix)))
10
11
11
12
(set! *warn-on-reflection* true )
12
13
14
+ (defmacro locking* ; ; patched version of clojure.core/locking to workaround GraalVM unbalanced monitor issue
15
+ " Executes exprs in an implicit do, while holding the monitor of x.
16
+ Will release the monitor of x in all circumstances."
17
+ {:added " 1.0" }
18
+ [x & body]
19
+ `(let [lockee# ~x]
20
+ (LockFix/lock lockee# (^{:once true } fn* [] ~@body))))
21
+
22
+ (defn dynaload ; ; patched version of clojure.spec.gen.alpha/dynaload to use patched locking macro
23
+ [s]
24
+ (let [ns (namespace s)]
25
+ (assert ns )
26
+ (locking* #'clojure.spec.gen.alpha/dynalock
27
+ (require (symbol ns )))
28
+ (let [v (resolve s)]
29
+ (if v
30
+ @v
31
+ (throw (RuntimeException. (str " Var " s " is not on the classpath" )))))))
32
+
33
+ (alter-var-root #'clojure.spec.gen.alpha/dynaload (constantly dynaload))
34
+
13
35
(def cli-options
14
36
[[" -u" " --uri URI" " URI of request"
15
37
:id :url
You can’t perform that action at this time.
0 commit comments