Skip to content

Commit ae771d1

Browse files
committed
Graal native-image no longer fails with graal-build-time
Because the Graal team has deprecated use of global --initalize-at-build-time for native-image, we want to switch to using clj-easy/graal-build-time. After attempting this switch, our Windows native-image builds started to consistently to fail. The resolution turned out to be simple and has allowed us to re-apply clj-easy/graal-build-time. Details: The native-image -H:Name option is used to specify a target executable. It seems that on Windows, some components of native-image recognize that -H:Name can include a path and others do not. And/or some components understand a forward slash path separator in -H:Name and others do not. We do not need to work out the nuances of what paths and syntax work for -H:Name because we now instead specify our target path via -H:Path. We can assume that switching away from a global --initialize-at-build-time evokes different components in GraalVM native-image. It might be interesting to explore why someday, but that is out of scope for this issue. Closes #165
1 parent a5be07e commit ae771d1

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

deps.edn

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,17 @@
9595
;; Running tests under Graal
9696
;;
9797
;; We have two main Graal scenarios:
98-
;; sci-test - interpret tests via sci over natively compiled rewrite-clj
99-
;; native-test - natively compile src and tests and run
98+
;; graal:sci-test - interpret tests via sci over natively compiled rewrite-clj
99+
;; graal:native-test - natively compile src and tests and run
100100

101-
:sci-test {:override-deps {org.clojure/clojure {:mvn/version "1.10.3"}}
102-
:extra-paths ["target/generated/sci-test/src"]
101+
:graal {:override-deps {org.clojure/clojure {:mvn/version "1.10.3"}}
102+
:extra-deps {com.github.clj-easy/graal-build-time {:mvn/version "0.1.4"}}}
103+
104+
:sci-test {:extra-paths ["target/generated/sci-test/src"]
103105
:extra-deps {lread/sci-test {:git/url "https://github.com/lread/sci-test.git"
104106
:sha "2af0994d7b4554be08c38f166400fc79f1c28b3e"}}}
105107

106-
:native-test {:override-deps {org.clojure/clojure {:mvn/version "1.10.3"}}
107-
:extra-paths ["target/generated/graal"]}
108+
:native-test {:extra-paths ["target/generated/graal"]}
108109

109110
;; usage -M:sci-test:gen-reflection
110111
:gen-reflection {:main-opts ["-m" "sci-test.generate-reflection-file"]}

script/helper/graal.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,18 @@
7373
classpath))
7474

7575
(defn run-native-image [{:keys [:graal-native-image :graal-reflection-fname
76-
:target-exe :classpath :native-image-xmx
76+
:target-path :target-exe :classpath :native-image-xmx
7777
:entry-class]}]
7878
(status/line :head "Graal native-image compile AOT")
7979
(fs/delete-file-recursively target-exe true)
8080
(let [native-image-cmd (->> [graal-native-image
81+
(str "-H:Path=" target-path)
8182
(str "-H:Name=" target-exe)
8283
"-H:+ReportExceptionStackTraces"
8384
"-J-Dclojure.spec.skip-macros=true"
8485
"-J-Dclojure.compiler.direct-linking=true"
8586
(when graal-reflection-fname
8687
(str "-H:ReflectionConfigurationFiles=" graal-reflection-fname))
87-
"--initialize-at-build-time"
8888
"-H:Log=registerResource:"
8989
"-H:EnableURLProtocols=http,https,jar"
9090
"--verbose"

script/test_native.clj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
(defn -main [& args]
2020
(when (main/doc-arg-opt args)
2121
(let [native-image-xmx "6g"
22-
target-exe "target/rewrite-clj-test"]
22+
target-path "target"
23+
target-exe "rewrite-clj-test"
24+
full-target-exe (str (io/file target-path target-exe))]
2325
(status/line :head "Creating native image for test")
2426
(status/line :detail "java -version")
2527
(shell/command "java -version")
@@ -28,17 +30,18 @@
2830
test-runner-dir "target/generated/graal"]
2931
(graal/clean)
3032
(generate-test-runner test-runner-dir)
31-
(let [classpath (graal/compute-classpath "test-common:native-test")]
33+
(let [classpath (graal/compute-classpath "test-common:graal:native-test")]
3234
(graal/aot-compile-sources classpath "clj-graal.test-runner")
3335
(graal/run-native-image {:graal-native-image graal-native-image
36+
:target-path target-path
3437
:target-exe target-exe
3538
:classpath classpath
3639
:native-image-xmx native-image-xmx
3740
:entry-class "clj_graal.test_runner"})))
3841
(status/line :head "Native image built")
39-
(status/line :detail "built: %s, %d bytes" target-exe (.length (io/file target-exe)))
42+
(status/line :detail "built: %s, %d bytes" full-target-exe (.length (io/file full-target-exe)))
4043
(status/line :head "Running tests natively")
41-
(shell/command target-exe)))
44+
(shell/command full-target-exe)))
4245
nil)
4346

4447
(main/when-invoked-as-script

script/test_native_sci.clj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,28 @@
3131
(when (main/doc-arg-opt args)
3232
(let [native-image-xmx "6g"
3333
graal-reflection-fname "target/native-image/reflection.json"
34-
target-exe "target/sci-test-rewrite-clj"]
34+
target-path "target"
35+
target-exe "sci-test-rewrite-clj"
36+
full-target-exe (str (io/file target-path target-exe))]
3537
(status/line :head "Creating native image for testing via sci")
3638
(status/line :detail "java -version")
3739
(shell/command "java -version")
3840
(status/line :detail (str "\nnative-image max memory: " native-image-xmx))
3941
(let [graal-native-image (graal/find-graal-native-image)]
4042
(graal/clean)
4143
(expose-api-to-sci)
42-
(let [classpath (graal/compute-classpath "sci-test")]
44+
(let [classpath (graal/compute-classpath "graal:sci-test")]
4345
(graal/aot-compile-sources classpath "sci-test.main")
4446
(generate-reflection-file graal-reflection-fname)
4547
(graal/run-native-image {:graal-native-image graal-native-image
4648
:graal-reflection-fname graal-reflection-fname
49+
:target-path target-path
4750
:target-exe target-exe
4851
:classpath classpath
4952
:native-image-xmx native-image-xmx
5053
:entry-class "sci_test.main"})))
5154
(status/line :head "build done")
52-
(status/line :detail "built: %s, %d bytes" target-exe (.length (io/file target-exe)))
55+
(status/line :detail "built: %s, %d bytes" full-target-exe (.length (io/file full-target-exe)))
5356
(interpret-tests)))
5457
nil)
5558

0 commit comments

Comments
 (0)