From eae7c5b5dfdfaeb07fb39deec5622823e3b950eb Mon Sep 17 00:00:00 2001 From: Nicolas Kosinski Date: Mon, 1 Jul 2019 07:01:21 +0200 Subject: [PATCH] Generate executable via GraalVM 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/ --- .gitignore | 1 + README.md | 5 +++++ generate-executable.sh | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100755 generate-executable.sh diff --git a/.gitignore b/.gitignore index 1be5112..cf9d6d4 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ *.iml /lib .idea +hubstats.core diff --git a/README.md b/README.md index f429ecf..58b5088 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,8 @@ Examples: ## Command line installation +### As a Java application (portable) + Create JAR with all dependencies: ```shell lein uberjar @@ -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. diff --git a/generate-executable.sh b/generate-executable.sh new file mode 100755 index 0000000..00ae5f0 --- /dev/null +++ b/generate-executable.sh @@ -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" \ No newline at end of file