about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/compilers/graalvm/community-edition/repository.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/compilers/graalvm/community-edition/repository.nix')
-rw-r--r--nixpkgs/pkgs/development/compilers/graalvm/community-edition/repository.nix195
1 files changed, 119 insertions, 76 deletions
diff --git a/nixpkgs/pkgs/development/compilers/graalvm/community-edition/repository.nix b/nixpkgs/pkgs/development/compilers/graalvm/community-edition/repository.nix
index 50a3b53c579c..5b3cdf75bc5b 100644
--- a/nixpkgs/pkgs/development/compilers/graalvm/community-edition/repository.nix
+++ b/nixpkgs/pkgs/development/compilers/graalvm/community-edition/repository.nix
@@ -10,17 +10,26 @@
 , gtkSupport ? true, cairo, glib, gtk3 }:
 
 let
-  platform = if stdenv.isDarwin then "darwin-amd64" else "linux-amd64";
+  platform = {
+    aarch64-linux = "linux-aarch64";
+    x86_64-linux = "linux-amd64";
+    x86_64-darwin = "darwin-amd64";
+  }.${stdenv.system} or (throw "Unsupported system: ${stdenv.system}");
+
   runtimeDependencies = [ cups ]
     ++ lib.optionals gtkSupport [ cairo glib gtk3 ];
+
   runtimeLibraryPath = lib.makeLibraryPath runtimeDependencies;
+
   javaVersionPlatform = "${javaVersion}-${platform}";
