Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions byte-streams/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/target
/classes
/checkouts
profiles.clj
pom.xml
pom.xml.asc
*.jar
*.class
/.lein-*
/.nrepl-port
.hgignore
.hg/
17 changes: 17 additions & 0 deletions byte-streams/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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

If you want to avoid the warning about `--initialize-at-build-time` try with:

lein do clean, uberjar+graal-build-time, native, run-native
34 changes: 34 additions & 0 deletions byte-streams/project.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(defproject byte-streams "0.1.0-SNAPSHOT"

:dependencies [[org.clojure/clojure "1.10.3"]
[org.clj-commons/byte-streams "0.2.11"]
]

:main simple.main

: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
{"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}"
]

"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}"]})
26 changes: 26 additions & 0 deletions byte-streams/src/simple/main.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(ns simple.main
(: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))

(defn -main []
(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)))