Merge pull request #169353 from thiagokokada/graalvm-cleanup

graalvmXX-ce: refactor
This commit is contained in:
Thiago Kenji Okada 2022-04-19 21:34:46 +01:00 committed by GitHub
commit 8ec683742b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -29,8 +29,8 @@
# See `update.nix` file for a description on how this file works
, sourcesPath ? ./. + "/graalvm${javaVersion}-ce-sources.json"
# Use musl instead of glibc to allow true static builds in GraalVM's
# Native Image (i.e.: `--static --libc=musl`). This will cause glibc builds
# to fail, so it should be used with care
# Native Image (i.e.: `--static --libc=musl`). This will cause glibc static
# builds to fail, so it should be used with care
, useMusl ? false
}:
@ -85,7 +85,7 @@ let
] ++ 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 "$@"'')
(writeShellScriptBin "${stdenv.hostPlatform.system}-musl-gcc" ''${lib.getDev musl}/bin/musl-gcc "$@"'')
]);
withNativeImageSvm = builtins.elem "native-image-installable-svm" platform.products;
@ -169,8 +169,6 @@ let
outputs = [ "out" "lib" ];
installPhase = ''
# 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/
@ -181,25 +179,26 @@ let
if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi
EOF
${
lib.optionalString (stdenv.isLinux) ''
# provide libraries needed for static compilation
${
if useMusl then
"for f in ${musl.stdenv.cc.cc}/lib/* ${musl}/lib/* ${zlib.static}/lib/*; do"
else
"for f in ${glibc}/lib/* ${glibc.static}/lib/* ${zlib.static}/lib/*; do"
}
ln -s $f $out/lib/svm/clibraries/${platform.arch}/$(basename $f)
done
lib.optionalString (stdenv.isLinux) ''
# provide libraries needed for static compilation
${
if useMusl then
''for f in "${musl.stdenv.cc.cc}/lib/"* "${musl}/lib/"* "${zlib.static}/lib/"*; do''
else
''for f in "${glibc}/lib/"* "${glibc.static}/lib/"* "${zlib.static}/lib/"*; do''
}
ln -s "$f" "$out/lib/svm/clibraries/${platform.arch}/$(basename $f)"
done
# add those libraries to $lib output too, so we can use them with
# `native-image -H:CLibraryPath=''${lib.getLib graalvmXX-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
''
# add those libraries to $lib output too, so we can use them with
# `native-image -H:CLibraryPath=''${lib.getLib graalvmXX-ce}/lib ...` and reduce
# closure size by not depending on GraalVM $out (that is much bigger)
# we always use glibc here, since musl is only supported for static compilation
mkdir -p "$lib/lib"
for f in "${glibc}/lib/"*; do
ln -s "$f" "$lib/lib/$(basename $f)"
done
''
}
'';
@ -210,17 +209,11 @@ let
autoPatchelfIgnoreMissingDeps = withRubySvm && stdenv.isDarwin;
preFixup = lib.optionalString (stdenv.isLinux) ''
# We cannot use -exec since wrapProgram is a function but not a
# command.
#
# jspawnhelper is executed from JVM, so it doesn't need to wrap it,
# and it breaks building OpenJDK (#114495).
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
wrapProgram "$bin" \
--prefix LD_LIBRARY_PATH : "${runtimeLibraryPath}" \
--prefix PATH : "${runtimeDependencies}"
fi
# Find all executables in any directory that contains '/bin/'
for bin in $(find "$out" -executable -type f -wholename '*/bin/*'); do
wrapProgram "$bin" \
--prefix LD_LIBRARY_PATH : "${runtimeLibraryPath}" \
--prefix PATH : "${runtimeDependencies}"
done
find "$out" -name libfontmanager.so -exec \