Merge pull request #140287 from thiagokokada/reduce-graalvm-closure-size
This commit is contained in:
commit
f865ed612f
|
@ -130,37 +130,53 @@ let
|
||||||
unpack_jar ''${arr[4]}
|
unpack_jar ''${arr[4]}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
installPhase = {
|
outputs = [ "out" "lib" ];
|
||||||
"8-linux-amd64" = ''
|
|
||||||
|
installPhase = let
|
||||||
|
nativePRNGWorkaround = path: ''
|
||||||
# BUG workaround http://mail.openjdk.java.net/pipermail/graal-dev/2017-December/005141.html
|
# BUG workaround http://mail.openjdk.java.net/pipermail/graal-dev/2017-December/005141.html
|
||||||
substituteInPlace $out/jre/lib/security/java.security \
|
substituteInPlace ${path} \
|
||||||
--replace file:/dev/random file:/dev/./urandom \
|
--replace file:/dev/random file:/dev/./urandom \
|
||||||
--replace NativePRNGBlocking SHA1PRNG
|
--replace NativePRNGBlocking SHA1PRNG
|
||||||
|
'';
|
||||||
|
copyClibrariesToOut = basepath: ''
|
||||||
# provide libraries needed for static compilation
|
# provide libraries needed for static compilation
|
||||||
for f in ${glibc}/lib/* ${glibc.static}/lib/* ${zlib.static}/lib/*; do
|
for f in ${glibc}/lib/* ${glibc.static}/lib/* ${zlib.static}/lib/*; do
|
||||||
ln -s $f $out/jre/lib/svm/clibraries/${platform}/$(basename $f)
|
ln -s $f ${basepath}/${platform}/$(basename $f)
|
||||||
done
|
done
|
||||||
|
'';
|
||||||
|
|
||||||
|
copyClibrariesToLib = ''
|
||||||
|
# add those libraries to $lib output too, so we can use them with
|
||||||
|
# `native-image -H:CLibraryPath=''${graalvm11-ce.lib}/lib ...` and reduce
|
||||||
|
# closure size by not depending on GraalVM $out (that is much bigger)
|
||||||
|
mkdir -p $lib/lib
|
||||||
|
for f in ${glibc}/lib/*; do
|
||||||
|
ln -s $f $lib/lib/$(basename $f)
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
in {
|
||||||
|
"8-linux-amd64" = ''
|
||||||
|
${nativePRNGWorkaround "$out/jre/lib/security/java.security"}
|
||||||
|
|
||||||
|
${copyClibrariesToOut "$out/jre/lib/svm/clibraries"}
|
||||||
|
|
||||||
|
${copyClibrariesToLib}
|
||||||
|
|
||||||
# allow using external truffle-api.jar and languages not included in the distrubution
|
# allow using external truffle-api.jar and languages not included in the distrubution
|
||||||
rm $out/jre/lib/jvmci/parentClassLoader.classpath
|
rm $out/jre/lib/jvmci/parentClassLoader.classpath
|
||||||
'';
|
'';
|
||||||
"11-linux-amd64" = ''
|
"11-linux-amd64" = ''
|
||||||
# BUG workaround http://mail.openjdk.java.net/pipermail/graal-dev/2017-December/005141.html
|
${nativePRNGWorkaround "$out/conf/security/java.security"}
|
||||||
substituteInPlace $out/conf/security/java.security \
|
|
||||||
--replace file:/dev/random file:/dev/./urandom \
|
|
||||||
--replace NativePRNGBlocking SHA1PRNG
|
|
||||||
|
|
||||||
# provide libraries needed for static compilation
|
${copyClibrariesToOut "$out/lib/svm/clibraries"}
|
||||||
for f in ${glibc}/lib/* ${glibc.static}/lib/* ${zlib.static}/lib/*; do
|
|
||||||
ln -s $f $out/lib/svm/clibraries/${platform}/$(basename $f)
|
${copyClibrariesToLib}
|
||||||
done
|
|
||||||
'';
|
'';
|
||||||
"11-darwin-amd64" = ''
|
"11-darwin-amd64" = ''
|
||||||
# BUG workaround http://mail.openjdk.java.net/pipermail/graal-dev/2017-December/005141.html
|
# create empty $lib/lib to avoid breaking builds
|
||||||
substituteInPlace $out/conf/security/java.security \
|
mkdir -p $lib/lib
|
||||||
--replace file:/dev/random file:/dev/./urandom \
|
${nativePRNGWorkaround "$out/conf/security/java.security"}
|
||||||
--replace NativePRNGBlocking SHA1PRNG
|
|
||||||
'';
|
'';
|
||||||
}.${javaVersionPlatform} + ''
|
}.${javaVersionPlatform} + ''
|
||||||
# jni.h expects jni_md.h to be in the header search path.
|
# jni.h expects jni_md.h to be in the header search path.
|
||||||
|
|
|
@ -23,6 +23,7 @@ stdenv.mkDerivation rec {
|
||||||
|
|
||||||
# https://github.com/babashka/babashka/blob/v0.6.1/script/compile#L41-L52
|
# https://github.com/babashka/babashka/blob/v0.6.1/script/compile#L41-L52
|
||||||
args=("-jar" "$BABASHKA_JAR"
|
args=("-jar" "$BABASHKA_JAR"
|
||||||
|
"-H:CLibraryPath=${graalvm11-ce.lib}/lib"
|
||||||
# Required to build babashka on darwin. Do not remove.
|
# Required to build babashka on darwin. Do not remove.
|
||||||
"${lib.optionalString stdenv.isDarwin "-H:-CheckToolchain"}"
|
"${lib.optionalString stdenv.isDarwin "-H:-CheckToolchain"}"
|
||||||
"-H:Name=$BABASHKA_BINARY"
|
"-H:Name=$BABASHKA_BINARY"
|
||||||
|
|
|
@ -4,12 +4,6 @@ stdenv.mkDerivation rec {
|
||||||
pname = "clj-kondo";
|
pname = "clj-kondo";
|
||||||
version = "2021.09.25";
|
version = "2021.09.25";
|
||||||
|
|
||||||
reflectionJson = fetchurl {
|
|
||||||
name = "reflection.json";
|
|
||||||
url = "https://raw.githubusercontent.com/clj-kondo/${pname}/v${version}/reflection.json";
|
|
||||||
sha256 = "sha256-C4QYk5lLienCHKnWXXZPcKmsCTMtIIkXOkvCrZfyIhA=";
|
|
||||||
};
|
|
||||||
|
|
||||||
src = fetchurl {
|
src = fetchurl {
|
||||||
url = "https://github.com/clj-kondo/${pname}/releases/download/v${version}/${pname}-${version}-standalone.jar";
|
url = "https://github.com/clj-kondo/${pname}/releases/download/v${version}/${pname}-${version}-standalone.jar";
|
||||||
sha256 = "sha256-kS6bwsYH/cbjJlIeiDAy6QsAw+D1uHp26d4NBLfStjg=";
|
sha256 = "sha256-kS6bwsYH/cbjJlIeiDAy6QsAw+D1uHp26d4NBLfStjg=";
|
||||||
|
@ -20,21 +14,21 @@ stdenv.mkDerivation rec {
|
||||||
buildInputs = [ graalvm11-ce ];
|
buildInputs = [ graalvm11-ce ];
|
||||||
|
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
native-image \
|
runHook preBuild
|
||||||
-jar ${src} \
|
|
||||||
-H:Name=clj-kondo \
|
# https://github.com/clj-kondo/clj-kondo/blob/v2021.09.25/script/compile#L17-L21
|
||||||
${lib.optionalString stdenv.isDarwin ''-H:-CheckToolchain''} \
|
args=("-jar" "$src"
|
||||||
-H:+ReportExceptionStackTraces \
|
"-H:CLibraryPath=${graalvm11-ce.lib}/lib"
|
||||||
-J-Dclojure.spec.skip-macros=true \
|
# Required to build babashka on darwin. Do not remove.
|
||||||
-J-Dclojure.compiler.direct-linking=true \
|
"${lib.optionalString stdenv.isDarwin "-H:-CheckToolchain"}"
|
||||||
"-H:IncludeResources=clj_kondo/impl/cache/built_in/.*" \
|
"-H:+ReportExceptionStackTraces"
|
||||||
-H:ReflectionConfigurationFiles=${reflectionJson} \
|
"--verbose"
|
||||||
--initialize-at-build-time \
|
"--no-fallback"
|
||||||
-H:Log=registerResource: \
|
"-J-Xmx3g")
|
||||||
--verbose \
|
|
||||||
--no-fallback \
|
native-image ''${args[@]}
|
||||||
--no-server \
|
|
||||||
"-J-Xmx3g"
|
runHook postBuild
|
||||||
'';
|
'';
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
|
@ -47,6 +41,6 @@ stdenv.mkDerivation rec {
|
||||||
homepage = "https://github.com/clj-kondo/clj-kondo";
|
homepage = "https://github.com/clj-kondo/clj-kondo";
|
||||||
license = licenses.epl10;
|
license = licenses.epl10;
|
||||||
platforms = graalvm11-ce.meta.platforms;
|
platforms = graalvm11-ce.meta.platforms;
|
||||||
maintainers = with maintainers; [ jlesquembre bandresen ];
|
maintainers = with maintainers; [ jlesquembre bandresen thiagokokada ];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,16 @@ stdenv.mkDerivation rec {
|
||||||
buildPhase = with lib; ''
|
buildPhase = with lib; ''
|
||||||
runHook preBuild
|
runHook preBuild
|
||||||
|
|
||||||
bash ./graalvm/native-unix-compile.sh
|
# https://github.com/clojure-lsp/clojure-lsp/blob/2021.09.30-15.28.01/graalvm/native-unix-compile.sh#L19-L24
|
||||||
|
args=("-jar" "$CLOJURE_LSP_JAR"
|
||||||
|
"-H:CLibraryPath=${graalvm11-ce.lib}/lib"
|
||||||
|
"-H:+ReportExceptionStackTraces"
|
||||||
|
"--verbose"
|
||||||
|
"--no-fallback"
|
||||||
|
"--native-image-info"
|
||||||
|
"$CLOJURE_LSP_XMX")
|
||||||
|
|
||||||
|
native-image ''${args[@]}
|
||||||
|
|
||||||
runHook postBuild
|
runHook postBuild
|
||||||
'';
|
'';
|
||||||
|
|
|
@ -24,6 +24,7 @@ stdenv.mkDerivation rec {
|
||||||
-H:Name=${pname} \
|
-H:Name=${pname} \
|
||||||
-H:EnableURLProtocols=https,http \
|
-H:EnableURLProtocols=https,http \
|
||||||
-H:+ReportExceptionStackTraces \
|
-H:+ReportExceptionStackTraces \
|
||||||
|
-H:CLibraryPath=${graalvm11-ce.lib}/lib \
|
||||||
${lib.optionalString stdenv.isDarwin ''-H:-CheckToolchain''} \
|
${lib.optionalString stdenv.isDarwin ''-H:-CheckToolchain''} \
|
||||||
--report-unsupported-elements-at-runtime \
|
--report-unsupported-elements-at-runtime \
|
||||||
--initialize-at-build-time \
|
--initialize-at-build-time \
|
||||||
|
|
Loading…
Reference in a new issue