buildDartApplication: Allow supplying runtime dependencies

This commit is contained in:
hacker1024 2023-10-21 22:00:54 +11:00
parent 64c638bfc0
commit 234b63b0f0
3 changed files with 30 additions and 2 deletions

View file

@ -23,6 +23,7 @@
else if dartOutputType == "js" then "${nodejs}/bin/node"
else null
, runtimeDependencies ? [ ]
, pubspecLockFile ? null
, vendorHash ? ""
, ...
@ -39,25 +40,28 @@ let
buildDrvArgs = args;
inherit pubGetScript vendorHash pubspecLockFile;
};
inherit (dartHooks.override { inherit dart; }) dartConfigHook dartBuildHook dartInstallHook;
inherit (dartHooks.override { inherit dart; }) dartConfigHook dartBuildHook dartInstallHook dartFixupHook;
in
assert !(builtins.isString dartOutputType && dartOutputType != "") ->
throw "dartOutputType must be a non-empty string";
stdenv.mkDerivation (args // {
inherit pubGetScript dartCompileCommand dartOutputType dartRuntimeCommand
dartCompileFlags dartJitFlags;
dartCompileFlags dartJitFlags runtimeDependencies;
dartEntryPoints =
if (dartEntryPoints != null)
then writeText "entrypoints.json" (builtins.toJSON dartEntryPoints)
else null;
runtimeDependencyLibraryPath = lib.makeLibraryPath runtimeDependencies;
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [
dart
dartDeps
dartConfigHook
dartBuildHook
dartInstallHook
dartFixupHook
makeWrapper
] ++ lib.optionals stdenv.isDarwin [
darwin.sigtool

View file

@ -0,0 +1,21 @@
# shellcheck shell=bash
dartFixupHook() {
echo "Executing dartFixupHook"
echo "Providing runtime dependencies"
if [[ ! -z "$runtimeDependencyLibraryPath" ]]; then
# Add runtime library dependencies to the LD_LIBRARY_PATH.
# For some reason, the RUNPATH of the executable is not used to load dynamic libraries in dart:ffi with DynamicLibrary.open().
#
# This could alternatively be fixed with patchelf --add-needed, but this would cause all the libraries to be opened immediately,
# which is not what application authors expect.
for f in "$out"/bin/*; do
wrapProgram "$f" --suffix LD_LIBRARY_PATH : "$runtimeDependencyLibraryPath"
done
fi
echo "Finished dartFixupHook"
}
postFixupHooks+=(dartFixupHook)

View file

@ -12,4 +12,7 @@
dartInstallHook = makeSetupHook {
name = "dart-install-hook";
} ./dart-install-hook.sh;
dartFixupHook = makeSetupHook {
name = "dart-fixup-hook";
} ./dart-fixup-hook.sh;
}