Skip to content

Commit

Permalink
Generate executable via GraalVM
Browse files Browse the repository at this point in the history
Note that the "--no-fallback" native-image option cannot be used for the
moment (the compilation to native code fails), so the application runs in the normal JVM.
See https://www.graalvm.org/docs/reference-manual/aot-compilation/
  • Loading branch information
nicokosi committed Jul 4, 2019
1 parent 4592d32 commit eae7c5b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*.iml
/lib
.idea
hubstats.core
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Examples:

## Command line installation

### As a Java application (portable)

Create JAR with all dependencies:
```shell
lein uberjar
Expand All @@ -74,3 +76,6 @@ On Unix-like systems, you can create an executable via the following command:
```
This executable, which requires Java, can be moved to `/usr/local/bin`, for example.

### As a *nix native executable

Create a native executable via GraalVM running `./generate-executable.sh`. Only works for Linux and macOS.
37 changes: 37 additions & 0 deletions generate-executable.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# Fail on error
set -e

echo "Build nicokosi/hubstats JAR file:"
lein uberjar

echo "Install GraalVM via SDKMAN!:"
curl --silent "https://get.sdkman.io" | bash || echo 'SDKMAN! already installed'
source "$HOME/.sdkman/bin/sdkman-init.sh"
GRAALVM_VERSION=19.0.2-grl
sdkman_auto_answer=true sdk install java $GRAALVM_VERSION > /dev/null
sdk use java $GRAALVM_VERSION

echo "Build executable from JAR via GraalVM:"
gu install native-image && \
native-image \
--allow-incomplete-classpath \
--force-fallback \
--initialize-at-build-time \
--no-server \
--report-unsupported-elements-at-runtime \
-Dclojure.compiler.direct-linking=true \
-H:+ReportExceptionStackTraces \
-jar ./target/hubstats-0.1.0-SNAPSHOT-standalone.jar \
hubstats.core

echo "Executable has been built! ✅
It can be run this way:
# Show last 10 days stats for GitHub repository docker/containerd:
$ ./hubstats.core --organization docker --repository containerd --since-days 10
# Show all parameters:
$ ./hubstats.core"

0 comments on commit eae7c5b

Please sign in to comment.