Merge pull request #147136 from thiagokokada/add-build-graalvm-native-image

buildGraalvmNativeImage: init
This commit is contained in:
Thiago Kenji Okada 2021-11-25 12:24:44 -03:00 committed by GitHub
commit 6080ef54eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 102 additions and 178 deletions

View File

@ -0,0 +1,52 @@
{ lib, stdenv, graalvmCEPackages, glibcLocales }:
{ name ? "${args.pname}-${args.version}"
# Final executable name
, executable ? args.pname
# JAR used as input for GraalVM derivation, defaults to src
, jar ? args.src
, dontUnpack ? (jar == args.src)
# Default native-image arguments. You probably don't want to set this,
# except in special cases. In most cases, use extraNativeBuildArgs instead
, nativeImageBuildArgs ? [
"-jar" jar
"-H:CLibraryPath=${lib.getLib graalvm}/lib"
(lib.optionalString stdenv.isDarwin "-H:-CheckToolchain")
"-H:Name=${executable}"
"--verbose"
]
# Extra arguments to be passed to the native-image
, extraNativeImageBuildArgs ? [ ]
# XMX size of GraalVM during build
, graalvmXmx ? "-J-Xmx6g"
# The GraalVM to use
, graalvm ? graalvmCEPackages.graalvm11-ce
, ...
} @ args:
stdenv.mkDerivation (args // {
inherit dontUnpack;
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ graalvm glibcLocales ];
nativeImageBuildArgs = nativeImageBuildArgs ++ extraNativeImageBuildArgs ++ [ graalvmXmx ];
buildPhase = args.buildPhase or ''
runHook preBuild
native-image ''${nativeImageBuildArgs[@]}
runHook postBuild
'';
installPhase = args.installPhase or ''
runHook preInstall
install -Dm755 ${executable} -t $out/bin
runHook postInstall
'';
meta.platforms = lib.attrByPath [ "meta" "platforms" ] graalvm.meta.platforms args;
meta.mainProgram = lib.attrByPath [ "meta" "mainProgram" ] executable args;
})

View File

