buildGraalvmNativeImage: init
For now it only takes care of the single Jar <-> single Executable case. This will take care of the majority (all?) use cases we have in nixpkgs currently.
This commit is contained in:
parent
4ec0d5209f
commit
1415e30830
53
pkgs/build-support/build-graalvm-native-image/default.nix
Normal file
53
pkgs/build-support/build-graalvm-native-image/default.nix
Normal file
|
@ -0,0 +1,53 @@
|
|||
{ lib, stdenv, graalvmCEPackages, glibcLocales }:
|
||||
|
||||
{ name ? "${args.pname}-${args.version}"
|
||||
# Final executable name
|
||||
, executable
|
||||
# JAR used as input for GraalVM derivation, defaults to src
|
||||
, jar ? args.src
|
||||
, dontUnpack ? (jar == args.src)
|
||||
# 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 = lib.flatten ([
|
||||
"-jar"
|
||||
jar
|
||||
"-H:CLibraryPath=${lib.getLib graalvm}/lib"
|
||||
"${lib.optionalString stdenv.isDarwin "-H:-CheckToolchain"}"
|
||||
"-H:Name=${executable}"
|
||||
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;
|
||||
mainProgram = lib.attrByPath [ "meta" "mainProgram" ] executable args;
|
||||
};
|
||||
})
|
|
@ -1,6 +1,6 @@
|
|||
{ lib, stdenv, graalvm11-ce, babashka, fetchurl, fetchFromGitHub, clojure, writeScript }:
|
||||
{ lib, stdenv, buildGraalvmNativeImage, graalvm11-ce, babashka, fetchurl, fetchFromGitHub, clojure, writeScript }:
|
||||
|
||||
stdenv.mkDerivation rec {
|
||||
buildGraalvmNativeImage rec {
|
||||
pname = "clojure-lsp";
|
||||
version = "2021.11.02-15.24.47";
|
||||
|
||||
|
@ -16,39 +16,17 @@ stdenv.mkDerivation rec {
|
|||
sha256 = "sha256-k0mzibcLAspklCPE6f2qsUm9bwSvcJRgWecMBq7mpF0=";
|
||||
};
|
||||
|
||||
GRAALVM_HOME = graalvm11-ce;
|
||||
CLOJURE_LSP_JAR = jar;
|
||||
CLOJURE_LSP_XMX = "-J-Xmx6g";
|
||||
|
||||
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"
|
||||
extraNativeImageBuildArgs = [
|
||||
"-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
|
||||
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
|
||||
'';
|
||||
|
||||
doCheck = true;
|
||||
|
@ -88,7 +66,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;
|
||||
|
|
|
@ -12344,6 +12344,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
|
||||
|
|
Loading…
Reference in a new issue