Fallback to native-image on PATH?
sogaiu opened this issue · 3 comments
sogaiu commented
I have native-image in my PATH but it isn't used. (As the documentation mentions, setting GRAALVM_HOME or having the bin subdirectory of my project contain a symlink to native-image works.)
clj.native-image/src/clj/native_image.clj
Lines 57 to 59 in 567176d
Does it sound reasonable for clj.native-image to make use of a native-image binary that's on one's PATH?
sogaiu commented
How is something like this?
diff --git a/src/clj/native_image.clj b/src/clj/native_image.clj
index 76766be..6cc8097 100644
--- a/src/clj/native_image.clj
+++ b/src/clj/native_image.clj
@@ -59,11 +59,17 @@
(.mkdir compile-path)))
(defn native-image-bin-path []
- (-> (io/file (System/getenv "GRAALVM_HOME")
- (if windows?
- "bin/native-image.cmd"
- "bin/native-image"))
- (.getAbsolutePath)))
+ (let [path (->> (clojure.string/split (System/getenv "PATH") #":")
+ (map #(str % "/native-image"))
+ (filter #(.isFile (java.io.File. %)))
+ first)]
+ (if (string? path)
+ path
+ (-> (io/file (System/getenv "GRAALVM_HOME")
+ (if windows?
+ "bin/native-image.cmd"
+ "bin/native-image"))
+ (.getAbsolutePath)))))
(defn- munge-class-name [class-name]
(cs/replace class-name "-" "_"))
taylorwood commented
@sogaiu let me know if latest commit works for you. Thanks!
sogaiu commented
It appears to work fine!
Thanks a lot :)