Merge pull request #152379 from thiagokokada/graalvm-ce-fixes
graalvm-ce: multiple fixes and improvements
This commit is contained in:
commit
33f9145d8f
1 changed files with 129 additions and 73 deletions
|
@ -1,13 +1,41 @@
|
||||||
{ version, javaVersion, platforms, hashes ? import ./hashes.nix }:
|
{ version
|
||||||
|
, javaVersion
|
||||||
|
, platforms
|
||||||
|
, hashes ? import ./hashes.nix
|
||||||
|
, useMusl ? false
|
||||||
|
}:
|
||||||
|
|
||||||
{ stdenv, lib, fetchurl, autoPatchelfHook, setJavaClassPath, makeWrapper
|
{ stdenv
|
||||||
# minimum dependencies
|
, lib
|
||||||
, Foundation, alsa-lib, fontconfig, freetype, glibc, openssl, perl, unzip, xorg
|
, autoPatchelfHook
|
||||||
|
, fetchurl
|
||||||
|
, makeWrapper
|
||||||
|
, setJavaClassPath
|
||||||
|
, writeShellScriptBin
|
||||||
|
# minimum dependencies
|
||||||
|
, alsa-lib
|
||||||
|
, fontconfig
|
||||||
|
, Foundation
|
||||||
|
, freetype
|
||||||
|
, glibc
|
||||||
|
, openssl
|
||||||
|
, perl
|
||||||
|
, unzip
|
||||||
|
, xorg
|
||||||
, zlib
|
, zlib
|
||||||
# runtime dependencies
|
# runtime dependencies
|
||||||
|
, binutils
|
||||||
, cups
|
, cups
|
||||||
# runtime dependencies for GTK+ Look and Feel
|
, gcc
|
||||||
, gtkSupport ? true, cairo, glib, gtk3 }:
|
, musl
|
||||||
|
# runtime dependencies for GTK+ Look and Feel
|
||||||
|
, gtkSupport ? stdenv.isLinux
|
||||||
|
, cairo
|
||||||
|
, glib
|
||||||
|
, gtk3
|
||||||
|
}:
|
||||||
|
|
||||||
|
assert useMusl -> stdenv.isLinux;
|
||||||
|
|
||||||
let
|
let
|
||||||
platform = {
|
platform = {
|
||||||
|
@ -16,10 +44,17 @@ let
|
||||||
x86_64-darwin = "darwin-amd64";
|
x86_64-darwin = "darwin-amd64";
|
||||||
}.${stdenv.system} or (throw "Unsupported system: ${stdenv.system}");
|
}.${stdenv.system} or (throw "Unsupported system: ${stdenv.system}");
|
||||||
|
|
||||||
runtimeDependencies = [ cups ]
|
runtimeLibraryPath = lib.makeLibraryPath
|
||||||
++ lib.optionals gtkSupport [ cairo glib gtk3 ];
|
([ cups ] ++ lib.optionals gtkSupport [ cairo glib gtk3 ]);
|
||||||
|
|
||||||
runtimeLibraryPath = lib.makeLibraryPath runtimeDependencies;
|
runtimeDependencies = lib.makeBinPath ([
|
||||||
|
binutils
|
||||||
|
stdenv.cc
|
||||||
|
] ++ lib.optionals useMusl [
|
||||||
|
(lib.getDev musl)
|
||||||
|
# GraalVM 21.3.0+ expects musl-gcc as <system>-musl-gcc
|
||||||
|
(writeShellScriptBin "${stdenv.system}-musl-gcc" ''${lib.getDev musl}/bin/musl-gcc "$@"'')
|
||||||
|
]);
|
||||||
|
|
||||||
javaVersionPlatform = "${javaVersion}-${platform}";
|
javaVersionPlatform = "${javaVersion}-${platform}";
|
||||||
|
|
||||||
|
@ -51,10 +86,6 @@ let
|
||||||
zlib
|
zlib
|
||||||
];
|
];
|
||||||
|
|
||||||
# Workaround for libssl.so.10 wanted by TruffleRuby
|
|
||||||
# Resulting TruffleRuby cannot use `openssl` library.
|
|
||||||
autoPatchelfIgnoreMissingDeps = true;
|
|
||||||
|
|
||||||
nativeBuildInputs = [ unzip perl autoPatchelfHook makeWrapper ];
|
nativeBuildInputs = [ unzip perl autoPatchelfHook makeWrapper ];
|
||||||
|
|
||||||
unpackPhase = ''
|
unpackPhase = ''
|
||||||
|
@ -108,55 +139,73 @@ let
|
||||||
|
|
||||||
outputs = [ "out" "lib" ];
|
outputs = [ "out" "lib" ];
|
||||||
|
|
||||||
installPhase = let
|
installPhase =
|
||||||
copyClibrariesToOut = basepath: ''
|
let
|
||||||
# provide libraries needed for static compilation
|
copyClibrariesToOut = basepath: ''
|
||||||
for f in ${glibc}/lib/* ${glibc.static}/lib/* ${zlib.static}/lib/*; do
|
# provide libraries needed for static compilation
|
||||||
ln -s $f ${basepath}/${platform}/$(basename $f)
|
${
|
||||||
done
|
if useMusl then
|
||||||
'';
|
"for f in ${musl.stdenv.cc.cc}/lib/* ${musl}/lib/* ${zlib.static}/lib/*; do"
|
||||||
copyClibrariesToLib = ''
|
else
|
||||||
# add those libraries to $lib output too, so we can use them with
|
"for f in ${glibc}/lib/* ${glibc.static}/lib/* ${zlib.static}/lib/*; do"
|
||||||
# `native-image -H:CLibraryPath=''${graalvm11-ce.lib}/lib ...` and reduce
|
}
|
||||||
# closure size by not depending on GraalVM $out (that is much bigger)
|
ln -s $f ${basepath}/${platform}/$(basename $f)
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
copyClibrariesToLib = ''
|
||||||
|
# add those libraries to $lib output too, so we can use them with
|
||||||
|
# `native-image -H:CLibraryPath=''${lib.getLib graalvm11-ce}/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
|
||||||
|
{
|
||||||
|
"11-linux-amd64" = ''
|
||||||
|
${copyClibrariesToOut "$out/lib/svm/clibraries"}
|
||||||
|
|
||||||
|
${copyClibrariesToLib}
|
||||||
|
'';
|
||||||
|
"17-linux-amd64" = ''
|
||||||
|
${copyClibrariesToOut "$out/lib/svm/clibraries"}
|
||||||
|
|
||||||
|
${copyClibrariesToLib}
|
||||||
|
'';
|
||||||
|
"11-linux-aarch64" = ''
|
||||||
|
${copyClibrariesToOut "$out/lib/svm/clibraries"}
|
||||||
|
|
||||||
|
${copyClibrariesToLib}
|
||||||
|
'';
|
||||||
|
"17-linux-aarch64" = ''
|
||||||
|
${copyClibrariesToOut "$out/lib/svm/clibraries"}
|
||||||
|
|
||||||
|
${copyClibrariesToLib}
|
||||||
|
'';
|
||||||
|
"11-darwin-amd64" = "";
|
||||||
|
"17-darwin-amd64" = "";
|
||||||
|
}.${javaVersionPlatform} + ''
|
||||||
|
# ensure that $lib/lib exists to avoid breaking builds
|
||||||
mkdir -p $lib/lib
|
mkdir -p $lib/lib
|
||||||
for f in ${glibc}/lib/*; do
|
# jni.h expects jni_md.h to be in the header search path.
|
||||||
ln -s $f $lib/lib/$(basename $f)
|
ln -s $out/include/linux/*_md.h $out/include/
|
||||||
done
|
|
||||||
'';
|
|
||||||
in {
|
|
||||||
"11-linux-amd64" = ''
|
|
||||||
${copyClibrariesToOut "$out/lib/svm/clibraries"}
|
|
||||||
|
|
||||||
${copyClibrariesToLib}
|
# copy-paste openjdk's preFixup
|
||||||
|
# Set JAVA_HOME automatically.
|
||||||
|
mkdir -p $out/nix-support
|
||||||
|
cat <<EOF > $out/nix-support/setup-hook
|
||||||
|
if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi
|
||||||
|
EOF
|
||||||
'';
|
'';
|
||||||
"17-linux-amd64" = ''
|
|
||||||
${copyClibrariesToOut "$out/lib/svm/clibraries"}
|
|
||||||
|
|
||||||
${copyClibrariesToLib}
|
|
||||||
'';
|
|
||||||
"11-linux-aarch64" = ''
|
|
||||||
${copyClibrariesToOut "$out/lib/svm/clibraries"}
|
|
||||||
|
|
||||||
${copyClibrariesToLib}
|
|
||||||
'';
|
|
||||||
"17-linux-aarch64" = ''
|
|
||||||
${copyClibrariesToOut "$out/lib/svm/clibraries"}
|
|
||||||
|
|
||||||
${copyClibrariesToLib}
|
|
||||||
'';
|
|
||||||
"11-darwin-amd64" = "";
|
|
||||||
"17-darwin-amd64" = "";
|
|
||||||
}.${javaVersionPlatform} + ''
|
|
||||||
# ensure that $lib/lib exists to avoid breaking builds
|
|
||||||
mkdir -p $lib/lib
|
|
||||||
# jni.h expects jni_md.h to be in the header search path.
|
|
||||||
ln -s $out/include/linux/*_md.h $out/include/
|
|
||||||
'';
|
|
||||||
|
|
||||||
dontStrip = true;
|
dontStrip = true;
|
||||||
|
|
||||||
preFixup = ''
|
# Workaround for libssl.so.10 wanted by TruffleRuby
|
||||||
|
# Resulting TruffleRuby cannot use `openssl` library.
|
||||||
|
autoPatchelfIgnoreMissingDeps = stdenv.isDarwin;
|
||||||
|
|
||||||
|
preFixup = lib.optionalString (stdenv.isLinux) ''
|
||||||
# We cannot use -exec since wrapProgram is a function but not a
|
# We cannot use -exec since wrapProgram is a function but not a
|
||||||
# command.
|
# command.
|
||||||
#
|
#
|
||||||
|
@ -165,19 +214,18 @@ let
|
||||||
for bin in $( find "$out" -executable -type f -not -path '*/languages/ruby/lib/gems/*' -not -name jspawnhelper ); do
|
for bin in $( find "$out" -executable -type f -not -path '*/languages/ruby/lib/gems/*' -not -name jspawnhelper ); do
|
||||||
if patchelf --print-interpreter "$bin" &> /dev/null || head -n 1 "$bin" | grep '^#!' -q; then
|
if patchelf --print-interpreter "$bin" &> /dev/null || head -n 1 "$bin" | grep '^#!' -q; then
|
||||||
wrapProgram "$bin" \
|
wrapProgram "$bin" \
|
||||||
--prefix LD_LIBRARY_PATH : "${runtimeLibraryPath}"
|
--prefix LD_LIBRARY_PATH : "${runtimeLibraryPath}" \
|
||||||
|
--prefix PATH : "${runtimeDependencies}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# copy-paste openjdk's preFixup
|
|
||||||
# Set JAVA_HOME automatically.
|
|
||||||
mkdir -p $out/nix-support
|
|
||||||
cat <<EOF > $out/nix-support/setup-hook
|
|
||||||
if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi
|
|
||||||
EOF
|
|
||||||
|
|
||||||
find "$out" -name libfontmanager.so -exec \
|
find "$out" -name libfontmanager.so -exec \
|
||||||
patchelf --add-needed libfontconfig.so {} \;
|
patchelf --add-needed libfontconfig.so {} \;
|
||||||
|
|
||||||
|
# Workaround for libssl.so.10/libcrypto.so.10 wanted by TruffleRuby
|
||||||
|
patchelf $out/languages/ruby/lib/mri/openssl.so \
|
||||||
|
--replace-needed libssl.so.10 libssl.so \
|
||||||
|
--replace-needed libcrypto.so.10 libcrypto.so
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# $out/bin/native-image needs zlib to build native executables.
|
# $out/bin/native-image needs zlib to build native executables.
|
||||||
|
@ -204,19 +252,26 @@ let
|
||||||
# run on JVM with Graal Compiler
|
# run on JVM with Graal Compiler
|
||||||
$out/bin/java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler HelloWorld | fgrep 'Hello World'
|
$out/bin/java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler HelloWorld | fgrep 'Hello World'
|
||||||
|
|
||||||
# Ahead-Of-Time compilation
|
${# --static flag doesn't work for darwin
|
||||||
$out/bin/native-image -H:-CheckToolchain -H:+ReportExceptionStackTraces --no-server HelloWorld
|
lib.optionalString (stdenv.isLinux && !useMusl) ''
|
||||||
./helloworld | fgrep 'Hello World'
|
echo "Ahead-Of-Time compilation"
|
||||||
|
$out/bin/native-image -H:-CheckToolchain -H:+ReportExceptionStackTraces --no-server HelloWorld
|
||||||
|
./helloworld | fgrep 'Hello World'
|
||||||
|
|
||||||
${
|
echo "Ahead-Of-Time compilation with --static"
|
||||||
lib.optionalString stdenv.isLinux ''
|
|
||||||
# Ahead-Of-Time compilation with --static
|
|
||||||
# --static flag doesn't work for darwin
|
|
||||||
$out/bin/native-image --no-server --static HelloWorld
|
$out/bin/native-image --no-server --static HelloWorld
|
||||||
./helloworld | fgrep 'Hello World'
|
./helloworld | fgrep 'Hello World'
|
||||||
''
|
''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
${# --static flag doesn't work for darwin
|
||||||
|
lib.optionalString (stdenv.isLinux && useMusl) ''
|
||||||
|
echo "Ahead-Of-Time compilation with --static and --libc=musl"
|
||||||
|
$out/bin/native-image --no-server --libc=musl --static HelloWorld
|
||||||
|
./helloworld | fgrep 'Hello World'
|
||||||
|
''
|
||||||
|
}
|
||||||
|
|
||||||
${# TODO: Doesn't work on MacOS, we have this error:
|
${# TODO: Doesn't work on MacOS, we have this error:
|
||||||
# "Launching JShell execution engine threw: Operation not permitted (Bind failed)"
|
# "Launching JShell execution engine threw: Operation not permitted (Bind failed)"
|
||||||
lib.optionalString (stdenv.isLinux) ''
|
lib.optionalString (stdenv.isLinux) ''
|
||||||
|
@ -275,4 +330,5 @@ let
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in graalvmXXX-ce
|
in
|
||||||
|
graalvmXXX-ce
|
||||||
|
|
Loading…
Reference in a new issue