+
   graalvmXXX-ce = stdenv.mkDerivation rec {
     name = "graalvm${javaVersion}-ce";
     srcs = [
       (fetchurl {
         sha256 = {
           "8-linux-amd64" = "01gyxjmfp7wpcyn7x8b184fn0lp3xryfw619bqch120pzvr6z88f";
+          "11-linux-aarch64" = "sha256-u9841eaHH347JHCrm5u3YGZ9RSTuKiDq368TY2otAYw=";
           "11-linux-amd64" = "0w7lhvxm4nggqdcl4xrhdd3y6dqw9jhyca9adjkp508n4lqf1lxv";
           "11-darwin-amd64" = "0dnahicdl0vhrbiml9z9nbb7k75hbsjj8rs246i1lwril12dqb7n";
         }.${javaVersionPlatform};
@@ -29,6 +38,7 @@ let
       (fetchurl {
         sha256 = {
           "8-linux-amd64" = "1jlvrxdlbsmlk3ia43h9m29kmmdn83h6zdlnf8qb7bm38c84nhsc";
+          "11-linux-aarch64" = "sha256-7W5gkhj2kON2ocrGpyH/OL/phOyHkjNDId2CtyUAEWY=";
           "11-linux-amd64" = "1ybd7a6ii6582skr0nkxx7bccsa7gkg0yriql2h1lcz0rfzcdi3g";
           "11-darwin-amd64" = "1jdy845vanmz05zx5b9227gb1msh9wdrz2kf3fx9z54ssd9qgdhm";
         }.${javaVersionPlatform};
@@ -37,6 +47,7 @@ let
       (fetchurl {
         sha256 = {
           "8-linux-amd64" = "18ip0ay06q1pryqs8ja988mvk9vw475c0nfjcznnsd1zp296p6jc";
+          "11-linux-aarch64" = "sha256-i9ysgqbI52PiXofZQ5AnPSzs2TeR8An5CIYzcwhx28o=";
           "11-linux-amd64" = "1jszz97mkqavxzyhx5jxhi43kqjxk9c36j5l5hy3kn8sdfmbplm4";
           "11-darwin-amd64" = "1767ryhv2cn5anlys63ysax1p8ag79bykac1xfrjfan8yv6d8ybl";
         }.${javaVersionPlatform};
@@ -44,20 +55,23 @@ let
       })
       (fetchurl {
         sha256 = {
-          "8-linux-amd64" = "0il15438qnikqsxdsl7fcdg0c8zs3cbm4ry7pys7fxxr1ckd8szq";
-          "11-linux-amd64" = "07759sr8nijvqm8aqn69x9vq7lyppns7a6l6xribv43jvfmwpfkl";
-          "11-darwin-amd64" = "01l3as8dihc7xqy5sdkrpxmpzrqbcvvg84m2s6j1j8y2db1khf2s";
-        }.${javaVersionPlatform};
-        url = "https://github.com/graalvm/graalpython/releases/download/vm-${version}/python-installable-svm-java${javaVersionPlatform}-${version}.jar";
-      })
-      (fetchurl {
-        sha256 = {
           "8-linux-amd64" = "08s36rjy5irg25b7lqx0m4v2wpywin3cqyhdrywhvq14f7zshsd5";
+          "11-linux-aarch64" = "sha256-Lkc/mq1w18+PQ5McvLGyQBSOz/TMSUgwioRZ0Dtyhm4=";
           "11-linux-amd64" = "1ybjaknmbsdg8qzb986x39fq0h7fyiymdcigc7y86swk8dd916hv";
           "11-darwin-amd64" = "02dwlb62kqr4rjjmvkhn2xk9l1p47ahg9xyyfkw7im1jwlqmqnzf";
         }.${javaVersionPlatform};
         url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${version}/wasm-installable-svm-java${javaVersionPlatform}-${version}.jar";
       })
+    ] ++ lib.optionals (platform == "amd64") [
+      # graalpython is not available on aarch64 platforms yet
+      (fetchurl {
+        sha256 = {
+          "8-linux-amd64" = "0il15438qnikqsxdsl7fcdg0c8zs3cbm4ry7pys7fxxr1ckd8szq";
+          "11-linux-amd64" = "07759sr8nijvqm8aqn69x9vq7lyppns7a6l6xribv43jvfmwpfkl";
+          "11-darwin-amd64" = "01l3as8dihc7xqy5sdkrpxmpzrqbcvvg84m2s6j1j8y2db1khf2s";
+        }.${javaVersionPlatform};
+        url = "https://github.com/graalvm/graalpython/releases/download/vm-${version}/python-installable-svm-java${javaVersionPlatform}-${version}.jar";
+      })
     ];
 
     buildInputs = lib.optionals stdenv.isLinux [
@@ -124,43 +138,64 @@ let
          exit 1
       fi
 
-      unpack_jar ''${arr[1]}
-      unpack_jar ''${arr[2]}
-      unpack_jar ''${arr[3]}
-      unpack_jar ''${arr[4]}
+      for jar in "''${arr[@]:1}"; do
+        unpack_jar "$jar"
+      done
     '';
 
-    installPhase = {
-      "8-linux-amd64" = ''
+    outputs = [ "out" "lib" ];
+
+    installPhase = let
+      nativePRNGWorkaround = path: ''
         # BUG workaround http://mail.openjdk.java.net/pipermail/graal-dev/2017-December/005141.html
-        substituteInPlace $out/jre/lib/security/java.security \
+        substituteInPlace ${path} \
           --replace file:/dev/random    file:/dev/./urandom \
           --replace NativePRNGBlocking  SHA1PRNG
-
+      '';
+      copyClibrariesToOut = basepath: ''
         # provide libraries needed for static compilation
         for f in ${glibc}/lib/* ${glibc.static}/lib/* ${zlib.static}/lib/*; do
-          ln -s $f $out/jre/lib/svm/clibraries/${platform}/$(basename $f)
+          ln -s $f ${basepath}/${platform}/$(basename $f)
+        done
+      '';
+      copyClibrariesToLib = ''
+        # add those libraries to $lib output too, so we can use them with
+        # `native-image -H:CLibraryPath=''${graalvm11-ce.lib}/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)
         done
+      '';
+    in {
+      "8-linux-amd64" = ''
+        ${nativePRNGWorkaround "$out/jre/lib/security/java.security"}
+
+        ${copyClibrariesToOut "$out/jre/lib/svm/clibraries"}
+
+        ${copyClibrariesToLib}
 
         # allow using external truffle-api.jar and languages not included in the distrubution
         rm $out/jre/lib/jvmci/parentClassLoader.classpath
       '';
       "11-linux-amd64" = ''
-        # BUG workaround http://mail.openjdk.java.net/pipermail/graal-dev/2017-December/005141.html
-        substituteInPlace $out/conf/security/java.security \
-          --replace file:/dev/random    file:/dev/./urandom \
-          --replace NativePRNGBlocking  SHA1PRNG
+        ${nativePRNGWorkaround "$out/conf/security/java.security"}
 
-        # provide libraries needed for static compilation
-        for f in ${glibc}/lib/* ${glibc.static}/lib/* ${zlib.static}/lib/*; do
-          ln -s $f $out/lib/svm/clibraries/${platform}/$(basename $f)
-        done
+        ${copyClibrariesToOut "$out/lib/svm/clibraries"}
+
+        ${copyClibrariesToLib}
+      '';
+      "11-linux-aarch64" = ''
+        ${nativePRNGWorkaround "$out/conf/security/java.security"}
+
+        ${copyClibrariesToOut "$out/lib/svm/clibraries"}
+
+        ${copyClibrariesToLib}
       '';
       "11-darwin-amd64" = ''
-        # BUG workaround http://mail.openjdk.java.net/pipermail/graal-dev/2017-December/005141.html
-        substituteInPlace $out/conf/security/java.security \
-          --replace file:/dev/random    file:/dev/./urandom \
-          --replace NativePRNGBlocking  SHA1PRNG
+        # create empty $lib/lib to avoid breaking builds
+        mkdir -p $lib/lib
+        ${nativePRNGWorkaround "$out/conf/security/java.security"}
       '';
     }.${javaVersionPlatform} + ''
       # jni.h expects jni_md.h to be in the header search path.
@@ -203,53 +238,60 @@ let
 
     doInstallCheck = true;
     installCheckPhase = ''
-        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
-        $out/bin/javac HelloWorld.java
-
-        # run on JVM with Graal Compiler
-        $out/bin/java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler HelloWorld | fgrep 'Hello World'
-
-        # Ahead-Of-Time compilation
-        $out/bin/native-image -H:-CheckToolchain -H:+ReportExceptionStackTraces --no-server HelloWorld
-        ./helloworld | fgrep 'Hello World'
-
-        ${
-          lib.optionalString stdenv.isLinux ''
-            # Ahead-Of-Time compilation with --static
-            # --static flag doesn't work for darwin
-            $out/bin/native-image --no-server --static HelloWorld
-            ./helloworld | fgrep 'Hello World'
-          ''
-        }
-
-        echo "Testing interpreted languages"
-        $out/bin/graalpython -c 'print(1 + 1)'
-        $out/bin/ruby -e 'puts(1 + 1)'
-
-        echo '1 + 1' | $out/bin/graalpython
-
-        ${
-          lib.optionalString stdenv.isLinux ''
-            # TODO: `irb` on MacOS gives an error saying "Could not find OpenSSL
-            # headers, install via Homebrew or MacPorts or set OPENSSL_PREFIX", even
-            # though `openssl` is in `propagatedBuildInputs`. For more details see:
-            # https://github.com/NixOS/nixpkgs/pull/105815
-            echo '1 + 1' | $out/bin/irb
-          ''
-        }
-
-      ${lib.optionalString (javaVersion == "11" && stdenv.isLinux) ''
-        # Doesn't work on MacOS, we have this error: "Launching JShell execution engine threw: Operation not permitted (Bind failed)"
-        echo '1 + 1' | $out/bin/jshell
-      ''}'';
+          }
+        ''
+      } > HelloWorld.java
+      $out/bin/javac HelloWorld.java
+
+      # run on JVM with Graal Compiler
+      $out/bin/java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler HelloWorld | fgrep 'Hello World'
+
+      # Ahead-Of-Time compilation
+      $out/bin/native-image -H:-CheckToolchain -H:+ReportExceptionStackTraces --no-server HelloWorld
+      ./helloworld | fgrep 'Hello World'
+
+      ${
+        lib.optionalString stdenv.isLinux ''
+          # Ahead-Of-Time compilation with --static
+          # --static flag doesn't work for darwin
+          $out/bin/native-image --no-server --static HelloWorld
+          ./helloworld | fgrep 'Hello World'
+        ''
+      }
+
+      ${
+        lib.optionalString (platform == "amd64") ''
+          echo "Testing interpreted languages"
+          $out/bin/graalpython -c 'print(1 + 1)'
+          $out/bin/ruby -e 'puts(1 + 1)'
+
+          echo '1 + 1' | $out/bin/graalpython
+        ''
+      }
+
+      ${# TODO: `irb` on MacOS gives an error saying "Could not find OpenSSL
+        # headers, install via Homebrew or MacPorts or set OPENSSL_PREFIX", even
+        # though `openssl` is in `propagatedBuildInputs`. For more details see:
+        # https://github.com/NixOS/nixpkgs/pull/105815
+        # TODO: "truffleruby: an internal exception escaped out of the interpreter"
+        # error on linux-aarch64
+        lib.optionalString (platform == "linux-amd64") ''
+          echo '1 + 1' | $out/bin/irb
+        ''
+      }
+
+      ${# TODO: Doesn't work on MacOS, we have this error:
+        # "Launching JShell execution engine threw: Operation not permitted (Bind failed)"
+        lib.optionalString (javaVersion == "11" && stdenv.isLinux) ''
+          echo '1 + 1' | $out/bin/jshell
+        ''
+      }'';
 
     passthru.home = graalvmXXX-ce;
 
@@ -264,6 +306,7 @@ let
         glittershark
         babariviere
         ericdallo
+        thiagokokada
       ];
       platforms = platforms;
     };