Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graalvm-ce: 22.3.1 -> 21.0.0 #257433

Merged
merged 16 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions pkgs/build-support/build-graalvm-native-image/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,5 @@ stdenv.mkDerivation ({
platforms = graalvmDrv.meta.platforms;
# default to executable name
mainProgram = executable;
# need to have native-image-installable-svm available
broken = !(builtins.any (p: (p.product or "") == "native-image-installable-svm") graalvmDrv.products);
} // meta;
} // extraArgs)
116 changes: 74 additions & 42 deletions pkgs/development/compilers/graalvm/community-edition/buildGraalvm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@
, darwin
, fontconfig
, glib
, glibc
, gtk3
, makeWrapper
, musl
, setJavaClassPath
, unzip
, writeShellScriptBin
, xorg
, zlib
# extra params
, javaVersion
, meta ? { }
, products ? [ ]
, extraCLibs ? [ ]
, gtkSupport ? stdenv.isLinux
, useMusl ? false
, ...
} @ args:

assert useMusl -> stdenv.isLinux;
let
extraArgs = builtins.removeAttrs args [
"lib"
Expand All @@ -32,24 +35,36 @@ let
"darwin"
"fontconfig"
"glib"
"glibc"
"gtk3"
"makeWrapper"
"musl"
"setJavaClassPath"
"unzip"
"writeShellScriptBin"
"xorg"
"zlib"
"javaVersion"
"meta"
"products"
"extraCLibs"
"gtkSupport"
"useMusl"
"passthru"
"meta"
];

cLibs = [ glibc zlib.static ]
++ lib.optionals (!useMusl) [ glibc.static ]
++ lib.optionals useMusl [ musl ]
++ extraCLibs;

# GraalVM 21.3.0+ expects musl-gcc as <system>-musl-gcc
musl-gcc = (writeShellScriptBin "${stdenv.hostPlatform.system}-musl-gcc" ''${lib.getDev musl}/bin/musl-gcc "$@"'');
binPath = lib.makeBinPath ([ stdenv.cc ] ++ lib.optionals useMusl [ musl-gcc ]);

runtimeLibraryPath = lib.makeLibraryPath
([ cups ] ++ lib.optionals gtkSupport [ cairo glib gtk3 ]);
mapProducts = key: default: (map (p: p.graalvmPhases.${key} or default) products);
concatProducts = key: lib.concatStringsSep "\n" (mapProducts key "");

