nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 43 lines 1.5 kB view raw
1# On macOS, binaries refer to dynamic library dependencies using 2# either relative paths (e.g. "libicudata.dylib", searched relative to 3# $DYLD_LIBRARY_PATH) or absolute paths 4# (e.g. "/nix/store/.../lib/libicudata.dylib"). In Nix, the latter is 5# preferred since it allows programs to just work. When linking 6# against a library (e.g. "-licudata"), the linker uses the install 7# name embedded in the dylib (which can be shown using "otool -D"). 8# Most packages create dylibs with absolute install names, but some do 9# not. This setup hook fixes dylibs by setting their install names to 10# their absolute path (using "install_name_tool -id"). It also 11# rewrites references in other dylibs to absolute paths. 12 13fixupOutputHooks+=('fixDarwinDylibNamesIn $prefix') 14 15fixDarwinDylibNames() { 16 local flags=() 17 local old_id 18 19 for fn in "$@"; do 20 flags+=(-change "$(basename "$fn")" "$fn") 21 done 22 23 for fn in "$@"; do 24 if [ -L "$fn" ]; then continue; fi 25 echo "$fn: fixing dylib" 26 set +e 27 int_out=$(@targetPrefix@install_name_tool -id "$fn" "${flags[@]}" "$fn" 2>&1) 28 result=$? 29 set -e 30 if [ "$result" -ne 0 ] && 31 ! grep -q -e "shared library stub file and can't be changed" \ 32 -e "is not a Mach-O file" <<< "$int_out" 33 then 34 echo "$int_out" >&2 35 exit "$result" 36 fi 37 done 38} 39 40fixDarwinDylibNamesIn() { 41 local dir="$1" 42 fixDarwinDylibNames $(find "$dir" -name "*.dylib" -o -name "*.so" -o -name "*.so.*") 43}