Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delocate makes links that do not match the filenames of the libraries #103

Open
reynoldsnlp opened this issue Mar 9, 2021 · 1 comment
Labels

Comments

@reynoldsnlp
Copy link

Using the icu library as installed from brew install icu4c, delocate did copy the dylib files into my wheel, and adjusted the links, but it got the filenames wrong, presumably because of variation in filenames because of symlinks in the original library installation from brew. The files copied in by delocate look like this (note the 68.2 in the libicu filenames):

.
├── .dylibs
│   ├── libhfst.53.dylib
│   ├── libicudata.68.2.dylib
│   ├── libicui18n.68.2.dylib
│   └── libicuuc.68.2.dylib
└── _libhfst.cpython-36m-darwin.so

The main so file correctly links the the underlying libhfst library...

$ otool -L _libhfst.cpython-36m-darwin.so
_libhfst.cpython-36m-darwin.so:
	@loader_path/.dylibs/libhfst.53.dylib (compatibility version 54.0.0, current version 54.0.0)
$ ls .dylibs/libhfst.53.dylib
.dylibs/libhfst.53.dylib

...and the libhfst library has correct links...

$ otool -L .dylibs/libhfst.53.dylib
.dylibs/libhfst.53.dylib:
	/DLC/hfst/libhfst.53.dylib (compatibility version 54.0.0, current version 54.0.0)
	@loader_path/libicui18n.68.2.dylib (compatibility version 68.0.0, current version 68.2.0)
	@loader_path/libicuuc.68.2.dylib (compatibility version 68.0.0, current version 68.2.0)
	@loader_path/libicudata.68.2.dylib (compatibility version 68.0.0, current version 68.2.0)

...but the libicu libraries link to one another with incorrect filenames (note the 68 instead of 68.2)...

$ otool -L .dylibs/libicu*
.dylibs/libicudata.68.2.dylib:
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.100.1)
.dylibs/libicui18n.68.2.dylib:
	@loader_path/libicuuc.68.dylib (compatibility version 68.0.0, current version 68.2.0)
	@loader_path/libicudata.68.dylib (compatibility version 68.0.0, current version 68.2.0)
.dylibs/libicuuc.68.2.dylib:
	@loader_path/libicudata.68.dylib (compatibility version 68.0.0, current version 68.2.0)

I was able to postprocess this correctly with the following bash script, but implementing similar logic in delocate would be the ideal solution.

$ cat macos_fix_links.sh
#!/bin/bash

# The links in the dylib files do not match the actual filenames.
# This script automatically renames the links using `install_name_tool`.

set -x


wheel_dir=$1
wheel_fname=$2

pushd ${wheel_dir}

unzip -d tmp/ ${wheel_fname}
cd tmp/hfst/.dylibs/
for each_dylib in libhfst*.dylib libicu*.dylib; do
    for link in $(otool -L ${each_dylib} | tail -n +2 | grep libicu | sed "s/(.*)//g" | sed "s/\s+//g"); do
        # get the actual filename
        link_fname=$(ls "$(echo ${link} | rev | cut -d "/" -f 1 | rev | cut -d "." -f 1)"*)
        new_link=$(echo ${link} | sed "s#libicu.*\.dylib#${link_fname}#g")
	sudo install_name_tool -change ${link} ${new_link} ${each_dylib}
    done
done

cd ../..
# zip new wheel
zip -r ${wheel_fname} *

# overwrite the original wheel
mv ${wheel_fname} ${wheel_dir}

# go back to where we started
popd
@HexDecimal
Copy link
Collaborator

I can you check this again with the latest version 0.9.1? The versions of delocate before 0.9.0 did not handle recursive libraries correctly.

I expect that the latest version of delocate will still use the 'real names' of the libraries but they will now link to each other correctly.

@HexDecimal HexDecimal added the bug label Sep 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants