tonysimpson / nanomsg-python

nanomsg wrapper for python with multiple backends (CPython and ctypes) should support 2/3 and Pypy
MIT License
382 stars 85 forks source link

Create custom `build_ext` for correct rpath linking on mac #79

Open noahness opened 4 years ago

noahness commented 4 years ago

Workaround distutils bug 36353; see https://bugs.python.org/issue36353. On MacOS, the build_ext --rpath option is getting converted to -L rather than -Wl,-rpath=. This change sub-classes build_ext and correctly passes appropriate rpath options to clang linker.

Snippet from distutils.unixccompiler.py:

  compiler = os.path.basename(sysconfig.get_config_var("CC"))
        if sys.platform[:6] == "darwin":
            # MacOSX's linker doesn't understand the -R flag at all
            return "-L" + dir
        elif sys.platform[:7] == "freebsd":
            return "-Wl,-rpath=" + dir
        elif sys.platform[:5] == "hp-ux":
            if self._is_gcc(compiler):
                return ["-Wl,+s", "-L" + dir]
            return ["+s", "-L" + dir]

Workaround code taken from https://github.com/python/cpython/pull/12418.