Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/borkdude/jayfu
Jayfu is a tutorial on how to create a Clojure CLI with GraalVM native-image and SCI.
https://github.com/borkdude/jayfu
clojure graalvm-native-image
Last synced: 1 day ago
JSON representation
Jayfu is a tutorial on how to create a Clojure CLI with GraalVM native-image and SCI.
- Host: GitHub
- URL: https://github.com/borkdude/jayfu
- Owner: borkdude
- License: epl-1.0
- Created: 2021-05-16T10:48:47.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-07T17:10:35.000Z (about 1 year ago)
- Last Synced: 2024-11-02T02:33:28.944Z (8 days ago)
- Topics: clojure, graalvm-native-image
- Language: Clojure
- Homepage:
- Size: 23.4 KB
- Stars: 54
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jayfu
Learn how to make a native Clojure CLI with GraalVM native-image and SCI!
This example is set up around an example CLI, `jayfu`, that reads JSON from
stdin and transforms it using a function which is dynamically evaluated:``` clojure
$ echo '{"a": {"b": 2}}' | ./jayfu -f '#(-> % :a :b)' -k keyword
2
```See this [talk](https://www.youtube.com/watch?v=L2LAaQBVvxM) which guides you through this project.
## Prerequisites
- Download [GraalVM](https://www.graalvm.org/downloads/). Just download it to
your Downloads folder and unzip the archive. No further installation
required. This tutorial is based on version 21.1.0 JDK11.- Set the `GRAALVM_HOME` environment variable. E.g.:
`export GRAALVM_HOME=/Users/borkdude/Downloads/graalvm-ce-java11-21.1.0/Contents/Home`
- To run with Clojure or Java, you will need to have a
Java 8 or 11 installation available. You can also use the downloaded GraalVM for this.- Install [babashka](https://github.com/babashka/babashka#installation) (0.4.1 or higher).
### Windows
Always use `cmd.exe` for executing GraalVM compilation, do not use PowerShell.
On Windows, install Visual Studio 2017 or 2019 and in `cmd.exe` load:
```
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
```This will set the right environment variables for GraalVM.
After this you should be able to run `bb native-image`.
## Tasks
To see all available tasks in this project, run `bb tasks`:
``` text
$ bb tasks
The following tasks are available:run-main Run main
uberjar Builds uberjar
run-uber Run uberjar
graalvm Checks GRAALVM_HOME env var
native-image Builds native image
```## Run
To run this example using Clojure, run:
``` clojure
$ bb run-main --help
Usage:
-f, --func FUNCTION identity The function applied to JSON from stdin
-k, --key-fn KEY-FN identity The function applied to keywords
-h, --help$ echo '{"a": {"b": 2}}' | bb run-main -f '#(-> % :a :b)' -k keyword
2
```## Build
To build the native image, run:
``` text
$ bb native-image
```This should produce a binary called `jayfu`:
``` clojure
$ echo '{"a": {"b": 2}}' | ./jayfu -f '#(-> % :a :b)' -k keyword
2
```## Talk
See this [talk](https://www.youtube.com/watch?v=L2LAaQBVvxM) which guides you through this project.
## Tutorial
Coming soon.
## License
Copyright © 2021 Michiel Borkent
Distributed under the EPL License. See LICENSE.