graalvmXX-ce: refactor

- Simplify `preFixup` phase
- Update documentation
- Quote some variables
This commit is contained in:
Thiago Kenji Okada 2022-04-19 19:36:51 +01:00
parent bf27ea9cdb
commit aa2a396048

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/
@ -185,19 +183,20 @@ let
# provide libraries needed for static compilation
${
if useMusl then
"for f in ${musl.stdenv.cc.cc}/lib/* ${musl}/lib/* ${zlib.static}/lib/*; do"
''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"
''for f in "${glibc}/lib/"* "${glibc.static}/lib/"* "${zlib.static}/lib/"*; do''
}
ln -s $f $out/lib/svm/clibraries/${platform.arch}/$(basename $f)
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)
# 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
# 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}"
fi
done
find "$out" -name libfontmanager.so -exec \