Skip to content

Commit

Permalink
Fix build issue when libhiredis.so is available
Browse files Browse the repository at this point in the history
If it is, the linker would dynamically link to it instead of statically
linking the bundled version of hiredis.

Closes redis#15.
  • Loading branch information
pietern committed Jan 5, 2014
1 parent d33f52e commit ceaec64
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,27 @@ def build(self):
if self.distribution.has_ext_modules():
self.run_command('build_ext')

lib = ("hiredis", {
"sources": ["vendor/hiredis/%s.c" % src for src in ("hiredis", "net", "sds")],
"include_dirs": ["vendor/hiredis"]})
# To link the extension with the C library, distutils passes the "-lLIBRARY"
# option to the linker. This makes it go through its library search path. If it
# finds a shared object of the specified library in one of the system-wide
# library paths, it will dynamically link it.
#
# We want the linker to statically link the version of hiredis that is included
# with hiredis-py. However, the linker may pick up the shared library version
# of hiredis, if it is available through one of the system-wide library paths.
# To prevent this from happening, we use an obfuscated library name such that
# the only version the linker will be able to find is the right version.
#
# This is a terrible hack, but patching distutils to do the right thing for all
# supported Python versions is worse...
#
# Also see: https://github.com/pietern/hiredis-py/issues/15
lib = ("hiredis_for_hiredis_py", {
"sources": ["vendor/hiredis/%s.c" % src for src in ("hiredis", "net", "sds")]})

ext = Extension("hiredis.hiredis",
sources=glob.glob("src/*.c"),
include_dirs=["src", "vendor"],
libraries=["hiredis"])
include_dirs=["vendor"])

setup(
name="hiredis",
Expand Down

0 comments on commit ceaec64

Please sign in to comment.