babashka/script/compile

86 lines
2.1 KiB
Text
Raw Normal View History

2019-08-09 12:51:42 +00:00
#!/usr/bin/env bash
2019-08-15 07:02:43 +00:00
set -eo pipefail
2020-03-29 14:07:30 +00:00
GU=`which gu` || true
if [ -z "$GU" ]; then
if [ -z "$GRAALVM_HOME" ]; then
echo "Please set GRAALVM_HOME"
exit 1
fi
GU="$GRAALVM_HOME/bin/gu"
else
GRAALVM_HOME=`echo $GU | sed -e "s/\/bin\/gu$//"`
fi
2019-08-09 12:51:42 +00:00
2020-01-09 10:28:11 +00:00
if [ -z "$BABASHKA_XMX" ]; then
2020-01-09 10:19:48 +00:00
export BABASHKA_XMX="-J-Xmx3g"
fi
2020-03-29 14:07:30 +00:00
NATIVE_IMAGE=`which native-image` || true
if [ -z "$NATIVE_IMAGE" ]; then
$GU install native-image || true
NATIVE_IMAGE=`which native-image` || true
if [ -z "$NATIVE_IMAGE" ]; then
if [ -z "$GRAALVM_HOME" ]; then
echo "Please set GRAALVM_HOME"
exit 1
fi
NATIVE_IMAGE="$GRAALVM_HOME/bin/native-image"
fi
fi
## --- THE ACTUAL SCRIPT ---
2020-01-09 10:11:12 +00:00
2019-08-09 12:51:42 +00:00
BABASHKA_VERSION=$(cat resources/BABASHKA_VERSION)
2020-01-09 10:11:12 +00:00
export JAVA_HOME=$GRAALVM_HOME
$GRAALVM_HOME/bin/javac -cp $GRAALVM_HOME/jre/lib/svm/builder/svm.jar resources/CutOffCoreServicesDependencies.java
2020-03-29 14:07:30 +00:00
if [ -z "$JAR" ]; then
lein with-profiles +reflection do run
lein do clean, uberjar
JAR=${JAR:-"target/babashka-$BABASHKA_VERSION-standalone.jar"}
fi
2020-03-29 14:07:30 +00:00
BINARY_NAME=${BINARY_NAME:-"bb"}
args=( -jar $JAR \
-H:Name=$BINARY_NAME \
2020-02-23 11:04:18 +00:00
-H:+ReportExceptionStackTraces \
-J-Dclojure.spec.skip-macros=true \
-J-Dclojure.compiler.direct-linking=true \
"-H:IncludeResources=BABASHKA_VERSION" \
"-H:IncludeResources=SCI_VERSION" \
-H:ReflectionConfigurationFiles=reflection.json \
--initialize-at-run-time=java.lang.Math\$RandomNumberGeneratorHolder \
--initialize-at-build-time \
-H:Log=registerResource: \
-H:EnableURLProtocols=http,https \
--enable-all-security-services \
-H:+JNI \
--verbose \
--no-fallback \
--no-server \
--report-unsupported-elements-at-runtime \
2020-02-23 11:04:18 +00:00
"$BABASHKA_XMX" )
if [ "$BABASHKA_STATIC" = "true" ]; then
args+=("--static")
fi
$GRAALVM_HOME/bin/native-image "${args[@]}"
2019-08-09 12:51:42 +00:00
2020-03-29 14:07:30 +00:00
LEIN=`which lein` || true
if [ -z "$LEIN" ]; then
echo "nothing to clean"
else
lein clean
fi