diff options
author | hacker1024 <hacker1024@users.sourceforge.net> | 2023-10-21 22:00:54 +1100 |
---|---|---|
committer | hacker1024 <hacker1024@users.sourceforge.net> | 2023-10-21 22:22:02 +1100 |
commit | 234b63b0f0668770f9136eb06c718787aed4d342 (patch) | |
tree | cf3f7d19f00538f36b069ac6dc7f113f709f9042 /pkgs/build-support | |
parent | 64c638bfc07d05370c7f5a3833b5871f4210ef6e (diff) |
buildDartApplication: Allow supplying runtime dependencies
Diffstat (limited to 'pkgs/build-support')
3 files changed, 30 insertions, 2 deletions
diff --git a/pkgs/build-support/dart/build-dart-application/default.nix b/pkgs/build-support/dart/build-dart-application/default.nix index b2535123e3826..2246c5634d27c 100644 --- a/pkgs/build-support/dart/build-dart-application/default.nix +++ b/pkgs/build-support/dart/build-dart-application/default.nix @@ -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 diff --git a/pkgs/build-support/dart/build-dart-application/hooks/dart-fixup-hook.sh b/pkgs/build-support/dart/build-dart-application/hooks/dart-fixup-hook.sh new file mode 100644 index 0000000000000..6e1995aebc13c --- /dev/null +++ b/pkgs/build-support/dart/build-dart-application/hooks/dart-fixup-hook.sh @@ -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) \ No newline at end of file diff --git a/pkgs/build-support/dart/build-dart-application/hooks/default.nix b/pkgs/build-support/dart/build-dart-application/hooks/default.nix index 463061c54a8dd..134989426d96b 100644 --- a/pkgs/build-support/dart/build-dart-application/hooks/default.nix +++ b/pkgs/build-support/dart/build-dart-application/hooks/default.nix @@ -12,4 +12,7 @@ dartInstallHook = makeSetupHook { name = "dart-install-hook"; } ./dart-install-hook.sh; + dartFixupHook = makeSetupHook { + name = "dart-fixup-hook"; + } ./dart-fixup-hook.sh; } |