diff --git a/pkgs/development/compilers/graalvm/community-edition/default.nix b/pkgs/development/compilers/graalvm/community-edition/default.nix index f53e9a03896..6f42bfcc453 100644 --- a/pkgs/development/compilers/graalvm/community-edition/default.nix +++ b/pkgs/development/compilers/graalvm/community-edition/default.nix @@ -1,17 +1,60 @@ -{ lib, callPackage, Foundation }: +{ callPackage, Foundation }: +/* + Add new graal versions and products here and then see update.nix on how to + generate the sources. +*/ 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 + */ + graalvm11-ce-release-version = "22.0.0.2"; + graalvm17-ce-release-version = "22.0.0.2"; + graalvm11-ce-dev-version = "22.2.0-dev-20220401_1942"; + graalvm17-ce-dev-version = "22.2.0-dev-20220401_1942"; + + commonProducts = [ + "graalvm-ce" + "native-image-installable-svm" + "ruby-installable-svm" + "wasm-installable-svm" + ]; + in { inherit mkGraal; graalvm11-ce = mkGraal rec { - version = "22.0.0.2"; + config = { + x86_64-darwin = { + arch = "darwin-amd64"; + products = commonProducts ++ [ "python-installable-svm" ]; + }; + x86_64-linux = { + arch = "linux-amd64"; + products = commonProducts ++ [ "python-installable-svm" ]; + }; + aarch64-darwin = { + arch = "darwin-aarch64"; + products = [ + "graalvm-ce" + "native-image-installable-svm" + ]; + version = graalvm11-ce-dev-version; + }; + aarch64-linux = { + arch = "linux-aarch64"; + products = commonProducts; + }; + }; + defaultVersion = graalvm11-ce-release-version; javaVersion = "11"; - platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ]; + platforms = builtins.attrNames config; }; # TODO: fix aarch64-linux, failing during Native Image compilation @@ -20,8 +63,26 @@ in # directory"/tmp/SVM-4194439592488143713"): error=0, Failed to exec spawn # helper: pid: 19865, exit value: 1" graalvm17-ce = mkGraal rec { - version = "22.0.0.2"; + config = { + x86_64-darwin = { + arch = "darwin-amd64"; + products = commonProducts ++ [ "python-installable-svm" ]; + }; + x86_64-linux = { + arch = "linux-amd64"; + products = commonProducts ++ [ "python-installable-svm" ]; + }; + aarch64-darwin = { + arch = "darwin-aarch64"; + products = [ + "graalvm-ce" + "native-image-installable-svm" + ]; + version = graalvm17-ce-dev-version; + }; + }; + defaultVersion = graalvm17-ce-release-version; javaVersion = "17"; - platforms = [ "x86_64-linux" "x86_64-darwin" ]; + platforms = builtins.attrNames config; }; } diff --git a/pkgs/development/compilers/graalvm/community-edition/graalvm11-ce-sources.json b/pkgs/development/compilers/graalvm/community-edition/graalvm11-ce-sources.json new file mode 100644 index 00000000000..070c783d033 --- /dev/null +++ b/pkgs/development/compilers/graalvm/community-edition/graalvm11-ce-sources.json @@ -0,0 +1,74 @@ +{ + "darwin-aarch64": { + "graalvm-ce|java11|22.2.0-dev-20220401_1942": { + "sha256": "c83dee740ae148486598759e44a717b09d8124e4ea50f9da1e7d49d016572b89", + "url": "https://github.com/graalvm/graalvm-ce-dev-builds/releases/download/22.2.0-dev-20220401_1942/graalvm-ce-java11-darwin-aarch64-dev.tar.gz" + }, + "native-image-installable-svm|java11|22.2.0-dev-20220401_1942": { + "sha256": "661311ae26bfd6c46360b9e65aabe9361dc5cd05878a404343adf16925ae78fa", + "url": "https://github.com/graalvm/graalvm-ce-dev-builds/releases/download/22.2.0-dev-20220401_1942/native-image-installable-svm-java11-darwin-aarch64-dev.jar" + } + }, + "darwin-amd64": { + "graalvm-ce|java11|22.0.0.2": { + "sha256": "8280159b8a66c51a839c8079d885928a7f759d5da0632f3af7300df2b63a6323", + "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/graalvm-ce-java11-darwin-amd64-22.0.0.2.tar.gz" + }, + "native-image-installable-svm|java11|22.0.0.2": { + "sha256": "03c27de6cce61ee8073e89252212457f3fbac2c0bc9bfa4acbff12176476c176", + "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/native-image-installable-svm-java11-darwin-amd64-22.0.0.2.jar" + }, + "python-installable-svm|java11|22.0.0.2": { + "sha256": "67ee2f1cc10b0189e359344c31b22f423e636ff4ec2dd7d9437c3eb0ef54e601", + "url": "https://github.com/graalvm/graalpython/releases/download/vm-22.0.0.2/python-installable-svm-java11-darwin-amd64-22.0.0.2.jar" + }, + "ruby-installable-svm|java11|22.0.0.2": { + "sha256": "a25c0099a21ca1ca9904dd3acdeef509f67a13b96c6135b6de199e9805330df9", + "url": "https://github.com/oracle/truffleruby/releases/download/vm-22.0.0.2/ruby-installable-svm-java11-darwin-amd64-22.0.0.2.jar" + }, + "wasm-installable-svm|java11|22.0.0.2": { + "sha256": "d74c210a8a87b8eb0c4d18a65fde6f2c03ebc94d9bf7ed87bbb9cacc460006d7", + "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/wasm-installable-svm-java11-darwin-amd64-22.0.0.2.jar" + } + }, + "linux-aarch64": { + "graalvm-ce|java11|22.0.0.2": { + "sha256": "1cc0263d95f642dada4e290dca7f49c0456cefa7b690b67e3e5c159b537b2c58", + "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/graalvm-ce-java11-linux-aarch64-22.0.0.2.tar.gz" + }, + "native-image-installable-svm|java11|22.0.0.2": { + "sha256": "51d41e890a5aabf8e7b9d4f4e0f88206ee70a261f7dbb0315d51770ab8f3009e", + "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/native-image-installable-svm-java11-linux-aarch64-22.0.0.2.jar" + }, + "ruby-installable-svm|java11|22.0.0.2": { + "sha256": "e0fb582a9c6b4167e7dc267c58ca1968bd1c471b3bc5c56061b436f175486d80", + "url": "https://github.com/oracle/truffleruby/releases/download/vm-22.0.0.2/ruby-installable-svm-java11-linux-aarch64-22.0.0.2.jar" + }, + "wasm-installable-svm|java11|22.0.0.2": { + "sha256": "a48470ae391c75cb2805b7fe27cde2c925c0466fdbc0623dfbb67c54f19dbf8c", + "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/wasm-installable-svm-java11-linux-aarch64-22.0.0.2.jar" + } + }, + "linux-amd64": { + "graalvm-ce|java11|22.0.0.2": { + "sha256": "bc86083bb7e2778c7e4fe4f55d74790e42255b96f7806a7fefa51d06f3bc7103", + "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/graalvm-ce-java11-linux-amd64-22.0.0.2.tar.gz" + }, + "native-image-installable-svm|java11|22.0.0.2": { + "sha256": "8504a3441f5b28b8fd625f676674a9216f082ae63a4e30d43930c80f9672e71d", + "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/native-image-installable-svm-java11-linux-amd64-22.0.0.2.jar" + }, + "python-installable-svm|java11|22.0.0.2": { + "sha256": "2f01d1bbc2ed2c507952d8ceaab1cb2176fc67e2d8c4b3bf5864e8d930c60c55", + "url": "https://github.com/graalvm/graalpython/releases/download/vm-22.0.0.2/python-installable-svm-java11-linux-amd64-22.0.0.2.jar" + }, + "ruby-installable-svm|java11|22.0.0.2": { + "sha256": "e90f7ebc13b6c1f8e3f98881bb4fe2336870744174b2b6d41dc672d15f0b9a40", + "url": "https://github.com/oracle/truffleruby/releases/download/vm-22.0.0.2/ruby-installable-svm-java11-linux-amd64-22.0.0.2.jar" + }, + "wasm-installable-svm|java11|22.0.0.2": { + "sha256": "c0fdfc40374b70f6f1597dd21660535c813dc5c3948c8a6ea9559a20f4d3fb5e", + "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/wasm-installable-svm-java11-linux-amd64-22.0.0.2.jar" + } + } +} diff --git a/pkgs/development/compilers/graalvm/community-edition/graalvm17-ce-sources.json b/pkgs/development/compilers/graalvm/community-edition/graalvm17-ce-sources.json new file mode 100644 index 00000000000..65e28b8b11c --- /dev/null +++ b/pkgs/development/compilers/graalvm/community-edition/graalvm17-ce-sources.json @@ -0,0 +1,56 @@ +{ + "darwin-aarch64": { + "graalvm-ce|java17|22.2.0-dev-20220401_1942": { + "sha256": "f0409c59adbce62da7be46ab7d0e01abe5c080ef97d0b555e6c773f94dbfdecf", + "url": "https://github.com/graalvm/graalvm-ce-dev-builds/releases/download/22.2.0-dev-20220401_1942/graalvm-ce-java17-darwin-aarch64-dev.tar.gz" + }, + "native-image-installable-svm|java17|22.2.0-dev-20220401_1942": { + "sha256": "3770dc4810d7ebae8f9ca2212e91112629096a964d3caea1667b0aaf5f70c1e0", + "url": "https://github.com/graalvm/graalvm-ce-dev-builds/releases/download/22.2.0-dev-20220401_1942/native-image-installable-svm-java17-darwin-aarch64-dev.jar" + } + }, + "darwin-amd64": { + "graalvm-ce|java17|22.0.0.2": { + "sha256": "d54af9d1f4d0d351827395a714ed84d2489b023b74a9c13a431cc9d31d1e8f9a", + "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/graalvm-ce-java17-darwin-amd64-22.0.0.2.tar.gz" + }, + "native-image-installable-svm|java17|22.0.0.2": { + "sha256": "007fa742cd139d447f83d776b6d78e717c9df11d56a61061a5937547c20028b7", + "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/native-image-installable-svm-java17-darwin-amd64-22.0.0.2.jar" + }, + "python-installable-svm|java17|22.0.0.2": { + "sha256": "af887b0304d5ec98fab1be2cd1fca2aa3b10e84e823142a7f274560b1e0ea7c1", + "url": "https://github.com/graalvm/graalpython/releases/download/vm-22.0.0.2/python-installable-svm-java17-darwin-amd64-22.0.0.2.jar" + }, + "ruby-installable-svm|java17|22.0.0.2": { + "sha256": "fc5eb6f833136ae3fda61f46fe0af66a8454ca2f803ca35eaff7336521cb468d", + "url": "https://github.com/oracle/truffleruby/releases/download/vm-22.0.0.2/ruby-installable-svm-java17-darwin-amd64-22.0.0.2.jar" + }, + "wasm-installable-svm|java17|22.0.0.2": { + "sha256": "b76e6d872ce07ca9facd5b997dbb6e557ba72aa369ddd5f1664431bd11b98796", + "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/wasm-installable-svm-java17-darwin-amd64-22.0.0.2.jar" + } + }, + "linux-amd64": { + "graalvm-ce|java17|22.0.0.2": { + "sha256": "4f743e0ed3d974b7d619ca2ed6014554e8c12e5ebbb38b9bc9e820b182169bd4", + "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/graalvm-ce-java17-linux-amd64-22.0.0.2.tar.gz" + }, + "native-image-installable-svm|java17|22.0.0.2": { + "sha256": "8c25f650d58c2649c97061cb806dfaec9e685d5d2b80afc7cf72fe61d6891831", + "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/native-image-installable-svm-java17-linux-amd64-22.0.0.2.jar" + }, + "python-installable-svm|java17|22.0.0.2": { + "sha256": "b3b78a15bd29b4eaaf0f2607e21181ca2a5b41b38ba43a3ff2656c2f6effda8a", + "url": "https://github.com/graalvm/graalpython/releases/download/vm-22.0.0.2/python-installable-svm-java17-linux-amd64-22.0.0.2.jar" + }, + "ruby-installable-svm|java17|22.0.0.2": { + "sha256": "d86c9ad50cbed980fa69d69b2eccd47d31880d8c55553483f59ce9eda15628bd", + "url": "https://github.com/oracle/truffleruby/releases/download/vm-22.0.0.2/ruby-installable-svm-java17-linux-amd64-22.0.0.2.jar" + }, + "wasm-installable-svm|java17|22.0.0.2": { + "sha256": "7f7e51e4a24384b3dd960c12ab9b05b1fea58a0457d6b80e3797228fab93c0bd", + "url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/wasm-installable-svm-java17-linux-amd64-22.0.0.2.jar" + } + } +} diff --git a/pkgs/development/compilers/graalvm/community-edition/hashes.nix b/pkgs/development/compilers/graalvm/community-edition/hashes.nix deleted file mode 100644 index f21fdb25270..00000000000 --- a/pkgs/development/compilers/graalvm/community-edition/hashes.nix +++ /dev/null @@ -1,57 +0,0 @@ -# Generated by ./update.sh script -{ javaVersionPlatform, ... }: -[ - { - sha256 = { - "11-linux-aarch64" = "0n1cgd9rn5aw7rzbd45nlzpnqif095zwl3999vddlhpnjlyjdh0w"; - "17-linux-aarch64" = "1iw27igiyzzl43yfgid1h6h7hd0xnv0rfdkp4r7r8i51sa3q7my7"; - "11-linux-amd64" = "00vipkrhc7d5xxznm07pjrdjahhfg5s5vxg49xz8qxz2nwxhi1mw"; - "17-linux-amd64" = "1m4v2s1b2878r6dqpcxvbqpc3s2l8l0xcbna37bbfx6rsc73wx2g"; - "11-darwin-amd64" = "08v37avg439hywx2yqx0bnfpazwaja2xhyc0kj1imib6iadib042"; - "17-darwin-amd64" = "16lg3qfx7j8w8cxc3abl7c19nj6jhkni99wmff153lyhyk8zjjnm"; - }.${javaVersionPlatform} or null; - url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/graalvm-ce-java${javaVersionPlatform}-22.0.0.2.tar.gz"; - } - { - sha256 = { - "11-linux-aarch64" = "17h0yfw0lxsiblqv1nzpc6i71vh6hbwf1x6lp7kziass1a4ixm2i"; - "17-linux-aarch64" = "1nvm04smzbis1jy9znac2a4yf9ajqvvmadcf5ffr521rm784g2br"; - "11-linux-amd64" = "07g7fab0zj1h77a30kiswqm0hvr1m5s6crszcbyvha2v3x2a6145"; - "17-linux-amd64" = "0c8qi7b63zkjrz3sz01bbmfni7pcz9nq1jv1f34lj9lcsm8gc9cc"; - "11-darwin-amd64" = "0xn1frj1f4pzrd5gm6xwq31blgvz8l9249c97q3yh7p6rkk7vhh3"; - "17-darwin-amd64" = "1dr80314fxcklmhi19jn3pqrsz3iivbvcxnphdzl978krm1afzq0"; - }.${javaVersionPlatform} or null; - url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/native-image-installable-svm-java${javaVersionPlatform}-22.0.0.2.jar"; - } - { - sha256 = { - "11-linux-aarch64" = "103d91sz2dmlc5hcbi9v3d3irgb83755hz16vkknfhbbkhm5iyz0"; - "17-linux-aarch64" = "0vas98knpvpajmv8bkgcf0fh7n5fy361nd47002cpppg6hrp7k9q"; - "11-linux-amd64" = "0h4s1dgx2wn63pabdckl85s70s1kw97vp0c8z7izihdn2fy7w3z9"; - "17-linux-amd64" = "1g98ashyvscwyn1k8mamih6qhcbxsk62x6ynd7x81ndy1karlv6q"; - "11-darwin-amd64" = "1y8d6c2ri7hrvsv3aqbcp49pmxh9yppcsfnx0jcwm88wlach0p52"; - "17-darwin-amd64" = "13a6rchnaczpmxga6g405z55913ayq5gwihzlvyy6shk6gwbcppw"; - }.${javaVersionPlatform} or null; - url = "https://github.com/oracle/truffleruby/releases/download/vm-22.0.0.2/ruby-installable-svm-java${javaVersionPlatform}-22.0.0.2.jar"; - } - { - sha256 = { - "11-linux-aarch64" = "135zkpqm8z5nzcyn5h6vdx3c09f9wb6jgzmp0llcnx8w76p71154"; - "17-linux-aarch64" = "0pij3kh70lxrzmbzx8zw97f9nb0rr492l7x3n13wcr859cr8akas"; - "11-linux-amd64" = "0ppvsgs216jmm5p8m34lqg2kv0awadh1dlkxb7qzcw2b6x0grzf0"; - "17-linux-amd64" = "1gf0jfmqy8lp6w7bimjp0j5abzmi0ndsn4hcjvfv7123lbj52zkz"; - "11-darwin-amd64" = "1mq6013crjmrpf3yvxwv9p4yn0rcdzg5z9hq9l6fpf47i8522k6p"; - "17-darwin-amd64" = "15l7p48vsca4cvqxbpb9lcmafysmdsxpv6avrpxajz705j3nsvmp"; - }.${javaVersionPlatform} or null; - url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/wasm-installable-svm-java${javaVersionPlatform}-22.0.0.2.jar"; - } - { - sha256 = { - "11-linux-amd64" = "0m8cqqqdks34b2zv7i6qw9kzqxi1rfqsmknqa9wm0b7dqaxx209g"; - "17-linux-amd64" = "12nszxp2yv35y8zkm94bnd0mnanah48y41r61ypymd19plaqmdxk"; - "11-darwin-amd64" = "00g6akpv0gkw8gcxfbgcyipn6gj25yr32k1lb7iqj08bq4f2zvk7"; - "17-darwin-amd64" = "1hd71qg0nmklyakl4cc29vl10fxalbyd2b5yn7x9iv6m0h1pp25g"; - }.${javaVersionPlatform} or null; - url = "https://github.com/graalvm/graalpython/releases/download/vm-22.0.0.2/python-installable-svm-java${javaVersionPlatform}-22.0.0.2.jar"; - } -] diff --git a/pkgs/development/compilers/graalvm/community-edition/mkGraal.nix b/pkgs/development/compilers/graalvm/community-edition/mkGraal.nix index ee016e71d31..5b20890ced1 100644 --- a/pkgs/development/compilers/graalvm/community-edition/mkGraal.nix +++ b/pkgs/development/compilers/graalvm/community-edition/mkGraal.nix @@ -1,7 +1,7 @@ -{ version -, javaVersion +{ javaVersion +, defaultVersion , platforms -, hashes ? import ./hashes.nix +, config , useMusl ? false }: @@ -33,16 +33,19 @@ , cairo , glib , gtk3 +, writeShellScript +, jq +, gnused }: assert useMusl -> stdenv.isLinux; let - platform = { - aarch64-linux = "linux-aarch64"; - x86_64-linux = "linux-amd64"; - x86_64-darwin = "darwin-amd64"; - }.${stdenv.system} or (throw "Unsupported system: ${stdenv.system}"); + platform = config.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}"); + version = platform.version or defaultVersion; + name = "graalvm${javaVersion}-ce"; + sourcesFilename = "${name}-sources.json"; + sources = builtins.fromJSON (builtins.readFile (./. + "/${sourcesFilename}")); runtimeLibraryPath = lib.makeLibraryPath ([ cups ] ++ lib.optionals gtkSupport [ cairo glib gtk3 ]); @@ -56,21 +59,11 @@ let (writeShellScriptBin "${stdenv.system}-musl-gcc" ''${lib.getDev musl}/bin/musl-gcc "$@"'') ]); - javaVersionPlatform = "${javaVersion}-${platform}"; - graalvmXXX-ce = stdenv.mkDerivation rec { inherit version; - name = "graalvm${javaVersion}-ce"; - srcs = - let - # Some platforms doesn't have all GraalVM features - # e.g.: GraalPython on aarch64-linux - # When the platform doesn't have a feature, sha256 is null on hashes.nix - # To update hashes.nix file, run `./update.sh ` - maybeFetchUrl = url: if url.sha256 != null then (fetchurl url) else null; - in - (lib.remove null - (map maybeFetchUrl (hashes { inherit javaVersionPlatform; }))); + pname = name; + + srcs = map fetchurl (builtins.attrValues sources.${platform.arch}); buildInputs = lib.optionals stdenv.isLinux [ alsa-lib # libasound.so wanted by lib/libjsound.so @@ -86,7 +79,8 @@ let zlib ]; - nativeBuildInputs = [ unzip perl autoPatchelfHook makeWrapper ]; + nativeBuildInputs = [ unzip perl makeWrapper ] + ++ lib.optional stdenv.hostPlatform.isLinux autoPatchelfHook; unpackPhase = '' unpack_jar() { @@ -139,65 +133,40 @@ let outputs = [ "out" "lib" ]; - installPhase = - let - copyClibrariesToOut = basepath: '' - # provide libraries needed for static compilation - ${ - if useMusl then - "for f in ${musl.stdenv.cc.cc}/lib/* ${musl}/lib/* ${zlib.static}/lib/*; do" - else - "for f in ${glibc}/lib/* ${glibc.static}/lib/* ${zlib.static}/lib/*; do" - } - 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=''${lib.getLib graalvm11-ce}/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 - { - "11-linux-amd64" = '' - ${copyClibrariesToOut "$out/lib/svm/clibraries"} + 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. + ln -s $out/include/linux/*_md.h $out/include/ - ${copyClibrariesToLib} - ''; - "17-linux-amd64" = '' - ${copyClibrariesToOut "$out/lib/svm/clibraries"} + # 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 + ${ + lib.optionalString (stdenv.isLinux) '' + # provide libraries needed for static compilation + ${ + if useMusl then + "for f in ${musl.stdenv.cc.cc}/lib/* ${musl}/lib/* ${zlib.static}/lib/*; do" + else + "for f in ${glibc}/lib/* ${glibc.static}/lib/* ${zlib.static}/lib/*; do" + } + ln -s $f $out/lib/svm/clibraries/${platform.arch}/$(basename $f) + done - ${copyClibrariesToLib} - ''; - "11-linux-aarch64" = '' - ${copyClibrariesToOut "$out/lib/svm/clibraries"} - - ${copyClibrariesToLib} - ''; - "17-linux-aarch64" = '' - ${copyClibrariesToOut "$out/lib/svm/clibraries"} - - ${copyClibrariesToLib} - ''; - "11-darwin-amd64" = ""; - "17-darwin-amd64" = ""; - }.${javaVersionPlatform} + '' - # ensure that $lib/lib exists to avoid breaking builds + # add those libraries to $lib output too, so we can use them with + # `native-image -H:CLibraryPath=''${lib.getLib graalvmXX-ce}/lib ...` and reduce + # closure size by not depending on GraalVM $out (that is much bigger) mkdir -p $lib/lib - # 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 - if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi - EOF - ''; + for f in ${glibc}/lib/*; do + ln -s $f $lib/lib/$(basename $f) + done + '' + } + ''; dontStrip = true; @@ -281,7 +250,7 @@ let } ${ - lib.optionalString (platform != "linux-aarch64") '' + lib.optionalString (builtins.any (a: a == "python-installable-svm") platform.products) '' echo "Testing GraalPython" $out/bin/graalpython -c 'print(1 + 1)' echo '1 + 1' | $out/bin/graalpython @@ -289,10 +258,14 @@ let } echo "Testing TruffleRuby" + ${ + lib.optionalString (builtins.any (a: a == "ruby-installable-svm") platform.products) '' # Hide warnings about wrong locale export LANG=C export LC_ALL=C $out/bin/ruby -e 'puts(1 + 1)' + '' + } ${# FIXME: irb is broken in all platforms # TODO: `irb` on MacOS gives an error saying "Could not find OpenSSL # headers, install via Homebrew or MacPorts or set OPENSSL_PREFIX", even @@ -311,7 +284,11 @@ let passthru = { home = graalvmXXX-ce; - updateScript = ./update.sh; + updateScript = import ./update.nix { + inherit lib writeShellScript jq sourcesFilename name config gnused defaultVersion; + graalVersion = version; + javaVersion = "java${javaVersion}"; + }; }; meta = with lib; { diff --git a/pkgs/development/compilers/graalvm/community-edition/update.nix b/pkgs/development/compilers/graalvm/community-edition/update.nix new file mode 100644 index 00000000000..191f3cb45a1 --- /dev/null +++ b/pkgs/development/compilers/graalvm/community-edition/update.nix @@ -0,0 +1,223 @@ +{ javaVersion +, graalVersion +, defaultVersion +, config +, sourcesFilename +, name +, lib +, writeShellScript +, jq +, gnused +}: + +/* + How to use: + run `nix-shell maintainers/scripts/update.nix --argstr package graalvmXX-ce` + to update the graalvmXX-ce-sources.json file. + E.g: nix-shell maintainers/scripts/update.nix --argstr package graalvm17-ce + + Basic idea: + If we know the platform, product, javaVersion and graalVersion + we can create the url. This leads to the following json structure: + { + "platform/arch1": { + "product1|javaVersion|graalVersion": { "sha256": "...", "url": "..."}, + "product2|javaVersion|graalVersion": { "sha256": "...", "url": "..."}, + ... + }, + "platform/arch2": { + ... + } + } +*/ + +let + separator = "|"; + + # isDev :: String -> Boolean + isDev = version: + lib.hasInfix "dev" version; + + # getLatestVersion :: String -> String + getLatestVersion = currentVersion: + let + dev = if isDev currentVersion then "dev-" else ""; + url = "https://api.github.com/repos/graalvm/graalvm-ce-${dev}builds/releases/latest"; + file = builtins.fetchurl url; + json = builtins.fromJSON (builtins.readFile file); + in + lib.removePrefix "vm-" json.tag_name; + + # getArchString :: String -> String + getArchString = nixArchString: + { + "aarch64-linux" = "linux-aarch64"; + "x86_64-linux" = "linux-amd64"; + "x86_64-darwin" = "darwin-amd64"; + }.${nixArchString}; + + + # getProductSuffix :: String -> String + getProductSuffix = productName: + { + "graalvm-ce" = ".tar.gz"; + "native-image-installable-svm" = ".jar"; + "ruby-installable-svm" = ".jar"; + "wasm-installable-svm" = ".jar"; + "python-installable-svm" = ".jar"; + }.${productName}; + + # getProductSuffix :: String -> String + getProductBaseUrl = productName: + { + "graalvm-ce" = "https://github.com/graalvm/graalvm-ce-builds/releases/download"; + "native-image-installable-svm" = "https://github.com/graalvm/graalvm-ce-builds/releases/download"; + "ruby-installable-svm" = "https://github.com/oracle/truffleruby/releases/download"; + "wasm-installable-svm" = "https://github.com/graalvm/graalvm-ce-builds/releases/download"; + "python-installable-svm" = "https://github.com/graalvm/graalpython/releases/download"; + }.${productName}; + + # getDevUrl :: String + getDevUrl = { arch, graalVersion, product, javaVersion }: + let + baseUrl = https://github.com/graalvm/graalvm-ce-dev-builds/releases/download; + in + "${baseUrl}/${graalVersion}/${product}-${javaVersion}-${arch}-dev${getProductSuffix product}"; + + # getReleaseUrl :: AttrSet -> String + getReleaseUrl = { arch, graalVersion, product, javaVersion }: + let baseUrl = getProductBaseUrl product; + in + "${baseUrl}/vm-${graalVersion}/${product}-${javaVersion}-${arch}-${graalVersion}${getProductSuffix product}"; + + # getUrl :: AttrSet -> String + getUrl = args@{ arch, graalVersion, product, javaVersion }: + if isDev graalVersion + then getDevUrl args + else getReleaseUrl args; + + # computeSha256 :: String -> String + computeSha256 = url: + builtins.hashFile "sha256" (builtins.fetchurl url); + + # downloadSha256 :: String -> String + downloadSha256 = url: + let sha256Url = url + ".sha256"; + in + builtins.readFile (builtins.fetchurl sha256Url); + + # getSha256 :: String -> String -> String + getSha256 = graalVersion: url: + if isDev graalVersion + then computeSha256 url + else downloadSha256 url; + + # cartesianZipListsWith :: (a -> b -> c) -> [a] -> [b] -> [c] + cartesianZipListsWith = f: fst: snd: + let + cartesianProduct = lib.cartesianProductOfSets { a = fst; b = snd; }; + fst' = builtins.catAttrs "a" cartesianProduct; + snd' = builtins.catAttrs "b" cartesianProduct; + in + lib.zipListsWith f fst' snd'; + + # zipListsToAttrs :: [a] -> [b] -> AttrSet + zipListsToAttrs = names: values: + lib.listToAttrs ( + lib.zipListsWith (name: value: { inherit name value; }) names values + ); + + # genProductJavaVersionGraalVersionAttrSet :: String -> AttrSet + genProductJavaVersionGraalVersionAttrSet = product_javaVersion_graalVersion: + let + attrNames = [ "product" "javaVersion" "graalVersion" ]; + attrValues = lib.splitString separator product_javaVersion_graalVersion; + in + zipListsToAttrs attrNames attrValues; + + # genUrlAndSha256 :: String -> String -> AttrSet + genUrlAndSha256 = arch: product_javaVersion_graalVersion: + let + productJavaVersionGraalVersion = + (genProductJavaVersionGraalVersionAttrSet product_javaVersion_graalVersion) + // { inherit arch; }; + url = getUrl productJavaVersionGraalVersion; + sha256 = getSha256 productJavaVersionGraalVersion.graalVersion url; + in + { + ${arch} = { + ${product_javaVersion_graalVersion} = { + inherit sha256 url; + }; + }; + }; + + # genArchProductVersionPairs :: String -> -> String -> AttrSet -> [AttrSet] + genArchProductVersionList = javaVersion: graalVersion: archProducts: + let + arch = archProducts.arch; + products = archProducts.products; + javaGraalVersion = javaVersion + separator + (getLatestVersion (archProducts.version or graalVersion)); + productJavaGraalVersionList = + cartesianZipListsWith (a: b: a + separator + b) + products [ javaGraalVersion ]; + in + cartesianZipListsWith (genUrlAndSha256) [ arch ] productJavaGraalVersionList; + + + # genSources :: String -> String -> AttrSet -> Path String + genSources = javaVersion: defaultVersion: config: + let + archProducts = builtins.attrValues config; + sourcesList = builtins.concatMap (genArchProductVersionList javaVersion defaultVersion) archProducts; + sourcesAttr = builtins.foldl' (lib.recursiveUpdate) { } sourcesList; + in + builtins.toFile "sources.json" (builtins.toJSON sourcesAttr); + + # isNew :: String -> String -> Boolean + isNew = newVersion: currentVersion: + { + "-1" = false; + "0" = false; + "1" = true; + }.${builtins.toString (builtins.compareVersions newVersion currentVersion)}; + + newVersion = getLatestVersion graalVersion; + sourcesJson = genSources javaVersion defaultVersion config; + sourcesJsonPath = lib.strings.escapeShellArg ./. + "/${sourcesFilename}"; + + # versionKeyInDefaultNix String -> String + versionKeyInDefaultNix = graalVersion: + if isDev graalVersion + then "${name}-dev-version" + else "${name}-release-version"; + + /* + updateScriptText :: String -> String -> String + Writes the json file and updates the version in default.nix using sed + because update-source-version does not work srcs. + */ + updateScriptText = newVersion: currentVersion: + + if isNew newVersion currentVersion + then + let + versionKey = versionKeyInDefaultNix currentVersion; + in + '' + echo "New version found. Updating ${currentVersion} -> ${newVersion}". + export PATH="${lib.makeBinPath [ jq gnused ]}:$PATH" + jq . ${sourcesJson} > ${sourcesJsonPath} + sed -i 's|${versionKey} = "${currentVersion}";|${versionKey} = "${newVersion}";|' \ + ${lib.strings.escapeShellArg ./default.nix} + '' + else ''echo "No new version found. Skip updating."''; + +in +writeShellScript "update-graal.sh" '' + set -o errexit + set -o nounset + set -o pipefail + + ${updateScriptText newVersion graalVersion} +'' diff --git a/pkgs/development/compilers/graalvm/community-edition/update.sh b/pkgs/development/compilers/graalvm/community-edition/update.sh deleted file mode 100755 index c821c83a59c..00000000000 --- a/pkgs/development/compilers/graalvm/community-edition/update.sh +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env nix-shell -#!nix-shell -p coreutils curl nix jq gnused -i bash - -set -eou pipefail - -cd "$(dirname "${BASH_SOURCE[0]}")" - -info() { echo "[INFO] $*"; } - -echo_file() { echo "$@" >> hashes.nix; } - -verlte() { - [ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ] -} - -readonly nixpkgs=../../../../.. - -readonly old_version="$(nix-instantiate "$nixpkgs" --eval --strict -A graalvm11-ce.version)" - -if [[ -z "${1:-}" ]]; then - readonly gh_version="$(curl \ - ${GITHUB_TOKEN:+"-u \":$GITHUB_TOKEN\""} \ - -s https://api.github.com/repos/graalvm/graalvm-ce-builds/releases/latest | \ - jq --raw-output .tag_name)" - readonly new_version="${gh_version//vm-/}" -else - readonly new_version="$1" -fi - -if verlte "$old_version" "$new_version"; then - info "graalvm-ce $old_version is up-to-date." - [[ -z "${FORCE:-}" ]] && exit 0 -else - info "graalvm-ce $old_version is out-of-date. Updating..." -fi - -readonly urls=( - "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${new_version}/graalvm-ce-java@platform@-${new_version}.tar.gz" - "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${new_version}/native-image-installable-svm-java@platform@-${new_version}.jar" - "https://github.com/oracle/truffleruby/releases/download/vm-${new_version}/ruby-installable-svm-java@platform@-${new_version}.jar" - "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${new_version}/wasm-installable-svm-java@platform@-${new_version}.jar" - "https://github.com/graalvm/graalpython/releases/download/vm-${new_version}/python-installable-svm-java@platform@-${new_version}.jar" -) - -readonly platforms=( - "11-linux-aarch64" - "17-linux-aarch64" - "11-linux-amd64" - "17-linux-amd64" - "11-darwin-amd64" - "17-darwin-amd64" -) - -info "Deleting old hashes.nix file..." -rm -f hashes.nix -info "Generating hashes.nix file for 'graalvm-ce' $new_version. This will take a while..." - -echo_file "# Generated by $0 script" -echo_file "{ javaVersionPlatform, ... }:" -echo_file "[" - -for url in "${urls[@]}"; do - echo_file " {" - echo_file " sha256 = {" - for platform in "${platforms[@]}"; do - if hash="$(nix-prefetch-url "${url//@platform@/$platform}")"; then - echo_file " \"$platform\" = \"$hash\";" - fi - done - echo_file ' }.${javaVersionPlatform} or null;' - echo_file " url = \"${url//@platform@/\$\{javaVersionPlatform\}}\";" - echo_file " }" -done - -echo_file "]" - -info "Updating graalvm-ce version..." -# update-source-version does not work here since it expects src attribute -sed "s|$old_version|\"$new_version\"|" -i default.nix - -info "Done!"