summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorhacker1024 <hacker1024@users.sourceforge.net>2023-04-16 19:25:42 +1000
committerhacker1024 <hacker1024@users.sourceforge.net>2023-04-16 19:25:42 +1000
commitbbfc7911d3e5bbc1a4abb59fbc73b3059df4a705 (patch)
treead2a00de4c2639387a71bc8209c573a71b84a7c4 /pkgs/build-support
parenteefb67036f600783ef1284a6b1f635cc9ec6208b (diff)
downloadnixpkgs-bbfc7911d3e5bbc1a4abb59fbc73b3059df4a705.tar
nixpkgs-bbfc7911d3e5bbc1a4abb59fbc73b3059df4a705.tar.gz
nixpkgs-bbfc7911d3e5bbc1a4abb59fbc73b3059df4a705.tar.bz2
nixpkgs-bbfc7911d3e5bbc1a4abb59fbc73b3059df4a705.tar.lz
nixpkgs-bbfc7911d3e5bbc1a4abb59fbc73b3059df4a705.tar.xz
nixpkgs-bbfc7911d3e5bbc1a4abb59fbc73b3059df4a705.tar.zst
nixpkgs-bbfc7911d3e5bbc1a4abb59fbc73b3059df4a705.zip
flutter.buildFlutterApplication: Supply runtime dependencies
This wraps Flutter programs with an appropriate 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.

The name of the runtimeDependencies argument was chosen to match autoPatchelfHook, which has a similar feature.
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/flutter/default.nix20
1 files changed, 19 insertions, 1 deletions
diff --git a/pkgs/build-support/flutter/default.nix b/pkgs/build-support/flutter/default.nix
index 229d73366d4..f85c7a19ce2 100644
--- a/pkgs/build-support/flutter/default.nix
+++ b/pkgs/build-support/flutter/default.nix
@@ -1,6 +1,7 @@
 { lib
 , callPackage
 , stdenvNoCC
+, makeWrapper
 , llvmPackages_13
 , cacert
 , flutter
@@ -10,10 +11,12 @@
 # absolutely no mac support for now
 
 { pubGetScript ? "flutter pub get"
-, flutterBuildFlags ? []
+, flutterBuildFlags ? [ ]
+, runtimeDependencies ? [ ]
 , vendorHash
 , pubspecLockFile ? null
 , nativeBuildInputs ? [ ]
+, postFixup ? ""
 , ...
 }@args:
 let
@@ -33,6 +36,7 @@ let
   outputs = [ "out" "debug" ];
 
   nativeBuildInputs = [
+    makeWrapper
     deps
     flutter
     git
@@ -87,6 +91,20 @@ let
 
     runHook postInstall
   '';
+
+  postFixup = ''
+    # 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 : '${lib.makeLibraryPath runtimeDependencies}'
+    done
+
+    ${postFixup}
+  '';
 })) self;
 in
   self