From 72d3afa69863aa959f72baf80100cef2fb4885bf Mon Sep 17 00:00:00 2001 From: Eric Dallo Date: Sun, 22 Aug 2021 18:19:28 -0300 Subject: [PATCH] Migrate GraalVM configuration to jar (#973) --- .github/workflows/build.yml | 27 ----------- .gitignore | 2 +- resources/META-INF/babashka/deps.edn | 1 + .../babashka/babashka/native-image.properties | 23 +++++++++ script/compile | 47 +++++-------------- script/compile.bat | 24 +--------- script/reflection.clj | 2 +- src/babashka/impl/classes.clj | 4 +- 8 files changed, 41 insertions(+), 89 deletions(-) create mode 100644 resources/META-INF/native-image/babashka/babashka/native-image.properties diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c93c1ac4..ab01ccb5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -85,20 +85,11 @@ jobs: BABASHKA_VERSION=$(cat resources/BABASHKA_VERSION) echo "##[set-output name=version;]${BABASHKA_VERSION}" - - name: Reflection artifact - run: | - cp reflection.json babashka-${{ steps.babashka-version.outputs.version }}-reflection.json - - uses: actions/upload-artifact@v1 with: name: jar path: target/babashka-${{ steps.babashka-version.outputs.version }}-standalone.jar - - uses: actions/upload-artifact@v1 - with: - name: reflection.json - path: babashka-${{ steps.babashka-version.outputs.version }}-reflection.json - linux: if: "!contains(github.event.head_commit.message, 'skip ci')" needs: [jvm] @@ -115,11 +106,6 @@ jobs: name: jar path: . - - uses: actions/download-artifact@v1 - with: - name: reflection.json - path: . - - name: Cache deps uses: actions/cache@v1 id: cache-deps @@ -157,7 +143,6 @@ jobs: export BABASHKA_JAR=babashka-${{ steps.babashka-version.outputs.version }}-standalone.jar export BABASHKA_XMX="-J-Xmx6g" export GRAALVM_HOME="$HOME/graalvm-ce-java11-21.1.0" - cp babashka-${{ steps.babashka-version.outputs.version }}-reflection.json reflection.json script/compile - name: Test binary @@ -196,11 +181,6 @@ jobs: name: jar path: . - - uses: actions/download-artifact@v1 - with: - name: reflection.json - path: . - - name: Cache deps uses: actions/cache@v1 id: cache-deps @@ -239,7 +219,6 @@ jobs: export BABASHKA_XMX="-J-Xmx6g" export GRAALVM_HOME="$HOME/graalvm-ce-java11-21.1.0" export BABASHKA_STATIC=true - cp babashka-${{ steps.babashka-version.outputs.version }}-reflection.json reflection.json script/compile - name: Test binary @@ -279,11 +258,6 @@ jobs: name: jar path: . - - uses: actions/download-artifact@v1 - with: - name: reflection.json - path: . - - name: Cache GraalVM uses: actions/cache@v1 id: cache-graalvm @@ -312,7 +286,6 @@ jobs: export BABASHKA_JAR=babashka-${{ steps.babashka-version.outputs.version }}-standalone.jar export BABASHKA_XMX="-J-Xmx6g" export GRAALVM_HOME="$HOME/graalvm-ce-java11-21.1.0/Contents/Home" - cp babashka-${{ steps.babashka-version.outputs.version }}-reflection.json reflection.json script/compile - name: Test binary diff --git a/.gitignore b/.gitignore index 840b2df3..fb29f608 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,7 @@ pom.xml.asc !test-resources/babashka/src_for_classpath_test/foo.jar !test-resources/pom.xml .cpcache -*reflection.json +*reflect-config.json /tmp /reports *.dylib diff --git a/resources/META-INF/babashka/deps.edn b/resources/META-INF/babashka/deps.edn index b7c289c0..39c29550 100644 --- a/resources/META-INF/babashka/deps.edn +++ b/resources/META-INF/babashka/deps.edn @@ -87,6 +87,7 @@ com.grammarly/omniconf {:mvn/version "0.4.3"} crispin/crispin {:mvn/version "0.3.8"} org.clojure/data.json {:mvn/version "2.4.0"} + clj-commons/multigrep {:mvn/version "0.5.0"} amperity/vault-clj {:mvn/version "1.0.4"}} :classpath-overrides {org.clojure/clojure nil org.clojure/spec.alpha nil diff --git a/resources/META-INF/native-image/babashka/babashka/native-image.properties b/resources/META-INF/native-image/babashka/babashka/native-image.properties new file mode 100644 index 00000000..7df1b5a4 --- /dev/null +++ b/resources/META-INF/native-image/babashka/babashka/native-image.properties @@ -0,0 +1,23 @@ +ImageName=bb +Args=-H:+ReportExceptionStackTraces \ + -J-Dborkdude.dynaload.aot=true \ + -H:IncludeResources=BABASHKA_VERSION \ + -H:IncludeResources=META-INF/babashka/.* \ + -H:IncludeResources=SCI_VERSION \ + --initialize-at-build-time \ + -H:Log=registerResource: \ + -H:EnableURLProtocols=http,https,jar \ + --enable-all-security-services \ + -H:+JNI \ + --no-server \ + --report-unsupported-elements-at-runtime \ + --initialize-at-run-time=org.postgresql.sspi.SSPIClient \ + --initialize-at-run-time=org.httpkit.client.ClientSslEngineFactory\$SSLHolder \ + -H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.AudioFileReader \ + -H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.MidiFileReader \ + -H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.MixerProvider \ + -H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.FormatConversionProvider \ + -H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.AudioFileWriter \ + -H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.MidiDeviceProvider \ + -H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.SoundbankReader \ + -H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.MidiFileWriter diff --git a/script/compile b/script/compile index a58ab482..56dcb319 100755 --- a/script/compile +++ b/script/compile @@ -38,41 +38,18 @@ fi BABASHKA_BINARY=${BABASHKA_BINARY:-"bb"} -args=( "-jar" "$BABASHKA_JAR" - "-H:Name=$BABASHKA_BINARY" - "-H:+ReportExceptionStackTraces" - "-J-Dborkdude.dynaload.aot=true" - "-H:IncludeResources=BABASHKA_VERSION" - "-H:IncludeResources=META-INF/babashka/.*" - "-H:IncludeResources=SCI_VERSION" - "-H:ReflectionConfigurationFiles=reflection.json" - "--initialize-at-build-time" - #"-H:+PrintAnalysisCallTree" - # "-H:+DashboardAll" - # "-H:DashboardDump=reports/dump" - # "-H:+DashboardPretty" - # "-H:+DashboardJson" - "-H:Log=registerResource:" - "-H:EnableURLProtocols=http,https,jar" - "--enable-all-security-services" - "-H:+JNI" - "--verbose" - "--no-fallback" - "--no-server" - "--report-unsupported-elements-at-runtime" - "--initialize-at-run-time=org.postgresql.sspi.SSPIClient" - "--initialize-at-run-time=org.httpkit.client.ClientSslEngineFactory\$SSLHolder" - "--native-image-info" - "--verbose" - "-H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.AudioFileReader" - "-H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.MidiFileReader" - "-H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.MixerProvider" - "-H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.FormatConversionProvider" - "-H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.AudioFileWriter" - "-H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.MidiDeviceProvider" - "-H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.SoundbankReader" - "-H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.MidiFileWriter" - "$BABASHKA_XMX" ) +args=("-jar" "$BABASHKA_JAR" + "-H:Name=$BABASHKA_BINARY" + "-H:+ReportExceptionStackTraces" + # "-H:+PrintAnalysisCallTree" + # "-H:+DashboardAll" + # "-H:DashboardDump=reports/dump" + # "-H:+DashboardPretty" + # "-H:+DashboardJson" + "--verbose" + "--no-fallback" + "--native-image-info" + "$BABASHKA_XMX") BABASHKA_STATIC=${BABASHKA_STATIC:-} BABASHKA_MUSL=${BABASHKA_MUSL:-} diff --git a/script/compile.bat b/script/compile.bat index 5a2edc1a..56d3396c 100644 --- a/script/compile.bat +++ b/script/compile.bat @@ -27,30 +27,8 @@ call %GRAALVM_HOME%\bin\native-image.cmd ^ "-jar" "target/babashka-%BABASHKA_VERSION%-standalone.jar" ^ "-H:Name=bb" ^ "-H:+ReportExceptionStackTraces" ^ - "-J-Dclojure.spec.skip-macros=true" ^ - "-J-Dclojure.compiler.direct-linking=true" ^ - "-H:IncludeResources=BABASHKA_VERSION" ^ - "-H:IncludeResources=SCI_VERSION" ^ - "-H:IncludeResources=META-INF/babashka/.*" ^ - "-H:ReflectionConfigurationFiles=reflection.json" ^ - "--initialize-at-build-time" ^ - "--initialize-at-run-time=org.postgresql.sspi.SSPIClient" ^ - "--initialize-at-run-time=org.httpkit.client.ClientSslEngineFactory$SSLHolder" ^ - "-H:EnableURLProtocols=http,https,jar" ^ - "--enable-all-security-services" ^ - "-H:+JNI" ^ - "-H:Log=registerResource:" ^ - "--no-fallback" ^ "--verbose" ^ - "-H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.AudioFileReader" ^ - "-H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.MidiFileReader" ^ - "-H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.MixerProvider" ^ - "-H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.FormatConversionProvider" ^ - "-H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.AudioFileWriter" ^ - "-H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.MidiDeviceProvider" ^ - "-H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.SoundbankReader" ^ - "-H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.MidiFileWriter" ^ - "-H:ServiceLoaderFeatureExcludeServices=java.awt.Toolkit" ^ + "--no-fallback" ^ "%BABASHKA_XMX%" if %errorlevel% neq 0 exit /b %errorlevel% diff --git a/script/reflection.clj b/script/reflection.clj index 315872c0..8880a934 100755 --- a/script/reflection.clj +++ b/script/reflection.clj @@ -6,4 +6,4 @@ (def version (str/trim (slurp (io/file "resources" "BABASHKA_VERSION")))) (sh "lein" "with-profiles" "+reflection" "run") -(io/copy (io/file "reflection.json") (io/file (str "babashka-" version "-reflection.json"))) +(io/copy (io/file "resources/META-INF/native-image/babashka/babashka/reflect-config.json") (io/file (str "babashka-" version "-reflection.json"))) diff --git a/src/babashka/impl/classes.clj b/src/babashka/impl/classes.clj index ec65fa44..eafbe13b 100644 --- a/src/babashka/impl/classes.clj +++ b/src/babashka/impl/classes.clj @@ -474,12 +474,12 @@ all-entries)) (defn generate-reflection-file - "Generate reflection.json file" + "Generate reflect-config.json file" [& args] (let [all-entries (reflection-file-entries)] (spit (or (first args) - "reflection.json") (json/generate-string all-entries {:pretty true})))) + "resources/META-INF/native-image/babashka/babashka/reflect-config.json") (json/generate-string all-entries {:pretty true})))) (defn public-declared-method? [c m] (and (= c (.getDeclaringClass m))