@ -1,6 +1,6 @@
{ lib, stdenv, fetchurl, graalvm11-ce, glibcLocales, writeScript }:
{ lib, buildGraalvmNativeImage, fetchurl, writeScript }:
stdenv.mkDerivation rec {
buildGraalvmNativeImage rec {
pname = "babashka";
version = "0.6.5";
@ -9,48 +9,13 @@ stdenv.mkDerivation rec {
sha256 = "sha256-72D/HzDIxkGD4zTPE9gHf/uFtboLbNnT7CTslSlAqjc=";
};
dontUnpack = true;
executable = "bb";
nativeBuildInputs = [ graalvm11-ce glibcLocales ];
LC_ALL = "en_US.UTF-8";
BABASHKA_JAR = src;
BABASHKA_BINARY = "bb";
BABASHKA_XMX = "-J-Xmx4500m";
buildPhase = ''
runHook preBuild
# https://github.com/babashka/babashka/blob/v0.6.2/script/compile#L41-L52
args=("-jar" "$BABASHKA_JAR"
"-H:CLibraryPath=${graalvm11-ce.lib}/lib"
# Required to build babashka on darwin. Do not remove.
"${lib.optionalString stdenv.isDarwin "-H:-CheckToolchain"}"
"-H:Name=$BABASHKA_BINARY"
"-H:+ReportExceptionStackTraces"
# "-H:+PrintAnalysisCallTree"
# "-H:+DashboardAll"
# "-H:DashboardDump=reports/dump"
# "-H:+DashboardPretty"
# "-H:+DashboardJson"
"--verbose"
"--no-fallback"
"--native-image-info"
"$BABASHKA_XMX")
native-image ''${args[@]}
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp bb $out/bin/bb
runHook postInstall
'';
extraNativeImageBuildArgs = [
"-H:+ReportExceptionStackTraces"
"--no-fallback"
"--native-image-info"
];
installCheckPhase = ''
$out/bin/bb --version | grep '${version}'
@ -102,7 +67,6 @@ stdenv.mkDerivation rec {
homepage = "https://github.com/babashka/babashka";
changelog = "https://github.com/babashka/babashka/blob/v${version}/CHANGELOG.md";
license = licenses.epl10;
platforms = graalvm11-ce.meta.platforms;
maintainers = with maintainers; [
bandresen
bhougland

View File

@ -1,6 +1,6 @@
{ stdenv, lib, graalvm11-ce, fetchurl }:
{ lib, buildGraalvmNativeImage, fetchurl }:
stdenv.mkDerivation rec {
buildGraalvmNativeImage rec {
pname = "clj-kondo";
version = "2021.10.19";
@ -9,38 +9,15 @@ stdenv.mkDerivation rec {
sha256 = "sha256-i0OeQPZfQPUeXC/Bs84I91IahBKK6W1mFix97s8/lVA=";
};
dontUnpack = true;
buildInputs = [ graalvm11-ce ];
buildPhase = ''
runHook preBuild
# https://github.com/clj-kondo/clj-kondo/blob/v2021.10.19/script/compile#L17-L21
args=("-jar" "$src"
"-H:CLibraryPath=${graalvm11-ce.lib}/lib"
# Required to build babashka on darwin. Do not remove.
"${lib.optionalString stdenv.isDarwin "-H:-CheckToolchain"}"
"-H:+ReportExceptionStackTraces"
"--verbose"
"--no-fallback"
"-J-Xmx3g")
native-image ''${args[@]}
runHook postBuild
'';
installPhase = ''
mkdir -p $out/bin
cp clj-kondo $out/bin/clj-kondo
'';
extraNativeImageBuildArgs = [
"-H:+ReportExceptionStackTraces"
"--no-fallback"
];
meta = with lib; {
description = "A linter for Clojure code that sparks joy";
homepage = "https://github.com/clj-kondo/clj-kondo";
license = licenses.epl10;
platforms = graalvm11-ce.meta.platforms;
maintainers = with maintainers; [ jlesquembre bandresen thiagokokada ];
};
}

View File

@ -1,6 +1,6 @@
{ stdenv, lib, graalvm11-ce, fetchurl }:
{ lib, buildGraalvmNativeImage, fetchurl }:
stdenv.mkDerivation rec {
buildGraalvmNativeImage rec {
pname = "jet";
version = "0.1.0";
@ -14,46 +14,22 @@ stdenv.mkDerivation rec {
sha256 = "sha256-mOUiKEM5tYhtpBpm7KtslyPYFsJ+Wr+4ul6Zi4aS09Q=";
};
dontUnpack = true;
buildInputs = [ graalvm11-ce ];
buildPhase = ''
runHook preBuild
# https://github.com/borkdude/jet/blob/v0.1.0/script/compile#L16-L29
args=("-jar" "$src"
"-H:CLibraryPath=${graalvm11-ce.lib}/lib"
# Required to build jet on darwin. Do not remove.
"${lib.optionalString stdenv.isDarwin "-H:-CheckToolchain"}"
"-H:Name=jet"
"-H:+ReportExceptionStackTraces"
"-J-Dclojure.spec.skip-macros=true"
"-J-Dclojure.compiler.direct-linking=true"
"-H:IncludeResources=JET_VERSION"
"-H:ReflectionConfigurationFiles=${reflectionJson}"
"--initialize-at-build-time"
"-H:Log=registerResource:"
"--verbose"
"--no-fallback"
"--no-server"
"-J-Xmx3g")
native-image ''${args[@]}
runHook postBuild
'';
installPhase = ''
mkdir -p $out/bin
cp jet $out/bin/jet
'';
extraNativeImageBuildArgs = [
"-H:+ReportExceptionStackTraces"
"-J-Dclojure.spec.skip-macros=true"
"-J-Dclojure.compiler.direct-linking=true"
"-H:IncludeResources=JET_VERSION"
"-H:ReflectionConfigurationFiles=${reflectionJson}"
"--initialize-at-build-time"
"-H:Log=registerResource:"
"--no-fallback"
"--no-server"
];
meta = with lib; {
description = "CLI to transform between JSON, EDN and Transit, powered with a minimal query language";
homepage = "https://github.com/borkdude/jet";
license = licenses.epl10;
platforms = graalvm11-ce.meta.platforms;
maintainers = with maintainers; [ ericdallo ];
};
}

View File

@ -1,6 +1,6 @@
{ lib, stdenv, graalvm11-ce, babashka, fetchurl, fetchFromGitHub, clojure, writeScript }:
{ lib, stdenv, buildGraalvmNativeImage, babashka, fetchurl, fetchFromGitHub, clojure, writeScript }:
stdenv.mkDerivation rec {
buildGraalvmNativeImage rec {
pname = "clojure-lsp";
version = "2021.11.02-15.24.47";
@ -16,48 +16,22 @@ stdenv.mkDerivation rec {
sha256 = "sha256-k0mzibcLAspklCPE6f2qsUm9bwSvcJRgWecMBq7mpF0=";
};
GRAALVM_HOME = graalvm11-ce;
CLOJURE_LSP_JAR = jar;
CLOJURE_LSP_XMX = "-J-Xmx6g";
# https://github.com/clojure-lsp/clojure-lsp/blob/2021.11.02-15.24.47/graalvm/native-unix-compile.sh#L18-L27
DTLV_LIB_EXTRACT_DIR = "/tmp";
buildInputs = [ graalvm11-ce clojure ];
buildPhase = with lib; ''
runHook preBuild
# https://github.com/clojure-lsp/clojure-lsp/blob/2021.11.02-15.24.47/graalvm/native-unix-compile.sh#L18-L27
DTLV_LIB_EXTRACT_DIR=$(mktemp -d)
export DTLV_LIB_EXTRACT_DIR=$DTLV_LIB_EXTRACT_DIR
args=("-jar" "$CLOJURE_LSP_JAR"
"-H:+ReportExceptionStackTraces"
"-H:CLibraryPath=${graalvm11-ce.lib}/lib"
"-H:CLibraryPath=$DTLV_LIB_EXTRACT_DIR"
"--verbose"
"--no-fallback"
"--native-image-info"
"$CLOJURE_LSP_XMX")
native-image ''${args[@]}
runHook postBuild
'';
installPhase = ''
runHook preInstall
install -Dm755 ./clojure-lsp $out/bin/clojure-lsp
runHook postInstall
'';
extraNativeImageBuildArgs = [
"-H:CLibraryPath=${DTLV_LIB_EXTRACT_DIR}"
"--no-fallback"
"--native-image-info"
];
doCheck = true;
checkPhase = ''
runHook preCheck
export HOME="$(mktemp -d)"
./clojure-lsp --version | fgrep -q '${version}'
${babashka}/bin/bb integration-test ./clojure-lsp
./${pname} --version | fgrep -q '${version}'
${babashka}/bin/bb integration-test ./${pname}
runHook postCheck
'';
@ -88,7 +62,6 @@ stdenv.mkDerivation rec {
homepage = "https://github.com/clojure-lsp/clojure-lsp";
license = licenses.mit;
maintainers = with maintainers; [ ericdallo babariviere ];
platforms = graalvm11-ce.meta.platforms;
# Depends on datalevin that is x86_64 only
# https://github.com/juji-io/datalevin/blob/bb7d9328f4739cddea5d272b5cd6d6dcb5345da6/native/src/java/datalevin/ni/Lib.java#L86-L102
broken = !stdenv.isx86_64;

View File

@ -1,40 +1,22 @@
{ stdenv, lib, fetchurl, graalvm11-ce, glibcLocales }:
{ lib, buildGraalvmNativeImage, fetchurl }:
stdenv.mkDerivation rec {
buildGraalvmNativeImage rec {
pname = "zprint";
version = "1.1.2";
src = fetchurl {
url =
"https://github.com/kkinnear/${pname}/releases/download/${version}/${pname}-filter-${version}";
url = "https://github.com/kkinnear/${pname}/releases/download/${version}/${pname}-filter-${version}";
sha256 = "1wh8jyj7alfa6h0cycfwffki83wqb5d5x0p7kvgdkhl7jx7isrwj";
};
dontUnpack = true;
LC_ALL = "en_US.UTF-8";
nativeBuildInputs = [ graalvm11-ce glibcLocales ];
buildPhase = ''
native-image \
--no-server \
-J-Xmx7G \
-J-Xms4G \
-jar ${src} \
-H:Name=${pname} \
-H:EnableURLProtocols=https,http \
-H:+ReportExceptionStackTraces \
-H:CLibraryPath=${graalvm11-ce.lib}/lib \
${lib.optionalString stdenv.isDarwin ''-H:-CheckToolchain''} \
--report-unsupported-elements-at-runtime \
--initialize-at-build-time \
--no-fallback
'';
installPhase = ''
mkdir -p $out/bin
install ${pname} $out/bin
'';
extraNativeImageBuildArgs = [
"--no-server"
"-H:EnableURLProtocols=https,http"
"-H:+ReportExceptionStackTraces"
"--report-unsupported-elements-at-runtime"
"--initialize-at-build-time"
"--no-fallback"
];
meta = with lib; {
description = "Clojure/EDN source code formatter and pretty printer";
@ -45,7 +27,6 @@ stdenv.mkDerivation rec {
'';
homepage = "https://github.com/kkinnear/zprint";
license = licenses.mit;
platforms = graalvm11-ce.meta.platforms;
maintainers = with maintainers; [ stelcodes ];
};
}

View File

@ -12350,6 +12350,7 @@ with pkgs;
});
graalvm11-ce = graalvmCEPackages.graalvm11-ce;
graalvm17-ce = graalvmCEPackages.graalvm17-ce;
buildGraalvmNativeImage = callPackage ../build-support/build-graalvm-native-image { };
inherit (callPackages ../development/compilers/graalvm/enterprise-edition.nix { })
graalvm8-ee