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