From 3b8132538a54d7ecd4bf871d7a1ec9640414d1e9 Mon Sep 17 00:00:00 2001 From: piotr-yuxuan Date: Wed, 22 Dec 2021 06:44:08 +0000 Subject: [PATCH 1/2] add byte-streams --- byte-streams/.gitignore | 12 ++++++++++++ byte-streams/README.md | 18 ++++++++++++++++++ byte-streams/project.clj | 23 +++++++++++++++++++++++ byte-streams/src/simple/main.clj | 14 ++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 byte-streams/.gitignore create mode 100644 byte-streams/README.md create mode 100644 byte-streams/project.clj create mode 100644 byte-streams/src/simple/main.clj diff --git a/byte-streams/.gitignore b/byte-streams/.gitignore new file mode 100644 index 0000000..d18f225 --- /dev/null +++ b/byte-streams/.gitignore @@ -0,0 +1,12 @@ +/target +/classes +/checkouts +profiles.clj +pom.xml +pom.xml.asc +*.jar +*.class +/.lein-* +/.nrepl-port +.hgignore +.hg/ diff --git a/byte-streams/README.md b/byte-streams/README.md new file mode 100644 index 0000000..1fb38cc --- /dev/null +++ b/byte-streams/README.md @@ -0,0 +1,18 @@ +# Sample-project + +Use this project as template for testing a specific library with GraalVM **native-image** + +## Usage + +Currently testing: + + [org.clj-commons/byte-streams "0.2.10"] + +Test with: + + lein do clean, uberjar, native, run-native + + +Test with: + + lein do clean, uberjar, native, run-native diff --git a/byte-streams/project.clj b/byte-streams/project.clj new file mode 100644 index 0000000..57a6b2d --- /dev/null +++ b/byte-streams/project.clj @@ -0,0 +1,23 @@ +(defproject byte-streams "0.1.0-SNAPSHOT" + + :dependencies [[org.clojure/clojure "1.10.3"] + [org.clj-commons/byte-streams "0.2.10"] + ] + + :main simple.main + + :uberjar-name "simple-main.jar" + + :profiles {:uberjar {:aot :all} + :dev {:plugins [[lein-shell "0.5.0"]]}} + + :aliases + {"native" + ["shell" + "native-image" "--report-unsupported-elements-at-runtime" "--no-server" "--no-fallback" + "--initialize-at-build-time" + "-jar" "./target/${:uberjar-name:-${:name}-${:version}-standalone.jar}" + "-H:Name=./target/${:name}" + ] + + "run-native" ["shell" "./target/${:name}"]}) diff --git a/byte-streams/src/simple/main.clj b/byte-streams/src/simple/main.clj new file mode 100644 index 0000000..6479485 --- /dev/null +++ b/byte-streams/src/simple/main.clj @@ -0,0 +1,14 @@ +(ns simple.main + (:require [byte-streams :as byte-streams]) + (:gen-class)) + +;; +;; Update this file to use the libary you wish to test. +;; + + +(defn -main [] + (let [greetings "Hello GraalVM."] + (-> (byte-streams/to-byte-array greetings) + (byte-streams/convert String) + println))) From a6b5a636430d8b9eaf5b3348e0332685a00e3360 Mon Sep 17 00:00:00 2001 From: piotr-yuxuan Date: Wed, 22 Dec 2021 18:56:17 +0000 Subject: [PATCH 2/2] update byte-streams example --- byte-streams/README.md | 5 ++--- byte-streams/project.clj | 13 ++++++++++++- byte-streams/src/simple/main.clj | 30 +++++++++++++++++++++--------- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/byte-streams/README.md b/byte-streams/README.md index 1fb38cc..1e114cd 100644 --- a/byte-streams/README.md +++ b/byte-streams/README.md @@ -12,7 +12,6 @@ Test with: lein do clean, uberjar, native, run-native +If you want to avoid the warning about `--initialize-at-build-time` try with: -Test with: - - lein do clean, uberjar, native, run-native + lein do clean, uberjar+graal-build-time, native, run-native diff --git a/byte-streams/project.clj b/byte-streams/project.clj index 57a6b2d..1dda749 100644 --- a/byte-streams/project.clj +++ b/byte-streams/project.clj @@ -1,7 +1,7 @@ (defproject byte-streams "0.1.0-SNAPSHOT" :dependencies [[org.clojure/clojure "1.10.3"] - [org.clj-commons/byte-streams "0.2.10"] + [org.clj-commons/byte-streams "0.2.11"] ] :main simple.main @@ -9,6 +9,7 @@ :uberjar-name "simple-main.jar" :profiles {:uberjar {:aot :all} + :graal-build-time [:uberjar {:dependencies [[com.github.clj-easy/graal-build-time "0.1.4"]]}] :dev {:plugins [[lein-shell "0.5.0"]]}} :aliases @@ -20,4 +21,14 @@ "-H:Name=./target/${:name}" ] + "uberjar+graal-build-time" + ["with-profile" "+graal-build-time" "uberjar"] + + "native+graal-build-time" + ["shell" + "native-image" "--report-unsupported-elements-at-runtime" "--no-fallback" + "-jar" "./target/${:uberjar-name:-${:name}-${:version}-standalone.jar}" + "-H:Name=./target/${:name}" + ] + "run-native" ["shell" "./target/${:name}"]}) diff --git a/byte-streams/src/simple/main.clj b/byte-streams/src/simple/main.clj index 6479485..fc574f6 100644 --- a/byte-streams/src/simple/main.clj +++ b/byte-streams/src/simple/main.clj @@ -1,14 +1,26 @@ (ns simple.main - (:require [byte-streams :as byte-streams]) + (:require [clj-commons.byte-streams :as bs] + [clj-commons.byte-streams.pushback-stream :as p]) + (:import (java.nio.channels ReadableByteChannel) + (java.io InputStream)) (:gen-class)) -;; -;; Update this file to use the libary you wish to test. -;; - - (defn -main [] - (let [greetings "Hello GraalVM."] - (-> (byte-streams/to-byte-array greetings) - (byte-streams/convert String) + (let [greetings "Hello GraalVM." + in (byte-array (range 100)) + p (p/pushback-stream 50) + x (p/put-array p in 0 100) + ary (byte-array 50)] + (= 50 @(p/take p ary 0 50)) + (= (range 50) (seq ary)) + (= true @x) + (= 50 @(p/take p ary 0 50)) + (bs/convert (p/put (bs/to-byte-buffer "a") + (bs/to-byte-buffer "b")) + String) + (-> (bs/to-byte-array greetings) + (bs/convert (bs/stream-of String)) + (bs/convert (bs/seq-of ReadableByteChannel)) + (bs/convert InputStream) + (bs/convert String) println)))