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