tricu

A lazy functional language based on Tree Calculus
Log | Files | Refs | README | LICENSE

package_runtime.py (1111B)


      1 #!/usr/bin/env python3
      2 """Install the ELF library's loaded Haskell runtime dependencies beside it.
      3 
      4 GHC's package environment points at a compiler-sized symlink farm. The embedding
      5 needs the resolved shared objects, not that development environment. Native
      6 libraries retain their ordinary Nix runtime paths. Run only inside the Nix build.
      7 """
      8 from pathlib import Path
      9 import shutil
     10 import subprocess
     11 import sys
     12 
     13 library = Path(sys.argv[1]).resolve()
     14 loaded = subprocess.check_output(['ldd', str(library)], text=True)
     15 native_paths = set()
     16 haskell = []
     17 for line in loaded.splitlines():
     18     parts = line.split()
     19     if len(parts) >= 3 and parts[1] == '=>' and parts[2].startswith('/'):
     20         path = Path(parts[2]).resolve()
     21         if parts[0].startswith('libHS'):
     22             target = library.parent/parts[0]
     23             shutil.copyfile(path, target)
     24             haskell.append(target)
     25         else:
     26             native_paths.add(str(path.parent))
     27 rpath = ':'.join(['$ORIGIN', *sorted(native_paths)])
     28 for path in [library, *haskell]:
     29     subprocess.run(['patchelf', '--set-rpath', rpath, str(path)], check=True)