graalvmXXX-ce = stdenv.mkDerivation ({
pname = "graalvm${javaVersion}-ce";
graalvm-ce = stdenv.mkDerivation ({
pname = "graalvm-ce";

unpackPhase = ''
runHook preUnpack
Expand All @@ -71,22 +86,16 @@ let

# Sanity check
if [ ! -d "$out/bin" ]; then
echo "The `bin` is directory missing after extracting the graalvm"
echo "tarball, please compare the directory structure of the"
echo "tarball with what happens in the unpackPhase (in particular"
echo "with regards to the `--strip-components` flag)."
exit 1
echo "The `bin` is directory missing after extracting the graalvm"
echo "tarball, please compare the directory structure of the"
echo "tarball with what happens in the unpackPhase (in particular"
echo "with regards to the `--strip-components` flag)."
exit 1
fi

runHook postUnpack
'';

postUnpack = ''
for product in ${toString products}; do
cp -Rv $product/* $out
done
'';

dontStrip = true;

nativeBuildInputs = [ unzip makeWrapper ]
Expand All @@ -106,7 +115,6 @@ let
xorg.libXtst
];

preInstall = concatProducts "preInstall";
postInstall = ''
# jni.h expects jni_md.h to be in the header search path.
ln -sf $out/include/linux/*_md.h $out/include/
Expand All @@ -115,52 +123,74 @@ let
# Set JAVA_HOME automatically.
mkdir -p $out/nix-support
cat > $out/nix-support/setup-hook << EOF
if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi
if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi
EOF
'' + concatProducts "postInstall";

${lib.optionalString stdenv.isLinux ''
wrapProgram $out/bin/native-image \
--prefix PATH : ${binPath} \
${toString (map (l: "--add-flags '-H:CLibraryPath=${l}/lib'") cLibs)}
''}
'';

preFixup = lib.optionalString (stdenv.isLinux) ''
for bin in $(find "$out/bin" -executable -type f); do
wrapProgram "$bin" --prefix LD_LIBRARY_PATH : "${runtimeLibraryPath}"
done
'' + concatProducts "preFixup";
postFixup = concatProducts "postFixup";
'';

doInstallCheck = true;
installCheckPhase = ''
runHook preInstallCheck

${# broken in darwin
lib.optionalString stdenv.isLinux ''
lib.optionalString stdenv.isLinux ''
echo "Testing Jshell"
echo '1 + 1' | $out/bin/jshell
''}

echo ${
lib.escapeShellArg ''
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
echo ${lib.escapeShellArg ''
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
''
} > HelloWorld.java
}
''} > HelloWorld.java
$out/bin/javac HelloWorld.java

# run on JVM with Graal Compiler
echo "Testing GraalVM"
$out/bin/java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler HelloWorld | fgrep 'Hello World'

${concatProducts "installCheckPhase"}
echo "Ahead-Of-Time compilation"
$out/bin/native-image -H:+UnlockExperimentalVMOptions -H:-CheckToolchain -H:+ReportExceptionStackTraces HelloWorld
./helloworld | fgrep 'Hello World'

${# --static is only available in Linux
lib.optionalString (stdenv.isLinux && !useMusl) ''
echo "Ahead-Of-Time compilation with -H:+StaticExecutableWithDynamicLibC"
$out/bin/native-image -H:+UnlockExperimentalVMOptions -H:+StaticExecutableWithDynamicLibC HelloWorld
./helloworld | fgrep 'Hello World'

echo "Ahead-Of-Time compilation with --static"
$out/bin/native-image --static HelloWorld
./helloworld | fgrep 'Hello World'
''}

${# --static is only available in Linux
lib.optionalString (stdenv.isLinux && useMusl) ''
echo "Ahead-Of-Time compilation with --static and --libc=musl"
$out/bin/native-image --static HelloWorld --libc=musl
./helloworld | fgrep 'Hello World'
''}

runHook postInstallCheck
'';

passthru = {
inherit products;
home = graalvmXXX-ce;
updateScript = ./update.sh;
};
home = graalvm-ce;
updateScript = [ ./update.sh "graalvm-ce" ];
} // (args.passhtru or { });

meta = with lib; ({
homepage = "https://www.graalvm.org/";
Expand All @@ -169,7 +199,9 @@ let
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
mainProgram = "java";
maintainers = with maintainers; teams.graalvm-ce.members ++ [ ];
} // meta);
# fatal error: 'Foundation/Foundation.h' file not found
broken = stdenv.isDarwin;
} // (args.meta or { }));
} // extraArgs);
in
graalvmXXX-ce
graalvm-ce
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
, autoPatchelfHook
, graalvm-ce
, makeWrapper
, perl
, unzip
, zlib
, libxcrypt-legacy
# extra params
, product
, javaVersion
, extraBuildInputs ? [ ]
, extraNativeBuildInputs ? [ ]
, graalvmPhases ? { }
, meta ? { }
, passthru ? { }
, ...
} @ args:

Expand All @@ -25,22 +19,18 @@ let
"autoPatchelfHook"
"graalvm-ce"
"makeWrapper"
"perl"
"unzip"
"zlib"
"libxcrypt-legacy"
"product"
"javaVersion"
"extraBuildInputs"
"extraNativeBuildInputs"
"graalvmPhases"
"meta"
"passthru"
];
in
stdenv.mkDerivation ({
pname = "${product}-java${javaVersion}";
pname = product;

nativeBuildInputs = [ perl unzip makeWrapper ]
nativeBuildInputs = [ makeWrapper ]
++ lib.optional stdenv.isLinux autoPatchelfHook
++ extraNativeBuildInputs;

Expand All @@ -53,56 +43,30 @@ stdenv.mkDerivation ({
unpackPhase = ''
runHook preUnpack

unpack_jar() {
local jar="$1"
unzip -q -o "$jar" -d "$out"
perl -ne 'use File::Path qw(make_path);
use File::Basename qw(dirname);
if (/^(.+) = (.+)$/) {
make_path dirname("$ENV{out}/$1");
symlink $2, "$ENV{out}/$1";
}' "$out/META-INF/symlinks"
perl -ne 'if (/^(.+) = ([r-])([w-])([x-])([r-])([w-])([x-])([r-])([w-])([x-])$/) {
my $mode = ($2 eq 'r' ? 0400 : 0) + ($3 eq 'w' ? 0200 : 0) + ($4 eq 'x' ? 0100 : 0) +
($5 eq 'r' ? 0040 : 0) + ($6 eq 'w' ? 0020 : 0) + ($7 eq 'x' ? 0010 : 0) +
($8 eq 'r' ? 0004 : 0) + ($9 eq 'w' ? 0002 : 0) + ($10 eq 'x' ? 0001 : 0);
chmod $mode, "$ENV{out}/$1";
}' "$out/META-INF/permissions"
rm -rf "$out/META-INF"
}
mkdir -p "$out"

unpack_jar "$src"
tar xf "$src" -C "$out" --strip-components=1

runHook postUnpack
'';

# Allow autoPatchelf to automatically fix lib references between products
fixupPhase = ''
runHook preFixup
# Sanity check
if [ ! -d "$out/bin" ]; then
echo "The `bin` is directory missing after extracting the graalvm"
echo "tarball, please compare the directory structure of the"
echo "tarball with what happens in the unpackPhase (in particular"
echo "with regards to the `--strip-components` flag)."
exit 1
fi

mkdir -p $out/lib
shopt -s globstar
ln -s $out/languages/**/lib/*.so $out/lib

runHook postFixup
runHook postUnpack
'';

dontInstall = true;
dontBuild = true;
dontStrip = true;

passthru = {
inherit product javaVersion;
# build phases that are going to run during GraalVM derivation build,
# since they depend in having the fully setup GraalVM environment
# e.g.: graalvmPhases.installCheckPhase will run the checks only after
# GraalVM+products is build
# see buildGraalvm.nix file for the available phases
inherit graalvmPhases;
} // passthru;
updateScript = [ ./update.sh product ];
} // (args.passhtru or { });

meta = with lib; ({
meta = ({
inherit (graalvm-ce.meta) homepage license sourceProvenance maintainers platforms;
description = "High-Performance Polyglot VM (Product: ${product})";
} // meta);
} // (args.meta or { }));
} // extraArgs)
Loading