@@ -5,7 +5,7 @@ your Clojure projects using GraalVM.
5
5
6
6
7
7
### Step1 - Download and install GraalVM
8
- Go to https://github.com/oracle/graal /releases and download the
8
+ Go to https://github.com/graalvm/graalvm-ce-builds /releases and download the
9
9
binaries for your platform.
10
10
11
11
Unpack the package in a folder and add it to the path:
@@ -14,24 +14,33 @@ Unpack the package in a folder and add it to the path:
14
14
$ export GRAALVM_HOME=/full/path/to/graalvm
15
15
$ export PATH=$GRAALVM_HOME /bin:$PATH
16
16
$ java -version
17
- openjdk version " 1.8.0_212 "
18
- OpenJDK Runtime Environment (build 1.8.0_212-20190420112649.buildslave.jdk8u-src-tar--b03 )
19
- OpenJDK GraalVM CE 19.0 .0 (build 25.212-b03- jvmci-19-b01 , mixed mode)
17
+ openjdk version " 11.0.7 " 2020-04-14
18
+ OpenJDK Runtime Environment GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02 )
19
+ OpenJDK 64-Bit Server VM GraalVM CE 20.1 .0 (build 11.0.7+10- jvmci-20.1-b02 , mixed mode, sharing )
20
20
```
21
21
22
22
Now install the ` native-image ` component:
23
23
24
24
``` bash
25
25
$ gu install native-image
26
26
Downloading: Component catalog from www.graalvm.org
27
- Processing component archive: Native Image
28
- Component Native Image (org.graalvm.native-image) installed.
27
+ Processing Component: Native Image
28
+ Downloading: Component native-image: Native Image from github.com
29
+ Installing new component: Native Image (org.graalvm.native-image, version 20.1.0)
29
30
30
31
$ gu list
31
32
ComponentId Version Component name Origin
32
33
--------------------------------------------------------------------------------
33
- graalvm 19.0.0 GraalVM Core
34
- native-image 19.0.0 Native Image licencegithub.com
34
+ graalvm 20.1.0 GraalVM Core
35
+ native-image 20.1.0 Native Image github.com
36
+ ```
37
+
38
+ ** NOTE** : * if you are on Mac OSX you might need to de-quarantine the binaries.*
39
+ Here a script to do so:
40
+
41
+ ``` bash
42
+ # for Mac OSX
43
+ sudo xattr -r -d com.apple.quarantine ${GRAALVM_HOME}
35
44
```
36
45
37
46
### Step2 - Your project
@@ -55,7 +64,7 @@ Update the `project.clj` and add the `:main`
55
64
:url " http://example.com/FIXME"
56
65
:license {:name " EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
57
66
:url " https://www.eclipse.org/legal/epl-2.0/" }
58
- :dependencies [[org.clojure/clojure " 1.9.0 " ]]
67
+ :dependencies [[org.clojure/clojure " 1.10.1 " ]]
59
68
; ; add the main namespace
60
69
:main hello-world.core
61
70
@@ -89,8 +98,8 @@ Now build a uberjar.
89
98
``` bash
90
99
$ lein do clean, uberjar
91
100
Compiling hello-world.core
92
- Created /private/tmp/5/ hello-world/target/hello-world-0.1.0-SNAPSHOT.jar
93
- Created /private/tmp/5/ hello-world/target/hello-world-0.1.0-SNAPSHOT-standalone.jar
101
+ Created /private/tmp/hello-world/target/hello-world-0.1.0-SNAPSHOT.jar
102
+ Created /private/tmp/hello-world/target/hello-world-0.1.0-SNAPSHOT-standalone.jar
94
103
```
95
104
96
105
Now that you have a ` -standalone.jar ` file which contains all the
@@ -103,26 +112,26 @@ can proceed to build the native binary.
103
112
``` bash
104
113
native-image --report-unsupported-elements-at-runtime \
105
114
--initialize-at-build-time \
115
+ --no-server \
106
116
-jar ./target/hello-world-0.1.0-SNAPSHOT-standalone.jar \
107
117
-H:Name=./target/hello-world
108
118
109
- Build on Server(pid: 76573, port: 63429)*
110
- [./target/hello-world:76573] classlist: 2,931.41 ms
111
- [./target/hello-world:76573] (cap): 2,494.11 ms
112
- [./target/hello-world:76573] setup: 4,030.12 ms
113
- [./target/hello-world:76573] (typeflow): 5,544.43 ms
114
- [./target/hello-world:76573] (objects): 2,177.19 ms
115
- [./target/hello-world:76573] (features): 225.10 ms
116
- [./target/hello-world:76573] analysis: 8,098.25 ms
117
- [./target/hello-world:76573] (clinit): 136.48 ms
118
- [./target/hello-world:76573] universe: 399.00 ms
119
- [./target/hello-world:76573] (parse): 1,106.76 ms
120
- [./target/hello-world:76573] (inline): 1,968.59 ms
121
- [./target/hello-world:76573] (compile): 9,156.00 ms
122
- [./target/hello-world:76573] compile: 12,728.30 ms
123
- [./target/hello-world:76573] image: 975.56 ms
124
- [./target/hello-world:76573] write: 252.32 ms
125
- [./target/hello-world:76573] [total]: 29,587.34 ms
119
+ [./target/hello-world:33840] classlist: 3,119.60 ms, 0.96 GB
120
+ [./target/hello-world:33840] (cap): 2,250.97 ms, 0.96 GB
121
+ [./target/hello-world:33840] setup: 3,980.23 ms, 0.96 GB
122
+ [./target/hello-world:33840] (clinit): 163.43 ms, 1.72 GB
123
+ [./target/hello-world:33840] (typeflow): 6,249.38 ms, 1.72 GB
124
+ [./target/hello-world:33840] (objects): 4,975.02 ms, 1.72 GB
125
+ [./target/hello-world:33840] (features): 202.49 ms, 1.72 GB
126
+ [./target/hello-world:33840] analysis: 11,819.61 ms, 1.72 GB
127
+ [./target/hello-world:33840] universe: 341.69 ms, 1.72 GB
128
+ [./target/hello-world:33840] (parse): 1,850.44 ms, 1.72 GB
129
+ [./target/hello-world:33840] (inline): 2,497.03 ms, 1.72 GB
130
+ [./target/hello-world:33840] (compile): 12,415.94 ms, 2.35 GB
131
+ [./target/hello-world:33840] compile: 17,341.60 ms, 2.35 GB
132
+ [./target/hello-world:33840] image: 1,197.96 ms, 2.35 GB
133
+ [./target/hello-world:33840] write: 643.75 ms, 2.35 GB
134
+ [./target/hello-world:33840] [total]: 38,716.97 ms, 2.35 GB
126
135
```
127
136
128
137
That's it! now you can test your native binary!
@@ -170,7 +179,7 @@ Now you can add an alias for it the `project.clj itself:
170
179
{" native"
171
180
[" shell"
172
181
" native-image" " --report-unsupported-elements-at-runtime"
173
- " --initialize-at-build-time"
182
+ " --initialize-at-build-time" " --no-server "
174
183
" -jar" " ./target/${:uberjar-name:-${:name}-${:version}-standalone.jar}"
175
184
" -H:Name=./target/${:name}" ]}
176
185
```
@@ -192,7 +201,7 @@ Overall your `project.clj` should look like as follow:
192
201
{" native"
193
202
[" shell"
194
203
" native-image" " --report-unsupported-elements-at-runtime"
195
- " --initialize-at-build-time"
204
+ " --initialize-at-build-time" " --no-server "
196
205
" -jar" " ./target/${:uberjar-name:-${:name}-${:version}-standalone.jar}"
197
206
" -H:Name=./target/${:name}" ]}
198
207
)
@@ -202,24 +211,26 @@ With this in place you can just run `lein native` to build the native binary:
202
211
203
212
``` bash
204
213
$ lein native
205
- Build on Server(pid: 76573, port: 63429)
206
- [./target/hello-world:76573 ] classlist: 925.69 ms
207
- [./target/hello-world:76573 ] (cap): 1,052.47 ms
208
- [./target/hello-world:76573 ] setup: 1,416.62 ms
209
- [./target/hello-world:76573 ] (typeflow ): 3,499.51 ms
210
- [./target/hello-world:76573 ] (objects ): 1,224.39 ms
211
- [./target/hello-world:76573 ] (features ): 129.42 ms
212
- [./target/hello-world:76573 ] analysis: 4,946.87 ms
213
- [./target/hello-world:76573 ] (clinit) : 95.94 ms
214
- [./target/hello-world:76573 ] universe: 298.63 ms
215
- [./target/hello-world:76573 ] (parse): 622.46 ms
216
- [./target/hello-world:76573 ] (inline): 1,119.10 ms
217
- [./target/hello-world:76573 ] (compile): 4,646.36 ms
218
- [./target/hello-world:76573 ] compile: 6,730.73 ms
219
- [./target/hello-world:76573 ] image: 672.79 ms
220
- [./target/hello-world:76573 ] write: 199.98 ms
221
- [./target/hello-world:76573 ] [total]: 15,268 .99 ms
214
+ OpenJDK 64-Bit Server VM warning: forcing TieredStopAtLevel to full optimization because JVMCI is enabled
215
+ [./target/hello-world:33980 ] classlist: 2,970.75 ms, 0.96 GB
216
+ [./target/hello-world:33980 ] (cap): 2,824.32 ms, 0.96 GB
217
+ [./target/hello-world:33980 ] setup: 4,532.29 ms, 0.96 GB
218
+ [./target/hello-world:33980 ] (clinit ): 180.49 ms, 1.72 GB
219
+ [./target/hello-world:33980 ] (typeflow ): 6,960.70 ms, 1.72 GB
220
+ [./target/hello-world:33980 ] (objects ): 4,050.59 ms, 1.72 GB
221
+ [./target/hello-world:33980 ] (features): 267.73 ms, 1.72 GB
222
+ [./target/hello-world:33980 ] analysis : 11,822.33 ms, 1.72 GB
223
+ [./target/hello-world:33980 ] universe: 322.57 ms, 1.72 GB
224
+ [./target/hello-world:33980 ] (parse): 1,758.44 ms, 1.72 GB
225
+ [./target/hello-world:33980 ] (inline): 2,497.64 ms, 1.72 GB
226
+ [./target/hello-world:33980 ] (compile): 12,186.63 ms, 2.35 GB
227
+ [./target/hello-world:33980 ] compile: 17,039.18 ms, 2.35 GB
228
+ [./target/hello-world:33980 ] image: 1,252.06 ms, 2.35 GB
229
+ [./target/hello-world:33980 ] write: 430.08 ms, 2.35 GB
230
+ [./target/hello-world:33980 ] [total]: 38,668 .99 ms, 2.35 GB
222
231
223
232
$ ./target/hello-world
224
233
Hello, World!
225
234
```
235
+
236
+ Happy hacking!
0 commit comments