Commits

Brandon Rhodes committed 078a0ef

Windows fixes: new setup.py tweaks for Visual Studio, and new DLL loading call.

Comments (0)

Files changed (3)

 --- zmq/__init__.py.orig	2011-05-12 02:25:07.000000000 -0400
-+++ zmq/__init__.py	2011-05-22 22:57:24.000000000 -0400
-@@ -31,6 +31,12 @@
-     if os.path.exists(libzmq):
-         ctypes.cdll.LoadLibrary(libzmq)
-     del here, libzmq, ctypes, os
++++ zmq/__init__.py	2011-06-15 11:16:09.000000000 -0400
+@@ -24,13 +24,15 @@
+ #-----------------------------------------------------------------------------
+ import sys
+ 
++import ctypes, os
++here = os.path.dirname(__file__)
+ if sys.platform.startswith('win'):
+-    import os, ctypes
+-    here = os.path.dirname(__file__)
+-    libzmq = os.path.join(here, 'libzmq.dll')
+-    if os.path.exists(libzmq):
+-        ctypes.cdll.LoadLibrary(libzmq)
+-    del here, libzmq, ctypes, os
++    library = os.path.join(here, '_zeromq.pyd')
++    ctypes.cdll.LoadLibrary(library)
 +else:
-+    import ctypes
-+    import os
-+    p = os.path.join(os.path.dirname(__file__), "_zeromq.so")
-+    _zeromq = ctypes.CDLL(p, mode=ctypes.RTLD_GLOBAL)
-+    del ctypes, os, p
++    library = os.path.join(here, "_zeromq.so")
++    _zeromq = ctypes.CDLL(library, mode=ctypes.RTLD_GLOBAL)
++del ctypes, os, here, library
  
  from zmq.utils import initthreads # initialize threads
  initthreads.init_threads()
 #-----------------------------------------------------------------------------
 
 static_sources = glob('src/*')
-libraries = []
 include_dirs = ['include']
 
 if hasattr(sys, 'getwindowsversion'):
-    libraries.extend([ 'rpcrt4', 'ws2_32' ])
     include_dirs.append('include_nt')
 else:
     if sys.platform == 'darwin':
     }
 )
 
-extensions = []
+extensions = [Extension('zmq._zeromq',
+                        sources=static_sources,
+                        include_dirs=include_dirs)]
+
 for submod, packages in submodules.items():
     for pkg in sorted(packages):
         sources = [pjoin('zmq', submod, pkg+'.c')]
         )
         extensions.append(ext)
 
-extensions.append(Extension('zmq._zeromq',
-                            sources=static_sources,
-                            include_dirs=include_dirs))
-
 package_data = {'zmq':['*.pxd'],
                 'zmq.core':['*.pxd'],
                 'zmq.devices':['*.pxd'],
                 'zmq.utils':['*.pxd', '*.h'],
 }
 
+# Visual Studio needs some encouragement to actually compile everything.
+
+if hasattr(sys, 'getwindowsversion'):
+
+    libzmq = extensions[0]
+    other_extensions = extensions[1:]
+
+    # When compiling the C++ code inside of libzmq itself, we want to
+    # avoid "warning C4530: C++ exception handler used, but unwind
+    # semantics are not enabled. Specify /EHsc".
+
+    libzmq.extra_compile_args.append('/EHsc')
+
+    # Because Visual Studio is given the option "/EXPORT:init_zeromq"
+    # when compiling libzmq, we need to provide such a function.
+
+    libzmq.sources.append(r'src_nt\init_zeromq.c')
+
+    # And things like sockets come from libraries that must be named.
+
+    libzmq.libraries.append('rpcrt4')
+    libzmq.libraries.append('ws2_32')
+
+    # Then all of the real extensions need to link against that first
+    # library.
+
+    for other in other_extensions:
+        thisdir = os.path.dirname(__file__)
+        libdir = os.path.join(thisdir, 'build',
+                              'temp.win32-%d.%d' % sys.version_info[:2],
+                              'Release', 'src')
+        other.library_dirs.append(libdir)
+        other.libraries.append('_zeromq')
+
+# The setup() call itself.
+
 long_description = open('README.txt').read().decode('utf-8')
 if sys.version_info < (2, 6):  # work around Python 2.5 UnicodeEncodeError
     description = u'zmq package that compiles its own 0MQ / ZeroMQ'
     description = u'zmq package that compiles its own ØMQ / 0MQ / ZeroMQ'
 
 setup(name='pyzmq-static',
-      version='2.1.7',
+      version='2.1.7.1',
       description=description,
       long_description=long_description,
       author='Brandon Craig Rhodes',
 #-----------------------------------------------------------------------------
 import sys
 
+import ctypes, os
+here = os.path.dirname(__file__)
 if sys.platform.startswith('win'):
-    import os, ctypes
-    here = os.path.dirname(__file__)
-    libzmq = os.path.join(here, 'libzmq.dll')
-    if os.path.exists(libzmq):
-        ctypes.cdll.LoadLibrary(libzmq)
-    del here, libzmq, ctypes, os
+    library = os.path.join(here, '_zeromq.pyd')
+    ctypes.cdll.LoadLibrary(library)
 else:
-    import ctypes
-    import os
-    p = os.path.join(os.path.dirname(__file__), "_zeromq.so")
-    _zeromq = ctypes.CDLL(p, mode=ctypes.RTLD_GLOBAL)
-    del ctypes, os, p
+    library = os.path.join(here, "_zeromq.so")
+    _zeromq = ctypes.CDLL(library, mode=ctypes.RTLD_GLOBAL)
+del ctypes, os, here, library
 
 from zmq.utils import initthreads # initialize threads
 initthreads.init_threads()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.