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-oracle: init at 22 #321026

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Empty file added neo-tree filesystem [1]
Empty file.
4 changes: 2 additions & 2 deletions pkgs/by-name/cq/cq/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
, fetchFromGitHub
, fetchurl
, buildGraalvmNativeImage
, graalvmCEPackages
, graalvmPackages
}:

buildGraalvmNativeImage rec {
Expand All @@ -23,7 +23,7 @@ buildGraalvmNativeImage rec {
hash = "sha256-yjAC2obipdmh+JlHzVUTMtTXN2VKe4WKkyJyu2Q93c8=";
};

graalvmDrv = graalvmCEPackages.graalvm-ce;
graalvmDrv = graalvmPackages.graalvm-ce;

executable = "cq";

Expand Down
241 changes: 241 additions & 0 deletions pkgs/development/compilers/graalvm/buildGraalvm.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
{
lib,
stdenv,
alsa-lib,
autoPatchelfHook,
cairo,
cups,
darwin,
fontconfig,
glib,
glibc,
gtk3,
makeWrapper,
musl,
runCommandCC,
setJavaClassPath,
unzip,
xorg,
zlib,
# extra params
extraCLibs ? [ ],
gtkSupport ? stdenv.isLinux,
useMusl ? false,
...
}@args:

assert useMusl -> stdenv.isLinux;
let
extraArgs = builtins.removeAttrs args [
"lib"
"stdenv"
"alsa-lib"
"autoPatchelfHook"
"cairo"
"cups"
"darwin"
"fontconfig"
"glib"
"glibc"
"gtk3"
"makeWrapper"
"musl"
"runCommandCC"
"setJavaClassPath"
"unzip"
"xorg"
"zlib"
"extraCLibs"
"gtkSupport"
"useMusl"
"passthru"
"meta"
];

cLibs = lib.optionals stdenv.isLinux (
[
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 = (
runCommandCC "musl-gcc" { } ''
mkdir -p $out/bin
ln -s ${lib.getDev musl}/bin/musl-gcc $out/bin/${stdenv.hostPlatform.system}-musl-gcc
''
);
binPath = lib.makeBinPath (lib.optionals useMusl [ musl-gcc ] ++ [ stdenv.cc ]);

runtimeLibraryPath = lib.makeLibraryPath (
[ cups ]
++ lib.optionals gtkSupport [
cairo
glib
gtk3
]
);

graalvm-ce = stdenv.mkDerivation (
{
pname = "graalvm-ce";

unpackPhase = ''
runHook preUnpack

mkdir -p "$out"

# The tarball on Linux has the following directory structure:
#
# graalvm-ce-java11-20.3.0/*
#
# while on Darwin it looks like this:
#
# graalvm-ce-java11-20.3.0/Contents/Home/*
#
# We therefor use --strip-components=1 vs 3 depending on the platform.
tar xf "$src" -C "$out" --strip-components=${if stdenv.isLinux then "1" else "3"}

# 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

runHook postUnpack
'';

dontStrip = true;

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

propagatedBuildInputs = [
setJavaClassPath
zlib
] ++ lib.optional stdenv.isDarwin darwin.apple_sdk_11_0.frameworks.Foundation;

buildInputs = lib.optionals stdenv.isLinux [
alsa-lib # libasound.so wanted by lib/libjsound.so
fontconfig
stdenv.cc.cc.lib # libstdc++.so.6
xorg.libX11
xorg.libXext
xorg.libXi
xorg.libXrender
xorg.libXtst
];

postInstall = ''
# jni.h expects jni_md.h to be in the header search path.
ln -sf $out/include/linux/*_md.h $out/include/

# copy-paste openjdk's preFixup
# 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
EOF

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
'';

doInstallCheck = true;
installCheckPhase = ''
runHook preInstallCheck

${
# broken in darwin
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");
}
}
''} > 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'

extraNativeImageArgs="$(export -p | sed -n 's/^declare -x \([^=]\+\)=.*$/ -E\1/p' | tr -d \\n)"

echo "Ahead-Of-Time compilation"
$out/bin/native-image -H:+UnlockExperimentalVMOptions -H:-CheckToolchain -H:+ReportExceptionStackTraces -march=compatibility $extraNativeImageArgs HelloWorld
./helloworld | fgrep 'Hello World'

${
# -H:+StaticExecutableWithDynamicLibC 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 -march=compatibility $extraNativeImageArgs 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 $extraNativeImageArgs -march=compatibility --libc=musl --static HelloWorld
./helloworld | fgrep 'Hello World'
''
}

runHook postInstallCheck
'';

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

meta =
with lib;
(
{
homepage = "https://www.graalvm.org/";
description = "High-Performance Polyglot VM";
license = with licenses; [
upl
gpl2Classpath
bsd3
];
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
mainProgram = "java";
maintainers = with maintainers; teams.graalvm-ce.members ++ [ ];
}
// (args.meta or { })
);
}
// extraArgs
);
in
graalvm-ce
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{ stdenv
, fetchurl
, graalvmCEPackages
, graalvmPackages
}:

graalvmCEPackages.buildGraalvmProduct {
graalvmPackages.buildGraalvmProduct {
src = fetchurl (import ./hashes.nix).hashes.${stdenv.system};
version = (import ./hashes.nix).version;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{ stdenv
, fetchurl
, graalvmCEPackages
, graalvmPackages
}:

graalvmCEPackages.buildGraalvmProduct {
graalvmPackages.buildGraalvmProduct {
src = fetchurl (import ./hashes.nix).hashes.${stdenv.system};
version = (import ./hashes.nix).version;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{ stdenv
, fetchurl
, graalvmCEPackages
, graalvmPackages
}:

graalvmCEPackages.buildGraalvmProduct {
graalvmPackages.buildGraalvmProduct {
src = fetchurl (import ./hashes.nix).hashes.${stdenv.system};
version = (import ./hashes.nix).version;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{ stdenv
, fetchurl
, graalvmCEPackages
, graalvmPackages
, useMusl ? false
}:

graalvmCEPackages.buildGraalvm {
graalvmPackages.buildGraalvm {
inherit useMusl;
src = fetchurl (import ./hashes.nix).hashes.${stdenv.system};
version = (import ./hashes.nix).version;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{ lib
, stdenv
, fetchurl
, graalvmCEPackages
, graalvmPackages
, libyaml
, openssl
}:

graalvmCEPackages.buildGraalvmProduct {
graalvmPackages.buildGraalvmProduct {
src = fetchurl (import ./hashes.nix).hashes.${stdenv.system};
version = (import ./hashes.nix).version;

Expand Down
13 changes: 13 additions & 0 deletions pkgs/development/compilers/graalvm/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{ callPackage }:

let
cePackages = callPackage ./community-edition { };
in
cePackages
// rec {
buildGraalvm = callPackage ./buildGraalvm.nix;

graalvm-oracle_22 = callPackage ./graalvm-oracle { version = "22"; };
graalvm-oracle_17 = callPackage ./graalvm-oracle { version = "17"; };
graalvm-oracle = graalvm-oracle_22;
}
16 changes: 16 additions & 0 deletions pkgs/development/compilers/graalvm/graalvm-oracle/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
lib,
stdenv,
fetchurl,
graalvmPackages,
useMusl ? false,
version ? "22",
}:

graalvmPackages.buildGraalvm {
inherit useMusl version;
src = fetchurl (import ./hashes.nix).${version}.${stdenv.system};
meta.platforms = builtins.attrNames (import ./hashes.nix).${version};
meta.license = lib.licenses.unfree;
pname = "graalvm-oracle";
}
38 changes: 38 additions & 0 deletions pkgs/development/compilers/graalvm/graalvm-oracle/hashes.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"22" = {
"aarch64-linux" = {
hash = "sha256-E0Fm6mFB7o39pu7JVWOoXT9BdPWiSXBx2hPvlruD5ls=";
url = "https://download.oracle.com/graalvm/22/archive/graalvm-jdk-22.0.1_linux-aarch64_bin.tar.gz";
};
"x86_64-linux" = {
hash = "sha256-1YPNsBygI6N+7UXZ0YS2i3qNf1C1jd4TaQQfKUw09KM=";
url = "https://download.oracle.com/graalvm/22/archive/graalvm-jdk-22.0.1_linux-x64_bin.tar.gz";
};
"x86_64-darwin" = {
hash = "sha256-waR39L44Ew8wznRc67tYD3HGFZ2UUD4+ELerWnxNpms=";
url = "https://download.oracle.com/graalvm/22/archive/graalvm-jdk-22.0.1_macos-x64_bin.tar.gz";
};
"aarch64-darwin" = {
hash = "sha256-dzUVPih81jopuxAx8sAYdwonNOXHyyirUUOhvStK1F8=";
url = "https://download.oracle.com/graalvm/22/archive/graalvm-jdk-22.0.1_macos-aarch64_bin.tar.gz";
};
};
"17" = {
"aarch64-linux" = {
hash = "sha256-0J/XaXGzNyBgxrW1HgUvtBCPPRfAvzwOx67p/QcY4u0=";
url = "https://download.oracle.com/graalvm/17/archive/graalvm-jdk-17.0.11_linux-aarch64_bin.tar.gz";
};
"x86_64-linux" = {
hash = "sha256-t0GHR7MGSZDSAGeX7bsI1ziugaP4euRcJq+covDBUYw=";
url = "https://download.oracle.com/graalvm/17/archive/graalvm-jdk-17.0.11_linux-x64_bin.tar.gz";
};
"x86_64-darwin" = {
hash = "sha256-q9b6I5hSVt67gkYzUtsJDSi4bPEkzpkoeC5ZyxfqJRc=";
url = "https://download.oracle.com/graalvm/17/archive/graalvm-jdk-17.0.11_macos-x64_bin.tar.gz";
};
"aarch64-darwin" = {
hash = "sha256-o4BGCfnD25AVYwG1Ol+2eDVCgiB+mk4I1JBIjyETK6s=";
url = "https://download.oracle.com/graalvm/17/archive/graalvm-jdk-17.0.11_macos-aarch64_bin.tar.gz";
};
};
}
Loading