From bbfc7911d3e5bbc1a4abb59fbc73b3059df4a705 Mon Sep 17 00:00:00 2001 From: hacker1024 Date: Sun, 16 Apr 2023 19:25:42 +1000 Subject: [PATCH] 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. --- pkgs/build-support/flutter/default.nix | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/flutter/default.nix b/pkgs/build-support/flutter/default.nix index 229d73366d4a..f85c7a19ce2e 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