From 4e51b4a5cbff4beaf0b88ed860ce675cd35b4cf2 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Wed, 8 Feb 2023 21:26:19 +0000 Subject: [PATCH] graalvm*-ce: refactor derivation to be stand-alone First step to separate the main GraalVM derivation and each of its products in separate derivations, making them more composable. --- .../community-edition/buildGraalvm.nix | 132 ++++++++++++++++++ .../graalvm/community-edition/default.nix | 78 ++--------- .../graalvm11-ce-sources.json | 8 +- .../graalvm17-ce-sources.json | 8 +- pkgs/top-level/all-packages.nix | 4 +- 5 files changed, 153 insertions(+), 77 deletions(-) create mode 100644 pkgs/development/compilers/graalvm/community-edition/buildGraalvm.nix diff --git a/pkgs/development/compilers/graalvm/community-edition/buildGraalvm.nix b/pkgs/development/compilers/graalvm/community-edition/buildGraalvm.nix new file mode 100644 index 000000000000..9161f21c8559 --- /dev/null +++ b/pkgs/development/compilers/graalvm/community-edition/buildGraalvm.nix @@ -0,0 +1,132 @@ +{ lib +, stdenv +, alsa-lib +, autoPatchelfHook +, cairo +, cups +, fontconfig +, glib +, gtk3 +, gtkSupport ? stdenv.isLinux +, makeWrapper +, unzip +, xorg +, zlib +}: +{ javaVersion +, meta ? { } +, ... } @ args: + +let + runtimeLibraryPath = lib.makeLibraryPath + ([ cups ] ++ lib.optionals gtkSupport [ cairo glib gtk3 ]); +in +stdenv.mkDerivation (args // { + pname = "graalvm${javaVersion}-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; + + buildInputs = [ + 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 + zlib + ]; + + postInstall = '' + # jni.h expects jni_md.h to be in the header search path. + ln -s $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 + ''; + + postFixup = lib.optionalString (stdenv.isLinux) '' + # 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}" + done + ''; + + doInstallCheck = true; + + installCheckPhase = '' + runHook preInstallCheck + + 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' + + runHook postInstallCheck + ''; + + meta = with lib; ({ + inherit platforms; + 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; [ + bandresen + hlolli + glittershark + babariviere + ericdallo + thiagokokada + ]; + } // meta); +}) diff --git a/pkgs/development/compilers/graalvm/community-edition/default.nix b/pkgs/development/compilers/graalvm/community-edition/default.nix index 17ecd5060ba2..3c2e7c5e41c7 100644 --- a/pkgs/development/compilers/graalvm/community-edition/default.nix +++ b/pkgs/development/compilers/graalvm/community-edition/default.nix @@ -1,75 +1,21 @@ -{ callPackage, Foundation }: -/* - Add new graal versions and products here and then see update.nix on how to - generate the sources. -*/ +{ stdenv, callPackage, fetchurl }: let - mkGraal = opts: callPackage (import ./mkGraal.nix opts) { - inherit Foundation; - }; - - /* - Looks a bit ugly but makes version update in the update script using sed - much easier - - Don't change these values! They will be updated by the update script, see ./update.nix. - */ - graalvm11-ce-release-version = "22.3.0"; - graalvm17-ce-release-version = "22.3.0"; - - products = [ - "graalvm-ce" - "native-image-installable-svm" - ]; - + buildGraalvm = callPackage (import ./buildGraalvm.nix) { }; + sources = javaVersion: builtins.fromJSON (builtins.readFile (./. + "/graalvm${javaVersion}-ce-sources.json")); in -{ - inherit mkGraal; - - graalvm11-ce = mkGraal rec { - config = { - x86_64-darwin = { - inherit products; - arch = "darwin-amd64"; - }; - x86_64-linux = { - inherit products; - arch = "linux-amd64"; - }; - aarch64-darwin = { - inherit products; - arch = "darwin-aarch64"; - }; - aarch64-linux = { - inherit products; - arch = "linux-aarch64"; - }; - }; - defaultVersion = graalvm11-ce-release-version; +rec { + graalvm11-ce = buildGraalvm rec { + version = "22.3.0"; javaVersion = "11"; + src = fetchurl (sources javaVersion).${stdenv.system}.${"graalvm-ce|java${javaVersion}|${version}"}; + meta.platforms = builtins.attrNames (sources javaVersion); }; - graalvm17-ce = mkGraal rec { - config = { - x86_64-darwin = { - inherit products; - arch = "darwin-amd64"; - }; - x86_64-linux = { - inherit products; - arch = "linux-amd64"; - }; - aarch64-darwin = { - inherit products; - arch = "darwin-aarch64"; - }; - aarch64-linux = { - inherit products; - arch = "linux-aarch64"; - }; - }; - defaultVersion = graalvm17-ce-release-version; + graalvm17-ce = buildGraalvm rec { + version = "22.3.0"; javaVersion = "17"; + src = fetchurl (sources javaVersion).${stdenv.system}.${"graalvm-ce|java${javaVersion}|${version}"}; + meta.platforms = builtins.attrNames (sources javaVersion); }; } diff --git a/pkgs/development/compilers/graalvm/community-edition/graalvm11-ce-sources.json b/pkgs/development/compilers/graalvm/community-edition/graalvm11-ce-sources.json index c9145e9654f8..705750cfe7f0 100644 --- a/pkgs/development/compilers/graalvm/community-edition/graalvm11-ce-sources.json +++ b/pkgs/development/compilers/graalvm/community-edition/graalvm11-ce-sources.json @@ -1,5 +1,5 @@ { - "darwin-aarch64": { + "aarch64-darwin": { "graalvm-ce|java11|22.3.0": { "sha256": "c9657e902c2ba674931c3cf233a38c4de3d5186ae5d70452f9df75ac0c4cacff", "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.0/graalvm-ce-java11-darwin-aarch64-22.3.0.tar.gz" @@ -9,7 +9,7 @@ "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.0/native-image-installable-svm-java11-darwin-aarch64-22.3.0.jar" } }, - "darwin-amd64": { + "x86_64-darwin": { "graalvm-ce|java11|22.3.0": { "sha256": "b8b39d6a3e3a9ed6348c2776ff071fc64ca90f98999ee846e6ca7e5fdc746a8b", "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.0/graalvm-ce-java11-darwin-amd64-22.3.0.tar.gz" @@ -19,7 +19,7 @@ "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.0/native-image-installable-svm-java11-darwin-amd64-22.3.0.jar" } }, - "linux-aarch64": { + "aarch64-linux": { "graalvm-ce|java11|22.3.0": { "sha256": "c6646149dad486a0b02c5fc10649786240f275efda65aa14a25d01d2f5bafe15", "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.0/graalvm-ce-java11-linux-aarch64-22.3.0.tar.gz" @@ -29,7 +29,7 @@ "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.0/native-image-installable-svm-java11-linux-aarch64-22.3.0.jar" } }, - "linux-amd64": { + "x86_64-linux": { "graalvm-ce|java11|22.3.0": { "sha256": "d4200bcc43e5ad4e6949c1b1edc1e59f63066e3a2280d5bd82d0c9b1d67c3f2c", "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.0/graalvm-ce-java11-linux-amd64-22.3.0.tar.gz" diff --git a/pkgs/development/compilers/graalvm/community-edition/graalvm17-ce-sources.json b/pkgs/development/compilers/graalvm/community-edition/graalvm17-ce-sources.json index dc2da450b699..93f598a66598 100644 --- a/pkgs/development/compilers/graalvm/community-edition/graalvm17-ce-sources.json +++ b/pkgs/development/compilers/graalvm/community-edition/graalvm17-ce-sources.json @@ -1,5 +1,5 @@ { - "darwin-aarch64": { + "aarch64-darwin": { "graalvm-ce|java17|22.3.0": { "sha256": "dfc0c8998b8d00fcca87ef1c866c6e4985fd20b0beba3021f9677f9b166dfaf8", "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.0/graalvm-ce-java17-darwin-aarch64-22.3.0.tar.gz" @@ -9,7 +9,7 @@ "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.0/native-image-installable-svm-java17-darwin-aarch64-22.3.0.jar" } }, - "darwin-amd64": { + "x86_64-darwin": { "graalvm-ce|java17|22.3.0": { "sha256": "422cd6abecfb8b40238460c09c42c5a018cb92fab4165de9691be2e3c3d0e8d1", "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.0/graalvm-ce-java17-darwin-amd64-22.3.0.tar.gz" @@ -19,7 +19,7 @@ "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.0/native-image-installable-svm-java17-darwin-amd64-22.3.0.jar" } }, - "linux-aarch64": { + "aarch64-linux": { "graalvm-ce|java17|22.3.0": { "sha256": "e27249d9eef4504deb005cf14c6a028aad1adfa37209e12e9d7407710c08ed90", "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.0/graalvm-ce-java17-linux-aarch64-22.3.0.tar.gz" @@ -29,7 +29,7 @@ "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.0/native-image-installable-svm-java17-linux-aarch64-22.3.0.jar" } }, - "linux-amd64": { + "x86_64-linux": { "graalvm-ce|java17|22.3.0": { "sha256": "3473d8b3b1bc682e95adfb3ac1d9a59b51b0f43e2b752f2a5b550e4ebfa2fd17", "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.0/graalvm-ce-java17-linux-amd64-22.3.0.tar.gz" diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 24181c424147..b997e0662649 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -14985,9 +14985,7 @@ with pkgs; openjdk_headless = jdk_headless; graalvmCEPackages = - recurseIntoAttrs (callPackage ../development/compilers/graalvm/community-edition { - inherit (darwin.apple_sdk.frameworks) Foundation; - }); + recurseIntoAttrs (callPackage ../development/compilers/graalvm/community-edition { }); graalvm11-ce = graalvmCEPackages.graalvm11-ce; graalvm17-ce = graalvmCEPackages.graalvm17-ce; buildGraalvmNativeImage = callPackage ../build-support/build-graalvm-native-image {