Created
March 16, 2019 03:01
-
-
Save cosmicexplorer/b8b4128315dfb4a30f462c5e73e5cd83 to your computer and use it in GitHub Desktop.
make a native image of the pants zinc wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euxo pipefail | |
# NB: `mx` needs to be on $PATH! | |
if [[ ! -d 'openjdk1.8.0_202-jvmci-0.56' ]]; then | |
if [[ "$(uname)" == 'Linux' ]]; then | |
_jvmci_url_component='linux' | |
else | |
_jvmci_url_component='darwin' | |
fi | |
curl -L -v -O "https://github.com/graalvm/openjdk8-jvmci-builder/releases/download/jvmci-0.56/openjdk-8u202-jvmci-0.56-${_jvmci_url_component}-amd64.tar.gz" | |
tar zxvf "openjdk-8u202-jvmci-0.56-${_jvmci_url_component}-amd64.tar.gz" | |
fi | |
export JAVA_HOME="$(pwd)/openjdk1.8.0_202-jvmci-0.56" | |
PANTS_ZINC_WRAPPER="$(pwd)/pants/dist/bin.jar" | |
if [[ ! -f "$PANTS_ZINC_WRAPPER" ]]; then | |
git clone [email protected]:cosmicexplorer/pants | |
pushd pants/ | |
git checkout graal-zinc-image | |
./pants binary src/scala/org/pantsbuild/zinc/compiler:bin | |
[[ -f "$PANTS_ZINC_WRAPPER" ]] | |
popd | |
fi | |
REFLECTIONS_JSON="$(pwd)/graalvm-demos/scala-days-2018/scalac-native/scalac-substitutions/reflection-config.json" | |
SUBSTITUTIONS_SNAPSHOT_JAR="$(pwd)/graalvm-demos/scala-days-2018/scalac-native/scalac-substitutions/target/scala-2.12/scalac-substitutions_2.12-0.1.0-SNAPSHOT.jar" | |
if [[ ! (-f "$REFLECTIONS_JSON" && -f "$SUBSTITUTIONS_SNAPSHOT_JAR" ) ]]; then | |
git clone [email protected]:cosmicexplorer/graalvm-demos | |
pushd graalvm-demos/ | |
git checkout build-zinc-native-image | |
pushd scala-days-2018/scalac-native/scalac-substitutions/ | |
REFLECTIONS_JSON="$(pwd)/reflection-config.json" | |
sbt package | |
SUBSTITUTIONS_SNAPSHOT_JAR="$(pwd)/target/scala-2.12/scalac-substitutions_2.12-0.1.0-SNAPSHOT.jar" | |
[[ -f "$REFLECTIONS_JSON" && -f "$SUBSTITUTIONS_SNAPSHOT_JAR" ]] | |
popd | |
popd | |
fi | |
function fetch_scala_compiler_jars { | |
local -r version="$1" | |
coursier fetch org.scala-lang:scala-{compiler,library,reflect}:"$version" \ | |
| tr '\n' ':' \ | |
| sed -re 's#:$##g' | |
} | |
# This is a hack, on my arch linux laptop it is necessary, this is pants's fault. | |
if hash scala && scala -version 2>&1 | grep --color '2.12.8'; then | |
SCALA_COMPILER_JARS="$(printf "%s\n" /usr/share/scala/lib/scala-{compiler,library,reflect}.jar \ | |
| tr '\n' ':' \ | |
| sed -re 's#:$##g')" | |
else | |
SCALA_COMPILER_JARS="$(fetch_scala_compiler_jars 2.12.8)" | |
fi | |
SVM_DIR="$(pwd)/substratevm" | |
pushd "$SVM_DIR" | |
mx build | |
popd | |
pushd pants/ | |
mx \ | |
-p "$SVM_DIR" \ | |
native-image \ | |
-cp "${PANTS_ZINC_WRAPPER}:${SCALA_COMPILER_JARS}:${SUBSTITUTIONS_SNAPSHOT_JAR}" \ | |
-H:SubstitutionResources=substitutions.json,substitutions-2.12.json \ | |
-H:ReflectionConfigurationFiles="$REFLECTIONS_JSON" \ | |
-H:ConfigurationFileDirectories="$(pwd)/native-image-configure/" \ | |
org.pantsbuild.zinc.compiler.Main \ | |
--verbose --no-server \ | |
--enable-all-security-services --allow-incomplete-classpath \ | |
-O0 -J-Xmx8g \ | |
--report-unsupported-elements-at-runtime \ | |
-H:+ReportExceptionStackTraces \ | |
--delay-class-initialization-to-runtime=org.pantsbuild.zinc.compiler.Main \ | |
--delay-class-initialization-to-runtime='org.pantsbuild.zinc.compiler.Main$' \ | |
--delay-class-initialization-to-runtime=scala.tools.nsc.interpreter.IMain \ | |
--delay-class-initialization-to-runtime='scala.tools.nsc.interpreter.IMain$' \ | |
--delay-class-initialization-to-runtime=scala.tools.nsc.interpreter.NamedParam \ | |
--delay-class-initialization-to-runtime=sbt.internal.util.StringTypeTag \ | |
--delay-class-initialization-to-runtime=org.pantsbuild.zinc.compiler.InputUtils \ | |
--delay-class-initialization-to-runtime='scala.tools.nsc.interpreter.IBindings' \ | |
--delay-class-initialization-to-runtime='scala.reflect.runtime.package$' \ | |
--delay-class-initialization-to-runtime='scala.tools.nsc.interpreter.StdReplTags$' \ | |
-H:NumberOfThreads=1 | |
./org.pantsbuild.zinc.compiler.main -help | |
popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment