tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Darwin and shared libraries paths



On 6/6/21 10:27 PM, Brook Milligan wrote:
I have a package that uses cython for building.  However, on Darwin pkgsrc complains about  relative paths in the libraries.

One attempt to address this is the following patch:

--- cy_build.py.orig	2018-02-07 21:01:12.000000000 +0000
+++ cy_build.py
@@ -60,12 +60,11 @@ class cy_build_ext(build_ext):
              ext.library_dirs.append(os.path.join(self.build_lib, "pysam"))
if sys.platform == 'darwin':
-            # The idea is to give shared libraries an install name of the form
-            # `@rpath/<library-name.so>`, and to set the rpath equal to
-            # @loader_path. This will allow Python packages to find the library
-            # in the expected place, while still giving enough flexibility to
-            # external applications to link against the library.
+            # Record the installation path in shared libraries with -rpath.
              relative_module_path = ext.name.replace(".", os.sep) + get_config_vars()["SO"]
+            rpath = os.path.join(
+                os.environ["PREFIX"], os.environ["PYSITELIB"], "pysam", os.path.basename(relative_module_path)
+            )
              library_path = os.path.join(
                  "@rpath", os.path.basename(relative_module_path)
              )
@@ -73,7 +72,7 @@ class cy_build_ext(build_ext):
              if not ext.extra_link_args:
                  ext.extra_link_args = []
              ext.extra_link_args += ['-dynamiclib',
-                                    '-rpath', '@loader_path',
+                                    '-Wl,-rpath,%s' % rpath,
                                      '-Wl,-headerpad_max_install_names',
                                      '-Wl,-install_name,%s' % library_path,
                                      '-Wl,-x']

This ends up creating shared libraries with the following structure (using part of the output of tool -l from one as an example):

Load command 4
           cmd LC_ID_DYLIB
       cmdsize 48
          name @rpath/libcsamfile.so (offset 24)
    time stamp 1 Wed Dec 31 17:00:01 1969
       current version 0.0.0
compatibility version 0.0.0
Load command 12
           cmd LC_LOAD_DYLIB
       cmdsize 80
          name /path/to/pkg/lib/libhts.3.dylib (offset 24)
    time stamp 2 Wed Dec 31 17:00:02 1969
       current version 3.1.12
compatibility version 3.1.12
Load command 13
           cmd LC_LOAD_DYLIB
       cmdsize 48
          name @rpath/libchtslib.so (offset 24)
    time stamp 2 Wed Dec 31 17:00:02 1969
       current version 0.0.0
compatibility version 0.0.0
Load command 16
           cmd LC_RPATH
       cmdsize 96
          path /path/to/pkg/lib/python3.8/site-packages/pysam/libcsamfile.so (offset 12)

I am still confused about how Darwin libraries are supposed to work, but it seems that this should set rpath to an absolute path and use that in place of @rpath in the relevant places.  Here is a portion of the ld man page:

      -rpath path
                  Add path to the runpath search path list for image being cre-
                  ated.  At runtime, dyld uses the runpath when searching for
                  dylibs whose load path begins with @rpath/.

Despite this, pkgsrc still complains about relative paths in the shared libraries.

This makes me wonder if the pkgsrc shared library checks are incorrect for Darwin.  Is this fundamentally different from other libraries that set rpath?  Should pkgsrc be recognizing this as legit or are the @rpath + LC_RPATH bits in fact incorrect?

Thanks for any help you can offer.

Cheers,
Brook


Here's how I solved this problem in the upstream Makefile for biolibc:

https://github.com/auerlab/biolibc/blob/master/Makefile

The ${DYLIB} target outlines what needs to be done.

Best,

	JB


Home | Main Index | Thread Index | Old Index